This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
An int is a "simple" primitive data type; its use in Java is pretty much the same as it is in other languages. An Integer is an actual class; a "wrapper" for the primitive int type for situations where you might need to use an object rather than a primitive.
sometimes if you want to cast int to String, you must use the wrapper class integer to get it. for example int i=5; String s=Integer.toString(5); or inverse cast: String s="5"; int i=Integer.parseInt(s); i always use the integer in casting type..... you also can cast int to Integer or inverse. int i=5; Integer in=new Integer(i); inverse cast Integer in=new Integer(5); int i=in.intValue(); generally data passing must be using Class.......and int/long/double is not a Class.... [ August 28, 2007: Message edited by: lei feng ]
Java provides wrapper classes to most of its primitive data types. Wrapper classes are nothing special they are normal classes with a place for primitive data type it represents along with some methods which act on its datatype. And there are times when we need these methods and hence some times we need to use wrapper classes instead of primitive data type. Another benefit is that primitive data types are not objects by themselves, but when you embed your primitive data type into its respective wrapper class you can create object and pass it, - useful when we need to pass an object to any method.