Data Types in java
The Data type specifies the type
of data stored in the system. Any variables declared in java have to be
specified with data type and has to be declared.
There are 2 types of Data Types in java,
Primitive Data type
Data Type
|
Default Value (for fields)
|
Byte
|
0
|
Short
|
0
|
Int
|
0
|
Long
|
0L
|
Float
|
0.0f
|
Double
|
0.0d
|
Char
|
'\u0000'
|
String (or any object)
|
null
|
Boolean
|
false
|
Wrapper Class
In Java everything is treated as an object. The wrapper class
used to convert Data types into Object.
As the name says, a wrapper class wraps (encloses) around
a data type and gives it an object appearance.
Wrapper classes include methods to
unwrap the object and give back the data type.
Primitive Data Type
|
Wrapper Class
|
byte
|
Byte
|
short
|
Short
|
int
|
Integer
|
char
|
Character
|
boolean
|
Boolean
|
double
|
Double
|
float
|
Float
|
Fields (variables)
Any
Field (variable) declared in java has to specify the Data type.
Int
x,y; //// x, y are variables of int data
type and used to store numbers
String
s1,s2; ///////// s1, s2 are variables
of string type and will allow to store alphanumeric values
Comments
Post a Comment