This cover Java Primitives. I wrote code to show the minimum, maximum and bit size for each primitive.
Main.java
public class Main {
public static void main(String[] args) {
System.out.println("\nPrimitive Integer Types");
System.out.printf("The range of an byte is: " + Byte.MIN_VALUE + " to " + Byte.MAX_VALUE);
System.out.println (" and the byte Size is " +Byte.SIZE + " bits");
System.out.print("The range of an Short is: " + Short.MIN_VALUE + " to " +Short.MAX_VALUE);
System.out.println(" and the short Size is " + Short.SIZE + " bits");
System.out.printf("The range of an int is: " + Integer.MIN_VALUE + " to " + Integer.MAX_VALUE);
System.out.println(" and the int Size is " + Integer.SIZE + " bits");
System.out.printf("The range of an long is: " + Long.MIN_VALUE + " to " + Long.MAX_VALUE);
System.out.println(" and the long size is " + Long.SIZE + " bits");
//What happens when you add 1 to the MaxValue
//Overflow
System.out.println("\nMaxIntMaxValue + 1 = " +( Integer.MAX_VALUE + 1 )
+ " rolls around to the Min Value called Overflow"
+ " or wrap around" ) ;
//What happens when you subtract 1 to the MinValue
// Underflow
System.out.println("MaxIntMaxValue + 1 = " +( Integer.MIN_VALUE - 1 )
+ " rolls around to the Max Value called Underflow"
+ " or wrap around" ) ;
System.out.println("\nPrimitive Floating-point Types");
System.out.printf("The range of an double is: " + Double.MIN_VALUE + " to " + Double.MAX_VALUE);
System.out.println(" and the double size is " + Double.SIZE + " bits");
System.out.printf("The range of an Float is: " + Float.MIN_VALUE + " to " + Float.MAX_VALUE );
System.out.println(" and the float size is " + Float.SIZE + " bits");
System.out.printf("\nCharacter size range is " + (Character.MIN_VALUE + 0) + " to " + (Character.MAX_VALUE + 0));
System.out.println(" and character size is " + Character.SIZE + " bits");
boolean TrueVal = true;
boolean FalseVal = false;
System.out.println("Boolean values are " + TrueVal + " or " + FalseVal);
System.out.println("Is 10 < 9: T/F: " + (10 < 9));
System.out.println("Is 10 > 9: T/F: " + (10 > 9));
System.out.println("Is 10 = 10: T/F: " + (10 == 10));
}
}
C:\Users\netadmin\.jdks\openjdk-23.0.1\bin\java.exe "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2024.2.4\lib\idea_rt.jar=52489:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2024.2.4\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath C:\Users\netadmin\IdeaProjects\MaxMINValues\out\production\MaxMINValues Main
Primitive Integer Types
The range of an byte is: -128 to 127 and the byte Size is 8 bits
The range of an Short is: -32768 to 32767 and the short Size is 16 bits
The range of an int is: -2147483648 to 2147483647 and the int Size is 32 bits
The range of an long is: -9223372036854775808 to 9223372036854775807 and the long size is 64 bits
MaxIntMaxValue + 1 = -2147483648 rolls around to the Min Value called Overflow or wrap around
MaxIntMaxValue + 1 = 2147483647 rolls around to the Max Value called Underflow or wrap around
Primitive Floating-point Types
The range of an double is: 4.9E-324 to 1.7976931348623157E308 and the double size is 64 bits
The range of an Float is: 1.4E-45 to 3.4028235E38 and the float size is 32 bits
Character size range is 0 to 65535 and character size is 16 bits
Boolean values are true or false
Is 10 < 9: T/F: false
Is 10 > 9: T/F: true
Is 10 = 10: T/F: true
Process finished with exit code 0