This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
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

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help on wrapper classes and autoboxing" Watch "Help on wrapper classes and autoboxing" New topic

Help on wrapper classes and autoboxing

Ankit Up

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

Joined: May 10, 2009
Posts: 15

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
I agree. Here's the link:
subject: Help on wrapper classes and autoboxing
jQuery in Action, 3rd edition