Rachel Glenn

Ranch Hand
+ Follow
since Oct 24, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Rachel Glenn

Himai Minh wrote:In the previous example, it prints out tree elm elm elm from the go method.
The first one outputs tree from the invocation t.getTree().
Since t is a tree, it calls getTree and getTree calls getmyOwnTree.

The most interesting invocation is new Elm().getTree().
The Elm instances inherits getTree. This getTree calls getmyOwnTree of Elm's version.
In the Elm's getmyOwnTree, the "return tree" returns the Elm's tree.
Why getmyOwnTree in Elm choose "elm" to return instead of "tree" ?
It is because Elm's getmyOwnTree overrides its parent's method. That means Elm behaves differently than its parent.


Let's go back to the original example:


When Elm instance calls getTree(), it reuses its parent's getTree method. So, this Elm instance should behaves in the same way as its parent. Therefore, it returns "tree" instead of "elm".

Summary: a child inherits a method meaning that this child behaves in the same way as its parent. A child overrides a method meaning that this child behaves differently than its parents.



That is a good way to describe it. I guess I get confused because even though Elm is a superclass of tree, I see it that when you create an instance of Elm, there is only one object created (an Elm instance), and so there is only one method of getTree(), which seems to 'belong' to Elem since it was inherited. So only if Elm provided an overridden verison of getTree() would it return tree="elm", but since it did not override it, it would call the parent class.

Mahtab Alam wrote:Well congrats >
Is 2:30 time was enough.And what was the level of questions .

I have my exam on 16 saturday



2:30 was enough time. But after I was done all of the questions, I went back through every single one and double checked my answers. and then with any time leftover, I worked on the ones I was unsure of.

The level of questions were not hard, but not easy either
12 years ago

Mahtab Alam wrote:many says that you will have 15-20 easy question on the ocjp test.
how much true is it.

and will there be drag and drop questions , and does you have to create them from starting while reviewing.
so its better to write them on the paper.



I took the exam today and there were NO drag and drop questions

Mahtab Alam wrote:Which are most commonly thrown by an API developer or application developer as opposed to be thrown by JVM
Answers are:
IllegalArgumentException
IllegalStateException
NumberFormatException


I can`t understand what it means to be thrown by API developer



What they mean is when you actually write a lne of code like this:



I don't think the Sierra and Bates book did a very good job of explaining the difference between JVM versus developer thrown exceptions and why a particular exception is thrown by JVM or developer.

I hope the example helps!
Finally, I did it! Passed it with an 83%, of which I was thrilled with.

I studied with the famous Sierra and Bates book. Its been almost 20 years since I have been in school, so picking up a book like that and trying to learn it turned out to be more challenging than I anticipated. I have always been a c++ programmer (I never programmed in Java before), and I thought learning Java would be easier than it was, but sometimes I think being a 20 year c++ programmer was to my disadvantage. I spent a total of 5 months reading and studying, but there were a lot of breaks in that time period (like for the holidays).

I practiced all 3 mock exams by Sierra and Bates. I scored low on these...65%, 45% and like 50%. I was devastated. So I made sure to understand WHY I got every problem wrong, and that is what really counted. I wish I had done more research and done other mock exams WHILE I was studying each chapter. I did the free exams on scjptest.com, and I also had access to the ORACLE practice exam. I told myself if I failed this exam, that I would have bought WHIZLABS.

If anything, studying for this exam really sharpened my mind and taught me HOW to read a book like that and to absorb it properly. This will be helpful since I plan to pursue more certifications (maybe mobile Java, C#, etc...).

Anyway, THANK YOU MUCH for answering all my stupid questions!!


P.S. there was NO drag and drop. 60 questions. I took the ENTIRE time frame of the exame, and just kept reviewing it.
12 years ago

Mahtab Alam wrote:many says that you will have 15-20 easy question on the ocjp test.
how much true is it.

and will there be drag and drop questions , and does you have to create them from starting while reviewing.
so its better to write them on the paper.



I would love to know the answer to this also!

Jesper de Jong wrote:You can ofcourse find that information on Oracle's website: Exam 1Z0-851: Java SE 6 Programmer Certified Professional



ah yes thank you!!

Henry Wong wrote:Please QuoteYourSources



my source is the Oracle mock exam

Greg Charles wrote:Yes, if you tell it that one comma is the delimiter, it will take you at your word and return empty strings for two commas in row. That's a good thing. Let's say you had the data:

"FirstName,Nickname,LastName"
"Ralph,'Macho',Camacho"
"Greg,'T-bone',Charles"
"Rachel,,Glenn"

You'd want your first and last names parsed out correctly even though you don't have a nickname.

If you really want to split the string on one or more commas, you just need to change the regular expression in the split() to string.split(",+"). In that case, the first three strings above get split into three pieces, but the last one only gets split into two.



thank you! makes sense now!

Greg Charles wrote:It's confusing because it's weird to think of digits as delimiters. Imagine the string was "x,,,, y,, z, a" and you split it on the commas. You'd expect to get eight strings returned, many of which would be empty because there are multiple commas in a row with nothing between them.



yes it is confusing!

but let me take this a step further.

If the string was "x,y" and I split on commas, I would expect 2 strings to be returned: "x" and "y"

If the string was "x,,y" and I split on commas, then this is where I get confused....it sees the first comma, and marks "x" as the first token. Does it then consider the "x" and first "," as 'consumed'? thus, when it sees the second comma, there is nothing to the left of it to tokenize, so it returns a blank? I am confused here,,,,
I have this example:



What is the result?
A. total: 3
B. total: 4
C. total: 7
D. total: 8
E. Compilation fails
F. An exception is thrown at runtime.


While I understand the concept of tokenizing, I am unsure how it works in this specific example. I even ran it in the debugger and am unclear about the output.

\d means the delimeter is a digit. So how does this example work then?? does the split() function see the first digit (1), and record that the first token is 'x'? What does the split() function do when it then sees the second digit (2)?

Zhenyi Luo wrote:

Rachel Glenn wrote:I have this sample question from a mock exam:

Given:

- list is a reference to a valid collection
- getCollection() returns a reference to a valid collection

Which two are valid? (Choose two.)
A. for(Object o ; list)
B. for(Object o : list.iterator())
C. for(Object o : getCollection())
D. for(Iterator i ; list.iterator() ; i.hasNext() )
E. for(Iterator i = list.iterator(); i.hasNext(); )



I understand that answer E is one of the correct options. But it seems to me that options A AND C are also valid. Can someone please explain? (Option C is the other correct option.)



A should be for(Object o : list) instead of for(Object o ; list) , so answer is CE



OOOPS!! THANK YOU!

BUT, if A was for(Object o: list), then it would also have been correct ?

Zhenyi Luo wrote:

Rachel Glenn wrote:UGH, another ambiguous question..this is from a mock exam

Given:

21. class Wheels {
22. private Bike bike;
23. void setBike(Bike b) { bike = b; }
24. }
25.
26. class Bike {
27. private Wheels [] wheels = new Wheels[5];
28. void setWheels(Wheels [] w) {
29. if( w.length == 2)
30. wheels = w;
31. }
32. }

Which is true?
A. Compilation fails.
B. These classes are NOT coupled.
C. These classes are loosely coupled.
D. These classes are tightly coupled.
E. These classes are abstractly coupled.



(Option D is correct because both classes have references to instances of each other.)

Why is this considered tight coupling? Internal changes to either Wheels or Bike classes do not affect the other class. What would make these considered as being loosely coupled?



Internal changes to either Wheels or Bike classes will affect the other class, setBike is in Wheels class and setWheels is in Bike class.



Thank you for your reply, but I am still unclear.

Lets look at the class Wheel. It has a member variable; Bike bike. But that is it. It only has a reference to this class. It doesn't call any of Bike's member functions or access any of Bikes' variables. To me, this is a simple has-a relationship. If the internal structure of Bike changes, Wheels is not affected at all. So how is this specific relationship 'tight coupling'?
UGH, another ambiguous question..this is from a mock exam

Given:

21. class Wheels {
22. private Bike bike;
23. void setBike(Bike b) { bike = b; }
24. }
25.
26. class Bike {
27. private Wheels [] wheels = new Wheels[5];
28. void setWheels(Wheels [] w) {
29. if( w.length == 2)
30. wheels = w;
31. }
32. }

Which is true?
A. Compilation fails.
B. These classes are NOT coupled.
C. These classes are loosely coupled.
D. These classes are tightly coupled.
E. These classes are abstractly coupled.



(Option D is correct because both classes have references to instances of each other.)

Why is this considered tight coupling? Internal changes to either Wheels or Bike classes do not affect the other class. What would make these considered as being loosely coupled?
I have this sample question from a mock exam:

Given:

- list is a reference to a valid collection
- getCollection() returns a reference to a valid collection

Which two are valid? (Choose two.)
A. for(Object o ; list)
B. for(Object o : list.iterator())
C. for(Object o : getCollection())
D. for(Iterator i ; list.iterator() ; i.hasNext() )
E. for(Iterator i = list.iterator(); i.hasNext(); )



I understand that answer E is one of the correct options. But it seems to me that options A AND C are also valid. Can someone please explain? (Option C is the other correct option.)