• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Errata-OCP Oracle Certified Professional Java SE 11 Programmer I Exam 1Z0-815 (Ch.5,Page no: 316,317

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Page No: 316
String singleString = "hello world";
String oneLine = "hello " + "world";
System.out.println(singleString == oneLine);

Both print false. Concatenation is just like calling a method and
results in a new String.


Page No: 317
15: String first = "rat" + 1;
16: String second = "r" + "a" + "t" + "1";

18: System.out.println(first == second);
19: System.out.println(first == second.intern());


On line 15, we have a compile-time constant that automatically gets
placed in the string pool as "rat1". On line 16, we have a more
complicated expression that is also a compile-time constant.
Therefore, first and second share the same string pool reference. This
makes line 18 and 19 print true.

You have discussed the same topics, but the logic is quite contradictory.
1.png
Screen shot
Screen shot
 
Bartender
Posts: 3692
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree, in the first code it seems that " helloworld" is compared with "hello world", which may not be true for sure 8-)
We can't consider it as an error, because false will be printed and false mentioned in the book, but probably it's a typo.
Only Authors know if it's a typo... 8-)
 
Shankar Ghimire
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mikalai Zaikin wrote:I agree, in the first code it seems that " helloworld" is compared with "hello world", which may not be true for sure 8-)
We can't consider it as an error, because false will be printed and false mentioned in the book, but probably it's a typo.
Only Authors know if it's a typo... 8-)



I'm not talking about "hello world" and "helloworld". or "hello " + "world", space after the letter 'o' in "hello ".

I am talking about the reason the author has mentioned.
"Concatenation is just like calling a method and results in a new String." on page no 316
and
"a compile-time constant that automatically gets placed in the string pool as "rat1" " on page no. 317.

On both examples, the concatenation operator '+' has been used. so, I got confused.

 
Ranch Foreman
Posts: 323
8
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See this recent thread:
https://coderanch.com/t/739996/certification/Java-String-compile-time-constant

It doesn't have the right book in the thread name, but I think it is the same stuff.
 
I got this tall by not having enough crisco in my diet as a kid. This ad looks like it had plenty of shortening:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic