Posts

Showing posts from May, 2018

Literals in Java

Image
Any constant value which can be assigned to the variable is called a Literal . Ex:- int x = 10 int => Data type or Keyword x => Name of Variable or Identifier 10 => Constant value or Literal Integral Literals For integral data types (byte, short, int, long) we can specify literal value in the following ways 1. Decimal form/Literals (base - 10) Allowed Digits are 0 to 9 Ex:- int x = 10 2. Octal form (base - 8) Allowed Digits are 0 to 7 Literal value should be prefixed with 0 Ex:- int x = 010 3. Hexadecimal form (base - 16) Allowed Digits are 0 to 9, a to f Note: for extra digits (a to f) we can use both lower case and upper case characters, this is one of very few areas where Java is NOT case sensitive. Literal value should be prefixed with 0x or 0X (both small x and capital X is allowed). Ex:- int x = 0X10 These are only possible ways to specify Literal value for Integral Data Types. Question: Which of the following declarations are Valid Literals