4. Primitive Data Types

Primitive data values are not objects. Each primitive data type defines the range of values in the data type.

Primitive data type also has a corresponding wrapper class that represents a primitive value as an object. We’ll learn more about it later chapter.

4.1. Integer Types

Represent signed integers (byte, short, int, long) and unsigned character values (char).

Table below lists the range of integer values in Java.

			package javatutorial;

			/**
			 * Example class showing the range of integer types
			 * 
			 * @author f5java.com
			 */
			public class IntergerRange {


				public static void main(String[] args) {
					
					byte byteMinValue = Byte.MIN_VALUE;
					byte byteMaxValue = Byte.MAX_VALUE;
					
					short shortMinValue = Short.MIN_VALUE;
					short shortMaxValue = Short.MAX_VALUE;
					
					int intMinValue = Integer.MIN_VALUE;
					int intMaxValue = Integer.MAX_VALUE;
					
					long longMinValue = Long.MIN_VALUE;
					long longMaxValue = Long.MAX_VALUE;
					
					// Printing the ranges of integer types
					
					System.out.println("Range of byte values " + byteMinValue + " to " + byteMaxValue);
					System.out.println("Range of short values " + shortMinValue + " to " + shortMaxValue);
					System.out.println("Range of int values " + intMinValue + " to " + intMaxValue);
					System.out.println("Range of long values " + longMinValue + " to " + longMaxValue);		

				}

			}