The code for Java classes and interfaces is in source files which have an extension of '.java'. This is called a Java source file. This section describes how to create and edit Java class and interface source files.
Creating New Java Class Source Files
To create a new Java class source file, select [Java] > [Class] from the [New] wizard. This launches the New Java Class wizard. Specify the package name, class name, superclass, interface to be implemented, and so on, and create the Java class.
Creating New Java Interface Source Files
To create a new Java interface source file, select [Java] > [Interface] from the [New] wizard. This launches the New Java Interface wizard. Specify the package name, class name, extension interface, and so on, and create the Java interface.
Editing Java Source Files
Use the Java editor to edit the Java source file. When the Java source file is opened using the Project Explorer or Navigator view, it is actually opened in the Java Editor. The Java editor provides the following editing support:
Content Assist
The [Ctrl+Space] keys can be pressed from the editor to display a list of possible elements that can be inserted at that location. For example, if the first few characters of a class name are entered and the [Ctrl+Space] keys are pressed, a list of class names starting with those characters is displayed. Input assist also offers suggestions for other method names, variable names, and so on.
Organize Imports
If other classes or interfaces are referenced within the source, the full name (the name including the package name) of that class must be written in the import statement. The Java editor assists with creating this import statement. When [Source] > [Organize Import] is executed, any import statements that are missing from the source are added, and any import statements that are unnecessary to the source are removed.
Refactoring
Refactoring is the changing of the internal structure of source code without changing the way the program behaves. The purpose of this is to arrange the program in a more concise and easily understood way and to make subsequent specification changes more flexible. For example, if a class name, method name, variable name, or similar has been changed, locations in other source files that reference that name are also changed at the same time. Many other refactoring techniques, such as extracting superclass or method, introducing factory or introducing parameter object, and so on, are also provided.
Quick Fix
On the Java editor, any places that have compile errors in the source or warnings are displayed with a wavy line. When the [Ctrl+1] keys are pressed at a wavy line, suggestions on how to correct the error or warning are displayed. For example, if a variable name was entered incorrectly, suggestions to either correct the name to the correct variable name or to add a new variable declaration are displayed. When one of the suggestions is selected, that correction is applied.