free classified ads and leads
domain website price


Java Literals

Java Question and Answer and Tutorial

A literal is a source code representation of a fixed value. They are represented directly in the code without any computation.
Literals can be assigned to any primitive type variable. For example:

byte a = 68;
char a = 'A'

byte, int, long, and short can be expressed in decimal(base 10),hexadecimal(base 16) or octal(base 8) number systems as well.
Prefix 0 is used to indicates octal and prefix 0x indicates hexadecimal when using these number systems for literals. For example:

int decimal = 100;
int octal = 0144;
inthexa = 0x64;

String literals in Java are specified like they are in most other languages by enclosing a sequence of characters between a pair of double quotes. Examples of string literals are:

"Hello World"
"two\nlines"
"\"This is in quotes\""

String and char types of literals can contain any Unicode characters. For example:

char a = '\u0001';
String a = "\u0001";

Java language supports few special escape sequences for String and char literals as well. They are:


Notation

Character represented

\n

Newline (0x0a)

\r

Carriage return (0x0d)

\f

Formfeed (0x0c)

\b

Backspace (0x08)

\s

Space (0x20)

\t

tab

\"

Double quote

\'

Single quote

\\

backslash

\ddd

Octal character (ddd)

\uxxxx

Hexadecimal UNICODE character (xxxx)

 

Bookmark and Share




Gallery

Related Topics

Comments



Submit Reviews:


(Enter the characters seen on the image below.)



Promotional Ads

Advertisement

Fertichem Industrial Corporation
478/1 Gali Number 2 , Adarsh Nagar, Sector 13, Chandigarh, 160101

Shree Ji Packers And Movers
478/1 Gali Number 2 , Adarsh Nagar, Sector 13, Chandigarh, 160101

Packers and Movers In Satna - VP Max
Ground Floor, Shop 2, JL Institute of Study Center, Tilak Ganj, Ward 14, Sagar, Madhya Pradesh 470002
Ground Floor, Shop 2, JL Institute of Study Center, Tilak Ganj, Ward 14, Sagar, Madhya Pradesh 470002
Shahdol

Packers and Movers in Sagar
Ground Floor, Shop 2, JL Institute of Study Center, Tilak Ganj, Ward 14, Sagar, Madhya Pradesh 470002
Ground Floor, Shop 2, JL Institute of Study Center, Tilak Ganj, Ward 14, Sagar, Madhya Pradesh 470002
Sagar

Packers and movers in Mohali
Plot No 636, Near HP Gas Agency, Dariya, Chandigarh - 160101
Mohali

JB Rock Bolts & SN BOLTS
10 A & B Industrial Area (at Vill. Nangal Jarialan)
Distt. Una Himachal Pradesh
Una

Packers and Movers in Zirakpur - Packers and Mover
SCO 3 AKS 2, Bhabat Rd, near Post Office, Zirakpur

Website Design and Development
Bangalore
Hyderabad

JF Engineering Products LLP
Parhar Village, Near Vasai Fata, Eastern Express Highway, Vasai (E), Palghar,
Motilal Nagar Mumbai

Nandishwar Steel
51 M.G. Mahimtura Marg, 3rd Kumbharwada Lane, Opp. Durgadevi Garden
August Kranti Marg Mumbai