1. List the numeric data types and their size & the range ?

Answer :

There are 6 numeric data type (4 integer & 2 floating-point) in java.

integer

2. What is a literal ? Explain with example ?

Answers :

In java, literal  is a source code representation of a fixed value.Literals an be any number,text or any character that represents a value.There are two numeric literals (Integer literals & floating-point literals).

Integer Literal :

An integer literal is a type of long if it ends with a letter l or L ; otherwise it is a type of int. Conventionally letter L is used to represent long type literals.

Floating-point literals :

A floating-point literal is type of float if it ends with letter f or F; otherwise its a double type. Optionally using letter d or D in the ends of a value we can represent double type.The floating-point types also an be represent using letter e or E (for scientific notation representation).

Below example shows some use of literals :

 

class Literals1{
    public static void main(String[] felight){
        int intType =100;
        // here intType is an int type
        long longType= 100L;
        //use of letter L at the end of 100 to represent same value of variable intType as long type
        double doubleType=3.142;
        // this value is a double type by default
        float floatType=3.142F;
        //use of letter F to represent same value of variable doubleType as a type float
        double doubleType1= 3.142D;
        //this is also type double 
        double scientific_Notation =3124e-3;
        //use of character sequences 'e-' to represent same value of variable doubleType(scientific notation).
        long credit_Card_Number=1234_2345_3456_4567L;
        //use of underscore to differentiate between digits
        System.out.println(intType);
        System.out.println(longType);
        System.out.println(doubleType);
        System.out.println(floatType);
        System.out.println(doubleType1);
        System.out.println(scientific_Notation);
        System.out.println(credit_Card_Number);
    }
}

/*

D:\Felight\Basic Java>javac Literals1.java

D:\Felight\Basic Java>java Literals1
100
100
3.142
3.142
3.142
3.124
1234234534564567
*/