In this section, we show you how to compile a program with the Sun ONE Studio Community version, a free integrated development environment from Oracle. You can download your copy from . Sun ONE Studio is written in Java and should run under any platform that has a Java 2 runtime environment. Preconfigured versions exist for Solaris, Linux, and Windows. You can also get a more bleeding-edge open-source version from . After starting Sun ONE Studio, various toolbars and windows are loaded (see ).

Starting Sun ONE Studio

Java graphics 02fig02-java-screenshot.jpg

Select File -> Open File from the menu, then load CoreJavaBook/v1ch2/Welcome/Welcome.java. You will be asked if this file should be in the "default package." Click Accept. (See for more information on packages. For now, all our programs are in the default package.) You should now see a window with the program code (see ).

The edit window of Sun ONE Studio

Java graphics 02fig03-java-screenshot.jpg

Select Build -> Compile from the menu. Your program is compiled. If it compiles correctly, select Build -> Execute from the menu. The edit window goes away, and an output window appears at the bottom of the screen. The program output is displayed in the output window (see ).

The output window of Sun ONE Studio

Java graphics 02fig04

To return to the edit window after the program is finished, click on the "Editing" tab at the top of the screen.

Locating Compilation Errors

Presumably, this program did not have typos or bugs. (It was only a few lines of code, after all.) Let us suppose, for the sake of argument, that you occasionally have a typo (perhaps even a bug) in your code. Try it out-ruin our file, for example, by changing the capitalization of String as follows:

string[] greeting = new String[3];

Now, run the compiler again. You will get error messages (see ). The first one complains about an unknown string type. Simply click on the error message. The cursor moves to the matching line in the edit window, and you can correct your error. This allows you to fix your errors quickly.

Error messages in Sun ONE Studio

Java graphics 02fig05-java-screenshot.jpg

To start a new program, select File -> New from Template from the menu. In the resulting dialog, open up the "doorlatch" labeled Classes by clicking on the icon. Then select Empty and click the Next button (see ).

Starting a new program in Sun ONE Studio

Java graphics 02fig06-java-screenshot.jpg

You will be asked if you want to add this file to the current project. Until you use projects in earnest, there is no harm in answering either Yes or No. Now you are ready to edit your new file, compile it, and run it. We will discuss the Sun ONE Studio debugger in .