• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

difference of int and INTEGER

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
whats is the diference in
int i="5"

Integer i=new Integer("5");

thanks
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
int is a primitive, whereas Integer is a class wrapping this primitive.
Integer provides you useful methods to work with integers.
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic