| 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: 14672
|
|
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: 26201
|
|
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: 26201
|
|
And clearly I should have looked at the FAQ before typing this. I like reg exps .
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
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: 536
|
|
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
|
 |
 |
|
|
subject: Questions from K&B 6
|
|
|