Understanding Java Data Types: A Comprehensive Guide

data types

“Data types are used for representing the data in main memory of the computer”.

cognizant 1

PRIMITIVE DATA TYPES

1. Integer Data Types:- These are used to represent integer data. This category of data type contains four data types.

Data Types Table
S No Data Type Size(type) Range
1 Byte 1 +127 to -128
2 Short 2 +32,767 to -32,768
3 Int 4 +2,147,483,647 to -2,147,483,648
4 Long 8 +-9.223*10 18

2. Float Data Types:- Float data types are used for representing the data in the form of scale, precision. These category data types are used for representing float values. This category contains two data types.

Data Types Table
S No Data Type Size(type) Range Number of Decimal Places
1 Float 4 +2,147,483,647 to -2,147,483,648 8
2 Double 8 +/-9.223*10 18 16

3. Character Data Types:- 

  • A character is an identifier which is enclosed within single quotes.
  • In JAVA to represent character data, we use a data type called char. This data type takes two bytes since if follows UNICODE character set.
Data Types Table
Data Type Size(type) Range
char 2 +32767 to -32768
  • Java is available in 18 international languages and it is following UNICODE character set.
  • UNICODE character set is one which contains all the character which are available in 18 international languages and it contains 65536 characters.

4. Boolean Category Data Types:- 

  • Boolean category data type is used for representing logical values. TRUE or FLASE values.
  • To represent logical values we use a Keyword called Boolean.
  • This data type takes 0 bytes of memory space.

     

NON-PRIMITIVE DATA TYPES

Non-Primitive data types are used to refer to objects. Unlike primitive data types, they do not store the actual data. Instead, they store references (memory addresses) to objects. 

  • String:- Represents a sequence of characters.
  • Arrays:- Collections of elements of the same type.
  • Classes:- User-defined types.
  • Interfaces:- Similar to classes but define a contract of methods that implementing classes must follow.
  • Enums:- A special kind of class used to represent a fixed set of constants.

Note:- All keywords in JAVA must be written in small letters only.

Leave a Comment

Your email address will not be published. Required fields are marked *