LogIn
I don't have account.

Java Integer.MIN_VALUE

DevSniper
196 Views

  • Name : Integer.MIN_VALUE
  • Value : -2147483648 OR -2^31
  • Data Type : int
  • Integer Range :- -2^31 to 2^31-1 OR -2147483648 to 2147483647
  • Binary Representation : 10000000 00000000 00000000 00000000

In Java programming, understanding the constants and predefined values provided by the Java language is crucial for writing efficient and error-free code. Integer.MIN_VALUE is a one such fundamental constant which denotes the smallest possible value that can be stored in an int data type. It is defined under Integer class.

Integer.MIN_VALUE plays a crucial role in ensuring accurate and efficient handling of integer values within Java programs. Understanding of such constant enhances your ability to write robust and reliable code in Java programming. In this article we will understand Integer.MIN_VALUE use cases and behavior with mathematical operation.

Integer.MIN_VALUE

Integer.MIN_VALUE is a minimum possible value that a integer data type can store in Java. It is a constant of Integer Class of Java.lang package.

public class RebootMemory 
{
    public static void main(String []args) 
    {
        System.out.println("Integer.MIN_VALUE = "+Integer.MIN_VALUE);
    }
}
Integer.MIN_VALUE = -2147483648

if we down grad or decrease Integer.MIN_VALUE that will lead a overflow in memory

Binary Representation of Integer.MIN_VALUE is `10000000 00000000 00000000 00000000` when we decrease this value by 1 wraps around to `01111111 11111111 11111111 11111111` which is Integer.MAX_VALUE.

public class RebootMemory 
{
    public static void main(String []args) 
    {
        System.out.println("Integer.MIN_VALUE -1 = "+(Integer.MIN_VALUE -1));
        System.out.println("Integer.MAX_VALUE = "+Integer.MAX_VALUE);
    }
}
Integer.MIN_VALUE -1 = 2147483647
Integer.MAX_VALUE = 2147483647

Type Casting Integer.MIN_VALUE in long , float and double

public class RebootMemory 
{
    public static void main(String []args) 
    {
        System.out.println("(long)Integer.MIN_VALUE = "+(long)Integer.MIN_VALUE);
        System.out.println("(float)Integer.MIN_VALUE = "+(float)Integer.MIN_VALUE);
        System.out.println("(double)Integer.MIN_VALUE = "+(double)Integer.MIN_VALUE);
    }
}
(long)Integer.MIN_VALUE = -2147483648
(float)Integer.MIN_VALUE = -2.1474836E9
(double)Integer.MIN_VALUE = -2.147483648E9

Downgrading Integer.MIN_VALUE with type casting in long , float and double

public class RebootMemory 
{
    public static void main(String []args) 
    {
        System.out.println("(long)(Integer.MIN_VALUE -1) = "+(long)(Integer.MIN_VALUE -1));
        System.out.println("(float)(Integer.MIN_VALUE -1) = "+(float)(Integer.MIN_VALUE -1));
        System.out.println("(double)(Integer.MIN_VALUE -1) = "+(double)(Integer.MIN_VALUE -1));
        
        System.out.println("(long)Integer.MIN_VALUE -1 = "+((long)Integer.MIN_VALUE -1));
        System.out.println("(float)Integer.MIN_VALUE -1 = "+((float)Integer.MIN_VALUE -1));
        System.out.println("(double)Integer.MIN_VALUE -1 = "+((double)Integer.MIN_VALUE -1));
    }
}
(long)(Integer.MIN_VALUE -1) = 2147483647
(float)(Integer.MIN_VALUE -1) = 2.1474836E9
(double)(Integer.MIN_VALUE -1) = 2.147483647E9
(long)Integer.MIN_VALUE -1 = -2147483649
(float)Integer.MIN_VALUE -1 = -2.1474836E9
(double)Integer.MIN_VALUE -1 = -2.147483649E9