In our fifth section on learning Java6 we begin our investigations of the Java API by looking at the
StringBuffer classes. These predefined classes come
with a multitude of methods for working with strings and are part of the
java.lang package which is implicitly imported into all out Java programs for us. After this we broaden our horizon of Java
by investigating classes that are not implicitly imported into our programs. Before we look at other parts of the Java API, we need to take a closer look at how Java stores predefined classes into namespaces,
which Java calls packages, and how we can import these packages into our programs. With knowledge of packages under our belt we can now look at parts of the Java API outside the default
package. Our first port of call is how we use I/O in Java and for this we will look at the
java.IO package. We start our exploration of Java I/O by looking at the class hierarchies involved
and then take an in-depth look at the byte stream classes and character stream classes used for this purpose. After this we look at the classes available for working with dates, numbers and
currencies. Most languages have an implementation of regular expressions and Java is no exception and we look at the classes used for pattern matching. We finish off our tour of the Java API
by looking at formatting and tokenizing our data.
In our first lesson of this section we learn all about the predefined
String object. We look at string immutability, creation and efficiency before finishing the lesson by looking at some of the methods available for use with this class.
In our second lesson on strings we learn about the predefined
StringBuffer objects and look at some of the methods available for use with these classes.
The rest of this section is about parts of the Java API, which unlike
java.lang, are not implicitly imported into our programs. Before we can look at other parts of the Java API, we need to take a
closer look at how Java stores predefined classes into namespaces, which Java calls packages. In this lesson we learn how we can import existing packages into programs and how to create our own.
Up until now we have been writing our output to the console, it's now time to look at the Java input and output mechanisms (I/O) in much more detail and we start three lessons on the subject with an overview of the various streams available in Java.
Now we have got an overview of the class hierarchies involved in Java I/O its time to investigate these classes in more detail. In our second lesson on Java I/O we take a closer look at some of the byte stream
classes that are available for our use in the
java.io package and how we use them.
In our final lesson on Java I/O we take a closer look at some of the character stream classes that are available in Java and how we use them.
In this lesson we look at the
NumberFormat classes that allow us to create and manipulate dates, times, numbers and
currencies for different regions of the world.
In this lesson we look at regular expressions (regex) and how we can use regular expression patterns for matching data. A regular expressions is a string containing normal characters as well as metacharacters which make a pattern we can use to match data. The metacharacters are used to represent concepts such as positioning, quantity and character types. The terminology used when searching through data for specific characters or groups of characters is known as pattern matching and is generally done from the left to the right of the input character sequence.
In our final lesson of the API Contents section we look at formatting and tokenizing our data. We begin the lesson by looking at formatting our output and Java offers us different options for doing this. In this
lesson we will look at formatting data using the
java.util.Formatter class as well as using the static
format() method of the
java.util.String class. We finish of our look at
formatting output by looking at the
printf() method contained in the
We finish off our tour of the Java API by looking at tokenizing our data. For this we will first look at the
split() method of the
String class which uses a regular expression
delimiter to tokenize our data. After this we look at the
java.io.Scanner class; objects of this class allow us to break input into tokens using a delimiter pattern which defaults to whitespace or can be
set using a regular expression.