Rodmar Conde

+ Follow
since Jul 09, 2010
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 Rodmar Conde


I'm preparing to take the SCJP exam also. I have read K&B book and scored about 60% in average. I haven't write any study code until now. I have 5+ years of professional experience with java and write code for work everyday.

I don't understand very well the purpose of writing study code on every chapter, is this only for "new to java" people or it does in fact has a benefit? I understand very well what the book says, that's why I haven't written any code. I think I scored 60% because the questions are hard.

I underlined the things that I didn't know before reading the book. My plan is to read again only the underlined pages, and then go over the mock exams on the CD. After that, I will take the exam. But, again, I don't have plans for writing study code. What do you think? Am I loosing a key point on taking the exam?

Although in real life situations you won't use that kind of access. You'll use setters to access instance variables.

For instance:

a1.setB1(b2); instead of a1.b1 = b2;

Hi Gari,

The error is in this line:

t1 is of type Tree, ¿right?

We hava that Redwood extends Tree.... in terms of hierachy, this means that Tree existed before Redwood did, in other words Tree class doesn't even know about the existence of class Redwood.

Then, t1 can't become a Redwood so that causes the error.


how I got out put "-5" can any body please explain ?

Hi Malatesh,

Well, the answer to that question is:

From Java Api Documentation:

binarySearch returns:
index of the search key, if it is contained in the list; otherwise, (-(insertion point) - 1).
The insertion point is defined as the point at which the key would be inserted into the list...

Then we have that after executing line 13 of your code, Array sa is: two three one four.

Since you invoke binarySearch without the comparator parameter, this method will try to use natural binary search assuming that the array is sorted in ascending order.

Then, according to the binarySearch algorithm the array will be splitted in two parts and try to find the element in the middle, so the first element to be compared with search key "two" will be the element "one", after comparing them (with natural comparator) the method will know that since "two" is greater than "one" it should continue searching after "one" so then "four" is evaluated. Again, "two" is greater than "four" so then "two" should be after "four", that is index number 4 (insertion point).

According to the formula indicated by the documentation, we have (-(4) - 1) which gives us -5.


And now I wonder. They say that myApp is a root directory of the package myApp.utils. But why? Why "ws" is not the root directory of the package ws.myApp.utils and the same with "test". Could someone please clarify this for me?

Hi Jan,

ws is not the root directory of ws.myApp.utils because that package doesn't exists. The example is only declaring the package myApp.utils (line 8 of the code). Then, to successfully locating classes in it you should be located at the directory in which myApp is directly accesible. The only place where this can happen is in directory ws.

Remember packages "reflect" a directory structure used to organize java classes. So if you code a class named Dates and declare it belongs to myApp.utils package what you're saying to the jvm is that the .class wil be located in a directory called utils that is inside a directory called myApp. So it's your responsibility to make that directories accesible to the jvm. So, the only ways to correctly load the Dates class are:

Inside out of directory test:
java -cp .\test\ws myApp.utils.Dates

Inside directory test:
java -cp .\ws myApp.utils.Dates

Inside directory ws:
java myApp.utils.Dates

Note that, inside directory myApp, if you try:
java myApp.utils.Dates
java utils.Dates

An error will be thrown... since myApp directory is not accesible in the first case and there is no class Dates defined to belong to a package named utils in the second case.

Hope I clarify your doubts.

Thanks Abimaran Kugathasan,

I've checked the for loop and the two possible outputs are:

a) yo yo dude dude


b) dude dude yo yo

b) is in option E in the question. I have to guess that it's not marked as correct because option a) always ocurrs. But in fact we don't have any warranty that thread in line 22 will always enter the chat method before thread in line 23. ¿do we?

Even if flag could be "touched", the only place where it can be modified is inside the chat method. Which, if is declared as synchronized can't be executed by two different threads at the same time. One thread has to wait for the other thread to completely execute the method.

So, when using synchronized, the output should be

yo yo yo dude dude dude


dude dude dude yo yo yo

Does anybody can confirm this please?

Thanks in advance.
Hi there,

I'm just starting preparation to SJCP. I'm a semi-experienced java programmer so I decided to go directly to the S/B study guide. I expect to be ready in two months.

As a study strategy and a contribution to native spanish speakers students interested in java, I've started a blog in which I'll be publishing the new things learned.

Hope this will be useful.

I don't remeber where do I read that during String initialization which involves concatenating what really happens (internally) is that a StringBuffer is created, then the append method is used to add each String and finally it's toString method is invoked.

According to that, the answer to your question would be: 1. Only one String object is created.
11 years ago

what sort of a change i have to make in order to get "regular" as output.

In fact, the original code that was posted won't compile. I really don't understand why, maybe because there should be a main thread in order to instantiate a class (Burger) or maybe simple because java don't allow code to be outside a method...

Besides, consider declaring enum members using upper case. It's a good practice.

Should be:

when we run the program next time, why the following values is same as before

I'm not an expert too, but I know that each time you run a class, the jvm allocates a new piece of memory for it to run (called heap). You can modify its size with the following parameters:


Please try java -Xms100m -Xmx105m Test and you should get a different value in "Total JVM Memory".