Java Reference
In-Depth Information
The other specifi ers are Java keywords from the following list:
static This modifi er declares a static method, also known as a class method.
final The method cannot be overridden by a child class.
abstract This modifi er declares an abstract method that must be overridden by any non-
abstract child classes.
native The Java method maps to a method written in a different language, usually C or
C++. The SCJP exam does not require knowledge of the native keyword.
synchronized The calling thread must obtain the object's lock before the method exe-
cutes. We will discuss synchronized methods in Chapter 5, “Concurrency.”
A method might not declare any of these modifi ers, or a method might declare more
than one of these. For example, you can have a final synchronized method.
A Java method must declare a return value. (A method declares void if it does not
actually return anything.) A list of the possible return values of a method follows:
void The method does not return anything.
Primitive type A method can return a byte , short , int , long , float , double , boolean ,
or char .
Reference type A method can return any reference, meaning a method can return any
data type.
The name of a method must be a valid Java identifi er. The name of a method should be a
verb starting with a lowercase letter using the mixed uppercase notation. For example, the
following list of method names is found in the Java API:
toString
run
getStackTrace
isEmpty
setTimeZone
The parameter list is a comma-separated list of variable declarations placed within the
parentheses. Use empty parentheses for a method that does not take in any arguments.
Here are some sample parameter lists:
yield() : No parameters.
read(byte [] b, int off, int len) : Three parameters — an array of bytes and two
ints .
connect(SocketAddress endpoint, int timeout) : Two parameters — a
SocketAddress and an int .
displayErrors(OutputStream out, String... errors) : An OutputStream followed
by any number of String references.
Search WWH ::




Custom Search