Data Types in Java

What is data types?
Generally, data types are used to create variables where variables will hold values, as defined in the range of values of a data types. 
Java supports two types of data types-
   1. Primitive data types
   2. Non-primitive data types

Primitive data types:- 
There are totally eight primitive data types in Java which are as follows:-


Why Java uses 2 bytes for characters and what is '\u0000'?
In Java almost 18 international languages are supported.
Now, the characters and symbols of these languages cannot be accommodated in 1 byte space in memory, so java takes 2 bytes for characters.
Java supports UNICODE but C language supports ASCII code. In ASCII code we can represent characters of English language, so for storing all English letters and symbols 1 byte is sufficient.
But UNICODE character set is superset of ASCII code in which all the characters which are available in 18 international languages are supported and it contains 65536 characters ranging from 0 to 65535.
To assign UNICODE values we have two options:-
1. Use the numeric value
2. Use the format '\uxxxx' (where xxxx is hexadecimal form of the value)
The '\u0000' is the lowest range of Unicode.
For Example:-
       char ch=65;
               or  (Both means we are assigning letter A)
       char ch='\u0041';

Non-primitive data types:- 
Non primitive data types are also called as reference data types.
Non primitive data type is used to refer to an object.
In java variables of type class, arrays, Strings, enums and interfaces are represented as objects.
We will discuss this in later chapters like Strings, arrays and classes and objects.

Post a Comment

0 Comments