Java - Data Types int type

Introduction

Java int data type is a 32-bit signed primitive data type.

A variable of the int data type takes 32 bits of memory.

int type valid range is -2,147,483,648 to 2,147,483,647 (-2^31 to 2^31 - 1).

All whole numbers in this range are known as integer literals (integer constants). For example, 10, -200, 0, 30, 19, 123123, etc. are integer literals of int.

An integer literal can be assigned to an int variable, say num1

int num1 = 21; 
  

Integer literals can be expressed in

  • Decimal number format
  • Octal number format
  • Hexadecimal number format
  • Binary number format

Integer class

Java has a class named Integer.

It defines two constants to represent maximum and minimum values for the int data type, Integer.MAX_VALUE and Integer.MIN_VALUE.

Demo

public class Main {
  public static void main(String[] args) {
    int max = Integer.MAX_VALUE; // Assigns maximum int value to max 
    int min = Integer.MIN_VALUE; // Assigns minimum int value to min 

    System.out.println(max);//from  w  w  w  .j a  v a 2 s  .  c  o m
    System.out.println(min);
  }
}

Result

Exercise