This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!

Suhrid Karthik

Ranch Hand
+ Follow
since Aug 31, 2008
Suhrid likes ...
Eclipse IDE Java Ubuntu
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Suhrid Karthik

The official objectives are here. As of now, Serialization is not an objective.
How to deal with changing objectives can help answer your other questions.
Serialization is not on the exam's objectives as of now. However, I suppose it was removed somewhat recently, so a lot of the mock exams do have serialization based questions. I guess, it's good to be familiar with the topic, but you wouldn't have to delve into it for the sake of the exam.
The Thread class itself implements Runnable. Hence, since C extends Thread, C also IS-A Runnable.
Thank you all.

@ravisankar: Regarding GC - The best way I think is to draw diagrams with references pointing to objects. For Regex, read the official Java tutorial and use the test harness program described there to practice different regex patterns. For Generics, I think the material in Sierra, Bates is good enough from the exam point of view - for better understanding try : official Java tutorial on Generics or the Effective Java book's chapter on Generics. (PDF)
10 years ago

Nitesh Nandwana wrote:Java class can be public and default, whereas it cant be private because it'll be useless but why it'cant be protected.I don't believe in rules although i believe in reason, please satisfied me .

Inner classes can be protected. Only classes in the same package and subclasses of the outer class in different packages would then be able to access the protected inner class.
Thanks go out to all the study guide and the official Java tutorials authors and the good folks here at JavaRanch.

Here's what worked for me :

Preparation material: The Sierra and Bates book, the Sierra, Bates Practice Exams book , the Mughal and Rasmussen book and the excellent Official Java SE tutorials. Sierra and Bates is the more readable and "fun" book. If you are buying just one book - this would be my choice. However, some of the topics are covered sparingly, for e.g. Enums and Generics. (Note: I had the older Sierra/Bates Java 5 Exam Guide). I understand that the authors are trying to focus on the content only from the examination point of view, but in case you feel that you need in depth coverage - then Mughal,Rasmussen is your bet. This book delves into all topics comprehensively and sometimes focuses on the API level stuff, the writing style is dry, but overall a great book to supplement Sierra,Bates. I would also highly recommend the official Java tutorials in case you don't find the books good enough. The Regular Expressions tutorial is especially good.

Preparation Technique: I went through Sierra,Bates completely more than once and used the Mughal book only for the topics I wanted more practice on. I made notes for all things that I felt were important to remember or were tricky. In the week leading up to the exam, I more or less looked only at my notes for revision.

If you are interested, they are available at :

I also wrote a lot of practice code using the Eclipse IDE. Sierra, Bates do not like using IDE's - but I found it very useful. If not for Eclipse, I dont think I would have written as much of practice code as I did. Eclipse's continuous compilation means you can keep experimenting without wasting time on the command-line. Of course the command-line javac/java/jar, classpaths etc needs to be practiced outside the IDE.

Mock Exams: I took all the exams in the separate Sierra, Bates Practice Exams book. I would highly highly recommend that you take all these exams and analyze your performance. I averaged between 70-80% in these exams. The questions are slightly tougher than those in the real exam - but they do a fantastic job in preparing you for the real thing. I also did the full mock exam in the Mughal,Rasmussen book. Finally, I did an online mock which Pearson offered me when I booked the OCPJP exam. If you get a chance, do take this - because it mimics the real exam interface closely and the difficulty of the questions are somewhat similar to the real exam.

The Real Exam: The real exam covers all the exam objectives well, the questions are well designed and the exam interface is excellent. Many exam takers have said that the questions are "easier" than those in the mock exam. I would say that yes, while some questions are a little easier, on the whole the questions do a good job of thoroughly testing your knowledge of the exams objectives and I did find some tricky ones in there as well.

Overall: Make sure you study all the objectives well, code a lot, take notes, take the mocks and analyze them and you'll be certified in no time.

Cheers !
10 years ago

Jeet Jain wrote:

I dont understand why "static final" prevent compilation?

Forget about the final keyword for the moment. An instance method cannot "override" a static method. Similarly a static method cannot "hide" instance methods - only static methods.
Now assuming growFast() was static in Thistle, then the final keyword will come into play - it prevents the subclass static method from "hiding" the superclass static method.

Jeet Jain wrote:How can 4 ever print before 2? Thread t will never enter synchronized block because it does not hold lock on itself. But 2nd thread can so it sleeps guaranteeing "2" be printed before 4, right? Right answer says it can be printed before.

4 can be printed before 2, if say the thread referenced by the statement "new Locker().start()" starts executing before the thread t. If it gets a chance to sleep before t does, then 4 will be printed before 2.

Thread t will never enter synchronized block because it does not hold lock on itself. But 2nd thread can ...

Both the threads will attempt to acquire t's lock and enter the synchronized block.

Matthew Brown wrote:

The important point is that do2() is synchronized. The two threads can't call it at the same time. So it's got to be called 8 times in sequence....that's at least 8 seconds.

I get this.

Matthew Brown wrote:

Each thread also calls do1() before do2(). So it's going to take another second to reach do2(). That's 9 seconds in total.

do1() isn't synchronized, so the two threads can call it at the same time...and one can call it at the same time as the other calls do2(). So there's nothing else to add to the minimum total time.

I didn't get this part. Both the threads have to spend one second sleeping whenever they enter do1() - since this is not synchronized, they can do it in parallel, so per iteration of the loop, the combined minimum time taken by both the threads is 1 second.
For four iterations it is four seconds. Therefore the minimum execution time required by the program should be 12 seconds ?

Tom Kowalski wrote:I have discovered today really strange (for me) thing in Java. On one hand it makes sense, but on the other, I just want to scream 'What the heal?'. I put it here, because it might be useful for people who are learning for SCJP.

Good point ! When I tried compiling it, the compiler throws up this informative warning:

warning: non-varargs call of varargs method with inexact argument type for last parameter;
cast to java.lang.Object for a varargs call
cast to java.lang.Object[] for a non-varargs call and to suppress this warning
foo(new String[] {"j","a","v","a"});

So, in essence when you pass a String[] to foo, the call is treated as a non-varargs call.
Thanks everyone. The book's answer makes sense now.
Here's a question from Khalid Mughal's SCJP book:

How many objects are eligible for garbage collection when control reaches (1) ?

Select the one correct answer:

(a) 0
(b) 5
(c) 10
(d) Hard to say.

My answer was (c) 10.
But the book says the answer is (d) Hard to say. The reasoning is that some of the object's could have been GC'ed when control reaches (1).
I see the point - some objects could have been automatically GC'ed before we explicitly call GC.

My question is that is this a valid way to think about GC questions on the real exam ? I would assume that ten objects will be eligible for GC as soon as the loop ends.

Sudhanshu Mishra wrote:This was the original code:

Please remember to place code inside code blocks, like above. Now, since you are using a synchronized list, calls to methods such as size() and remove() will be synchronized. t1 and t2 cannot execute those methods concurrently. As to your question on which object they will lock on, it depends on the implementation of the synchronized list. In this case the class returned by the Collections.synchronizedList() method ensures synchronization by using a synchronized block on a lock object. So, t1 and t2 will lock on that object. Instead, if the methods were to be marked as synchronized, then the List object itself would be used as the lock.
In this case, the t1 and t2 threads invoke the removeFirst() method using the NameList object nl. Therefore, the threads will attempt to acquire a lock on nl and not on the LinkedList object.
Seetharaman, good points. Thank you.
10 years ago