An Example to Understand Java int Data Type

The integer data type of Java

Among the eight primitive data types in Java, the int is one of those, to be used in the Java programs.

A few main points about the Java int data type:

  • The int type takes 32 bits or four bytes of memory.
  • It is a numeric type
  • The default value of the int variable is 0.
  • The minimum value of the Java integer type can be  – 2,147,483,648.
  • The maximum value of int Java type can be 2,147,483,647.

An example of int type

In the following example, two integer type variables are declared in a simple Java class. The first variable ‘a’ is declared and no value is assigned at the time of declaration. The value to the variable ‘a’ is assigned later. While a value is assigned to another variable ‘b’ at the time of declaration, which a negative value for the illustration purpose.

Finally, we will print the value of variable ‘a’ by using the System.out.println statement of Java. See the code and graphic of the output by clicking the link below:

See graphic of above example

The output after running the above code:


In the above example, you can see an integer variable is be declared and the value is assigned at the time of declaration.

Generally, integer data type is used to store numeric values in Java programs. To store smaller values like array index, you can use byte type variable, as it takes four times less space than the int type.