Sunday, April 6, 2025

Integer

Integer.MAX_VALUE is the maximum value of an int can hold in Java
Both int and Integer share the same range because Integer is just an Object representaion of int
2^31 = 2,147,483,647IntegerMAX_VALUE -> refers to the max value of an int.It is defined in the Integer class for convenienceBoth int and Integer can hold values from -2,147,483,648 to 2,147,483,647(2.147 billion)

 public class IntegerTest {
    public static void main(String[] args) {
Integer a = 100, b = 100;
Integer x = 200, y = 200;

System.out.println(a == b); // (A)
System.out.println(x == y); // (B)
}
}

Answer:

true
false
  • Java caches Integer values from -128 to 127.

No comments:

Post a Comment

Static vs Non Static Inner class

Understanding Static vs Non-Static Inner Classes in Java The Hidden Reference That Most Java Developers Never See One of the most misunderst...