Document Using Examples

 class​ Supply {
 
 /**
  * The code universally identifies a supply.
  *
» * It follows a strict format, beginning with an S (for supply), followed
  * by a five digit inventory number. Next comes a backslash that
  * separates the country code from the preceding inventory number. This
  * country code must be exactly two capital letters standing for one of
  * the participating nations (US, EU, RU, CN). After that follows a dot
  * and the actual name of the supply in lowercase letters.
  */
 static​ ​final​ Pattern CODE =
  Pattern.compile(​"^S\\d{5}\\\\(US|EU|RU|CN)\\.[a-z]+$"​);
 }

Some programming constructs are very powerful, but also very complex. Regular expressions fall into this category. ...

Get Java By Comparison now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.