Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please Help, need clarification about K&B book Self-Test Questions

 
David Yu
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I finished the K&B book during my week of vacation, studied key points and wrote the mock exam. Results wasn't that great, I achieved a mark of 56 percent which fell short of passing by 3 percent. I read in other posts that the real exam specifies the number of correct answers. Hopefully that will make selection easier. I plan to try several more mock exams before writing the actual one. By the way, for those who passed the exam, how difficult is the real exam compared to the K&B mock exam? despite studying hard, I still failed which I am a bit disappointed about.

While trying the Self-Test questions of the K&B, I stumbled upon a number of questions. I will greatly appreciate it if anyone can provide any clarification.

Solution to Question 7 on p.269:
segment of code contains 2 arrays: a string array and an array of long values. Is it okay to use either an object or array of objects as the reference variable of arrays?

Solution to Question 9 on P.271:
the last line where it says "System.out.println(tooth);", how does the compiler know whether to use the static variable or the local variable?

Solution to Question 12 on p.517
I am wondering what does the File.separtor do? I try looking it up on the internet but the explanation is a bit vague

Solution to Question 13 on p.752
the answer states that an "IllegalThreadStateException is thrown when the code does not acquire a lock on the object before calling wait()". However, on p.721, it states "if the thread calling wait() does not own the lock, it will throw an IllegalMonitorStateException, an unchecked exception". So which one is it, IllegalThreadState or IllegaalMonitorState? it makes a huge difference because one of them is an unchecked which does not need to be handled.


Thank you for your time. =)
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First off, have you checked the K & B errata (see link at the top of this forum)?
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
File.separator is simply a string with a File.separatorChar in it.
Documented in java.io.File API:
separatorChar

public static final char separatorChar

The system-dependent default name-separator character. This field is initialized to contain the first character of the value of the system property file.separator. On UNIX systems the value of this field is '/'; on Microsoft Windows systems it is '\\'.
 
Valery Lezhebokov
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David Yu:

Solution to Question 7 on p.269:
segment of code contains 2 arrays: a string array and an array of long values. Is it okay to use either an object or array of objects as the reference variable of arrays?


Any array is an Object. =>
Is it okay to use either an object - yes
Array of objects - yes for strings, no for long arrays


Solution to Question 9 on P.271:
the last line where it says "System.out.println(tooth);", how does the compiler know whether to use the static variable or the local variable?

read about shadowing...
 
Valery Lezhebokov
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and as for the last question: IllegalMonitorStateException
 
David Yu
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for the rapid responses, greatly appreciate it.

I am just going to ask one more question instead of opening another forum topic. Is it okay to mark an overridden method as final? I thought that overridden method has to be less restrictive than the superclass method. However, on the K&B mock exam, it states on one of the questions that it's okay to mark an overridden method as final.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please, in future, do use separate topics, otherwise the thread gets confusing.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. final prevents someone overriding the subclass' method any further. The access qualifiers private, package (default), protected, public have nothing to do with the method being final.
[ December 18, 2006: Message edited by: Barry Gaunt ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic