• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Questions from K&B 6

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kapil,
Maybe this FAQ will help you understand the problem.
 
author & internet detective
Posts: 41250
849
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jeanne Boyarsky
author & internet detective
Posts: 41250
849
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And clearly I should have looked at the FAQ before typing this. I like reg exps .
 
Sheriff
Posts: 9697
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kapil please Use Code Tags when you post a source code. Edit your message using button and then add code tags to it...
 
Kapil Shardha
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the question 2 from Self test of Chapter 6:


And its answer is "PCP" which is not clear.
 
Ranch Hand
Posts: 537
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
This is my favorite tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic