Java Reference
In-Depth Information
Exercise 5.3 Look up the startsWith method in the documentation for String . There
are two versions. Describe in your own words what they do and the differences between them.
Exercise 5.4 Is there a method in the String class that tests whether a string ends with a
given suffix? If so, what is it called and what are its parameters and return type?
Exercise 5.5 Is there a method in the String class that returns the number of characters
in the string? If so, what is it called and what are its parameters?
Exercise 5.6 If you found methods for the two tasks above, how did you find them? Is it
easy or hard to find methods you are looking for? Why?
5.3.1
Interfaces versus implementation
You will see that the documentation includes different pieces of information. They are, among
other things:
Concept:
the name of the class;
a general description of the purpose of the class;
a list of the class's constructors and methods;
The interface of
a class describes
what a class does
and how it can
be used with-
out showing the
implementation.
the parameters and return types for each constructor and method;
a description of the purpose of each constructor and method.
This information, taken together, is called the interface of a class. Note that the interface does
not show the source code that implements the class. If a class is well described (that is, if its
interface is well written) then a programmer does not need to see the source code to be able to
use the class. Seeing the interface provides all the information needed. This is abstraction in
action again.
Concept:
The complete
source code that
defines a class
is called the
implementation
of that class.
The source code behind the scene, which makes the class work, is called the implementation
of the class. Usually a programmer works on the implementation of one class at a time, while
making use of several other classes via their interfaces.
This distinction between the interface and the implementation is a very important concept, and
it will surface repeatedly in this and later chapters of this topic.
Note The word interface has several meanings in the context of programming and Java. It is used
to describe the publicly visible part of a class (which is how we have just been using it here), but
it also has other meanings. The user interface (often a graphical user interface) is sometimes re-
ferred to as just the interface , but Java also has a language construct called interface (discussed in
Chapter 10) that is related but distinct from our meaning here.
It is important to be able to distinguish between the different meanings of the word interface in a
particular context.
 
Search WWH ::




Custom Search