Java Reference
In-Depth Information
Variable-Length Argument List
As of Java 5.0, a method in Java can declare a variable-length argument list by using
the ellipsis ( . . . ) after the data type of the variable-length parameter. For example, the
following method can take in any number of String references:
public void displayErrors(OutputStream out, String... errors)
Behind the scenes, the errors variable is actually implemented as an array of String
references. We will discuss the details of variable-length arguments later in this section.
The exception list is a throws clause that lists the exceptions the method declares. Separate
multiple exceptions by commas. The throws clause is not needed if the method does not
throw any checked exceptions. Here are some examples of methods with a throws clause:
readLine() throws IOException
forName(String n) throws ClassNotFoundException
clone() throws CloneNotSupportedException
getResponse(int x) throws IOException, RMIException
We will discuss exceptions in detail in Chapter 3, “Flow Control.”
Method Signatures
A method signature consists only of a method's name and parameter types. The
modifi ers, return type, exception list, and method body are not considered a part
of a method's signature. The concept of a method signature is important in method
overriding, which we discuss later in this chapter.
JavaBeans Naming Convention
JavaBeans is a technology for developing software components in Java. Knowledge of
developing JavaBeans is not required for the SCJP exam. However, the exam objectives
specifi cally state knowledge of the JavaBeans naming convention for methods. The methods
in the Java API use this naming convention, as do most Java developers.
Search WWH ::




Custom Search