File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes difference of int and INTEGER Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "difference of int and INTEGER" Watch "difference of int and INTEGER" New topic
Author

difference of int and INTEGER

varungoyal goyal
Ranch Hand

Joined: May 31, 2006
Posts: 37
whats is the diference in
int i="5"

Integer i=new Integer("5");

thanks
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

int is a primitive, whereas Integer is a class wrapping this primitive.
Integer provides you useful methods to work with integers.


[My Blog]
All roads lead to JavaRanch
Arjun Palanichamy
Ranch Hand

Joined: Jul 15, 2006
Posts: 51
Hi Venu...

int is Java premitive data type. but INTEGER is Wropper Class .is it use for some java collection class dosnt support direct java primitive data type when we will cnvert and use primitive data type to wropper class object type.

you will refer all java util packages.

==============================================

Arjun Palanichamy.
Chennai.
Arjun Palanichamy
Ranch Hand

Joined: Jul 15, 2006
Posts: 51
Hi Varun...

Here int is Java primitive data type. but INTEGER is Wrapper Class .Is it use for some java collection class dosnt support direct java primitive data type when we will convert and use primitive data type to wrapper class object type.

you will refer the java util packages.

==============================================

Arjun Palanichamy.
Chennai.
Vlado Zajac
Ranch Hand

Joined: Aug 03, 2004
Posts: 245

This does not work, since "5" is String and String cannot be implicitly converted to int.

This is OK, is creates int variable i and initializes it with value 5;

This is also OK. It creates Integer variable i, creates an object using Integer(String) constructor with parameter "5" and initializes i with reference to that object.

This is also OK, it just uses different constructor.

This will compile, but throws exception at run-time, since "aaa" cannot be converted to any number.
[ August 18, 2006: Message edited by: Vlado Zajac ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: difference of int and INTEGER