Data types in Java
- In any programming language, we can have different data types.
- Data types are basically used to represent the data in the main memory of the computer by allocating sufficient memory space.
- In java, we have 3 types of data types. They are:
- Fundamental Data Type.
- Derived Data Type.
- User Defined / Custom Defined Data Type
- ) Fundamental Data Types:In java, we have 8 fundamental data types which are divided into 4 categories. They are:
- Integer Category: (i) Byte (ii) Short (iii) int (iv) long
- Float Category: (i) Float (ii) double
- Character Category: char
- Boolean Category: boolean
Integer Category Data Types:
- These category data types are used for representing whole numbers i.e. which don’t contain decimal places.
- This category contains 4 data types which are given in the following table:
DATA TYPE SIZE (in Bytes) RANGE byte 1(8 bits) -128 to +127 short 2 (16 bits) -32768 to +32768 int 4 (32 bits) -2,147,483,648 .. 2,147,483,647 long 8 (64 bits) -9,223,372,036,854,775,808 .. 9,223,372,036,854,775,807
Float Category Data Types:
- This category data types are used for representing the data in the form of (scale, precision) i.e. 13.75
- This category contains 2 data types which are given in the following table:
DATA TYPE SIZE IN BYTES RANGE Float 4(32 bits) 3.40282347 x 1038, 1.40239846 x 10-45 double 8(64 bits) 1.7976931348623157 x 10308, 4.9406564584124654 x 10-324
Character Category Data Types:
- A character is an identifier which is enclosed within the single quotes.
- To represent the character data type in java, we use a data type called ‘char’. This data type occupies 2 bytes since java follows UNICODE character set.
- A UNICODE character set is one which contains all characters of 18 international languages i.e. Java is available in all 18 international languages.
- ASCII (American Standard Code for Information Interchange) contains 256 characters (28) whereas UNICODE (Universal Code) contains 65536 characters (216).
- Java allows us to convert our java application from one international language to another. The process of such conversion is known as internationalization. The tool which is used to perform such conversion is “i18n”.
Boolean Category Data Types:
- Boolean category data types are used to represent the logical values i.e. true or false.
- In java, to represent the values true/false, we use a data type called “boolean”.
- This data type does not occupy any amount of memory space.
2) DERIVED DATA TYPES:
- Wrapper Class
Fundamental Data Type Wrapper Classes
Wrapper class encloses fundamental data types in form of object.
3) USER DEFINED DATA TYPES: