|
|
|
A wrapper class stores an entity and adds
operations that the original type did not support correctly. Java has
wrapper types for the 8 primitive types (e.g., Integer for int) |
|
An adapter class is used when the interface of
an existing class needs to be changed to a more appropriate one (e.g., InputStreamReader
and OutputStreamWriter that convert byte-oriented streams to
character-oriented streams). |
|
|
|
|
|
|
|
Group of related classes. |
|
Specified by package statement. |
|
Fewer restrictions on access among each other; |
|
if class is called public, then it is visible to
all classes |
|
if no visibility modifier is specified, its
visibility is termed as “package visibility” and is somewhere between: |
|
private (other classes in package cannot access
it) and |
|
public (other classes outside package can also
access it) |
|
Package locations can be specified by the CLASSPATH
environmental variables. |
|
The import statement helps to get multiple
packages. It saves typing. |
|
|
|
|
An exception is an object that is thrown from
the site of an error and can be caught by an appropriate exception handler. |
|
Separating the handler from error detection
makes the code easier to read and write. finally clause helps cleanup. |
|
User-defined exceptions can be created or
thrown. They are normally not caught in the same block, but passed up to a
calling block. For e.g., |
|
throw new NullPointerException(); |
|
The try region is a guarded region from which
errors can be caught by exceptions. Code that good generate an exception is
enclosed in a try region. Method is exited if exceptions are thrown from
outside try regions. Thus, there is more reliable error recovery without
simply exiting. |
|
It is also possible to rethrow exceptions. |
|
|
|
|
|
Automatically thrown (no need to explicitly
throw them). |
|
No need to specify explicitly that a method
might throw one of these exceptions. |
|
No need to catch them, dealt with automatically. |
|
It is possible to explicitly throw a runtime
exception. |
|
|
|
|
In C++ specifications are put in .h files and
implementations in .cpp files. In Java, only interfaces are put in separate
files. |
|
Appropriate documentation is added to the
implementation, and then we run javadoc program to automatically generate a
set of HTML files as documentation for the code. |
|
Javadoc comments start are delimited by /** and */.
Other useful comments are prefaced by @param, @author, @return, @throws. |
|
|
|
|
|
|