Creating a class

Although the details of each step may differ depending on whether you are using a Java development tool, the steps involved in creating your own class generally include the following:

To create a class

  1. Define your class.

    Write the Java code that defines your class. If you are using the Sun Java SDK then you can use a text editor. If you are using a development tool, the development tool provides instructions.

    Use only supported classes

    User classes must be 100% Java. Native methods are not allowed.

  2. Name and save your class.

    Save your class declaration (Java code) in a file with the extension .java. Make certain the name of the file is the same as the name of the class and that the case of both names is identical.

    For example, a class called Utility should be saved in a file called Utility.java.

  3. Compile your class.

    This step turns your class declaration containing Java code into a new, separate file containing byte code. The name of the new file is the same as the Java code file, but has an extension of .class. You can run a compiled Java class in a Java runtime environment, regardless of the platform you compiled it on or the operating system of the runtime environment.

    The Sun JDK contains a Java compiler, javac.