Witscale Test Center

7.3 Literals


7.3 Literals

A primitive literal is a primitive data value in the Java source code. For instance, when you type either an integer value or a floating-point value while writing Java code, it is a literal. Java also has string literals. For instance, the figure 7.3 shows different kinds of literals in a Java code.

 


Figure 7.3 Different kinds of literals in Java source code

 

Since literals are themselves values, you cannot assign any value to them. A literal simply means a value that can be typed directly into the code. Java literals can have either primitive values or string values. The primitive literals may be boolean, character, or integral literals. Let us see the specifics of each of these literals.