wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Help on wrapper classes and autoboxing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help on wrapper classes and autoboxing" Watch "Help on wrapper classes and autoboxing" New topic
Author

Help on wrapper classes and autoboxing

Ankit Up
Greenhorn

Joined: Jun 13, 2009
Posts: 4
Hey guys,
I have just started learning java from Thinking in Java 4th ed.
I read in chapter 2 about wrapper classes and autoboxing but i am unable to understand it.
Please explain it for me in simple words.
I am giving here the text.

Kumar Kamlesh
Greenhorn

Joined: May 10, 2009
Posts: 15
Ankit,

Java supports primitive data types such as byte, short, int, long, boolean etc. Since Java is a Object Oriented Programming language it provides a special class for each of the data type known as wrapper classes. For example, for int you have Integer, for long you have Long, for boolean you have Boolean and so on. Wrapper classes provide you the mean to convert a primitive type into corresponding wrapper type and vice versa. They also contain many utility methods in addition. For details you can refer to java documentation.

Autoboxing is a feature of Java SE 5, which automatically does the conversion between a primitive type to its wrapper type and vice versa. In your given example the following:

char c = ch;

won't work in the versions of java prior to Java SE 5. For the previous versions you explicitly need to write the code for conversion.

Hope this explains your question.

- Kamlesh
A Student of Java
 
 
subject: Help on wrapper classes and autoboxing