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


Whereisstuff is simple learing platform for beginer to advance level to improve there skills in technologies.we will provide all material free of cost.you can write a code in runkit workspace and we provide some extrac features also, you agree to have read and accepted our terms of use, cookie and privacy policy.
© Copyright 2024 www.whereisstuff.com. All rights reserved. Developed by whereisstuff Tech.