Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SCJP 5.0 objective 3

 
Ravith Botejue
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can somone explain to me about the regular expressions and how greedy, reluctant, possesive quantifiers work, also the new locale class and the printf() method.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might read MZ's SCJP Tiger Notes to dig out the answers.

Nick
 
Mikalai Zaikin
Ranch Hand
Posts: 3364
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nicholas Cheung:
You might read MZ's SCJP Tiger Notes to dig out the answers.

Nick


Thanks, Nick !

The direct link is : http://java.boot.by/scjp-tiger/ch03s05.html

regards,
MZ
 
Philip Heller
author
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For regular expressions, check out the API page for java.util.Scanner. Also Chapter 8 of the 5.0 rev of "Complete Java 2 Certification". Here's an example, reprinted with author's permission



The output is:

bcd
fgh
jkl

See how the vowels have been used as delimiters?

For more richly-defined pattern matching, you can use the quantifiers * + and ?. * matches zero or more occurrences of the preceding string. So "(ab)*" matches an empty string, "abab", "abababab", and so on. The + quantifier matches one or more occurrences, and the ? quantifier matches zero or one occurrences.

In certain arcane situations, it's hard to decide when a quantifier should stop matching. Should it match the longest possible string, or should it match something shorter? A greedy quantifier, which is the only kind covered in the exam, is the simplest: it matches the longest possible string. Reluctant and possissive quantifiers stop short of the longest match, using subtle algorithms that fortunately are WAY beyond the scope of the SCJP exam.

The Locale class is used for formatting text whose appearance depends on the part of the world where the text will be read. A simple example involves floating-point numbers. In the US and much of Asia, pi is written as 3.14159. But in many European countries the decimal "point" is actually a "comma", and pi is written as 3,14159. The following code prints pi, using the current machine's default locale:



The first string arg describes the format: a floating-point number occupying 7 characters, with 5 of those characters to the right of the decimal point/comma. I live in the US, so my output is "3.14159".

You can specify a locale like this:



Now the output is "3,14159".

Locales are especially good for formatting numbers, dates, and currency. These are all things that vary a lot from one locale to another. Again, there's more about this in the new "Complete Java 2 Certification".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic