Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Why need Integer class ?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(int) VarName // Standard Type Casting
(Integer) VarName // Is it still casting ?
Why do we need (Integer) class ?
When do we apply with it ?
Example please.
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tom
Welcome to the Java Ranch, we hope you�ll enjoy visiting as a regular however,
your name is not in keeping with our naming policy here at the ranch. Please change your display name to an appropriate name as shown in the policy.
Thanks again and we hope to see you around the ranch!!
Tom, a more appropriate question is why are there primitives if Java is supposed to be an object oriented language. The primitives are there to speed things up and allow the compiler to make optimizations. In a pure object oriented language there qwould be no primitives and you would only have the objects (Integer, Double, Boolean, etc. ).
A big use is in collections that can only hold objects you can not put an int there but an Integer works just fine.
hope that helps
 
author
Posts: 9034
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All of the primitive types have their own 'wrapper' class so that whenever you want to treat any of your primitives like an object you can 'wrap' them in an object.
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to use instead of primitive type (int,
float, double,...) wrapper classes if you use
it with Vector, Hashtable, ArrayList, Map, ... etc. Because in standard Java no exist Vector of
int, only Vector of Object.
(Of course exists a lot of non-standard implementation of int vector, because it's
important sometime to optimize code; wrapping isn't time and memory effective).
----------------------------------------------
As I understand will be in java 1.5 template
construction like Vector<...> is only syntax sugar. (I read somewhere that it will be the same
container library: Vector, Hashtable... for template and non-template syntax usage)
And doesn't solve the problem.
Am I right ?
 
My favorite is a chocolate cupcake with white frosting and tiny ad sprinkles.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic