23.07.2013 Views

Java IO.pdf - Nguyen Dang Binh

Java IO.pdf - Nguyen Dang Binh

Java IO.pdf - Nguyen Dang Binh

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Java</strong> I/O<br />

tie, and a few similar characters that may be included in the interior of a Unicode identifier<br />

but may not start it.<br />

The is<strong>Java</strong>IdentifierStart() method returns true if the specified character is a valid<br />

beginning of an identifier in <strong>Java</strong> source code; that is, if it's a letter as determined by<br />

isLetter(), or if it's a currency indicator like $ or £, or if it's a connecting punctuation<br />

character like the underscore (_).<br />

public static boolean is<strong>Java</strong>IdentifierStart(char c)<br />

This method might be used by <strong>Java</strong> compilers and similar tools.<br />

The is<strong>Java</strong>IdentifierPart() method is similar but also returns true if the specified<br />

character is a digit in any of Unicode's supported scripts. Digits are legal parts of <strong>Java</strong><br />

identifiers but may not begin an identifier.<br />

public static boolean is<strong>Java</strong>IdentifierPart(char c)<br />

Numeric letters like Roman numerals, combining marks, nonspacing marks, and ignorable<br />

control characters are also allowed in <strong>Java</strong> identifiers as long as they aren't the first characters<br />

of the identifier. is<strong>Java</strong>IdentifierStart() and is<strong>Java</strong>IdentifierPart() are new in <strong>Java</strong><br />

1.1. <strong>Java</strong> 1.0 had identical methods, now deprecated, called is<strong>Java</strong>Letter() and<br />

is<strong>Java</strong>LetterOrDigit():<br />

public static boolean is<strong>Java</strong>Letter(char c)<br />

public static boolean is<strong>Java</strong>LetterOrDigit(char c)<br />

Certain Unicode characters are classified as ignorable within the context of Unicode and <strong>Java</strong><br />

identifiers. The name is something of a misnomer, since these characters aren't ignored. A<br />

better name would be "illegal," since they can't be used in <strong>Java</strong> or Unicode identifiers.<br />

Nonetheless, the word is ignorable; and the isIdentifierIgnorable() method returns true<br />

if the character is ignorable:<br />

public static boolean isIdentifierIgnorable(char c)<br />

Ignorable characters include the nonwhitespace ASCII control characters through 8 and 14<br />

through 27; the Latin-1 control characters 127 through 159; the joining characters 8024<br />

through 8027; the bidirectional controls 8202 through 8206; the format controls 8298 through<br />

8303; and the zero-width nonbreaking space 65,279.<br />

14.5.1.5 Numeric values<br />

java.lang.Character also has several methods for interpreting characters as numbers. The<br />

digit() method returns the numeric value of the character c in the specified base:<br />

public static int digit(char c, int base)<br />

For example, Character.digit('A', 16) returns 10, because in hexadecimal (base 16) the<br />

letter A is used as a digit with the value 10. This method handles bases between 2 and 36.<br />

(The latter is 10 plus the 26 letters in the Roman alphabet.) These limits are available in the<br />

mnemonic constants Character.MIN_RADIX and Character.MAX_RADIX respectively:<br />

353

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!