Literals in Java Simplified

0
24
Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

Literals in Java
Literals in Java

Literals in Java Simplified:

In general when we insert a literal value into a program the compiler knows what type to make it.However if the type is ambiguous,we need to provide compiler some more information about it and guide it in the form of characters associated with the literal value.

Details:

Hexadecimal:

Hexadecimal(base-16) is denoted by leading ox or OX followed by 0 to 9 and a-f either in upper case or lower case Exp-ox7fff

Octal:

Octal (base-8) is denoted by a leading zero and digits from 0 to 7.

Binary:

Binary has no representation except 0 and 1.
A training character after a literal is its type.like l/L stand for long,D/d stand for double,f/F stands for float.If we try to initialize a variable with a value bigger than it can hold,the compiler will provide an error message or it will automatically makes a bigger datatype and ask us to narrow it for assignment. To convert a lower capacity data type to higher capacity is called promotion.
In an operation,where two different types of data are present , the resultant automatically get promoted to max of the two data type.
Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

LEAVE A REPLY

Please enter your comment!
Please enter your name here