Java Development Tools (JDT) Features


The JDT plug-in builds on the Eclipse platform by adding robust Java-related capabilities to Eclipse. The JDT is such a core part of the Eclipse SDK that it is bundled with it.

The Eclipse platform combined with the JDT plug-in provides so many features that it would fill up an entire book. Hence, for the sake of conciseness, I will list the numerous features provided by plug-ins next, with a brief description of each. The online help bundled with Eclipse provides more detail on how these features work (the Eclipse help system is covered later in this chapter).

  • Management of Java projects and files such as .java, .class, .jar, and Javadocs.

  • Java source editing with keyword/syntax highlighting, truly intelligent content (code) assist, quick fix, import organization, and more.

  • A variety of Java views. For example, Figure 8.19 shows a sample of the Java Browsing perspective, which allows us to browse Java packages, types (classes, interfaces), members, and variables; this is also a great way to browse other jar files (for example, spring.jar). Other Java views include JUnit, Ant, Package Explorer, and more.

    Figure 8.19. Java Browsing perspective.

  • Every time we save a .java file, it is instantly compiled to a .class file (see the sidebar "Save Compiles Within the Blink of an Eye!").

  • Intelligent quick fix (Ctrl+1) and content assist (Ctrl+spacebar)If there are two keyboard shortcuts you should remember in Eclipse, these are the ones! Use one of these when you are stuck or are feeling lazy about typing. Try them anywhere and everywhere while coding, because these keys do too many things to list here. The assistance will be provided based on your cursor position, in the way of an intelligently narrowed applicable list of choices. For example, Ctrl+spacebar can fill in the remainder of your line of code, provide a drop-down list of choices, show us the signature of the method we are calling, and much more. Again, there are too many features to list here, but the Eclipse online help provides detailed information on these keys.

  • Generation of code using prepackaged or custom templates (for code snippets), surround code with try/catch, add imports automatically, and more. Figure 8.20 shows the Source context menu. Generate setters/getters.

    Figure 8.20. Source context menu.

  • Eclipse JDT provides so many code formatting options that it can overwhelm you at first. If I had to take a guess about how many customization options are available to enable us to format our code, I would probably say about 100 or more. Figure 8.21, shows a sample of what I'm referring to. Notice all the options on the first tab; now multiply that by the eight tabs shown on this screen (you get the picturethere are a lot of options).

    Figure 8.21. Java code formatting options.

  • Compiler warnings and errors are displayed in the left and right side of the margins of the editor windows. Red is for errors and yellow is for warnings. Figure 8.22, shows an intentional error I generated. The marker on the left margin is the position on the page level; the indicator on the right margin is the position in the file. Also, notice that the warnings and errors are displayed in the Problems view.

    Figure 8.22. Compiler errors and warnings.

  • JDT provides all the debugging features you would expect, such as breakpoints, variable inspection, watch expressions, and more. Eclipse also provides a hotswap feature if your JRE supports it; this allows us to change code in the debugger and have it reloaded instantly, without the need to restart your debugging session (a very cool feature!). We will cover debugging in depth in the next chapter.

  • The JDT provides reliable renaming of methods or classes and their references across a project. For example, if we rename a class, Eclipse will attempt to update all references to this class in Java code and XML files.

  • Powerful searching using Java method signatures and more is another feature provided by the JDT. Figure 8.23 shows the Search dialog box. Notice that we can do file searches, Java searches, and even plug-in searches. In addition, we have other options for searching and repeating previous searches.

    Figure 8.23. Search dialog box.

  • The JDT goes beyond syntax highlighting and debugging by providing such features as the capability to add comments with the word TODO (we can choose other words as well) and have it appear in the Tasks view (Figure 8.24), which shows us every single TODO item we have in all the source files.

Figure 8.24. TODO comments and Tasks view.


As I mentioned earlier, Eclipse provides many types of wizards. The JDT-specific wizards include the capability to create classes, packages, annotations, simple files, and more. Each of these wizards is powerful in their own respect. For example, Figure 8.25 shows the Class Wizard. Notice how we can specify just about everything we need to create a skeleton class belonging to some package, extending another class or implementing various interfaces, containing a main method, inheriting constructors from the super class, and more. Now if Eclipse could only write our business logic, we would all be set.

Figure 8.25. New Java Class Wizard.


The JDT comes preconfigured with JUnit. The JUnit plug-in provides a wizard and a view to create and test classes. Figure 8.26 shows the JUnit Wizard. We will use the JUnit view later in this chapter.

Figure 8.26. New JUnit Test Case Wizard.


As you would guess, Ant is an integral part of Eclipse. Figure 8.27 shows the Ant view for running Ant tasks and the Ant editor for editing Ant build XML files (notice the Ctrl+spacebar-based context help for the XML elements and attributes). Also, the Console view shows the output of the Ant command with clickable filenames that take us directly to the point of the error!

Figure 8.27. Ant editor and view.


Eclipse's Export feature provides the capability to export many types of files. I like the fact that any exportable files by any plug-ins show up in one place. Also, export is a term used loosely here because we can even create JAR files using this option. Figure 8.28 shows the list of files we can export to (in our setup so far).

Figure 8.28. Export options.


The Java Scrapbook feature is a very handy feature to experiment with single lines of Java code, as shown in Figure 8.29. You can create a new Java scrapbook from the File, New, Other wizard (look for Java, Java Run/Debug, Scrapbook Page in the tree) and then execute it by highlighting your line of code and selecting Execute from the context (right-click) menu or the Run menu (or by pressing Ctrl+U on Microsoft Windows, for example).

Figure 8.29. Java Scrapbook page.


The JDT provides extensive code refactoring options, although I must admit this is my weak area in that I have not used these features extensively. According to the Eclipse online help, "The refactoring tools support a number of transformations described in Martin Fowler's book Refactoring: Improving the Design of Existing Code, Addison Wesley, 1999, such as Extract Method, Inline Local Variable, etc." The point behind refactoring is to improve the code without impacting the functionality it provides. Perhaps it's a personal preference for me to come up with my own refactoring ideas rather than trusting software to do it for me, although many of the refactoring options in Eclipse are simple and harmless to use.

Figure 8.30 shows the Refactor menu items. For example, we can extract (create) an interface class using the concrete methods of a concrete class. Other options provide the capability to pull up a method to a parent class, rename a package, class, or method, inline variables, add exceptions, and much more.

Figure 8.30. Refactor menu.


We just went through a lot of features provided by the combination of the Eclipse platform and the JDT plug-in, but as they say, you ain't seen nothing yet!

There is so much to Eclipse that it would take a few books to cover what's available on the eclipse.org website and elsewhere (and so much more under development, just waiting to surface). Nonetheless, I will cover a lot by the end of this chapter.

As I mentioned earlier, what makes Eclipse so powerful are the plug-ins available for this platform. So far, we have discussed only one plug-in, the JDT. I also mentioned earlier that hundreds of plug-ins are available out theresome small and simple, others more complex. Borland is one example; however, there is a very long list of companies developing plug-ins for Eclipse, including the Eclipse Foundation itself, as we will see in the next section.



Agile Java Development with Spring, Hibernate and Eclipse
Agile Java Development with Spring, Hibernate and Eclipse
ISBN: 0672328968
EAN: 2147483647
Year: 2006
Pages: 219

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