by Dinesh Thakur Category: Data Type

Data types are the domains which determine what type of contents can be stored in a variable. In Java, there are two types of data types:

1. Primitive data types

2. Reference data types

Primitive Data Types

 Primitive data types are non grouped pieces of data which can have only one value at a time. They are the simplest built in forms of data in Java. Other data types are made up of combination of primitive data types. Java initializes all primitive data types to default values if an initial value is not explicitly specified by the programmer. Integer and floating-point variables are initialized to 0. The char data type is initialized to null and Boolean data types are set to false.

The types byte, short, int, long, float, double, boolean and char are called primitive data types , as they are built into the Java language at low level .

The primitive data type keywords are as shown:









Reference Data Types

Reference data types are made by the logical grouping of primitive data types. These are called reference data types because they contain the address of a value rather than the value itself. Arrays, objects, interfaces, enum etc. are examples of reference data types.

Integer Data Types

There are four integer data types: byte, short, int, and long. Each can handle different ranges of numbers, as shown:

Integer data type ranges




Minimum Value                     

Maximum Value


8 bits   








32 bits
















Possible values ​​are two - true or false










byte: The byte data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive).
short: The short data type is a 16-bit signed two's complement integer. It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive). As with
int: The int data type is a 32-bit signed two's complement integer. It has a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647 (inclusive). For integral values, this data type is generally the default choice unless there is a reason (like the above) to choose something else
long: The long data type is a 64-bit signed two's complement integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive). Use this data type when you need a range of values wider than those provided by int.

char Data Types

Type char is basically a 16-bit unsigned integer that represents a Unicode value. Each printable and nonprintable character has a Unicode value. Because Java stores all characters as Unicode, it can be used with virtually any written language in the world.

Floating-Point Data Types

Type float designates that the variable is a single-precision, 32-bit, floating-point number. Type double is a double-precision, 64-bit floating-point number.


float m;

double n;

boolean Data Types

Type boolean can only have a value of true or false. Internal to Java, a Boolean value is a I-bit logical quantity. Boolean values are used in branching/looping statements to check validity of the logical expression included.

double Data Types

The double data type is a double-precision 64-bit IEEE 754 floating point. For decimal values, this data type is generally the default choice. As mentioned above, this data type should never be used for precise values, such as currency.

In addition to the eight primitive data types listed above, the Java programming language also provides special support for character strings via the java.lang.String class.

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.