Content deleted Content added
Reverted edits by 2a02:2788:824:f4:e813:aaa2:e9bc:1f97 |
m Task 70: Update syntaxhighlight tags - remove use of deprecated <source> tags |
||
Line 9:
In a Java source file, the package that this file's class or classes belong to is specified with the <code>package</code> [[keyword (computer programming)|keyword]]. This keyword is usually the first keyword in the source file. At most one package declaration can appear in a source file.
<
package java.awt.event;
</syntaxhighlight>
To use a package's classes inside a Java source file, it is convenient to import the classes from the package with an <code>import</code> declaration. The following declaration
<
import java.awt.event.*;
</syntaxhighlight>
imports all classes from the <code>java.awt.event</code> package, while the next declaration
<
import java.awt.event.ActionEvent;
</syntaxhighlight>
imports only the <code>ActionEvent</code> class from the package. After either of these import declarations, the <code>ActionEvent</code> class can be referenced using its simple class name:
<
ActionEvent myEvent = new ActionEvent();
</syntaxhighlight>
Classes can also be used directly without an import declaration by using the fully qualified name of the class. For example,
<
java.awt.event.ActionEvent myEvent = new java.awt.event.ActionEvent();
</syntaxhighlight>
does not require a preceding import declaration.
|