Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

please help me out wityh this program

 
Shyam Sunder V R
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • 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 ]
 
Ankit Garg
Sheriff
Posts: 9580
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
chander shivdasani
Ranch Hand
Posts: 206
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
Paul Somnath
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic