Java Literals

A literal in Java is a source code representation of a settled worth. They are spoken to specifically in the code without any calculation. Literals can be appointed to any primitive sort variable. Case in point:

byte x = 86;
char x = “a”

int, byte, short and long can be communicated in hexadecimal(base 16), decimal(base 10) or octal(base 8) number frameworks too. Prefix 0 is utilized to show octal while prefix 0x demonstrates hexadecimal when utilizing these number frameworks for literals. For example,

int numd = 134;
int numo = 0243;
int numx = 0x95;

String literals in Java are determined like they are in most different programming languages by encasing a grouping of characters between a couple of twofold quotes. Illustrations of string literals are:

“Hi Everyone” “two\nlines” “”these characters are inside quotes””

String sorts of literals can contain any Unicode characters. For instance:

String news = “\u0001”

You can also use escape sequences with Java. Here is a list of escape sequences that you can use.

Double quote – ”
Carriage return (0x0d) – \r
Newline (0x0a) – \n
Single quote – ‘
Backspace (0x08) – \b
Formfeed (0x0c) – \fTab – \t
Space (0x20) – \s
Octal character (ddd) – \ddd
Backslash – \
Hexadecimal UNICODE character (xxxx) – \uxxxx