The Class Character

The following is the declaration of class java.lang.Character. The important point here is to notice all the routines for classifying a character as an identifier, a digit, etc:

public final class java.lang.Character
        implements java.io.Serializable, java.lang.Comparable {
    public java.lang.Character(char); // constructor




     public static final int MIN_RADIX = 2;
     public static final int MAX_RADIX = 36;
     <a id="page_260/">public static final char MIN_VALUE = 'u0000';
     public static final char MAX_VALUE = 'uffff';
     public static final java.lang.Class TYPE = Class.getPrimitiveClass("char");
     public static final byte UNASSIGNED;//about 20 other Unicode types
     public static final byte UPPERCASE_LETTER;
     public static int getType(char); // returns the Unicode type

     public char charValue();
     public int compareTo(java.lang.Character);
     public int compareTo(java.lang.Object);
     public static int digit(char, int);
     public boolean equals(java.lang.Object);
     public static char forDigit(int, int);
     public static int getNumericValue(char);
     public int hashCode();

     public static boolean isDefined(char);
     public static boolean isDigit(char);
     public static boolean isISOControl(char);
     public static boolean isIdentifierIgnorable(char);
     public static boolean isJavaIdentifierPart(char);
     public static boolean isJavaIdentifierStart(char);
     public static boolean isJavaLetter(char); // deprecated
     public static boolean isJavaLetterOrDigit(char); // deprecated
     public static boolean isLetter(char);
     public static boolean isLetterOrDigit(char);
     public static boolean isLowerCase(char);
     public static boolean isSpace(char);
     public static boolean isSpaceChar(char);
     public static boolean isTitleCase(char);
     public static boolean isUnicodeIdentifierPart(char);
     public static boolean isUnicodeIdentifierStart(char);
     public static boolean isUpperCase(char);
     public static boolean isWhitespace(char);
     public static char toLowerCase(char);
     public java.lang.String toString();
     public static char toTitleCase(char);
     public static char toUpperCase(char);

     // class Character is continued on the next page ...
     // class Character continued ...
     // Character contains two top-level nested classes

     public static class java.lang.Character.Subset {
// represents a particular subset of the Unicode characters
        protected java.lang.Character.Subset(java.lang.String);
        public final boolean equals(java.lang.Object);
        public final int hashCode();
        public final java.lang.String toString();
    } // end of Subset

     <a id="page_261/">public static final class java.lang.Character.UnicodeBlock
                                    extends java.lang.Character.Subset {
// Names for Unicode Blocks. Any given character is contained by
// at most one Unicode block.
          public static final UnicodeBlock BASIC_LATIN;
          public static final UnicodeBlock LATIN_1_SUPPLEMENT;
          public static final UnicodeBlock LATIN_EXTENDED_A;
          public static final UnicodeBlock LATIN_EXTENDED_B;
          public static final UnicodeBlock IPA_EXTENSIONS;
          public static final UnicodeBlock SPACING_MODIFIER_LETTERS;
          public static final UnicodeBlock COMBINING_DIACRITICAL_MARKS;
          public static final UnicodeBlock GREEK;
          public static final UnicodeBlock CYRILLIC;
          public static final UnicodeBlock ARMENIAN;
          public static final UnicodeBlock HEBREW;
          public static final UnicodeBlock ARABIC;
          public static final UnicodeBlock DEVANAGARI;
               ... there are about 65 of these in all ...
          public static final UnicodeBlock COMBINING_MARKS_FOR_SYMBOLS;
          public static final UnicodeBlock LETTERLIKE_SYMBOLS;
          public static final UnicodeBlock NUMBER_FORMS;
          public static UnicodeBlock of(char);
     } // end of UnicodeBlock class
} // end of Character class

Java coding style

This seems like a good point in the text to tell you about the recommended coding style for Java. These recommendations are actually in section 6.8, “Naming Conventions,” in the Java Language Specification (JLS).

  • Package names are guaranteed unique by using the Internet domain name in reverse order, as in com.afu.applications.arby. The com (or edu, gov, etc.) part used to be in uppercase, but now lowercase is the recommendation.

  • Class and interface names should be descriptive nouns with the first letter of each word capitalized, as in PolarCoords. Interfaces are often (not always) called something-able, e.g., Runnable or Sortable. There is a caution here: java.util.Observable is not an interface, though java.util.Observer is. These two classes are not well designed.

  • Object and field names are nouns or noun phrases with the first letter lowercase and the first letter of subsequent words capitalized, as in currentLimit.

  • Method names are verbs or verb phrases with the first letter lowercase and the first letter of subsequent words capitalized, as in calculateCurrentLimit.

  • Constant (final) names are in caps, as in UPPER_LIMIT.

If you keep to these simple conventions, you'll be giving useful stylistic hints to those who must maintain your code. Maybe they will do the same for you. There aren't any recommendations in the JLS on brace style, but all the Java run-time code I've ever seen uses this style:

compoundStatement {               void someMethod() {
     statement;                             statement;
     statement;                             statement;
}                                 }

It's a slight variant of “K&R style” (it comes from Kernighan and Ritchie who developed C), known as “The Original One True Brace Style” (TOOTBS).[1] With this style, the else part of an if-else statement and the while part of a do-while statement appear on the same line as the close brace. With most other styles, the braces are always alone on a line. When maintaining someone else's code, always use the style used in that code.

The One True Brace Style has methods formatted like the following:

void someMethod()
{
          statement;
          statement;
}

The Original One True Brace Style, and Java, has them like this:

void someMethod() {
          statement;
          statement;
}

The Java way is more consistent, but makes it a little harder to find functions and review their signatures. You'll be enchanted to hear that there are many further styles and variations that different programmers champion. Stick with TOOTBS.


[1] I'm not making another one of my acronym wisecracks here—this is all true.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.109.234