Definition :
- A Data Type is the characteristic of a variable that determines what kind of data it can hold.
Java comes with eight primitive data types to handle simple data values. A primitive type is predefined by the language and is named by a reserved keyword. The eight primitive data types supported by the Java programming language are listed below.
boolean :
The boolean data type has only two possible values: true and false. We use this data type for conditional statements. true and false are not the same as True and False. Boolean may not be cast into any other type of variable nor may any other variable be cast into a boolean.
Example : boolean a = true ;
byte :
The byte data type can be useful for saving memory in large arrays, where the memory savings actually matters. It has a minimum value of -128 and a maximum value of 127.
Example : byte a = 200 ;
short :
The short data type is a 16-bit signed two's complement integer. It has a minimum value of -32,768 and a maximum value of 32,767.Short data type can also be used to save memory as byte data type. A short is 2 times smaller than an int.
Example : short a = 20000 ;
int :
The int data type is a 32-bit signed two's complement integer. It has a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647. Int is generally used as the default data type for integral values unless there is a concern about memory. The default value is 0.
Example : int a = 500 ;
long :
The long data type is a 64-bit signed two's complement integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807.
This type is used when a wider range than int is needed. Default value is 0L.
Example : long a = 100000L ;
float :
Float data type is a single-precision 32-bit IEEE 754 floating point. Float is mainly used to save memory in large arrays of floating point numbers. Default value is 0.0f.
Example : float a = 132.5f ;
double :
The double data type is a double-precision 64-bit IEEE 754 floating point. This data type is generally used as the default data type for decimal values. Double data type should never be used for precise values such as currency. Default value is 0.0d.
Example : double a = 123.4 ;
char :
The char data type is a single 16-bit Unicode character. Char data type is used to store any character.It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65,535 inclusive).
Example : char a = 'b' ;
This are the eight primitive data types in java and you can know about access specifiers which are used with this data types from Access Specifiers In Java.
- A Data Type is the characteristic of a variable that determines what kind of data it can hold.
Java comes with eight primitive data types to handle simple data values. A primitive type is predefined by the language and is named by a reserved keyword. The eight primitive data types supported by the Java programming language are listed below.
boolean :
The boolean data type has only two possible values: true and false. We use this data type for conditional statements. true and false are not the same as True and False. Boolean may not be cast into any other type of variable nor may any other variable be cast into a boolean.
Example : boolean a = true ;
byte :
The byte data type can be useful for saving memory in large arrays, where the memory savings actually matters. It has a minimum value of -128 and a maximum value of 127.
Example : byte a = 200 ;
short :
The short data type is a 16-bit signed two's complement integer. It has a minimum value of -32,768 and a maximum value of 32,767.Short data type can also be used to save memory as byte data type. A short is 2 times smaller than an int.
Example : short a = 20000 ;
int :
The int data type is a 32-bit signed two's complement integer. It has a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647. Int is generally used as the default data type for integral values unless there is a concern about memory. The default value is 0.
Example : int a = 500 ;
long :
The long data type is a 64-bit signed two's complement integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807.
This type is used when a wider range than int is needed. Default value is 0L.
Example : long a = 100000L ;
float :
Float data type is a single-precision 32-bit IEEE 754 floating point. Float is mainly used to save memory in large arrays of floating point numbers. Default value is 0.0f.
Example : float a = 132.5f ;
double :
The double data type is a double-precision 64-bit IEEE 754 floating point. This data type is generally used as the default data type for decimal values. Double data type should never be used for precise values such as currency. Default value is 0.0d.
Example : double a = 123.4 ;
char :
The char data type is a single 16-bit Unicode character. Char data type is used to store any character.It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65,535 inclusive).
Example : char a = 'b' ;
This are the eight primitive data types in java and you can know about access specifiers which are used with this data types from Access Specifiers In Java.
good job.
ReplyDelete