Eclipse is a remarkably ambitious project. It's not specifically a Java IDE, but rather an extensible development platform intended to support any programming language. However, the reference implementation -- the Java Development Toolkit (JDT) -- is a Java IDE, and that is what most people (especially Java programmers) mean when they talk about Eclipse. But even if all you care about is Java development and the JDT, Eclipse's open, extensible nature is the driving force behind the growth of Eclipse and the Eclipse community.
Eclipse 3.0 and IntelliJ IDEA 4 have a number of important differences, but the most obvious difference is price: You must pay for a license to use IDEA, but Eclipse is free. How important this is depends on your (or your company's) budget, but many professional developers find that IDEA has all the features they need at a relatively attractive price. Nonetheless, while Eclipse doesn't have all the features that IDEA does, the robust community that has developed around Eclipse has been quite thorough in providing the missing pieces in the form of third-party plug-ins.
More important than price and sheer number of features is how effectively an IDE allows you to work. A number of things contribute to how useful an IDE is for you -- in addition to features -- including overall design, stability, and performance. This article surveys the basic features that come with the Eclipse 3.0 JDT and contrasts them with what is available in IDEA.
IDEA and Eclipse are quite equal to each other in the basic features required for editing, running, and debugging Java code, although they do some things slightly differently. In addition to basic programming features, Eclipse and IDEA also share support for more advanced Java development tools such as Ant, CVS, JUnit, and refactoring. (For an article describing Eclipse's refactoring features, see the Resources section later in this article.) Often, the hardest thing about migrating to Eclipse is learning how to do old things in the new environment -- with its myriad features, it can often be hard to find a particular feature. Fortunately, Eclipse has a very complete and easy-to-use help system with online documentation.
Until recently, one of IDEA's main advantages over Eclipse has been an integrated GUI builder. This is changing now that Eclipse has introduced its Visual Editor. Eclipse's GUI builder is a separate component, but it has an important advantage over IDEA's in that it provides round-tripping between code and graphical views (a change in one is reflected in the other nearly immediately) and doesn't require additional metadata or other files.
The Eclipse Visual Editor (VE) release 0.5, which supports AWT/Swing, is available for Eclipse 2.1.x. now. A version for Eclipse 3.0, release 1.0, will be available soon. VE 1.0 will be available as a separate download on the Eclipse Web site and will support not only AWT/Swing, but SWT as well. For more information and a preview of VE, see the Visual Editor article listed in the Resources section.
Another advantage IDEA has is integrated Web development support. Even if you need this, this doesn't necessarily stop you from using Eclipse, however. Several third-party plug-ins add this functionality to Eclipse, such as Lomboz and the Sysdeo Tomcat plug-in. See Resources for articles that will show you how to obtain, install, and use these and other third-party plug-ins.
Overall design and ease-of-use
A common criticism among new users of Eclipse is that it's difficult to use. This is largely because Eclipse takes a unique approach to organizing its user interface. In particular, it introduces the concept of perspective to provide an environment designed for performing specific tasks, such as coding, debugging, using a source control system, and so on. After a bit of orientation and practice, which this article provides, most users find this concept clear and powerful.
Another hallmark of the Eclipse user interface is that it makes extensive use of wizards: sequences of dialog boxes guide you through the steps necessary for performing a specific task, such as creating new projects or classes and connecting to a CVS repository. IDEA has wizards, too, of course, but Eclipse is distinct in that its wizards are more thorough and provide more options than you may be used to.
Theoretically speaking, Eclipse should have the edge in performance because it uses SWT, which uses native widgets -- the operating system's UI elements -- whereas IDEA uses Swing/AWT. Practically speaking, however, IntelliJ has done an excellent job in implementing the IDEA user interface and, on a reasonably powerful machine, performance differences are negligible. Users will generally find either sufficiently snappy. Likewise, both Eclipse and IDEA are very stable applications, and users are unlikely to encounter difficulties with either.
Ultimately, if you are evaluating Eclipse's suitability for your development purposes, you'll need to take it for a test drive to get a feel for it. That's really the only way to judge its ease of use and see if it fits your style of working. The next section provides a brief tour of Eclipse. If you've downloaded and installed Eclipse, you may want to follow along. If you haven't installed Eclipse yet, you can refer to the article "Getting started with the Eclipse Platform" listed in Resources.
Before getting started, it's useful to introduce a few terms to describe the Eclipse user interface. At the highest level is the Eclipse application window. This, in Eclipse parlance, is called the workbench, and it contains a main menu, a row of tool buttons, and a number of different panes. These panes, like those in IDEA, are each dedicated to a particular purpose such as displaying resources (packages, source code, build scripts, and the like), listing to-do items, and showing console output when running a program. These panes are called views.
In addition to views, each perspective typically has an editor pane. Because the editor provides the primary means of creating and modifying resources such as source, text, and image files, this is the principal pane in the Eclipse workbench, and the contents in the other views will change to reflect the file that is selected here. If you are editing a Java file, for example, the Outline view will show the structure of the class in the Java file you've selected.
As you perform different tasks, such as coding, debugging, or merging your code changes with those in a centralized code repository, you can use an arrangement of views chosen specifically for that task. These task-specific arrangements of windows are called perspectives.
The first time you start Eclipse, you'll be greeted by a welcome screen. This screen has links to an overview of Eclipse, a tutorial, and other interesting things. For now, dismiss this by clicking the "X" in the Welcome tab below the main menu. (You can return to the Welcome screen later by selecting it from the Help menu.) Eclipse will be in the default Resource perspective, as shown in Figure 1:
Figure 1.The Resource perspective
The nice thing about perspectives is that they keep your screen free from clutter. If you are not debugging a program, for example, you don't need to see tool buttons and menu selections for debugging. This makes it easier to find the tool buttons and menu selections relevant to the task at hand.
Opening an IDEA module into Eclipse
If you're migrating to Eclipse from IDEA, you probably have an IDEA module that you'll want to open. To do this, you'll need to create an Eclipse project for it and specify the module's directory -- note that the word project in Eclipse corresponds to IDEA's idea of a module.
Let's assume that you have a project you created using IDEA called Zoo, which is located in a directory called C:\Documents and Settings\user\IdeaProjects\Zoo. Let's also assume that the source files are in subdirectories called src and the class files are in a directory called classes.
Then start Eclipse by following these instructions:
- Open the New Project wizard by selecting File > New > Project from the main menu.
- Make sure Java Project is selected (see Figure 2 below) and press Next.
Figure 2.The New Project wizard
- Enter a name, such as Zoo for the Project name.
- Under Location, click Create project at external location.
- Browse for (or type in) the directory of your IDEA project. See Figure 3.
Figure 3. Browse for a folder
- Click OK. You'll notice that once you've selected the external location, the option to select a project layout will be grayed out. This is because Eclipse will evaluate the project and determine the layout automatically -- in this case, identifying
srcas the source directory (or folder, as Eclipse prefers to call it) andclassesas the class file folder. - When the Browse Folder box is closed, you'll find that the Create a Java Project box will now allow you to click either Next or Finish to continue creating the project. Clicking Next will allow you to set up additional options, such as adding other projects or libraries to the class path. Assuming that Zoo is a stand-alone project, you don't need to do this. Instead simply:
- Click Finish.
- Eclipse will notify you that this type of project is associated with the Java perspective and ask if you want to switch to this perspective. Click on the Remember my decision checkbox (so it won't ask you the next time you create a Java project) and then click OK.
Now you'll find you're in the Java perspective and the Zoo project is listed in the Package Explorer view. To explore it, you can click the plus sign to expand this project and then click the src folder to locate your source files.
It's instructive to introduce an error in the source so you can compare how IDEA and Eclipse flag errors. Open Snake.java, for example, and comment out the speak() method. (Just as in IDEA, you can do this by highlighting the method's code and pressing Ctrl-/.) This results in an error, which Eclipse flags in the left margin by placing an "X" in a red box (indicating an error) next to a light bulb (indicating that Eclipse has a suggestion for fixing the error).
If you place the cursor over the light bulb, a message alerts you that the Snake class doesn't implement the abstract method speak() declared in the Animal superclass. Figure 4 shows this source in both the IDEA and Eclipse editors. As you can see, they are very similar.
Figure 4. IDEA vs. Eclipse editors
Editing source code with Eclipse
Eclipse offers many of the same features as IDEA for editing code, including several types of automated code completion. If you begin typing a Java keyword, class name, or method name, for example, and press Ctrl-Space, Eclipse presents you with a list of candidates that you can choose from and inserts your selection into the code.
Eclipse also has a feature called QuickFix, which corresponds to IDEA's Intention Actions. As you've seen above, Eclipse displays a light bulb in the left margin if it has a suggestion for fixing your code. You can either click this light bulb or select the element containing the error (underlined with a red squiggle, like Snake above) and press Ctrl-1 to invoke a QuickFix. In the case of the missing method above, Eclipse presents you with three options: Add unimplemented methods, Make type 'Snake' abstract, or Rename in file. Here, of course, you want to add the unimplemented method. (Ignore the commented-out code for now.)
The last option that QuickFix presented, Rename in file, might seem erroneous, but that's because it's actually a suggestion unrelated to fixing the missing method problem. Instead it's an interesting Eclipse feature that allows you to change all instances of an identifier in a file at one time. To try this out, open the Animal.java file, click the variable lion, press Ctrl-1, and then select Rename in file. You'll notice that both instances of the variable name are enclosed in a rectangle; as you begin typing a new name, leona for example, they both change.
As you type code in Eclipse, you may notice that on occasion a green bar appears somewhere ahead of the cursor. For example, return to the new speak() method in the Snake class, and type System.out.println(. Eclipse adds the closing parenthesis automatically (like IDEA) and a green bar appears after the closing parenthesis. (See Figure 5.) This is called an insertion point.
Figure 5. Pressing tab moves the cursor to the insertion point -- the green bar
Next, type an open quote mark inside the parentheses. Again, Eclipse helps you by adding the closing quote mark, which is followed by a green bar. (The first green bar disappears at the same time.) Type something that a snake might say, such as "Sssss," and then press Tab. You'll see that the cursor moves out of the quotes to the insertion point. Also notice that the original insertion point outside the parentheses reappears. Press Tab again to move to the end of the line and type the closing semicolon.
As you can see, this example doesn't save much typing because, instead of pressing Tab, you could have pressed the right arrow to achieve the same end, but once you're used to it, you'll probably find it to be very convenient. In some cases -- in particular, when using code templates -- the insertion points can be especially helpful. If you invoke a template for a for loop, for example, Tab and Shift-Tab will move you back and forth between the different parts of the loop -- the iterator, the test expression, the increment expression, and the loop body.
One Eclipse feature not immediately obvious is its ability to split the editing screen. This is done by clicking one of the file tabs at the top of the editor and dragging it to one of the edges of the editor pane. Assume, for example, that the files Animal and Snake are open.
- Click the
Snake.javatab and drag it to the bottom edge of the pane. - A black arrow appears indicating that you've selected a valid docking position. See Figure 6 below.
- Releasing the mouse button splits the editor horizontally with Snake in the bottom half of the pane.
- To return to a single file view, click and drag the Snake tab back to its position next to the Animal tab.
Figure 6. Splitting the editor pane by dragging the Snake tab to the bottom edge
Running and debugging a program
Eclipse uses an incremental compiler, so it isn't necessary to explicitly compile your Java files; the compiled class files are saved automatically when you save your Java files. To run a program, the easiest way is to select the file containing a main() method in the Package Explorer and then select Run > Run As > Java Application from the main Eclipse menu. (Notice that this is different from the Run > Run... menu option, which we'll see later.) If you select Animal.java and run it, it produces output in the Console view below the Editor, as shown in Figure 7:
Figure 7. Java output in the console view
Running a simple program in the debugger is similar. First, set a breakpoint in the main() method by double-clicking in the left margin next to the call for lion.speak(), for example. If this code were a little less trivial, it would also be possible to set a conditional breakpoint -- one that stops when a particular expression (such as i==2) is true, or one that stops after a specific number of hits -- by right-clicking the breakpoint and selecting Breakpoint properties from the context menu.
To start debugging, select Run > Debug As > Java Application from the main menu. Because Eclipse has a Debug perspective that is better suited for debugging than the Java perspective, it will ask if you want to change to this perspective. Check the box Remember my decision and then click Yes. See Figure 8.
Figure 8. Debugging using the Debug perspective
Most of the views in the Debug perspective should be more or less familiar to you from windows in IDEA, although they may have different names and are arranged a little differently. Notice, for example, that the Debug view (not to be confused with the Debug perspective) shows the call stack; this combines the frames and threads that you are familiar with in IDEA. The Variables view shows the current state of the program's variables, and the Console view shows the program.
You'll also notice that the tool buttons (Step over, Step into, and so on) for controlling execution are located in the Debug view's tool bar. These controls are located here, together with the call stack, so that you can select the program or thread to control by clicking it in the call stack if you are debugging more than one program (or instance of a program), or a program with multiple threads. If you like, you can play with this by launching this example program again without terminating the first instance.
Sometimes you don't want to (or can't) run a program using the simple menu selection Run > Run As > Java Application. If you need to pass arguments to either the program or the VM it runs under, you'll instead need to use the Run > Run... menu option. This will bring up a dialog that you can use to set these and other options as shown in Figure 9:
Figure 9. Launching a Java program with options
One of the nice features that IDEA and Eclipse share is the availability of keyboard shortcuts to perform common commands. Some of these shortcuts, such as cut and paste commands, are alike in both applications, but most commands are not. While you may decide to start from scratch and learn Eclipse's shortcuts, if you are used to IDEA's shortcuts, you also have the option of customizing Eclipse's keyboard shortcuts (or key bindings) to match. Doing this for all shortcuts would be tedious (and ultimately impractical, as you'll see) but a good compromise might be to identify and add the shortcuts that you use most often, and slowly learn the rest.
For example, if you're like many programmers who have become spoiled from using an obliging IDE, you probably like to type code in quickly without much regard for style, stopping only every so often to straighten things out by using the format command. In IDEA, you would do this by pressing Ctrl-Alt-L, but in Eclipse the shortcut is Ctrl-Shift-F. If formatting code this way has become a nearly autonomous function, you may find it easier and less frustrating to change the key binding in Eclipse than to try to retrain yourself. You can make Ctrl-Alt-L a shortcut for formatting in Eclipse as follows:
- Select Window > Preferences from the main menu.
- Expand the Workbench selection (if necessary) and click Keys.
- In the Command section, under Category, select Source; under Name, select Format.
- In the Key Sequence section, click inside the Name box and then press the desired key combination, Ctrl-Alt-L.
- In the box labeled "When", select Editing Java Source.
- Click Add (see Figure 10) and then press OK.
Figure 10. Adding a keyboard shortcut for formatting source code
As mentioned above, it isn't possible to completely change Eclipse to work like IDEA, because Eclipse and IDEA don't have the same set of commands. That is to say, even though they have many of the same features, they are often implemented differently. In particular, a command in one may correspond to two or more commands in the other. Eclipse, for example, uses a single command for finding and replacing text, whereas IDEA has separate commands for each of these functions.
Both Eclipse 3.0 and IntelliJ IDEA 4 are feature-rich, Java IDEs that provide syntax checking, code assistance, and code generation for coding. In addition, they both provide support for refactoring, Ant, unit testing, and CVS. And soon, the Eclipse Visual Editor 1.0 for building GUIs using either AWT/Swing or SWT will be available. But some important differences exist between the two.
One important difference lies in the way the Eclipse user interface is designed using the concept of a perspective, a collection of views, editors, and other UI elements that are best suited for performing a specific task. This makes it easier to get the job done because the appropriate tools (and only the appropriate tools) are close at hand.
Another important difference is that Eclipse is an open source project. This open-source nature has attracted a large community of developers developing plug-ins, both free and commercial, for Eclipse. If you need a feature -- anything from aspect-oriented development support or a built-in MP3 player -- you are likely to find a free plug-in that extends Eclipse to provide it.
- Learn more at the Eclipse Web site and get a comprehensive listing of Eclipse plug-ins.
- The latest version of IntelliJ IDEA is at the JetBrains Web site.
- David's article Getting started with the Eclipse Platform (developerWorks, November 2002) provides a history and overview of Eclipse, including details on how to install Eclipse and plug-ins. Also his book, Eclipse In Action: A Guide for Java Developers (Independent Pub Group, 2003), is a must-read for Java developers using Eclipse.
- For an overview of Visual Editor and the technology behind it, along with a short demonstration of Visual Editor 0.5's features for building AWT/Swing applications and a preview of the SWT support in Visual Editor 1.0, see Build GUIs with the Eclipse Visual Editor (developerWorks, May 2004).
- Refactoring for everyone (developerWorks, September 2003) shows how and why to use Eclipse's automated refactoring features with examples of all the refactoring features in Eclipse 2.1.x and most refactoring features in Eclipse 3.0.
-
Using Eclipse as development environment with Jakarta Tomcat (developerWorks, May 2004) shows how to develop Tomcat applications using Eclipse and the Sysdeo Tomcat plug-in. Instructions are included for installing Tomcat and the plug-in.
-
Debugging with the Eclipse Platform (developerWorks, May 2003) provides an overview of debugging in Eclipse.
- David has written similar how-to articles to help Netbeans and JBuilder users migrate to Eclipse: Migrating from Netbeans to Eclipse (developerWorks, September 2004) and Migrating from JBuilder to Eclipse (developerWorks, September 2004).
- Visit the developerWorks Migration station for many other migration paths to open standards-based development.
- In addition to all Eclipse articles on developerWorks, find more resources for developing with Eclipse in the developerWorks Open source zone and developerWorks Java zone.
- Get involved in the developerWorks community by participating in
developerWorks blogs.
- Browse for books on these and other technical topics.
David Gallardo, a Studio B author, is an independent software consultant and author specializing in software internationalization, Java Web applications, and database development. He has been a professional software engineer for over 15 years and has experience with many operating systems, programming languages, and network protocols. His recent experience includes leading database and internationalization development at a business-to-business e-commerce company, TradeAccess, Inc. Prior to that, he was a senior engineer in the International Product Development group at Lotus Development Corporation where he contributed to the development of a cross-platform library providing Unicode and international language support for Lotus products including Domino. David is co-author of Eclipse In Action: A Guide for Java Developers (Independent Pub Group, 2003). You can contact David at david@gallardo.org.
Comments (Undergoing maintenance)





