Saturday, 23 July 2022

Literals in Java

A literal represent a value that is stored into a variable directly in the program. In an expression the right hand side data is called literal which are stored in variable. When data type changes the literal value will be changed.

For example, the expression int a=10; will store literal value "10" in variable "a". Depending upon the data types java supports five types of literals they are list below

  1. Integer literal
  2. Floating literal
  3. Character literal 
  4. String literal
  5. Boolean literal

1. Integer literal

  1. These literals represents fixed integer values
  2. All these numbers belongs to decimal number system which uses 10 digits
  3. Example: int a=10;

2.  Floating literal

  1. These literals represents fractional numbers 
  2. These are the numbers with decimal points
  3. While writing these literals, we can use E or e for scientific notation.
  4. Example: float f=1250.4f;

3. Character literal 

  1. These literal include characters, special characters, Unicode characters, and escape sequences 
  2. These literals  should be enclosed in single quotation marks.
  3. Example: char ch='A';

4. String literal

  1. String literal represents objects of string class
  2. All String literals can be directly stored in a string object

5.  Boolean literal

  1. Boolean literals represents only two value - True and False
  2. It means we can store either true or false into Boolean type variable

0 comments :

Post a Comment

Note: only a member of this blog may post a comment.

Machine Learning

More

Advertisement

Java Tutorial

More

UGC NET CS TUTORIAL

MFCS
COA
PL-CG
DBMS
OPERATING SYSTEM
SOFTWARE ENG
DSA
TOC-CD
ARTIFICIAL INT

C Programming

More

Python Tutorial

More

Data Structures

More

computer Organization

More
Top