• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

The meaning of () in the following SCJP test Objective

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

This is an extract of the Test Objective for 3.API Content

"Write code that uses standard J2SE APIs in the java.util and java.util.regex packages to format or parse strings or streams. For strings, write code that uses the Pattern and Matcher classes and the String.split method. Recognize and use regular expression patterns for matching (limited to: . (dot), * (star), + (plus), ?, \d, \s, \w, [], ()). The use of *, +, and ? will be limited to greedy quantifiers, and the parenthesis operator will only be used as a grouping mechanism, not for capturing content during matching"

I am not sure exactly what the bold bit means. Is it possible for someone to clarify it, maybe even with examples.

Thanks
Katrin
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Generally, the parenthesis operator '()' will be used in compound expressions for grouping in order to determine the exact way how an expression should be evaluated.

For e.g.,

x + (y / z)

if we dont specify the paranthesis here, the operator with higher preference i.e., '+' will be evaluated first.

I believe that the statement means : the above explained grouping concepts will be tested in the cert exam (atleast for Java 2 this is what tested) for the parenthesis operator.
 
Krithika Srinath
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, of you check the Pattern and Matcher class details, it will make things more obvious.
 
Author
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's an example:

This will print false, true. The parens apply the ? quantifier to the whole expression in the parens (in the latter case, making the whole phrase "abc" optional), vs. making only the "c" optional in the first case. Hopefully that illustrates the difference.
[ September 13, 2007: Message edited by: Peter Mularien ]
 
Katrin Perry
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you both for your explainations. Peter the example was very clear in showing me how to use () in regular expressions.
Katrin
reply
    Bookmark Topic Watch Topic
  • New Topic