Java platform provides primitive data types has a class dedicated to it. These are known as wrapper classes, because they "wrap" the primitive data type into an object of that class. Often, the wrapping is done by the compiler-if you use a primitive where an object is expected, the compiler boxes the primitive in its wrapper class for you. Similarly, if you use a number object when a primitive is expected, the compiler unboxes the object for you.So, there is anInteger class that holds an int variable, there is a Double class that holds a double variable, and so on.
Example for primitive data types and classes
Primitive type Wrapper class Constructor Arguments
int Integer int or String
long Long long or String
float Float float, double or String
boolean Boolean boolean or String
Example for primitive data types and classes
Primitive type Wrapper class Constructor Arguments
byte Byte byte or String
short Short short or String int Integer int or String
long Long long or String
float Float float, double or String
double Double double or String
char Character charboolean Boolean boolean or String
No comments:
Post a Comment