A literal is a constant value written directly in the code.
It represents a fixed value assigned to a variable.
int a = 42;
a > Primitive Variable
= > Assignment Operator
42 > Integer Literal
| Literal Type | Example(s) | Description |
|------------------------|-------------------------|--------------------------------------------|
| Integer Literal | `42`, `-7`, `88` | Whole numbers without decimals |
| Floating Point Literal | `3.0`, `-2.5`, `0.99f` | Numbers with decimal points |
| Character Literal | `'a'`, `'1'`, `'%'` | Single characters in **single quotes** |
| String Literal | `"Hello"`, `"123abc"` | Sequence of characters in **double quotes**|
| Boolean Literal | `true`, `false` | Represents logical values |
| Null Literal | `null` | Represents **null reference** for objects |
Literals are used with primitive data types like int, float, char, boolean.
null is used with non-primitive types (like objects or Strings).
Each literal tells the compiler what kind of value is being assigned.
int score = 88; // Integer Literal
float pi = 3.14f; // Floating Point Literal
char grade = 'A'; // Character Literal
String name = "John"; // String Literal
boolean isPassed = true; // Boolean Literal
String city = null; // Null Literal