François Pinard's site

Java classes





1   Fundamental types

  • Objects are either of primitive type or reference type. Object is the base for all reference types, look for SoftReference and WeakReference within java.lang.ref. Get Class for inspection and, within java.lang.reflect, Modifier, AnnotatedElement
  • Among Throwable, Error (unchecked) and Exception (checked). However, in the latter, there is RuntimeException (unchecked). To debug, StackTraceElement and java.util.logging.

2   System issues

Runtime gives access to the OS environment, and System to SecurityManager and Properties.

3   Structural types

3.1   Primitive types

        Type      Width   Default   Examples of constants

        bool      ≥ 1     false     false  true

        char      16      '\u0000'  'C'  '\u0043'

        byte       8      0         26  032  0x1a

        short     16      0

        int       32      0

        long      64      0

        float     32      0.0f      123.4f

        double    64      0.0d      123.4, 1.234e2

For classes boxing primitive types, use this chart:

                   boxed           unboxed     

                   Boolean         bool    

                   Character       char    

         Number    Byte            byte    

                   Short           short   

                   Integer         int     

                   Long            long    

                   Float           float   

                   Double          double  

Also see Void.

  • For arithmetic: Number and Math. Number is also extended by BigInteger, BigDecimal, AtomicInteger and AtomicLong, see common methods implemented in all its subtypes.
  • For characters and strings: Character, String, StringBuilder and StringBuffer. Also, within java.util.regex: Pattern, Matcher and PatternSyntaxException.

Example of a constant string: "ABC\\\"\'\t\f\r\n\u0042xyz".

3.2   Arrays

  • Declaration: TYPE[DIM] VARIABLE;
  • Allocation: VARIABLE = new TYPE[DIM];
  • Literal: {【EXPRESSION【, EXPRESSION】☼】♭}
  • Attributes
    • .length
  • Useful:

      void arraycopy(Object src, int srcPos,

                     Object dest, int destPos,

                     int length)


  • Also see Arrays, Comparator◊ and Comparable◊.

3.3   Miscellaneous

  Calendar.

4   Collections

  • The collection framework is based on Collection◊ (and Iterator◊, which replaces Enumeration◊). Collections holds related utilities.
  • Set◊ includes HashSet, TreeSet and LinkedHashSet. There is also SortedSet◊. EnumSet and CopyOnWriteArraySet are special implementations.
  • List◊ includes ArrayList and LinkedList (and ListIterator◊). Older Vector has been amended as well. CopyOnWriteArrayList is a special implementation.
  • Queue◊ includes LinkedList. PriorityQueue is a special implementation. BlockingQueue◊ includes LinkedBlockingQueue, ArrayBlockingQueue, PriorityBlockingQueue, DelayQueue and SynchronousQueue.
  • Map◊ includes HashMap, TreeMap and LinkedHashMap. Older Hashtable (a kind of Dictionary) has been amended as well. There is also SortedMap◊ and NavigableMap◊. EnumMap, WeakHashMap and IdentityHashMap are special implementations. ConcurrentMap◊ includes ConcurrentHashMap, while ConcurrentNavigableMap◊ includes ConcurrentSkipListMap.

5   Parallelism

  • Besides the basics, mainly within java.util.concurrent, java.util.concurrent.locks and java.util.concurrent.atomic.
  • ProcessBuilder may create Process objects.
  • Runnable◊ includes Thread.
  • Lock◊ includes ReentrantLock, which may create Condition◊.
  • Executor◊ (and derived interfaces) may go through Executors tools. In particular, they may accept Callable◊ and return Future◊.

6   Input and output

  • Mainly within java.io, but also within java.nio.
  • Handling File names and FileLock, and RandomAccessFile.
  • For unbuffered input/output: FileInputStream and FileOutputStream are byte oriented. FileReader and FileWriter are character oriented. InputStreamReader and OutputStreamWriter establishes a bridge between byte oriented and character oriented.
  • For buffered input/output: BufferedInputStream and BufferedOutputStream are byte oriented. BufferedReader and BufferedWriter are character oriented.
  • For binary input/output: DataInputStream and DataOutputStream for primitive types. ObjectInputStream and ObjectOutputStream for serializable types.
  • For in-memory input/output: ByteArrayInputStream and ByteArrayOutputStream are byte oriented. CharArrayReader and CharArrayWriter are character oriented.
  • For Formatted input/output: Scanner and Formatter are related tools. PrintStream is byte oriented, yet it features a character stream internally. This is historically the type of System.{out,err}. PrintWriter is character oriented. Console may be used if standard streams are not redirected. System.in is byte oriented and has no character feature.