Java Literals are Numeric, Boolean, Character and String representation of data.
Example of a Numeric Literal –
int var = 5;
Here the value 5 is the Numeric literal.
Example of Boolean Literals –
boolean var1 = true, var2 = false;
Here the values true & false are the Boolean literals.
Example of Character Literals –
char var1 = ‘c’, var2 =’$’, var3=’5’;
Here the values ‘c’, ‘$’, ‘5’ including single quotes are the Character Literals.
Example of a String Literal –
String var = “Sample Text”;
Here the value “Sample Text” including the double quotes is the String Literal.
Now you have got the basic understanding of what is a Java Literal. It’s nothing but the syntactical representation of data in Java. For example, integer value is represented as 5 whereas character is represented as ‘$’. So there is a variation in how we represent different types of data in Java and we call their representation as Literals in Java.
As I have explained above that there are three categories in Java Literal –
Character literal is a part of Numeric category.