Print the limits of the primitive types in Java
Written on December 8, 2008 at 9:32 am by
mkyong
The Java programming language is a strongly-typed language and it consist of eight primitive data types (byte, short, int, long, float, double, boolean, char). For more about java primitive data type, please visit http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html
Well, sometime we really need to know what is the limit of the primitive types in java. With following simple code, we can print out the limit of each of the java primitive data types (except boolean and char)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | public class PrintTypeLimit { public static void main(String args[]) { System.out.println("Min byte value = " + Byte.MIN_VALUE); System.out.println("Max byte value = " + Byte.MAX_VALUE); System.out.println("Min short value = " + Short.MIN_VALUE); System.out.println("Max short value = " + Short.MAX_VALUE); System.out.println("Min int value = " + Integer.MIN_VALUE); System.out.println("Max int value = " + Integer.MAX_VALUE); System.out.println("Min long value = " + Long.MIN_VALUE); System.out.println("Max long value = " + Long.MAX_VALUE); System.out.println("Min float value = " + Float.MIN_VALUE); System.out.println("Max float value = " + Float.MAX_VALUE); System.out.println("Min double value = " + Double.MIN_VALUE); System.out.println("Max double value = " + Double.MAX_VALUE); } } |
Output
Min byte value = -128 Max byte value = 127 Min short value = -32768 Max short value = 32767 Min int value = -2147483648 Max int value = 2147483647 Min long value = -9223372036854775808 Max long value = 9223372036854775807 Min float value = 1.4E-45 Max float value = 3.4028235E38 Min double value = 4.9E-324 Max double value = 1.7976931348623157E308
This article was posted in Java category.
All Java Tutorials
- Java Core Technology - Java RegEx, Java XML, Java I/O, Java Misc
- J2EE Frameworks - Hibernate, Spring 2.5, Spring MVC, Struts 1.x, Struts 2.x
- Build Tools - Maven, Archiva
- Unit Test - jUnit, TestNG
- Client Scripts - jQuery