wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Difficulty in following Devakas practice exam Question 7 Practice Exam 1 - Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Difficulty in following Devakas practice exam Question 7 Practice Exam 1 -" Watch "Difficulty in following Devakas practice exam Question 7 Practice Exam 1 -" New topic
Author

Difficulty in following Devakas practice exam Question 7 Practice Exam 1 -

Stephen Davies
Ranch Hand

Joined: Jul 23, 2008
Posts: 352
Sorry for the repeat post, but when i was submitting my post after preview, all my code formatting was being dropped, and my text cut short.

I understand pattern and matcher design, however looking at the following question from Devakas SCJP 5.0 exam (Q 7 practice exam 1), Im having difficulty following the conditional logic.

The Question:What will be the result of running and compiling the following code?
Answer: Prints "Hal"



Any one offer any insight (particularly on the conditional logic). Devakas explanation is far from satisfactory.


be a well encapsulated person, don't expose your privates, unless you public void getWife()!
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


Steve ,

I worked out like this..


The first call sets the Patern to H[a-b][k-m]
The second call sets the Matcher object
The third call finds the pattern using Matcher find() method and matches "Hal" in Hallo
group() method is used to gather the returned info from find().


Stephen Davies
Ranch Hand

Joined: Jul 23, 2008
Posts: 352
Thanks Balu,

I got it now, I was having an issue with the null return types, but since the object references are never called, apart from the obj 3 which actually is a returned match group, so no worries. Its a sticky question though:

Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874

Its a sticky question though:


Absolutely..
Fritz Guerilus
Ranch Hand

Joined: Jun 20, 2009
Posts: 65
Hi,
I have 2 questions about this:

1. Why does the method have the 2nd String Var-arg argument? It doesn't look to me like it's doing anything.
2. Inside the method:

how does this statement work?
st.pt1=((Pattern)ob).compile(s[0])
Isn't the 1st argument of the method passing the pattern, and then we're casting it into a Pattern and invoking the compile method again

Any help on understanding the logic would be helpful

Thanks


SCJP 6.0
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Difficulty in following Devakas practice exam Question 7 Practice Exam 1 -
 
Similar Threads
Pattern and matcher
Parameter passing into a method-Examlab
Devakas Diagnostic Exam and Garbage collection example
Why does this method call compile with only one argument ?
How pattern works?