Static fields are shared among all the instances
of the class.
Static fields can be initialized in a static block:
public class MyClass {
private static int value;
static {
value = ...;
}
// ...
}
Inner class
A class nested inside another class.
An inner class has access to the variables and methods
of the outer class, even if they are declared private.
Inner classes can be protected by the outer class
from external use.
Intended for small helper classes of the outer class.
Interfaces
A Java interface consists of declarations of abstract
methods and constants.
An abstract method declaration is a method header
without a method body.
An interface defines a contact without an implementation.
An interface cannot be instantiated, since it has
no implementation.
Interfaces are to be implemented by classes.
A class that implements an interface is responsible for providing implementations
of all the abstract methods declared in the interface.
An interface provides a client's view of a software
component, and a class implementing the interface provides the implementer's
view of the software component.
Examples:
public interface Comparable {
public int compareTo(Object
o);
}
public interface Iterator {
public boolean hasNext();
public Object next();
public void remove();
}
Java Applet
Java programs that run in web browsers.
Embedded into an HTML file using the <applet>
tag.
No main() method
Must extend the Applet class
There are several special methods that serve specific
purposes
public void paint(Graphics g)
Automatically executed to draw the applets contents
A Graphics
object defines a graphics context on which
we can draw shapes and text
The Graphics
class has several methods for drawing shapes