Linux

  1. Home
  2. Computing & Technology
  3. Linux

By Juergen Haas, About.com

Step 1. Create a Java Source File.

A source file contains text written in the Java programming language. You can use any text editor to create and edit source files.

You have two options:

* You can save the FatCalories.java file (at the end of this article) onto your computer. This way can save you some typing. Then, you can go straight to step 2.

* Or, you can follow the longer instructions:

(1) Bring up a shell (sometimes called terminal) window.

When the prompt first comes up, your current directory will usually be your home directory. You can change your current directory to your home directory at any time by typing cd at the prompt (typically a “%”) and then pressing Return.

The Java 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 java in your home directory, you would first change your current directory to your home directory by entering the following command:
% cd

Then, you would enter the following command:
% mkdir java

To change your current directory to this new directory, you would then enter: % cd java

Now you can start creating your source file.

(2) Start the Pico editor by typing pico at 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.

(3) Type the code listed at the end of this article (under “Sample Java Program”) into the blank buffer. Type everything exactly as shown. The Java compiler and interpreter are case-sensitive.

(4) Save the code by typing Ctrl-O. When you see File Name to write:, type FatCalories.java, preceded by the directory in which you want the file to go. If you wish to save FatCalories.java in the directory /home/smith/java, then you would type

/home/smith/java/FatCalories.java and press Return.

Use Ctrl-X to exit Pico.

Explore Linux

About.com Special Features

Linux

  1. Home
  2. Computing & Technology
  3. Linux

©2009 About.com, a part of The New York Times Company.

All rights reserved.