• 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

what is the answer?

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


am getting the answer false..but my friend is getting true on his computer....

what according to you be the answer?
 
Ranch Hand
Posts: 400
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankur kothari wrote:but my friend is getting true on his computer....



Are you sure? because I'm also getting true
 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


according to this a new Integer would be created....so == should be false....even in one of the earlier
posts the answer was false

https://coderanch.com/t/456591/Programmer-Certification-SCJP/certification/Difference#2035712
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It depends. The default Integer cache used by Integer.valueOf() ranges from -128 to 127 (inclusive), but as of release 1.6.0_14 the cache size is configurable.

See: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6807702
 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankur kothari wrote:
am getting the answer false..but my friend is getting true on his computer....

what according to you be the answer?




It should be false. The integer cache doesn't apply to the valueOf method, that takes a string. It applies to the valueOf() method that takes an int.

Henry
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jelle Klap wrote:It depends. The default Integer cache used by Integer.valueOf() ranges from -128 to 127 (inclusive), but as of release 1.6.0_14 the cache size is configurable.

See: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6807702



This is actually within specs. The JLS specifies the range that must be cached. It doesn't state that those values outside of that range must not be cache. It is perfectly valid to cache a range that is larger than required by the JLS.

Henry
 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so you mean getting true on my friends computer is right in ways too? what if this comes in the exam?
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See also:
https://coderanch.com/t/466883/Programmer-Certification-SCJP/certification/Integer-valueOf-method

apparently JVM dependend.
so probably not on exam.
 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic