Data Types and keywords in Java

What is a Data Type?
Data type is used to specify the type and their size of data,different languages have different sizes fo the different data types
The data types of Java are classified into two types
- Primitive Data type
- Non-Primitive Data type

Integer type data types
Type | size in bytes | range | Default value | example |
---|---|---|---|---|
int | 4 | โ2,147,483,648 to 2,147,483,647 | 0 | int i=32 |
short | 2 | โ32,768 to 32,767 | 0 | short s=11 |
long | 8 | โ9,223,372,036,854,775,808 to9,223,372,036,854,775,807 | 0 | long l=24235345 |
byte | 1 | โ128 to 127 | 0 | byte b=13 |
float type data types
Type | size in bytes | range | Default value | example |
---|---|---|---|---|
float | 4 | ยฑ3.40282347E+38F | 0.0f | float f=123.10f |
double | 8 | ยฑ1.79769313486231570E | 0.0d | double d=12.10 |
decimal numbers are always classified into double, if user doest use character f .if the user uses suffix f with the value, then it is a float datatype
- Q) Should i use suffix d in the value for double data type in java?
A) There is no difference ,you can use suffix d,or if you wont use the datatype is automatically taken as double
Characters datatype
Type | size in bytes | range | Default value | example |
---|---|---|---|---|
char | 2 | 0 to 65535 | \u0000 (0) | char c=โaโ |
For char type the input value should in singe quotes ,like in the example above the value for c is a ,and this character a is between singles quotes โaโ
Boolean datatype
a boolean data type can be declared using the below syntax, and the value can be either true or false, and this data type cannot be converted into other data types
Non-Primitive Data type
- Non-Primitive Data types are the data types which are called as refernce data types, beacuse they are used to refer objects
- Non-Primitive Data types are not predifined data types,they are user defined by the user ,(string is the only Non-prmitive datatype which is defined by java)
- These are used to refer the objects and they can be used to call methods ,from the class and perform some operations
- While prmitive data tyes have some value,Non prmitive datatype can be assigned with a null .
- Examples for Non-Primitive Data types are Strings, Classes, Arrays, Interface
Keywords in Java
Keywords are the reserved words which can be used to name any variable in the java program. these are predefine and have special meaning and does special task inside the program
abstract | assert | boolean | break | byte |
---|---|---|---|---|
case | catch | char | class | const |
continue | default | do | double | else |
enum | extends | final | finally | float |
for | goto | if | implements | import |
instanceof | int | interface | long | native |
new | package | private | protected | public |
return | short | static | strictfp | super |
switch | synchronized | this | throw | throws |
transient | try | void | volatile | while |