Advertisement

Google Ad Slot: content-top

Java Litreals


In Java, literals are fixed values assigned to variables. They represent the actual data used in the code. Java supports different types of literals based on the data types.

Literal Type

Description

Example

Integer Literals

Represents whole numbers (decimal, binary, octal, or hexadecimal).

10, 0b1010, 012, 0xA

Floating-Point Literals

Represents numbers with decimal points.

3.14, 1.5e2, 0.0

Character Literals

Represents single characters enclosed in single quotes.

'A', '1', '\n'

String Literals

Represents a sequence of characters enclosed in double quotes.

"Hello", "123"

Boolean Literals

Represents logical values true or false.

true, false

Example
int num1=0b101;
int num2=0x7E;
int num3=10_00_00_000;
float num4=56;
double num5=56;
double num6=12e10;
char c='a';
c++;
Try it yourself