First, open a shell, or "terminal," window.
A new terminal window.
When you first bring up the prompt, your current directory will usually be your home directory. You can change your current directory to your home directory at any time by typing cdat the prompt and then pressing Return.
The source files you create should be kept in a separate directory. You can create a directory by using the command mkdir. For example, to create the directory javain your home directory, use the following commands:
To change your current directory to this new directory, you then enter:
Now you can start creating your source file.
Start the Pico editor by typing picoat the prompt and pressing Return. If the system responds with the message pico: command not found, then Pico is most likely unavailable. Consult your system administrator for more information, or use another editor.
When you start Pico, it'll display a new, blank buffer. This is the area in which you will type your code.
Type the following code into the new buffer:
/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
Be Careful When You Type
Note: Type all code, commands, and file names exactly as shown. Both the compiler (javac) and launcher (java) are case-sensitive, so you must capitalize consistently.
HelloWorldAppis not the same as helloworldapp.
Save the code in a file with the name HelloWorldApp.java. In the Pico editor, you do this by typing Ctrl-O and then, at the bottom where you see the prompt File Name to write:, entering the directory in which you wish to create the file, followed by HelloWorldApp.java. For example, if you wish to save HelloWorldApp.javain the directory /home/jdoe/java, then you type /home/jdoe/java/HelloWorldApp.javaand press Return.
You can type Ctrl-X to exit Pico.
Compile the Source File into a .classFile
Bring up another shell window. To compile your source file, change your current directory to the directory where your file is located. For example, if your source directory is /home/jdoe/java, type the following command at the prompt and press Return:
If you enter pwdat the prompt, you should see the current directory, which in this example has been changed to /home/jdoe/java.
If you enter lsat the prompt, you should see your file.
Results of the lscommand, showing the .javasource file.
Now are ready to compile the source file. At the prompt, type the following command and press Enter
0 comments
Post a Comment