• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

please help me out wityh this program

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ieveryone,
I was going through teh K& B SCJP exam guide .....In the third chapter(Assignments) the section about Wrapper classes quoted something like this.....



It was said that the output would be
same objs
equal objs
since to save memory two wrapper instances with same primitive always satisfy ==

but when I tried out i got the output as
equal objs

can you elucidate why it is so?

P.S :
i also tried out this code(since the int range is -128 to 127) the result is same.......

[ August 21, 2008: Message edited by: Shyam Sunder V R ]
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think what you are saying is in the book

The book has this example



The authors have themselves said that Integer objects are pooled which have a value in the range -128 to 127...
 
Shyam Sunder V R
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also tried the code that you have quoted but it is throwing a type mismatch error for mw....
does this mean all this == and != stuff corrwsponds to java 5 and above bcos I am using java1.4
 
Ranch Hand
Posts: 206
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Shyam

This feature is available with Java5 and not with Java 1.4.

And in the next page of the K&B where that example is given, it is clearly mentioned that the range should be between -128 to 127.
 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Shyam Sunder V R:
Hi ieveryone,
I was going through teh K& B SCJP exam guide .....In the third chapter(Assignments) the section about Wrapper classes quoted something like this.....



It was said that the output would be
same objs
equal objs
since to save memory two wrapper instances with same primitive always satisfy ==

but when I tried out i got the output as
equal objs

can you elucidate why it is so?

P.S :
i also tried out this code(since the int range is -128 to 127) the result is same.......


[ August 21, 2008: Message edited by: Shyam Sunder V R ]



Hey,
did you read the code properly? You initialised a new object using the keyword new
There is a difference between

and


Now I hope you will get the point when you read the book again.
 
Everybody's invited. Even this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic