2.3 Defining the Class

The beginning of an Oolong source file gives information about the class as a whole, including its name, superclass, and interfaces.

The .class directive names the class

 .class public final foo/Bar 

The class name is a collection of words separated by forward slashes (/). Everything up to the last slash is called the package; everything after it is the class name. Throughout the virtual machine, only the fully qualified name (both the package and class name) is used.

The Java import statement lets you refer to classes just by the class name. However, the JVM doesn't permit this, since it can lead to ambiguities. When a Java compiler turns the Java source into JVM bytecodes, it must figure out the fully qualified name before it builds the class file.

The .class directive may also list some properties of the class. The keywords in Table 2.1 may be used.

Table 2.1. .class directive keywords
Keyword Meaning
public This class may be referenced from anywhere. If it's not given, only other classes with the same package name may refer to it.
final This class may not be subclassed; that is, no class may use it as a superclass.
super In the method bodies for this class, the invokespecial instruction has a special meaning when it's used on methods of superclasses. See section 4.5.5 for more information.
interface This class is used as an interface. It may not be instantiated.
abstract Programs are not allowed to create instances of this class. This keyword must be given if any of the methods are marked abstract.
strictfp All methods in this class use strictly conforming floating-point arithmetic. If this keyword is not present, implementations may use extra precision. (Ignored on pre-Java 2 platform JVMs.)



Programming for the Java Virtual Machine
Programming for the Javaв„ў Virtual Machine
ISBN: 0201309726
EAN: 2147483647
Year: 1998
Pages: 158
Authors: Joshua Engel

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net