DATAYPE AND WRAPPER CLASS
DATATYPE
- Java language support the concept of primitive datatype like c or c++
- If a language support primitive datatype that language cannot be a pure object oriented programming language.
- To make java language pure object oriented it supports the concept of wrapper class.
- As java language support the concept of architecture neutral the size of primitive data type is fixed for all the environment.
WRAPPER CLASS
- For each datatype java provide a predefined class ,technically known as wrapper class in java.
- Wrapper class are used to convert data type an object .In java primitive datatype are not object they don’t belongs to any class.
- All the wrapper class present in java.lang package.
- Wrapper class are also used for type conversion.
- All the wrapper class are final class it can’t be inherited.
DATATYPES | WRAPPER CLASS |
SIZE |
DEFAULT VALUE |
byte | Byte | 8bits | 0 |
char | Character | 16bits | /u |
short | Short | 16bits | 0 |
int | Integer | 32bits | 0 |
long | Long | 64bits | 0L/0l |
float | Float | 32bits | 0.0f |
double | Double | 64bits | 0.0 |
Boolean | Boolean | 1bit | false |
NOTE Signed and unsigned keyword are not available in java like c or c++,by default datatype is always signed in nature.
PARSEBYTE( ) –This is a static method present in byte wrapper class which is used to convert a string to a byte type.
TOSTRING( )- This is a predefined static method present in each wrapper class which convert a datatype to string format.
charAt( )- This method is used to get character of a specific index.
ToBinaryString( )- This method is convert integer to binary and return value into a string format.
toOctalString( )- This method is convert integer to octal and return value into a string format.
toHexaString( )-This method is convert integer to hexadecimal and return value into a string format.
CurrentTimeMillis( )-It is a predefined static method present in system class which always return the system time in mill sec format.
6 replies on “Data type and Wrapper class in java”
This actually answered my problem, thank you!
Thanks for giving the feedback
This is really interesting, You’re a very skilled blogger. I have joined your feed and look forward to seeking more of your wonderful post. Also, I’ve shared your web site in my social networks!
Thanks for giving the feedback. Thanks a lot
Your story was really informative, thanks!
thanks