M250 Java Reference
M250 Java Reference
Unless otherwise stated, copyright © 2026 The Open University, all rights reserved.
Printable page generated Wednesday 7 January 2026 at 12:55
Introduction
This booklet provides a reference to many of the classes and interfaces you have encountered in M250
and is intended for use during your study of the module and in the final exam. It is based on the Java
Application Programming Interface (API) for those classes and interfaces, but differs from the Javadoc in
the following respects:
We have simplified the class and method comments and, in places, the method headings.
We have not mentioned exceptions thrown by some of the methods.
For each class or interface we do not necessarily show every method that is available; we omit some
methods that are not needed for your study of M250. If you require more detail you can access the
full documentation for the Java Class Libraries from BlueJ’s Help menu.
Similarly, we do not always list any or all of the interfaces implemented by a class.
This booklet is not designed to be read from cover to cover; rather, you should use the navigation pane
and search function to find the documentation for a particular method, class or interface.
1 Strings
The String and StringBuilder classes have a number of methods that differ only in the type of their
argument. In such cases, we list the method only once and give the argument as T anArgument, which is
M250 shorthand to tell you that there are multiple methods, one for each of the primitive types and one
that takes an argument of type Object. For example:
Class String
[Link]
[Link]
The String class represents character strings. All string literals in Java programs, such as "abc", are
implemented as instances of this class. Instances of the String class are immutable: they cannot be
changed once created.
[Link] 1/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
Constructor summary
String()
String(char[] value)
Initialises a new String object so that it represents the sequence of characters currently contained
in the character array argument.
String(String original)
Initialises a new String object so that it represents the same sequence of characters as the
argument; in other words, the new string is a copy of the argument string.
String(StringBuilder builder)
Initialises a new String object that contains the sequence of characters currently contained in the
StringBuilder argument.
Method summary
In the following methods, where the formal argument is of type CharSequence, you can assume for our
purposes that the actual argument is a String object. If a formal argument is given as int ch, you can
assume for our purposes that the actual argument is of type char.
Compares this string to the argument string character by character, based on the Unicode value of
each character in the strings.
If this String comes before the argument string alphabetically, returns a negative int. If this String
comes after the argument string alphabetically, returns a positive int. (Note that an upper-case letter
comes before the same lower-case letter.)
The size of the returned int (positive or negative) tells you how far apart in the character sequence
the first unequal characters are.
If the two strings are exactly equal, 0 is returned.
[Link] 2/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
Compares this string to the argument string character by character as for the compareTo() method,
but ignoring case differences.
Returns this string if the length of the argument string is 0. Otherwise, returns a new String object
that is the concatenation of this string followed by the argument string.
boolean contains(CharSequence s)
Returns true if this string contains the sequence of char values contained in the argument as a
subsequence, false otherwise.
Returns true if this string contains the same sequence of char values as the argument, false
otherwise.
Returns a new String that has the same characters, in the same order, as the char array argument.
Returns true if this string ends with the argument, false otherwise.
Returns true if the argument is not null and is a String object that holds the same sequence of
characters as this string, false otherwise.
Returns a formatted string using the specified format string and arguments. (The notation ‘...’ in an
argument list indicates that a variable number of arguments (0 or more) is allowed.)
int hashCode()
[Link] 3/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
Returns the index of the first occurrence of the argument ch within this string. If the character does
not occur within this string, -1 is returned.
Returns the index of the first occurrence of the argument ch within this string, starting the search at
fromIndex. If the character does not occur within this string, -1 is returned.
Returns the index of the first character of the first occurrence of the argument str within this string. If
the string does not occur within this string, -1 is returned.
Returns the index of the first character of the first occurrence of the argument str within this string,
starting the search at fromIndex. If the string does not occur within this string, -1 is returned.
boolean isEmpty()
int length()
Returns a copy of this string in which all occurrences of oldChar have been replaced with newChar.
Returns an array of strings computed by splitting this string around matches of the given regular
expression. Any trailing empty strings are discarded. For example:
"boo:and:foo".split(":");
[Link] 4/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
As another example:
"boo:and:foo".split("o");
Returns true if this string starts with the argument, false otherwise.
Returns a substring of this string beginning at beginIndex and continuing to the end of the string.
char[] toCharArray()
Returns an array of char that has the same characters, in the same order, as this string.
String toLowerCase()
Returns a copy of this string with all the characters in lower case.
String toString()
String toUpperCase()
Returns a copy of this string with all the characters in upper case.
String trim()
Returns a copy of this string with leading and trailing whitespace omitted.
Returns the string representation of the actual argument, which can be of any primitive or reference
type. For example, if x references an object, [Link](x) and [Link]() return the
[Link] 5/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
same string.
Class StringBuilder
[Link]
[Link]
The StringBuilder class represents character strings. However, unlike instances of String, instances
of StringBuilder are mutable, so can be changed once created.
StringBuilder implements the Appendable interface, which means that it has the append(char)
method.
Constructor summary
StringBuilder()
StringBuilder(String str)
Initialises a new StringBuilder object so that it represents the same sequence of characters as
the argument.
Method summary
See also the Appendable interface.
Appends a string representation of the actual argument (which can be of any primitive or reference
type) to this object. Returns this StringBuilder.
Removes a substring from this object, from start to end - 1. Returns this object.
[Link] 6/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
Removes the char value at the index specified by the argument. Returns this object.
Returns the index of the first character of the first occurrence of the argument str within this object.
If the string does not occur within this object, -1 is returned.
Returns the index of the first character of the first occurrence of the argument str within this object,
starting the search at fromIndex. If the string does not occur within this object, -1 is returned.
Inserts a string representation of the second argument (which can be of any primitive or reference
type) into this object at the index specified by offset. Returns this object.
int length()
Removes a substring of this object, which is specified as start to end - 1, and then inserts the
String argument at start. Returns this object.
StringBuilder reverse()
Returns the String that is a substring of this object from start to end - 1.
[Link] 7/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
String toString()
We have simplified the documentation in two ways. Where standard Javadoc for collections would show
the declaration of a formal argument for a method as:
or
and
to:
‘Views’ of collections
[Link] 8/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
Note that when a method returns a ‘view’ of a collection, it means that the returned collection is not
independent of the original collection. In other words, changes made to a view of a collection are
reflected in the original collection. Changes to the original collection may also affect a view you have
of it.
Superinterfaces: Iterable
The root interface in the collection hierarchy, representing a group of objects, known as its elements.
Some collections allow duplicate elements and others do not. Some are ordered and others unordered.
The Java Development Kit provides implementations of more specific subinterfaces such as Set and
List. The Collection interface is typically used to pass collections around and manipulate them where
maximum generality is desired.
Method summary
boolean add(E element)
Adds the argument to this collection. Returns true if the operation was successful, false otherwise.
Adds all the elements in the argument to this collection. Returns true if the operation was
successful, false otherwise.
void clear()
Removes all the elements from this collection (if there are any).
[Link] 9/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
Returns true if this collection contains all of the elements in the argument collection, false
otherwise.
Returns true if the argument object is equal to this collection, false otherwise.
int hashCode()
boolean isEmpty()
Tests whether this collection is empty. Returns true if empty, false otherwise.
Removes one occurrence of the argument from this collection. Returns true if the operation is
successful, false otherwise.
Removes one occurrence of each of the argument’s elements from this collection. Returns true if
the operation is successful, false otherwise.
Retains only the elements in this collection that are also contained in the argument. Returns true if
the operation is successful, false otherwise.
int size()
Object[] toArray()
[Link] 10/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
Returns an array containing all the elements in this collection; if this collection is ordered, the
returned array preserves the original order. The runtime type of the returned array is that of the
argument.
Interface Iterable
[Link]
Implementing this interface allows a collection class’s instances to be iterated over by a for-each
statement.
Method summary
For more information, see the Iterator interface.
Iterator<T> iterator()
Interface Iterator
[Link]
Method summary
boolean hasNext()
E next()
[Link] 11/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
void remove()
Optional operation to remove the last element returned by this iterator. (The method may throw an
UnsupportedOperationException if the remove operation is not supported.) Iterator behaviour is
unspecified if the underlying collection is modified – while the iteration is in progress – in any way
other than by calling this method.
Interface List
[Link]
An ordered collection providing control over where in the list each element is inserted and retrieved from.
Method summary
See also the Collection and Iterable superinterfaces.
Appends the argument to the end of this list. Returns true if the operation was successful, false
otherwise.
Inserts the argument element into this list at the position specified by the argument index. Shifts the
element currently at that position (if any) and any subsequent elements to the right (adds one to their
indices).
Appends all the elements in the argument to the end of this list, in the order that they are returned by
the argument’s iterator. Returns true if the operation is successful, false otherwise.
Inserts all the elements in the argument aCol into this list at the position specified by the argument
index. Shifts the element currently at that position (if any) and any subsequent elements to the right
(adds one to their indices). Returns true if the operation is successful, false otherwise.
[Link] 12/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
Compares the argument obj with this list for equality. Returns true if, and only if, the argument is
also a list, both this list and the argument have the same size, and all corresponding pairs of
elements in the two lists are equal; returns false otherwise.
E get(int index)
int hashCode()
Returns the index in this list of the first occurrence of the argument, or -1 if this list does not contain
this element.
Returns the index in this list of the last occurrence of the argument, or -1 if this list does not contain
this element.
E remove(int index)
Removes and returns the element at the position in the list specified by the argument.
Removes the first occurrence in this list of the argument. Returns true if the operation is successful,
false otherwise.
Replaces the element at the position specified by the argument index with the argument element
and returns the original element.
int size()
[Link] 13/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
Returns a view of the portion of this list between the indices specified by the arguments fromIndex
(inclusive) and toIndex (exclusive).
Object[] toArray()
Returns an array containing all the elements in this list in the same order.
Returns an array containing all the elements in this list in the same order. The runtime type of the
returned array is that of the argument.
Interface Set
[Link]
A collection that contains no duplicate elements, and at most one null element. As implied by its name, this
interface models the mathematical ‘set’ abstraction.
Method summary
See also the Collection and Iterable superinterfaces.
Adds the argument to this set, unless it is already there. Returns true if the argument is added,
false otherwise.
Adds all the elements in the argument to this set, unless they are already there. Returns true if the
operation is successful, false otherwise.
[Link] 14/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
Compares the argument with this set for equality. Returns true if the argument is also a set, the two
sets have the same size, and every element in the argument is also contained in this set; returns
false otherwise.
int hashCode()
A set that keeps its elements ordered according to their natural ordering. Several additional operations are
provided to take advantage of this ordering.
Method summary
See also the Collection, Set and Iterable superinterfaces.
E first()
Returns a view of the portion of this set whose elements are strictly less than toElement.
E last()
Returns a view of the portion of this set between the elements specified by the arguments
fromElement (inclusive) and toElement (exclusive).
[Link] 15/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
Returns a view of the portion of this set whose elements are greater than or equal to fromElement.
Interface Map
[Link]
A collection that maps keys to values. A map cannot contain duplicate keys; each key can map to at most
one value.
Method summary
void clear()
Tests whether a given key is present in this map. Returns true if the key is present, false
otherwise.
Tests whether the argument is present as a value in this map. Returns true if the argument is
present as a value, false otherwise.
Compares the argument with this map for equality. Returns true if the argument is also a map and
the two maps represent the same key–value pairs.
V get(Object key)
If the argument exists as a key in this map, returns the associated value. Otherwise, returns null.
int hashCode()
[Link] 16/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
boolean isEmpty()
Tests whether this map contains any key–value pairs. Returns true if the map is empty, false
otherwise.
Set keySet()
Returns a view of the keys contained in this map as a set. If a key is removed from the returned set,
the associated key–value pair is removed from the map and vice versa.
Inserts a key–value pair into this map. If a key–value pair already exists with the same key, the old
value is overwritten by the new value. Returns the previous value for the key, if there was one, null
otherwise.
Copies all the key–value pairs from the argument into this map.
V remove(Object key)
Removes the key–value pair associated with the argument (if the key exists). Returns the previous
value for the key, if there was one, null otherwise.
int size()
Collection values()
Superinterfaces: Map
[Link] 17/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
A map that guarantees that its elements are sorted in ascending key order, according to the natural
ordering of its keys.
Method summary
See also the Map superinterface.
K firstKey ()
Returns a view of the portion of this map whose keys are strictly less than toKey.
K lastKey ()
Returns a view of the portion of this sorted map between the keys specified by the arguments
fromKey (inclusive) and toKey (exclusive).
Returns a view of the portion of this sorted map whose keys are greater than or equal to fromKey.
Implementation of the Set interface, ‘backed’ by a hash table. It makes no guarantees as to the iteration
order of the set.
Constructor summary
[Link] 18/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
HashSet()
HashSet(Collection aCol)
Method summary
See the Set, Collection and Iterable interfaces.
Class TreeSet
[Link]
[Link]
[Link]
[Link]
Implementation of the SortedSet interface. It guarantees that the sorted set is in ascending element
order, according to the natural order of the elements.
Constructor summary
TreeSet()
TreeSet(Collection aCol)
Constructs a TreeSet containing the elements in the Collectionargument, sorted according to the
elements’ natural order.
TreeSet(SortedSet aSortedSet)
Constructs a TreeSet containing the elements in the SortedSet argument, sorted according to the
elements’ natural order.
Method summary
See the Collection, Set, SortedSet and Iterable interfaces.
Class HashMap
[Link] 19/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
[Link]
[Link]
[Link]
Implementation of the Map interface based on a hash table. Ordering of keys is not supported.
Constructor summary
HashMap()
HashMap(Map aMap)
Method summary
See the Map interface.
Class TreeMap
[Link]
[Link]
[Link]
Implementation of the SortedMap interface. It guarantees that the map keys are sorted in ascending key
order, according to the natural order of the keys.
Constructor summary
TreeMap()
TreeMap(Map aMap)
Constructs a TreeMap containing the same mappings as the argument, sorted according to the keys’
natural order.
[Link] 20/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
TreeMap(SortedMap aSortedMap)
Constructs a TreeMap containing the same mappings as the argument, sorted according to the same
ordering.
Method summary
See the Map and SortedMap interfaces.
Class ArrayList
[Link]
[Link]
[Link]
[Link]
Constructor summary
ArrayList()
ArrayList(Collection aCol)
Constructs an ArrayList containing the elements of the argument, in the order they appear in the
argument.
Method summary
See the List, Collection and Iterable superinterfaces.
A utility class that contains static methods for manipulating arrays (such as sorting and searching). The
methods of this class throw a NullPointerException if the array references provided to them as
arguments are null.
[Link] 21/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
Method summary
static List asList(E[] anArray)
Returns a fixed-size list ‘backed’ by the array argument. (Changes to the returned list are reflected in
the array and vice versa.)
Searches the array argument for the value specified by the second argument using the binary search
algorithm. If found, returns the index of the element, otherwise returns (−(insertion point) − 1).
The array being searched must be sorted (as by the sort(int) method, below); if not, the results
are undefined. If the array contains multiple elements with the same specified value, there is no
guarantee which one is found.
There are equivalent methods for the primitive types byte, char, double, float, long and short.
Searches the array argument for the object specified by the second argument using the binary
search algorithm. If found, returns the index of the element, otherwise returns (−(insertion point) − 1).
The array being searched must be sorted into ascending order according to the natural ordering of its
elements (as by the sort(Object[] method, below); if not, the results are undefined. If the array
contains multiple elements equal to the specified object, there is no guarantee which one is found.
Returns true if the two array arguments are deeply equal to one another. Two array references are
considered deeply equal if both are null or they refer to arrays that contain the same number of
elements and all corresponding pairs of elements in the two arrays are deeply equal.
Returns a hash code based on the ‘deep contents’ of the array argument. If the array contains other
arrays as elements, the hash code is based on their contents and so on, ad infinitum.
Returns a string representation of the ‘deep contents’ of the array argument. If the array contains
other arrays as elements, the string representation contains their contents and so on, ad infinitum.
[Link] 22/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
Returns true if the two array arguments are equal to one another, false otherwise. There are
equivalent methods for the primitive types boolean, byte, char, double, float, long and short.
Returns true if the two array arguments are equal to one another, false otherwise.
Assigns the int argument val to each component of the array argument. There are equivalent
methods for the primitive types boolean, byte, char, double, float, long and short.
static void fill(int[] anArray, int fromIndex, int toIndex, int val)
Assigns the int argument val to the components of a subarray of the array argument. The range of
the subarray is given by the arguments fromIndex (inclusive) and toIndex (exclusive). There are
equivalent methods for the primitive types boolean, byte, char, double, float, long and short.
static void fill(Object[] anArray, int fromIndex, int toIndex, Object val)
Assigns the Object argument val to the components of a subarray of the array argument. The
range of the subarray is given by the arguments fromIndex (inclusive) and toIndex (exclusive).
Assigns the Object argument val to each component of the array argument.
Returns a hash code based on the contents of the array argument. There are equivalent methods for
the primitive types boolean, byte, char, double, float, long and short.
Sorts the argument, an array of integers, into ascending numerical order. There are equivalent
methods for the primitive types byte, char, double, float, long and short.
[Link] 23/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
Sorts a subarray of the array argument into ascending numerical order. The subarray is specified by
the arguments fromIndex (inclusive) and toIndex (exclusive). There are equivalent methods for the
primitive types byte, char, double, float, long and short.
Sorts the argument, an array of objects, into ascending order, according to the natural ordering of its
elements.
Sorts a subarray of the array argument into ascending order, according to the natural ordering of its
elements. The subarray is specified by the arguments fromIndex (inclusive) and toIndex
(exclusive).
Returns a string representation of the contents of the array argument. There are equivalent methods
for the primitive types boolean, byte, char, double, float, long and short.
A utility class that consists exclusively of static methods that operate on, or return, collections. The
methods of this class throw a NullPointerException if the objects provided to them as arguments are
null.
Method summary
static boolean disjoint(Collection col1, Collection col2)
Returns true if the two arguments have no elements in common, false otherwise.
[Link] 24/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
Returns the number of elements in the argument aCol that are equal to the argument obj.
If sublist is a sublist of source, returns the index of the first element of subList within source;
otherwise, returns -1.
If sublist is a sublist of source, returns the index of the last element of subList within source;
otherwise, returns -1.
Returns the maximum element in the argument, according to the natural ordering of its elements. All
elements in the collection must implement the Comparable interface.
Returns the minimum element in the argument, according to the natural ordering of its elements. All
elements in the collection must implement the Comparable interface.
Sorts the argument into ascending order, according to the natural ordering of its elements. All
elements in the list must implement the Comparable interface.
[Link] 25/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
Constructor summary
Random()
Random(long seed)
Method summary
boolean nextBoolean()
double nextDouble()
int nextInt()
[Link] 26/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
[Link]
Method summary
In the following methods, where the formal argument is of type CharSequence, you can assume for our
purposes that the actual argument is a String object.
append(char c)
append(CharSequence csq)
An object that may hold file-related resources until its close() method is called. The subinterface
Closeable specifies the same method, but only resources managed by try-with-resources statements are
auto-closed.
Method summary
void close() throws Exception
Closes this resource, relinquishing any underlying resources. This method is invoked automatically
on objects managed by a try-with-resources statement.
[Link] 27/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
Interface Readable
[Link]
Method summary
int read(CharBuffer cb)
Constructor summary
File(String pathname)
Constructs a File instance by converting the given pathname string into an abstract pathname.
Method summary
boolean canRead()
Returns true if the application can read the file denoted by this object, false otherwise.
boolean canWrite()
Returns true if the application can modify the file denoted by this object, false otherwise.
boolean exists()
[Link] 28/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
Returns true if the file or directory denoted by this object exists, false otherwise.
boolean isDirectory()
Returns true if the file denoted by this object is a directory, false otherwise.
boolean isFile()
Returns true if the file denoted by this object is a normal file, false otherwise.
String toString()
Class Reader
[Link]
[Link]
An abstract class for reading character streams. Instances of subclasses of the Reader class handle (16-
bit) character streams; this means that they correctly handle textual information based on characters and
strings.
Method summary
abstract void close() throws IOException
Reads a single character. Returns the character read, as an integer in the range 0 to 65535, or -1 if
the end of the stream has been reached.
[Link] 29/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
Reads characters into an array specified by the argument cbuf. Returns the number of characters
read, or -1 if the end of the stream has been reached.
abstract int read(char[] cbuf, int offSet, int length) throws IOException
Reads characters into a portion of cbuf, storing the first character at offSet and reading length
characters. Returns the number of characters read, or -1 if the end of the stream has been reached.
Attempts to read characters into the specified character buffer target. Returns the number of
characters added to the buffer, or -1 if this source of characters is at its end.
Skips n characters.
Class FileReader
[Link]
[Link]
[Link]
[Link]
The simplest Reader subclass to use to open an input stream to read characters from a text file.
Constructor summary
FileReader(File file) throws FileNotFoundException
Method summary
See the Reader abstract class.
Class BufferedReader
[Link]
[Link]
[Link]
[Link] 30/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
Reads text from a character-input stream, buffering characters for efficiency. In general, each read request
made of a Reader causes a corresponding read request to be made of the underlying character or byte
stream. It is therefore advisable to use a BufferedReader to wrap any Reader whose read() operations
may be costly, such as instances of FileReader.
Constructor summary
BufferedReader(Reader in)
Method summary
See also the Reader abstract class.
Reads a line of text. A line is considered to be terminated by any one of a linefeed ('\n'), a carriage
return ('\r') or a carriage return followed immediately by a linefeed. Returns a String containing
the contents of the line, not including any line-termination characters, or null if the end of the stream
has been reached.
Class Scanner
[Link]
[Link]
A simple text scanner that can parse primitive types and strings using regular expressions. A Scanner
breaks its input into tokens using a delimiter pattern, which by default matches whitespace. The resulting
tokens may then be converted into values of different types using the various next methods.
Constructor summary
Scanner(File source) throws FileNotFoundException
Constructs a Scanner that produces values scanned from the file specified by the argument.
Scanner(Readable source)
Constructs a Scanner that produces values scanned from the source specified by the argument.
Note that the Reader class implements the Readable interface so subclasses of Reader can be
wrapped by a scanner.
Scanner(String source)
[Link] 31/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
Constructs a Scanner that produces values scanned from the string specified by the argument.
Method summary
void close()
Pattern delimiter()
boolean hasNext()
boolean hasNextInt()
Returns true if the next token in this scanner’s input can be interpreted as an int value, false
otherwise.
boolean hasNextLine()
Returns true if there is another line in the input from this scanner.
String next()
Finds and returns the next complete token from this scanner.
int nextInt()
String nextLine()
Advances this scanner past the current line and returns the input that was skipped as a string.
[Link] 32/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
Sets this scanner’s delimiting pattern to a pattern constructed from the String argument. Returns
this scanner.
Class Writer
[Link]
[Link]
An abstract class for writing to character streams. Instances of subclasses of the Writer class handle (16-
bit) character streams; this means that they correctly handle textual information based on characters and
strings.
Method summary
In the following methods, where the formal argument is of type CharSequence, you can assume for our
purposes that the actual argument is a String object or a StringBuilder object.
Appends the argument character sequence csq to this object. Returns this object.
Appends a subsequence of the argument character sequence csq to this object, where start is the
index of the first character in the subsequence and end is the index of the character following the last
character. Returns this object.
[Link] 33/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
Flushes the stream. If the stream has saved any characters from the various write() methods in a
buffer, they are written immediately to their intended destination. Then, if that destination is another
character or byte stream, it is flushed. Thus one flush() invocation flushes all the buffers in a chain
of Writers and OutputStreams. If the intended destination of this stream is an abstraction provided
by the underlying operating system, for example a file, flushing the stream guarantees only that bytes
previously written to the stream are passed to the operating system for writing; it does not guarantee
that they are actually written to a physical device such as a disk drive.
abstract void write(char[] cbuf, int offSet, int length) throws IOException
Writes length characters of the array cbuf starting with the character in index position offSet.
Writes a string.
Writes length characters of the string str starting with the character in index position offSet.
Class FileWriter
[Link]
[Link]
[Link]
[Link]
The simplest Writer subclass to use to open an output stream to write characters to a text file.
[Link] 34/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
Constructor summary
FileWriter(File file) throws IOException
Constructs a FileWriter object given a File object. Anything written to file is added at the
beginning, therefore overwriting any existing contents.
Constructs a FileWriter object given a File object. If append is true, anything written to file is
added at the end. If append is false, anything written to file is added at the beginning, therefore
overwriting any existing contents.
Method summary
See the Writer abstract class.
Class BufferedWriter
[Link]
[Link]
[Link]
Writes text to a character-output stream, buffering characters to provide for the efficient writing of single
characters, arrays and strings. It is advisable to use a BufferedWriter to wrap any Writer whose
write() operations may be costly, such as instances of FileWriter.
Constructor summary
BufferedWriter(Writer out)
Method summary
See also the Writer abstract class.
Writes a line separator. This method uses the platform’s own notion of line separator as defined by
the system property [Link]. Using this method to terminate each output line is therefore
preferred to writing a newline character directly.
4 Exceptions
[Link] 35/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
The most important examples of error and exception classes are listed in this section. All of these classes
have a zero-argument constructor as well as a constructor taking a String as an argument (which is used
as the error or exception message).
Class Throwable
[Link]
[Link]
The Throwable class is the superclass of all errors and exceptions in the Java language. Only objects
that are instances of this class (or one of its subclasses) are thrown by the Java Virtual Machine or can be
thrown by the Java throw statement. Similarly, only this class or one of its subclasses can be the
argument type in a catch clause.
Method summary
Throwable getCause()
Returns the cause of this throwable or null if the cause is non-existent or unknown.
String getMessage()
void printStackTrace()
String toString()
Class AssertionError
[Link]
[Link]
[Link]
[Link]
[Link] 36/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
Method summary
See the Throwable class.
Class Exception
[Link]
[Link]
[Link]
The class Exception and its subclasses are a form of Throwable that indicates conditions that an
application might reasonably want to catch. All direct subclasses of Exception (except
RuntimeException and its subclasses) are checked exceptions.
Method summary
See the Throwable class.
Signals that an attempt to open the file denoted by a specified pathname has failed. This exception is
thrown by the FileInputStream and FileOutputStream constructors when a file with the specified
pathname does not exist. It is also thrown by these constructors if the file does exist but for some reason is
inaccessible, for example when an attempt is made to open a read-only file for writing.
Method summary
See the Throwable class.
Class IOException
[Link]
[Link]
[Link]
[Link]
[Link] 37/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
Signals that an I/O exception of some sort has occurred. This class is the general class of exceptions
produced by failed or interrupted I/O operations.
Method summary
See the Throwable class.
RuntimeException is the superclass of those exceptions that can be thrown during the normal operation
of the Java Virtual Machine. A method is not required to catch any instances of subclasses of
RuntimeException that might be thrown during the execution of that method as these exceptions are
unchecked exceptions.
Method summary
See the Throwable class.
Class ArrayIndexOutOfBoundsException
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
Thrown to indicate that an array has been accessed with an illegal index. The index is either negative or
greater than or equal to the size of the array.
Method summary
See the Throwable class.
Class ArithmeticException
[Link]
[Link]
[Link] 38/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
[Link]
[Link]
[Link]
Method summary
See the Throwable class.
Class IllegalArgumentException
[Link]
[Link]
[Link]
[Link]
[Link]
Thrown to indicate that a method has been passed an illegal or inappropriate argument.
Method summary
See the Throwable class.
Class NullPointerException
[Link]
[Link]
[Link]
[Link]
[Link]
Thrown when an application attempts to use null in a case where an object is required.
Method summary
See the Throwable class.
Class NumberFormatException
[Link]
[Link]
[Link]
[Link]
[Link] 39/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
[Link]
[Link]
Thrown to indicate that the executing method has attempted to convert a string to one of the numeric
types, but the string does not have the appropriate format.
Method summary
See the Throwable class.
Class StringIndexOutOfBoundsException
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
Thrown to indicate that a string has been accessed with an illegal index. The index is either negative or
greater than or equal to the size of the string.
Method summary
See the Throwable class.
1 postfix ++ --
2 unary - !
3 multiplicative * / %
4 additive + -
6 equality == !=
[Link] 40/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
8 logical OR ||
9 assignment =
6 Java keywords
The following table includes all the keywords in the Java language, version 1.8.
[Link] 41/42
07/01/2026, 12:55 M250 Java Reference: View as single page | OU online
[Link] 42/42