This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes clarify my doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "clarify my doubt" Watch "clarify my doubt" New topic

clarify my doubt

karthik. G gopalan

Joined: Oct 17, 2006
Posts: 5
what is the difference between using int and Integer types in java. and also tel me about the wrapper classes and why they are used.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15101

The data type "int" is a primitive type, and "Integer" is a class; it's a wrapper class for "int".

In Java, primitives are not objects. Sometimes that is inconvenient. For example, in collection classes such as ArrayList, Vector etc. you can only store objects. You can't store primitives in those collections. Wrapper classes are used to represent the primitive types as objects, so you can for example store them in a collection.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: clarify my doubt
It's not a secret anymore!