This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Questions from K&B 6 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Questions from K&B 6" Watch "Questions from K&B 6" New topic
Author

Questions from K&B 6

Kapil Shardha
Greenhorn

Joined: Jun 18, 2009
Posts: 9
I am not able to understand the reason behind the answer for Qs 1 in Self Test for Chapter 6 in K&B's book for SCJP 6

And the command line:
java Regex2 "\d*" ab34ef
What is the result?
A. 234
B. 334
C. 2334
D. 0123456
E. 01234456
F. 12334567
G. Compilation fails


Moreover, the answer to question 2 of same test is also not clear. Any explanation to these two questions will be of great help.


SCJP 6 (83%)
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Hi Kapil,
Maybe this FAQ will help you understand the problem.


[My Blog]
All roads lead to JavaRanch
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30392
    
150

Kapil,
Welcome to JavaRanch!

That code matches 0 or more digits. The regular expression tries to find a match as soon as it can. So it thinks something like this.
Position 0 - finds a letter (a). Yup - that's zero digits.
Position 1 - Another letter (b). Great - zero digits.
Position 2 - Ooh - a number. Let's keep looking. Two digits. Outputs "34" and skips outputting the index for the third position since it already matched the "4"
Position 4 - Another letter (e) - Zero digits
Position 5 - Another letter (f) - Zero digits
Position 6 - "End of string" - Yup - zero digits

Kapil Shardha wrote:Moreover, the answer to question 2 of same test is also not clear. Any explanation to these two questions will be of great help.

Can you share question 2 (or a shorter version of it) ? I have the SCJP 5 book (not 6 so things may have changed.) My question #2 deals with Serializable not regular expressions. If you have a question about Serializable, you want to start a new thread. You'll also want to share what your specific doubt is as that isn't a question that can be traced/diagrammed.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30392
    
150

And clearly I should have looked at the FAQ before typing this. I like reg exps .
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

Kapil please Use Code Tags when you post a source code. Edit your message using button and then add code tags to it...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Kapil Shardha
Greenhorn

Joined: Jun 18, 2009
Posts: 9
Here is the question 2 from Self test of Chapter 6:


And its answer is "PCP" which is not clear.
Nitish Bangera
Ranch Hand

Joined: Jul 15, 2009
Posts: 537


the CardPlayer's and Player's constructor will run printing PC.

CardPlayer is serializable while Player isn't. So while deserializing, Player's constructor will run printing P

Hence PCP.


[ SCJP 6.0 - 90% ] , JSP, Servlets and Learning EJB.
Try out the programs using a TextEditor. Textpad - Java 6 api
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Questions from K&B 6