Java Reference
In-Depth Information
The Scanner class has other features, such as the ability to fi nd the next occurrence of a
token, skip tokens, and work with locales. However, the information provided in this sec-
tion is suffi cient for the types of questions that you can expect on the SCJP exam regarding
Scanner .
Summary
This chapter covered the “API Contents” section of the SCJP exam objectives. We discussed
many useful classes in the Java language, starting with the primitive wrapper classes in java
.lang . Each primitive type has a corresponding class that is used to “wrap” the primitives
into objects. As of Java 5.0, a primitive type is automatically boxed into its corresponding
wrapper class and automatically unboxed whenever necessary.
Strings were discussed in detail, including the differences between the String , String-
Builder , and StringBuffer classes. The String class represents an immutable string of
characters. StringBuilder and StringBuffer represent mutable strings of characters, and
the two classes have the same method signatures and constructor parameters. The only dif-
ference between them is that StringBuffer is thread-safe and StringBuilder is not.
A key topic discussed in this chapter was the input and output of data, including the
difference between byte streams and character streams (readers and writers). Low-level
streams connect to the source of the data, and high-level streams are chained to existing
streams. We saw how to buffer data streams using the BufferedInputStream , Buffered-
OutputStream , BufferedReader , and BufferedWriter classes. We also discussed how to
read and write primitive types and strings using the DataInputStream and DataOutput-
Stream classes.
The java.io.File class represents the pathname of a fi le or directory, and the class
contains methods for determining information about the fi le or directory is represents. The
FileInputStream and FileOutputStream classes read and write raw bytes to fi les, and the
FileReader and FileWriter classes read and write characters streams to fi les. We saw how
to use the format/printf methods of the PrintWriter class to format strings. We also dis-
cussed the Console class, which represents the JVM environment's console.
Serialization refers to taking the state of an object and writing it to a stream. An object's
class must implement java.io.Serializable to be serialized. Use the ObjectInputStream
and ObjectOutputStream classes to read and write objects to a stream.
We spent a large portion of this chapter discussing how to format numbers, currency,
dates, and strings, including how to use the java.util.Locale class to perform these
operations within a given locale. Use the format methods of the java.text.Number
Format class to format numbers and currency for a specifi c locale. The DecimalFormat
class is a child class of NumberFormat and formats fl oating-point numbers for a specifi c
locale. We discussed how to use the parse method of NumberFormat to parse numbers
and currency. We also discussed how to format and parse dates using the DateFormat
class of java.text .
Search WWH ::




Custom Search