Using an Integrated Development Environment

   

Core Java™ 2: Volume I - Fundamentals
By Cay S. Horstmann, Gary Cornell
Table of Contents
Chapter 2.  The Java Programming Environment


In this section, we show you how to compile a program with the Sun ONE Studio Community Edition, a free integrated development environment from Sun Microsystems. You can download your copy from http://www.sun.com/software/sundev/jde. 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 http://netbeans.org.

After starting Sun ONE Studio, various toolbars and windows are loaded (see Figure 2-2).

Figure 2-2. Starting Sun ONE Studio

graphics/02fig02.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 Chapter 4 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 Figure 2-3).

Figure 2-3. The edit window of Sun ONE Studio

graphics/02fig03.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 Figure 2-4).

Figure 2-4. The output window of Sun ONE Studio

graphics/02fig04.gif

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 Figure 2-5). 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.

Figure 2-5. Error messages in Sun ONE Studio

graphics/02fig05.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 Figure 2-6).

Figure 2-6. Starting a new program in Sun ONE Studio

graphics/02fig06.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 Chapter 11.


       
    Top
     



    Core Java 2(c) Volume I - Fundamentals
    Building on Your AIX Investment: Moving Forward with IBM eServer pSeries in an On Demand World (MaxFacts Guidebook series)
    ISBN: 193164408X
    EAN: 2147483647
    Year: 2003
    Pages: 110
    Authors: Jim Hoskins

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net