Java Design Pattern
Introduction to Java 10
Introduction to Java 11
Introduction to Java 12

Java Literals

A literal is nothing but a value which is stored into a variable in the program.

Example

int x =1520;
char c =”x”;
boolen b =false;

In the above statement the right hand side values are called literals. java support different types of literals such as:

  1. Integer literal
  2. Floating literal
  3. Character literal
  4. String literal
  5. Boolean literal
Integer literal:
  • • Integer literal represent the fixed integer value such as 10,15,-35,1234 etc.
  • • All these numbers belongs to decimal system which uses 10 digits (from 0 to 9) to represent any number.
  • • Suppose we want to write an integer in octal number system (octal number system uses 8 digit from 0 to 7) then we should prefix 0 before the number. To represent hexadecimal number (hexadecimal number system uses 16 digit from 0 to 9 and from A to F ) we should prefix 0 before the value.

int x =25; // The number 25 in decimal
int y =031; // The number 25 in octal
int z =0x19; // The number 25 is in hexadecimal

Floating Literal:

Floating literal represent the decimal value with a fractional component. Like 5.2,0.0004,2.15 etc .while writing the floating literals we can use E or e for scientific notation, F or f for float literal and D or d for double literal

Example

double x =345.67;

Character Literals:

Character literals represents the following

  • • General characters like q, b, t.7.9, ets.
  • • Special characters like ?,@, etc.
  • • Unicode characters like \, U, 0042 (this represent ‘a’ in ISO Latin-1 character set).

Character literals should be enclosed in single quotation mark.

String Literals:

String literals represent objects of string class. For example vivtech, lakshya, rajeshKumar, BQ1210, etc comes under string literals which can be directly stored into a string object.

Boolean Literals:

Boolean literals represent only two values such as True and False that means we can store either true or false into a boolean type variables.

About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.


We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc






 PreviousNext