Javatpoint Logo
Javatpoint Logo

Java int keyword

The Java int keyword is a primitive data type. It is used to declare variables. It can also be used with methods to return integer type values. It can hold a 32-bit signed two's complement integer.

Points to remember

  • The int contains minimum value of -231 and a maximum value of 231-1.
  • From Java 8, we can use int as an unsigned 32-bit integer, which has a minimum value of 0 and a maximum value of 232-1.
  • Its default value is 0.
  • Its default size is 4 byte.
  • It is generally used as a default data type for integral values.
Java int keyword

Examples of Java byte keyword

Example 1

Let's see an example to use int data type with positive and negative value.

Output:

num1: 10
num2: -10

Example 2

Let's see an example to check whether the int data type holds decimal value.

Output:

error: incompatible types: possible lossy conversion from double to int

Example 3

Let's see an example to check whether the int data type holds float value.

Output:

error: incompatible types: possible lossy conversion from float to int

Example 4

Let's see an example to check whether the int data type holds char value.In such case, the compiler typecast the character implicitly into int type and returns the corresponding ASCII value.

Output:

num: 97

Example 5

In this example, int data type holds the minimum and maximum value.

Output:

min: -2147483648
max: 2147483647

Example 6

Let's create a method that returns an integer value.

Output:

10
Next TopicJava Keywords





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA