permaculture playing cards*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes question: Wrappers are immutable 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 "question: Wrappers are immutable" Watch "question: Wrappers are immutable" New topic
Author

question: Wrappers are immutable

Ruobo Wang
Greenhorn

Joined: Jul 27, 2011
Posts: 11


this is from the practice exam1, the answer is D,
i thought it was B.
isn't Wrappers are immutable, and i and i2 both uses the int 420 in the pool.
i actually tested it out.



is there anybody have the same question? thanks!.
John Stark
Ranch Hand

Joined: Jul 19, 2011
Posts: 185
If you change in your example to you get false. In the K & B book it says on page 246 that if you compare (with ==) two wrapper object of type Integer with the same values then you get true when the common value is between -128 and 127.

John
Naveen Madarapu
Ranch Hand

Joined: May 24, 2011
Posts: 64

if wrapper1 and wrapper2 corresponding wrapper classes containing same primitive values then it is always the case that wrapper1 == wrapper2 as true when a char in the range \u0000 to \u007f(0-127), and remaining primitive numbers between -128 and 127.


OCPJP
Naveen Madarapu
Ranch Hand

Joined: May 24, 2011
Posts: 64

That is work when you are assigning the literal only if you are assigning the objects it show different result.

you can watch this thread it may be helpful to you.

http://www.coderanch.com/t/536466/java-programmer-SCJP/certification/Integer-class-ocp-exams-book
Ruobo Wang
Greenhorn

Joined: Jul 27, 2011
Posts: 11
ohhhhhhhh yes! can't believe i forgot about this!.

thank you john and naveen!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question: Wrappers are immutable