Definition: A literal is a fixed value that is directly represented in the source code.
Purpose: Used to assign constant values to variables of different data types.
Key Points to Remember
•Integer Types: Default to int. Use L for long (e.g., long num = 123L;). •Floating-point Types: Defaults to double. Use f for float (e.g., float value = 3.14f •Escape Sequences in Characters: Use \n, \t, \', \", etc., for special characters. •Null for Objects: Can be assigned to reference types to represent 'no value'. •Integer Literals: Used for numbers without a decimal. •Examples: int a = 100;, int b = 0x1A; // hexadecimal •Formats: Decimal (100), Binary (0b1010), Octal (014), Hexadecimal (0x1A) •Floating-point Literals: Used for numbers with decimal points. •Examples: float f = 10.5f;, double d = 20.05; •Note: f or F suffix for float, d or D (optional) for double •Character Literals: Represents a single character. •Examples: char ch = 'A';, char ch2 = '\n'; // newline character •Unicode Characters: Can use Unicode like char ch = '\u0041'; // 'A' •String Literals: Represents sequences of characters. •Examples: String name = "Hello"; •Immutability: Once created, string values can’t be changed. •Boolean Literals: Represents true or false values. •Examples: boolean flag = true;, boolean check = false; Includes classes, arrays, and interfaces. Example: String, arrays, custom objects.