Java Data Types

Data Types

Data types in Java fall under the following categories

  1. Primitive Data Types (Intrinsic)
  2. Non-Primitive Data Types (Derived)

Primitive Data Types

Java is statically typed, i.e., variables must be declared before use. Java supports 8 primitive data types:

Data TypeSizeValue Range
1. Byte1 byte-128 to 127
2. short1 byte-32,768 to 32,767
3. int2 byte-2,147,483,648 to 2,147,483,647
4. float4 byte3.40282347 x 1038 to 1.40239846 x 10-45
5. long8 byte-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
6. double8 byte1.7976931348623157 x 10308, 4.9406564584124654 x 10-324
7. char2 byte0 to 65,535
8. booleanDepends on JVMTrue or False

Exercise:  Write a Java program to add three numbers,

How to choose data types for our variables

In order to choose the data type, we first need to find the type of data we want to store. After that, we need to analyze the min & max value we might use.

Was this article helpful?

Leave a Comment

Your email address will not be published. Required fields are marked *