GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes 'Who wants to be a millionaire?' style practice test Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark " Watch " New topic
Author

'Who wants to be a millionaire?' style practice test

Robert James Miller
Greenhorn

Joined: Feb 26, 2005
Posts: 6
Hello, I'm a big fan of the JavaRanch community. I used these Forums and this site to help me pass each of my four Sun certifications. Recently, I created a practice test for the SCJP. I hope it will be beneficial for those studying to take the test. Let me know what you think:
http://www.jhound.com/java/quiz.do

Thanks,
Rob


SCJP,SCWCD,SCDJWS,SCEA
Kedar Dravid
Ranch Hand

Joined: May 28, 2004
Posts: 333
Thanks Robert,
your millionaire-style test is a really good one.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Very fun way of practicing. Just needs some more questions. And it would also be neat if as you go higher the questions get harder.

Thanks

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Very unique & good style .
I have beaten the test .. haha
[ February 27, 2005: Message edited by: rathi ji ]
Giovanni De Stefano
Ranch Hand

Joined: Aug 17, 2004
Posts: 144
Hi!

Your test is great!!!

You have beaten the JavaHound in Certification Millionaire! Good luck on passing the "Sun Certified Programmer for the Java 2 Platform" test.

I hope I will pass the REAL test...

Thank you!!!
Gio :-)


SCJP 1.4
Veer Batra
Ranch Hand

Joined: Mar 12, 2001
Posts: 35
Here it goes. I am millionare too. Thanks for this interesting format and giving an opportunity to raise the our confidence.

Beat the JavaHound in Certification Millionaire
You have beaten the JavaHound in Certification Millionaire! Good luck on passing the "Sun Certified Programmer for the Java 2 Platform" test.
Robert James Miller
Greenhorn

Joined: Feb 26, 2005
Posts: 6
Thank you for the feedback. I'll work on adding more questions and making the big money questions a little harder.

Rob
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608

Beat the JavaHound in Certification Millionaire
$1,000 Question: In which scenario will both sides of the relational operator be evaluated?
if(true && true)
if(false && true)
if(true || false)
if(true || true)


Correct Answer: None of the above. They will be evaluated at compile-time and no specification mandates how they are evaluated.


Tony Morris
Java Q&A (FAQ, Trivia)
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608

Beat the JavaHound in Certification Millionaire
$2,000 Question: Which statement regarding Strings is NOT true?
Strings are constants (A)
During String concatenation the compiler uses StringBuffers (B)
String tempA = "hello"; and String tempB = "hello"; share the same space in memory (C)
String tempA = "hello"; and String tempB = tempA+""; then (tempA == tempB) evaluates to true (D)


Correct answer: All of the above.
A Strings are not constants.
B String concatenation does not imply the use of a StringBuffer - a concatenation may be evaluated at compile-time using some compiler-specific mechanism.
C We've had this argument before - two String literals don't share the same instance, let alone memory space (which are two very distinct things) - this is false on 2 levels.
D Evaluates to false

Now which one will I pick?
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608

Beat the JavaHound in Certification Millionaire
$8,000 Question: Independent from each other, which line of code is NOT valid?
package com.jhound.java;
import java.util.ArrayList;
protected interface IJHoundMillionaireQuiz {
public class JavaCertificationQuiz implements IJHoundMillionaireQuiz {


They are all valid.
A nested interface may be declared protected, but I'm going to assume this is erroneously the correct answer (oxymoron).

*click*
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608

Beat the JavaHound in Certification Millionaire
$250,000 Question: Which statement regarding the garbage collector is NOT true?
An object is eligible for garbage collection when there are no more references to that object
Explicitly drop an object reference by setting the object's value to null, e.g. Object o = null;
It gives the object an opportunity to clean up after itself through a call to the object's finalize method
It only runs after a call to System.gc();


Correct Answer: None of the above, but I'm guessing the incorrect correct answer is the last one.
An object is eligible for garbage collection when there ae no more strong references to it. A very important distinction.
Reassigning a reference has got nothing to do with an object and whether or not it becomes eligible for garbage collection, other than it means there is one less strong reference to it.
The finalize() method is invoked when the object is garbage collected. It is not intended for cleaning up (though I've seen a few people try). It is not guaranteed to be executed because an object is not guaranteed to be collected. The only justifiable use that I've ever had was to fail early when an object is collected when it is not in a correct state to be collected i.e. public void finalize(){if(thisObjectHasntBeenCleanedIpProperly()){throw new IllegalStateException("Client of this object has a bug");}}

*click*
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
And now for the million dollar question, and I can't even guess the intended answer using intuition and common fallacy:


Beat the JavaHound in Certification Millionaire
$1,000,000 Question: Which statement regarding Threads is NOT true?
A thread will run until its stop() method is called
The start() method allocates system resources, schedules the thread to run, and calls the thread's run() method
The Thread class implements a generic thread that, by default, does nothing
Customize a Thread's run() method by either subclassing java.lang.Thread or implementing java.lang.Runnable


Well I know that the first one isn't true, or the second one, or the third one ... which will I choose? I can only choose one.

Great idea, a shame that the questions/answers are incorrect. Don't despair, every single mock exam that I've ever seen has some degree of error. Be the first person to have a correct mock exam and the benefits of actually doing them might increase!! I became sceptical of the value of mock exams after doing about 7 or 8 that were blatantly incorrect and misleading.

Good luck mate.

*click*

Woohoo!! I guessed right!
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Anyway, a nice game.

Nick


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Beat the JavaHound in Certification Millionaire
$1,000 Question: In which scenario will both sides of the relational operator be evaluated?
if(true && true)
if(false && true)
if(true || false)
if(true || true)


Correct Answer: None of the above. They will be evaluated at compile-time and no specification mandates how they are evaluated.


Tony , why the first one is not correct .

Thanks .
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
Because "They [the expressions] will be evaluated at compile-time and no specification mandates how they are evaluated."

How else can it be said? Is that unclear somehow?
Kedar Dravid
Ranch Hand

Joined: May 28, 2004
Posts: 333
Beat the JavaHound in Certification Millionaire
$1,000 Question: In which scenario will both sides of the relational operator be evaluated?
if(true && true)
if(false && true)
if(true || false)
if(true || true)


Correct Answer: None of the above. They will be evaluated at compile-time and no specification mandates how they are evaluated.

Correct answer: if(true && true)
Explanation:
The right-hand operand of the short-circuit && operator is evaluated only if the left-hand operand evaluates to true.
Joyce Lee
Ranch Hand

Joined: Jul 11, 2003
Posts: 1392
if(true && true)

Since both are boolean literals, the expression will be evaluated at compile-time.

For example,


would be evaluated at compile-time to become something like this


Another example,


would be evaluated to become something like this


This can be confirmed by reading the bytecodes or decompiled code.

JLS2 15.23

At run time, the left-hand operand expression is evaluated first; if its value is false, the value of the conditional-and expression is false and the right-hand operand expression is not evaluated. If the value of the left-hand operand is true, then the right-hand expression is evaluated and its value becomes the value of the conditional-and expression.

Joyce
[ March 01, 2005: Message edited by: Joyce Lee ]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[Tony]: Correct Answer: None of the above. They will be evaluated at compile-time and no specification mandates how they are evaluated.

Seems to me that the first answer is correct. They'll be evaluated at compile time, true, but they will be evaluated. The specification does seem to leave a loophole in that it doesn't really specify what the result of this compile-time evaluation should be - except to say it's "like" the & operator. Empirically, it's easy to verify in any JDK that

prints a different result than

which confirms that the second argument must have been evaluated, as we'd expect.


"I'm not back." - Bill Harding, Twister
Joyce Lee
Ranch Hand

Joined: Jul 11, 2003
Posts: 1392
Hmm...Jim, how about reverse? Can you be sure that the second operand is not evaluated?

Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
Jim,
You have a valid argument, not that I'm willing to concede
In any case, the intention here is to do a practice SCJP exam, not to guess the intention of the exam writer (which is how I answered most questions).

For example, my guess for that question is that the exam author intended to use non constant boolean expressions instead of true/false literals.

Perhaps I'm right in my assertion of the correct answer, or perhaps you are right given your perspective (which I was well aware of at the time), however, the fact that there is ambiguity here is more of a concern than the actual correct (if there is one) perspective. That is to say, the intention wasn't a lesson on compiler theory, but a certification exam.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[Joyce]: Hmm...Jim, how about reverse? Can you be sure that the second operand is not evaluated?

Not with a test link that, no, I don't see any way to do so (except maybe to analyze the source for the compiler, which doesn't sound like much fun to me.). From the JLS perspective, "The && operator is like & (�15.22.2), but evaluates its right-hand operand only if the value of its left-hand operand is true." (JLS 15.23) The "if and only if" seems to guarantee that the second operand is not evaluated in (false && true). The JLS does become ambiguous several lines later when it says "At run time..." and omits any mention of how compile-time constant expressions are to be evaluated (though we may guess they are intended to be evaluated much the same way, but at compile time). I don't think this ambiguity affects the earlier "if and only if" statement though.

[Tony]: the fact that there is ambiguity here is more of a concern than the actual correct (if there is one) perspective.

Agreed. Though there are those of us who are interested in the gritty details, this doesn't really matter for the purposes of most people here studying to take the exam. Perhaps instead of pronouncing answers right or wrong, it would be more constructive to give suggestions as to how ambiguities and unintentional subtleties could be removed, to make a better question. E.g. in this case, getting the compile-time constants away from the && and || would pretty much remove our concerns, right?

In which scenario will both sides of the relational operator be evaluated?
boolean a = true, b = false;
(1) System.out.println(a && a);
(2) System.out.println(b && a);
(3) System.out.println(a || b);
(4) System.out.println(a || a);

Or maybe:

Given these method definitions:

public boolean a() { System.out.print("X"); return true; }
public boolean b() { System.out.print("X"); return false; }

Which expressions would cause "XX" to be printed when evaluated?

(1) a && a
(2) b && a
(3) a || b
(4) a || a
[ March 01, 2005: Message edited by: Jim Yingst ]
Joyce Lee
Ranch Hand

Joined: Jul 11, 2003
Posts: 1392
Perhaps instead of pronouncing answers right or wrong, it would be more constructive to give suggestions as to how ambiguities and unintentional subtleties could be removed, to make a better question.

Good idea, Jim!
Kedar Dravid
Ranch Hand

Joined: May 28, 2004
Posts: 333
From the book by Khalid Mughal & Rolf Rasmussen:
The right hand operand of the && operator is evaluated if and only if the left-hand operand is true.
In the first case, true&&true, the right-hand operand is evaluated since the left-hand operand is true.
So, option 1 is correct.
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
When did some arbitrary technical book become the definitive source?

I might just break out the 10 or so books I have here that inadvertantly portray untruth (much like the author of the mock exam) and claim them as The Truth.
trivikram Kumar
Ranch Hand

Joined: Feb 21, 2005
Posts: 172
Hi Rob,

I have beaten the exam...where are my dollars???Hahahhaha...just kidding....
What a wondeful and interractive and interesting way to learn Java....
Hats off...for your talent Rob...Eager to see more and more questions of that type from you...

That was very evry helpful...
Hope i wou;d clear the real exam too with an easy comfort.....

Thanks,
S Javainn


Javainn<br /> <br />SCJP,SCWCD,SCBCD,<br />ICED (IBM-287,IBM-484,IBM-486)
IBM certified in DB2 V 8.1 Family Fundamentals (IBM 700)
Jay Pawar
Ranch Hand

Joined: Aug 27, 2004
Posts: 411
Originally posted by Joyce Lee:
Hmm...Jim, how about reverse? Can you be sure that the second operand is not evaluated?



Joyce,
I am making an humble attempt to prove this.


Hello is not printed that shows the second operand was not evaluated. Is that what you meant ?


Cheers,<br />Jay<br /> <br />(SCJP 1.4)<br />Heights of great men were not achieved in one day, they were toiling day and night while their companions slept.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Jay - we were talking specifically about the case where the expression is a compile-time constant expression. By replacing true with display(), the expression is no longer a compile-time constant. Getting rid of the constants would make a better test question, but it doesn't show anything about the behavior we were discussing, which is specifically about constants.
Jay Pawar
Ranch Hand

Joined: Aug 27, 2004
Posts: 411
Jim,
Ok I got your point. I am trying again with slight modification to the code. This time using final variable.Let me know if that is still wrong.



From the link you provided, here is excerpt about final variables.

A compile-time constant expression is an expression denoting a value of primitive type or a String that is composed using only the following:

# Simple names that refer to final variables whose initializers are constant expressions
# Qualified names of the form TypeName . Identifier that refer to final variables whose initializers are constant expressions.



I believe boolean variable b is compile-time constant.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[Jay]: I believe boolean variable b is compile-time constant.

Yes, it is. However in the expression ( false && display() ), display() is not a compile-time constant expression (because a method call can never be part of a constant expression). So this expression is evaluated at runtime, not compile time.
Jay Pawar
Ranch Hand

Joined: Aug 27, 2004
Posts: 411
Jim,
Ok I understood what you mean. Well... in that case it is very difficult to prove
 
GeeCON Prague 2014
 
subject: 'Who wants to be a millionaire?' style practice test