1.

Primitive types in Java

Answer»

The primitive data types in JAVA are BOOLEAN, byte, char, short, int, long, float and double. These data types have no special capabilities and are only single values.

A table that demonstrates all the primitive types in Java is as follows:

TypeDefault ValueSize (in bits)Description
booleanfalse1This signifies true or false
byte08Two’s complement integer
char\u000016Unicode Character
short016Two’s complement integer
int032Two’s complement integer
long064Two’s complement integer
float0.032IEEE 754 floating point
double0.064IEEE 754 floating point

A program that demonstrates all the primitive types in Java is given as follows:

public class Demo {    public static void main(String []args)    {        boolean var1 = true;        byte var2 = 127;        char var3 = 'A';        short var4 = -2000;        int var5 = 5000;        long var6 = 10000;        float var7 = 75.8756f;        double var8 = 28.84642387;        System.out.println("boolean: " + var1);          System.out.println("byte: " + var2);          System.out.println("char: " + var3);          System.out.println("short: " + var4);          System.out.println("int: " + var5);          System.out.println("long: " + var6);          System.out.println("float: " + var7);          System.out.println("double: " + var8);       } }

The output of the above program is as follows:

boolean: true byte: 127 char: A short: -2000 int: 5000 long: 10000 float: 75.8756 double: 28.84642387


Discussion

No Comment Found