In Java, a literal refers to a value that is expressed in source code exactly as it is meant to be interpreted by the compiler. In other words, a literal is a fixed value that is directly used in the code, rather than being stored in a variable or calculated at runtime.
There are several types of literals in Java:
Example:
int a = 10; // decimal literal
int b = 0x1F; // hexadecimal literal
int c = 012; // octal literal
Example:
float a = 3.14f; // decimal literal
double b = 1.23e-4; // scientific notation
Example:
char a = 'A'; // character literal
Example:
String a = "Hello, world!"; // string literal
Example:
boolean a = true; // boolean literal
Example:
String a = null; // null literal