3.3. Literals

A constant value in Java is called a literal. The value of the literal remains constant in the program. Literals can be numerical (integer or floating-point), character, boolean or string values. A null literal represents the null reference.

See the below table for examples of literals in Java.

3.3.1. Integer Literals

Integer data types comprise the following primitive data types:

In Java long by appending the suffix L (or l) and there is no direct way to specify a short or a byte literal.

			package javatutorial;

			/**
			 * Example usage of Integer literals in Java
			 * 
			 * @author f5java.com
			 */
			public class IntegerLiterals {

				public static void main(String[] args) {
					int age = 25;
					int number = -100;
					int zero = 0;
					
					long salary = 100000;
					long negvalue = -2000;
					long bookingNo = 234204389L;
					long ticketNo = 28934783l;
					
					System.out.println("int values " + age);
					System.out.println("int values " + number);
					System.out.println("int values " + zero);
					
					System.out.println("long values " + salary);
					System.out.println("long values " + negvalue);
					System.out.println("long values " + bookingNo);
					System.out.println("long values " + ticketNo);

				}

			}