• 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

Few remarks about Online Mock Exam 2 (Java OCA 8 Programmer I Study Guide)

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In question 56:



The answer says - Answer: F

But there is no methods in LocalDate class with year and month or year and date. So the answer should be D. -> The code does not compile.

 
Shiva Kotha
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
60. Which of the following are true? (Choose all that apply)



A. The code compiles.
B. The code does not compile.
C. If statements that do not compile are removed, the output contains one.
D. If statements that do not compile are removed, the output contains two.
E. If statements that do not compile are removed, the output contains three.
F. If statements that do not compile are removed, the output contains four.

The answer is mentioned as B and D. But D is not correct. s1.equals(s2) returns false in this case. So answer is only B.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Shiva Kotha,

First of all, a warm welcome to CodeRanch!

Shiva Kotha wrote:The answer says - Answer: F

But there is no methods in LocalDate class with year and month or year and date. So the answer should be D. -> The code does not compile.


Shiva Kotha wrote:60. Which of the following are true? (Choose all that apply)

The answer is mentioned as B and D. But D is not correct. s1.equals(s2) returns false in this case. So answer is only B.


You are correct on both occasions! These issues were already reported here and are already on the official errata overview.

Hope it helps!
Kind regards,
Roel

PS. Because both topics were about the same mock exam, I merged both topics into one. Hope that's ok with you!
 
Ranch Hand
Posts: 789
Python C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
s1.equals(s2) is false is unfathomable...
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Guillermo Ishi wrote:s1.equals(s2) is false is unfathomable...


It's not at all! StringBuilder doesn't override the equals() method of class Object. So the equals() method will only return true if s1 and s2 refer to the same StringBuilder instance.
 
Guillermo Ishi
Ranch Hand
Posts: 789
Python C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roel De Nijs wrote:

Guillermo Ishi wrote:s1.equals(s2) is false is unfathomable...


It's not at all! StringBuilder doesn't override the equals() method of class Object. So the equals() method will only return true if s1 and s2 refer to the same StringBuilder instance.


Is there a method behind that madness?
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Guillermo Ishi wrote:

Roel De Nijs wrote:

Guillermo Ishi wrote:s1.equals(s2) is false is unfathomable...


It's not at all! StringBuilder doesn't override the equals() method of class Object. So the equals() method will only return true if s1 and s2 refer to the same StringBuilder instance.


Is there a method behind that madness?


Sure! That's why it's not madness but common sense

A StringBuilder's main and only purpose is to build strings (without creating a new String on every operation), hence it's name So it's kind of a helper class, and you only will use it to do a bunch of string manipulations (append, replace, insert, remove,...) to end up with an actual String (by invoking the toString() method). So the Java API developers decided not to implement/override the equals() method, because nobody will ever be interested to know if two StringBuilders are meaningfully equal. Everybody will use them to create strings, not to compare them.

If I look at my own codebase of our application, only a very tiny percentage of our classes override the equals() (and hashCode()) method(s) for exactly the same reason. For example: a repository is used to access the database and perform some CRUD (create, read, update and delete) operations, not to compare if this repository is meaningfully equal to another one.

Hope it helps!
Kind regards,
Roel
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic