Katherine Reut

Greenhorn
+ Follow
since Jul 26, 2013
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Katherine Reut

Update: I tried out the below code as an experiment to see if I could do as "A" stated (i.e. make a class final and have it not implement Comparable, and then as a result not be able to use comparable to sort the class. The code works, so I'm doing something wrong. Does anyone have any ideas about how to demonstrate answer "A" with real code?



The result is:



A large part of my effort in studying for this exam is the effort involved *after* I have answered questions - in fact, I often have to take a break before marking questions because I know there's just as much effort involved in the marking bit.

I totally know what you mean - it seems like my poor book has more of my writing in it than that of the authors'! And I printed out each of the questions on the practice exams and wrote lengthy explanations of the answers that gave me trouble and the page numbers that they corresponded with. I was asked about my failure "Aren't you disappointed?" and "Aren't you mad?" I can honestly say if it had been a Finance exam (I'm a recovering Business major), I would be totally p***ed to have wasted that many hours/days/weeks/months of effort on something that I couldn't care less about. But man! Having gone through the Sierra/Bates book so thoroughly has given me SUCH a great foundation. Just a few months ago I barely recognized the words "polymorphism", "interface", or "exception", not to mention I didn't have a clue what a thread or a hashcode was. The work I've put in over the last few months gave me the ability to have an intelligent conversation with my coworkers about object oriented programming, not to mention the general foundation that I'd been wanting for almost a year! Now I just have to fine-tune it so I can pass that darn exam!

May I ask, why did you take OCPJSE6 and not OCPJSE7?


You have to either pass the 6 professional or the 7 associate before you can get your 7 professional certification. I wanted to take the six exam so that I would have the "professional" certification right away (instead of the associate) and then afterwards upgrade to the 7 professional.

Also, I am concerned now myself, because I have read somewhere that the questions in the Bates/Sierra books are WAY harder than those on the real exam.

That's what I heard too: I read it here in the Code Ranch and in the book, and one of the guys in my group who passed the exam (with a 90% - ugh!!) said that the exam was way easier. I guess maybe the questions on the exam aren't harder per se, but they are different. The exam asked questions about code examples that have issues that are addressed in the book (thoroughly), but the issues are not specifically in the practice exams or self-tests. I think I went in to exam thinking that it would be made up of questions just like what I had been practicing with, just with different class and variable names and wording. The exam seemed to be testing me more on my practical programming knowledge (i.e. "does this code compile/produce this output...") and less on my academic knowledge (definitions, true/false statements, etc), which is the style of about half of the questions that I practiced with. I think I have to take those academic practice questions a step farther and write code that applies to them, just to see exactly what it looks like.

How well did you do on the practice exams in Bates/Sierra?

The weekend before my exam, on quiz A attempts, I was getting between 80 and 90%. On quiz B, I was scoring a little lower, somewhere between the low 70s and mid 80s. I think that I was getting scores that high because by the fourth and fifth time I was taking the quizzes, even though I was trying not to, I was recognizing the problem, remembering what "the issue was" and honing in on it instead of really figuring it out or thoroughly understanding it.

Anyway, don't let my failure worry you - four of our seven passed, and two of them passed with flying colors, and I know for a fact at least one of them hardly studied. I think my floundering is mostly due to inexperience. I just started learning OO programming about a year ago and I bet someone with more experience will do just fine.
Drat! After about 160 hours of studying for the SCJP6 Exam 1Z0-851 (OCP, Java SE 6 Programmer), I failed it with a score of 50%. I'm going to take it again in about a month, after I try to shore up my understanding of the 25 different objectives about which I missed one or more questions.

My question is, does anyone know where to obtain statistics in regard to what percentage of people who take the exam fail it the first time? Does Oracle publish this information, or someone else? There is a group of us who sat for the exam, and out of the seven of us, three of us didn't pass. I am curious if this is the average pass rate for the exam, because although I am definitely not the brightest bulb in the chandelier (and I'm relatively new to programming), the rest of the group is well above average in smarts and ability. Yes, I am hoping to make myself feel better if I can see that only half or so pass the exam on their first attempt (or perhaps I will be horrified to find that most people pass it their first time!) Does anyone know of a reliable resource that I can use to satisfy my morbid curiosity?

As a side note, are there any additional study aides that anyone who succeeded recommends? I've been using the SCJP book (Sierra/Bates) which is super-excellent, the CD that came with it, and the Practice Exams book by the same authors. They are all labeled as being for exam 310-065 but that is the same thing as the 1Z0-851...uh, right? I did notice that the practice questions and exams were less similar to the real exam's questions than I expected. Am I maybe using the wrong tools to prepare? (I can't pay the thousands of dollars for the Oracle exam training package. I'd rather that money go towards my next certification attempt...Java7 or MySQL or something else cool.)

Thanks Ranchers!
I'm going through the quizzes on the CD that came with the SCJP6 book. I don't understand one of the explanations for Quiz B Question 54. The question is:

Which are true (Choose all that apply.)

A. You can use java.lang.Comparable and java.util.Comparator to sort collections whose elements are of any valid Java type as long as all of the collections elements are of the same class.
B. The java.lang.Object class implements the java.lang.Comparable interface.
C. Many commonly used classes in the Java AP (such as String, Integer, Date, and so on) implement the java.lang.Comparable interface.
D. If your class implements java.lang.Comparable but you don't explicitly override Comparable's method, collections containing elements of your class will be sorted in natural order by default.
E. When using the java.util.Comparator interface, you will typically create a separate class for every different sort sequence you want to implement.
F. The java.util.Comparator's interface's method can take either one or two arguments.
G. The binarySearch(), reverse(), and reverseOrder() methods in the java.util.Collections class all require that the collection is sorted before the method can be invoked successfully.

The answer states:
"A is incorrect because if a class is final and does not already implement Comparable, then Comparable can't be used to sort that class."

I don't understand. How would one use java.lang.Comparable other than having the class in question implement Comparable? What I mean is, I interpreted "A"'s statement "You can use java.lang.Comparable..." to mean that the class in question was implementing java.lang.Comparable. I think that I am missing something about a different way to use Comparable other than implementing it in the class definition.

Can one of the Ranchers here help me out with an example of how Comparable could be used unsuccessfully to sort a collections of elements that are of the same class? Thanks in advance everyone!
Is it possible to use the absolute filepath in this case? If it isn't, when can the absolute file path be used? I am a little confused when, why, and how it is used.
Oh cripes! I get it now! The array definition is saying how many arrays there are...not the maximum index!

b2 is a four dimensional array. Its first array [2] has a maximum index of "1". Its second index [3] has a maximum index of "2". Its third and fourth arrays both have maximum indexes of "1".

So the last "bucket" so to speak in the b2 array (short b2 [][][][] = new short [2][3][2][2];) would be:

b2 [1][2][1][1]

Anything higher/bigger/later than this would throw an arrayIndexOutOfBounds error. That's why your (excellent) example:

b2[2][0] = big

throws the error, but

b2[1][2] = big

would NOT throw an error.

Thank you so much, Greg, for your help on this! I would have totally flubbed it on the exam!

Himai Minh wrote:


If you are under a directory where there is /mp/classes, then you should use this command. This command means go to /mp/classes to find player.MusicPlayer.
For example, if you have d:/myproject/mp/classes/ where player.MusicPlayer is and your current directory is d:/myproject, then use this command.
But make sure MusicPlayer is under player package.



Hi Himai,

Thanks for helping me with this question so quickly! The problem says that I am currently in the directory /mp. Does this mean that
would indeed work for invoking the class player.MusicPlayer? I think this is what your answer said, but I wasn't sure if I was understanding it correctly.

This is the file structure that was given for the problem:



Thanks again!
I have two questions about this quiz question (Quiz A number 68) too:

My first question is that Option "F" is:

java -cp /mp/classes/player MusicPlayer

F is incorrect, and the answer says it's incorrect because F "has the wrong classpath".

I thought it would be correct to say:

java -cp /mp/classes player.MusicPlayer

...but it sounds like there's something different wrong? What would be the correct statement if you wanted to use the absolute path?

My second question is that the answer says that the CLASSPATH is no good to us.

The CLASSPATH is:

/mp/jars

Would one correct CLASSPATH be:

/mp/jars/mp.jar ?

and another correct CLASSPATH be:

/mp/classes ?

Thanks in advance for help!
Oh jeez! So I didn't quite figure it out yet. Why does "G" cause a runtime error and "F" doesn't? I'm looking and looking and can't see the difference that causes the problem. Thanks for helping me with this!!
This is from the CD in the back of the book, it's Quiz A's question #6:



Which one of the following lines of code could be inserted at line 7 and still allow the code to compile (Choose all that apply):

A: b2[1][1] = big;
B: b[1][0] = b3;
C: b2[0][1][1] = big;
D: b2[0][2][1] = b[1][0];
E: b2[1][1][0][1] = b[1][0];
F: b2[1][1] = b;

The answer is A, B, E, and F.

I understood one or two of these, but the b2 array blew my mind. After drawing many (huge and time-consuming) pictures trying to depict how the b2 array worked, I finally figured out an easy way to get the answer. I want to share it here so fewer people spend as much time as I did chasing their tails!

I knew that a single dimension array is something like this:

short[] sdArray = new short[3];

This says sdArray is an array with three primitive shorts in it.

For example, sdArray could be initialized as being {2,4,6}, so
sdArray[0] = 2
sdArray[1] = 4
sdArray[2] = 6

But then I had to realize what a multidimensional array was.

For example, short [][] b = new short[4][4]:

That means that b is an array of arrays...which sounds scary but all that means is this:

The [4] on the left says that there are four arrays.
The [4] on the right says that in each of the above four arrays, there are up to four primitive shorts.

So if these arrays were randomly filled with primitives, it might look something like this:

array0---{0,1,2,3,4}

array1---{2,4}

array2---{8,4,2,88,10}

array3---{5,1,2}

array4---{1,2,78,99}


So for example, b[2][4] would be equal to the primitive short "10".

Then for the really gnarly array b2, where b2 is equal to "short b2 [][][][] = new short[2][3][2][2]". This is where I really got buffaloed.
But then I though of it like this:

b2 is three arrays (because arrays are zero based, the first [2] means that there's array[0], array[1], and array[2])
Each of b2's three arrays have four arrays inside.
Each of those four arrays have three arrays inside of them.
Each of those three arrays have up to three primitive shorts in each of them.

For each possible line of code (A-F), I did the exact same thing. Here's "A" as an example:

A: b2[1][1] = big;

I took the left side of the equation and asked "What is it expecting?"

In this case, the left side of the equation is "b2[1][1]". b2 is defined as a multidimensional array of shorts:

short b2 [][][][] = new short[x][x][x][x];

...so b2[1][1] would be expecting [x][x].

(if the left side of the equation had been "b2[1][1][1]" then b2[1][1][1] would be expecting [x]
...or if the left side of the equation had been "b2[1]" then b2[1] would be expecting [x][x][x])
See the pattern?


So now look at the right side of the equation which is " = big"

So big is defined as: short[][] big = new short[x][x]

So the left side of the equation is expecting: [x][x] (a 2-dimensional array)
and the right side of the equation is: [x][x] (a 2-dimensional array)

So "A" is correct!

I did the same thing for B - F:

B: b[1][0] = b3;

b[1][0] is expecting a primative short (see the example above for how we know it's expecting a primitive short)

b3 = 8, and 8 is a primative short

So "B" is correct!

C: b2[0][1][1] = b;

b2[0][1][1] is expecting [x] (a single dimension array)

b = short [x][x] (a 2-dimensional array)

[x] != [x][x] so "C" is incorrect!

D: b2[0][2][1] = b[1][0];

b2[0][2][1] is expecting [x] (a single dimension array)

b[1][0] = a primitive short

a single dimension array != a primitive short so "D" is incorrect!

E: b2[1][1][0][1] = b[1][0];

b2[1][1][0][1] is expecting a primitive short.

b[1][0] is a primitive short.

primitive short = primitive short so "E" is correct!

F: b2[1][1] = b

b2[1][1] is expecting [x][x]

b = short [x][x]

[x][x] = [x][x] so "F" is correct!





Oops, sorry! The command line is:

java _ - A .
Given:



And the command line is:

java _ - A .

What is the result?

The answer is "A." (A and a period).

I was going to ask the Java Ranch why the dash didn't print - was it some sort of command? I figured out why on my own, but it took me long enough to make me feel like it was worthy passing the explanation on.

The for statement on line 6 is incrementing the x before it enters the loop. So x is never "0" when the statement on line 7 executes. The dash could have been any character and it still wouldn't have printed. If you change line 6 to:



then x is incremented as one would expect, and arguments 0, 1, and 2 are printed.

I had to go to tutorialspoint.com for a quick refresher on exactly how for loops work. They said:

Here is the flow of control in a for loop:

The initialization step is executed first, and only once. This step allows you to declare and initialize any loop control variables. You are not required to put a statement here, as long as a semicolon appears.

Next, the Boolean expression is evaluated. If it is true, the body of the loop is executed. If it is false, the body of the loop does not execute and flow of control jumps to the next statement past the for loop.

After the body of the for loop executes, the flow of control jumps back up to the update statement. This statement allows you to update any loop control variables. This statement can be left blank, as long as a semicolon appears after the Boolean expression.

The Boolean expression is now evaluated again. If it is true, the loop executes and the process repeats itself (body of loop, then update step,then Boolean expression). After the Boolean expression is false, the for loop terminates.


The rest of the problem's tricky-ness is explained on page 5 and on page 796 of the text.

Norbert Muench wrote:All you need to need to know about thread ids to answer this mock question is stated in the Javadoc for the getId() method in class java.lang.Thread:

Returns the identifier of this Thread. The thread ID is a positive long number generated when this thread was created. The thread ID is unique and remains unchanged during its lifetime. When a thread is terminated, this thread ID may be reused.


You should start by asking yourself which of the given lines will even compile. (This will eliminate one line)
Then ask yourself which of the remaining lines actually output two numbers. (This will eliminate another line)
Then you should ask yourself what it means when the output is "4 4". How many threads did the program start in this case?



To expand on Norbert's, and the author's, answers:

"Fragment I doesn’t start a new Thread."
This means that the Ids that are produced will be the same. (i.e. “2 2” or “4 4”)

"Fragment II doesn’t compile."
This means that there will be no output, and that “A” cannot be true.

"Fragment III creates a new thread and doesn’t start it."
This means that there will be only one Id output. (i.e "2" or "4")

"Fragment IV creates a new thread and invokes run( ) directly, but doesn’t start the new thread."
This means that the Ids that are produced will be the same. (i.e. “2 2” or “4 4”).

"Fragment V creates and starts a new thread."
This means that the Ids that are produced will be different. (i.e. “4 2”).

There's also a little information about getId() in the Exam Watch on page 716.

Sandra Bachan wrote:

Bert Bates wrote:Hey Sandra,

Have you tried adding a bunch of S.O.P.s to the code?



What's an S.O.P.?



S.O.P. is the acronym for "System.out.print()". I think what Bert means is that if you add these System.out.print() statements with different statements inside of the parentheses, it will be more clear what is going on with the code. For example, if between line 6 and 7 you added the line System.out.print("I'm in the abstract class Bar's getNum() method!") and then ran the program, you would be able to see if and when that method ran relative to the rest of the methods...if you added System.out.print statements to the other methods too of course.