Getting Started with eclipse

Source: Internet
Author: User
The first time you open Eclipse, you see the following Welcome screen:

Figure 1. Eclipse Workbench

The Eclipse Workbench consists of several panes called views (view), such as the Navigator view in the upper-left corner. The collection of panes is called a Perspective (perspective). The default perspective is the Resource perspective, which is a basic set of common views for managing projects and viewing and editing files in projects.

The Navigator view allows you to create, select, and delete items. The pane on the right side of the Navigator is the editor area . Depending on the type of document selected in Navigator, an appropriate editor window will open here. If eclipse does not register the appropriate editor for a particular document type (for example, a. doc file on a Windows system), Eclipse will try to open the document using an external editor.

Navigator the following Outline view Displays the outline of the document in the editor, the accuracy of which depends on the type of editor and document, and for Java source files, the outline displays all declared classes, properties, and methods.

The Tasks View collects information about the project you are working on, which can be information generated by Eclipse, such as compilation errors, or tasks that you add manually.

Most of the other features of the workbench, such as menus and toolbars, should be similar to those of other familiar applications. A handy feature is the shortcut toolbar for different perspectives, which is displayed in the left of the screen, which differs significantly from context to history. Eclipse also comes with a robust help system that includes a user's Guide to the Eclipse Workbench and included Plug-ins, such as Java development tools. It is worthwhile to browse through the Help system at least once, so that you can see what options are available and better understand the work flow of Eclipse.

To continue this brief Eclipse trip, we will create a project in Navigator. Right-click the Navigator view and select new=>project. When the New Project dialog box appears, select Java on the left. Standard Eclipse has only one type of Java project, named "Java Project." If plug-ins are installed to provide JSP and servlet support, we will see an additional option for WEB applications from here. For now, select Java Project, enter "Hello" when you are prompted for the project name, and then press Finish.

Next, we'll examine the Java perspective. Depending on how you prefer your screen management, you can change the perspective in the current window by selecting window=>open Perspective=>java , or by selecting window=>new window , and then select the new perspective to open a new window.

As you might expect, the Java perspective contains a set of views that are more appropriate for Java development. One is the upper-left view, which is a hierarchy of various Java packages, classes, jars, and other files. This view is called Package Explorer. Also note that the main menu is already expanded-and there are two new items: Source and refactor.

Java Development Environment (JDE)
To test the Java development environment, we will create and run a "Hello, World" application. Using the Java perspective, right-click the "Hello" item and select New=>class, as shown in Figure 2. In the dialog box that appears, type "Hello" as the class name. In the "Which method stubs would" and "create?" Next, select the public static void main (string[] args) check box, and then press Finish.

Figure 2. Create a new class in a Java perspective

This creates a. java file in the editor area that contains the Hello class and the empty main () method, as shown in Figure 3. Then add the following code to the method (note that the declaration of which I was intentionally omitted):

Figure 3. The Hello class in the Java editor

You will notice some of the features of the Eclipse editor as you type, including syntax checking and automatic code completion. In version 2.1 (I downloaded the M2 version to try out), when you type open brackets or double quotes, Eclipse automatically provides paired symbols and places the cursor inside a symbol pair.

In other cases, you can invoke the code completion function by pressing Ctrl-space. Code completion provides a context-sensitive list of suggestions that you can select from the list by keyboard or mouse. These recommendations can be either a list of methods for a particular object or a snippet of code that is expanded based on different keywords, such as for or while.

The syntax check relies on incremental compilation. Whenever you save your code, it accepts compilation and syntax checking in the background. By default, syntax errors are underlined with a red underline, and a red dot with a white "X" appears on the left edge. Other errors are indicated by a lightbulb icon on the left side of the editor, which is the problem that the editor may be able to fix for you-the so-called quick fix feature.

The code example above has a lightbulb icon behind the for statement, because the declaration of I is omitted. Double-clicking the icon will bring up the suggested fix list. In this example, it provides suggestions for creating a class field I, a local variable I, or a method parameter I; clicking each of these suggestions displays the code that will be generated. Figure 4 shows the list of recommendations and the code that is generated after a local variable is created.

Figure 4. Quick Fix recommend

Double-clicking the suggestion inserts the suggested code in the appropriate location in your code.

Once the code compiles without errors, you can choose Run from the Eclipse menu to execute the program (note that there is no separate compilation step here, because the compilation is done when you save the code.) If the code has no syntax errors, it can run. A Launch Configurations dialog box appears with the appropriate default settings, and press the Run button in the upper-right corner. A new tabbed pane appears in the following pane (console), showing the output of the program, as shown in Figure 5.

Figure 5. The output of the program

You can also run programs in the Java debugger. First double-click the gray edge of the left side of the editor view to set a breakpoint in main () System.out.println () after the call to System.out.println (). A blue dot will appear there. Then choose Debug from the Run menu. As described above, a Launch Configurations dialog box appears. Please select Run. The perspective will automatically switch to the Debug perspective, which has a number of interesting new views, as shown in Figure 6:

Figure 6. Debug Pivot Chart

First, notice the Debug view in the upper-left corner of the perspective. This view displays the call stack, and there is a toolbar in the title bar that allows you to control the execution of the program, including continuing, suspending or terminating it, tracking the next statement, stepping through the next statement, or returning from the method.

The upper-right pane contains a number of tabbed views, including Variables, breakpoints, Expressions, and Display. Here I clicked the Variables view so that we could see the current value of I.

You can get more information about these views with context-sensitive Help: Click the title of the view, and then press F1.

Additional plugins
In addition to plug-ins such as JDT for editing, compiling, and debugging applications, there are a number of plug-ins available that support the complete development process from modeling, build automation, unit testing, performance testing, versioning to configuration management.

The Eclipse standard comes with plug-ins that work with CVS, which is an open source concurrent version system for source control (Concurrent versions system). The team plug-in connects to the CVS server, allowing members of the development teams to manipulate a set of source code files without overwriting other people's changes. There is no further discussion of how to source control from within Eclipse, as this requires the installation of a CVS server, but it is an important and essential feature of Eclipse to support the development team rather than just stand-alone development.

Some of the Third-party plug-ins that are available or have been announced to be launched include:

version control and configuration management CVS merant PVCS Rational ClearCase

UML Modeling Omondo eclipseuml Rational XDE (instead of Rose) together WebSphere Studio Edition

graphic Batik SVG Macromedia Flash

Web Development, HTML, XML Macromedia Dreamweaver Xmlbuddy

Application Server Integration Sysdeo Tomcat Launcher

Example: A plug-in for UML modeling


To see examples of plug-ins and see how it is integrated with Eclipse, download the popular Omondo eclipseuml (http://www.eclipseuml.com/); You need to register, but the plugin is free. This plug-in relies on GEF, the graphical Editor Framework, which is another Eclipse plug-in. GEF is part of the Tools sub project. To download GEF, go to the Eclipse Web site, select "Downloads", and then click the "Tools PMC Downloads page" link. Note that you will need to download the GEF version recommended by Omondo (GEF 2.0 for Omondo 1.0.2).

After downloading, the installation of the plug-in is usually done by decompressing the download file and copying its contents to the Eclipse plug-in directory. In this case, GEF needs to extract the Eclipse directory (it will automatically enter the plug-in directory from that directory). For security reasons, you might want to unzip it to a temporary directory, and then copy the related directory from there accordingly. If Eclipse is running, you need to stop it and then restart it so that it recognizes the newly installed plug-in.

Once the ECLIPSEUML (and GEF) installation is complete, you can create a class diagram just as you would create a Java class file. In the Java perspective, right-click the "Hello" item in Package Explorer and choose new=>otherfrom the pop-up menu. There will be a new option for UML in the left pane of the New dialog box. The free version of ECLIPSEUML only supports class diagrams, so the only option on the right is UML class Diagram. Please select UML class Diagram and type a name for the class diagram, such as "Hello":

Figure 7. Class Diagram Editor

A graphical editor appears in the editor area with a canvas for drawing class diagrams. You can create class diagrams in two ways: reverse-engineer existing code by dragging Java files from Package Explorer onto class diagrams, or by using the drawing tools available on the toolbar above the blank class diagram. To experiment with the first method, create a new class named person (using file=>new=>class) and give it the two private properties listed below:

/** Person.java
 * @author David
 *
/public class Person {
private String name;
private address address;

/**
 * Returns the address.
 * @return Address
/getaddress () {return address
         ;
}

/**
 * Returns the name.
 * @return String
 *
/public string getName () {return
        name;
}

/**
 * Sets the address.
 * @param address "to set
 *
/public void setaddress (address) {
        this.address = Address;
     }

/**
 * Sets the name.
 * @param name the name to set
 *
/public void SetName (String name) {
       this.name = name;
}

}

Type only the lines for name and address. Getter and setter methods are generated automatically through Eclipse, that is, right-click the source code and select the source=>generate Getter and setter from the pop-up menu. )

Please save and close Person.java HELLO.UCD.

Figure 8. Person class diagram

To create a Java class from UML, click the New Class button on the toolbar at the top of the class Diagram window, the third button on the left, and then click the class Diagram. When the New Class Wizard opens, type adress as the class name, and then click Finish.

You can add properties to a class by right-clicking the class name and selecting new=>attribute. In the New Properties dialog box, enter the property name, type, and visibility. Then right-click the class name and select New=>method to add the method.

When you change a class diagram, the Source Editor window below the figure reflects the changes you made. Finally, you can draw a diagram of the two classes by clicking the association button (fifth from the left) and drawing a line segment from the person class to the address class. This will bring up another dialog box where you can enter the associated attributes (refer to ECLIPSEUML Help for more on the required information). The completed diagram should resemble the following:

Figure 9. Association

This UML plug-in demonstrates several typical features of the Eclipse plug-in. First, it shows the tight integration between tools. There is absolutely no way to see how many components are working; integration with the Eclipse platform and JDT is seamless. For example, when the person class is created, it displays a syntax error because one of its property address is not defined. Once the address class is created in a UML diagram, the components are displayed separately.

Another feature is the ability of ECLIPSEUML to leverage the functionality provided by other Plug-ins--in this case, the GEF plug-in, which provides tools for developing visual editors.

Another feature relates to the way eclipseuml Plug-ins use multi-level functionality for distribution. The basic plug-ins that support the class diagram are free, but more mature versions are paid to be used.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.