• 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

Wrapper classes?

 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The statements below,

Boolean b1 = Boolean.valueOf("True");
Boolean b2 = Boolean.valueOf("True");
System.out.println(b1 == b2); //prints true

Double d1 = Double.valueOf("10");
Double d2 = Double.valueOf("10");
System.out.println(d1 == d2);//prints false

Any reasons??
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have already asked this question here: https://coderanch.com/t/260776/java-programmer-SCJP/certification/Boolean-Wrappers

Also see https://coderanch.com/t/260471/java-programmer-SCJP/certification/Wrapper
[ December 21, 2006: Message edited by: Aniket Patil ]
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In order to save memory, two instances of the
following wrapper objects will always be == when their primitive values are the same:
Boolean
Byte
Character from \u0000 to \u007f (7f is 127 in decimal)
Short and Integer from -128 to 127

hope that will help.
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And what about this?

Long l = -128L;
Long m = -128L;
System.out.println(l==m);


Yours,
Bu
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is This applicable for 1.4 , as in my case below code is giving false...


Integer i = Integer.valueOf("1");
Integer j = Integer.valueOf("1");
System.out.println(i==j);

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


And what about this?

Long l = -128L;
Long m = -128L;
System.out.println(l==m);



its clearly written at SCJP FAQs on javaranch

Note: The Java Language Specification does not explicitly guarantee this behavior for long values within the range of a byte.
[ December 21, 2006: Message edited by: Kalpesh Jain ]
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[hemadri raju]: In order to save memory, two instances of the
following wrapper objects will always be == when their primitive values are the same:


Always?
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
can you please mention the source from where to study above all.
is it part of SCJP1.4???
I've read K&B (SCJP1.4) but this is not covered there so please tell me the source for the same.
Regards
 
Ranch Hand
Posts: 502
jQuery Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For SCJP 1.4 exam, whatever there in K&B book is fine.

If you want learn about wrapper classes. Lot of links available in SCJP FAQ
 
reply
    Bookmark Topic Watch Topic
  • New Topic