A literal is the fixed value you write directly in your source code. When you type 100 or 3.14 or "Java", you are not referring to a variable, you are writing the value itself.
int age = 25;
// 25 is an integer literal
double rate = 7.5;
// 7.5 is a floating-point literal
String city = "Pune";
// "Pune" is a String literalA literal is the opposite of a variable in one important way: it can never change. There is no valid Java code that reassigns 25, because 25 is not a name, it is the value itself.
VARIABLE VERSUS LITERAL
int age = 25;
| | | |
| | | +--> LITERAL a fixed value, cannot change
| | +-------> assignment copies it into the box
| +------------> VARIABLE a name you can change later
+----------------> TYPE always int here
age = 26; works, you changed the variable
25 = 26; ERROR, you cannot change a literalLiterals matter more than they look, because the compiler uses them to decide the type of everything around them. A literal is the starting point of Java's whole type system.