File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes please help me out wityh this program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "please help me out wityh this program" Watch "please help me out wityh this program" New topic
Author

please help me out wityh this program

Shyam Sunder V R
Greenhorn

Joined: Jul 29, 2008
Posts: 20
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

Joined: Aug 03, 2008
Posts: 9302
    
  17

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...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Shyam Sunder V R
Greenhorn

Joined: Jul 29, 2008
Posts: 20
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

Joined: Oct 09, 2007
Posts: 206

@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.


Enjoy, Chander
SCJP 5, Oracle Certified PL/SQL Developer
Paul Somnath
Ranch Hand

Joined: May 19, 2008
Posts: 177
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.


Preparing for SCJP 6.0
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: please help me out wityh this program