Use Eclipse to simplify development

Source: Internet
Author: User

Time: 2005-07-27

Author: Seth Roby

Keyword: Open Source

Each IDE allows you to manage files and build projects. Eclipse is not limited to this because it can process your code at a closer level than the typical file center view of most ides. As a developer, you can write only a small amount of code, so that Eclipse can complete searching, changing, switching, moving, and waiting for these complicated tasks, so as to benefit.

With Eclipse, you can focus on the real tasks at hand: write code that can complete the predefined functions.

Start with UI

First of all, please note that this article involves the new Eclipse3, which is different from the earlier version 2.1 and WSAD and RAD in some aspects. Eclipse looks very similar to most other ides, because the basic user interface (UI) is already familiar to developers everywhere-except for those who are still using Emacs or vi, but they can still find attractive things in Eclipse. Eclipse supports binding these two keys. The basic Eclipse User Interface 1 is shown.

On the left side of the screen, you can see the development resource list: source code, jars, and other components that make up your latest development project. In fact, the list is divided into different projects that you are currently developing. They can be mutually dependent or completely independent.

Eclipse saves project data in two files:. project file and. classpath file .. The project file stores information about the files contained in the project, how to use them, how to build the project, and more details. Any Java project has a. classpath file, which tells Eclipse what is used as the CLASSPATH variable during the build process.

All current projects exist in the current Workspace. The Workspace in Eclipse is a directory containing many files and may also contain the resources required by the project. Eclipse starts with a default Workspace. However, you can easily set it to open multiple workspaces. To open a different Workspace, you only need to use the-data flag when starting the executable file, for example, eclipse.exe-data E:/shared/workspaces/artemis

The middle part is a source code viewer that displays the source code of the currently opened file. Note that it is multi-label (tabbed), So you can open multiple files at a time. The right side is the summary of the currently opened file. Eclipse lists the classes, methods, and other parts of the file. Double-click an entry to jump to the corresponding position. Finally, at the bottom, there is another area with Multiple labels, which is used to transmit information about What Eclipse has done, what it has found, or what is problematic. Note that all the labels below are views. You can drag them and stack them to form a stack. The Information view is independent. If you want to see them at the same time and your screen is large enough, you can spread them out.

A view is grouped into a perspective. A perspective is usually environment-oriented. Here is a Java perspective for processing Java projects, a Debug perspective for tracking runtime problems, a CVS perspective for managing CVS connections, and so on. In fact, the number of perspectives and views is scalable, and almost every part of Eclipse is scalable. IDE provides multiple methods to add and expand existing features, which are used by many users in the Eclipse community.

All resources and projects of Eclipse have attributes. Right-click any item in the list on the left and select "Properties" to view more detailed information. For a file, you can see some basic information about the file, such as the modification date, location, and permission. There are more advanced options for projects, allowing you to set the Eclipse build project method.

If you click "Java Build Path", you will see four labels that control the building behavior. The first one is "Source", which allows you to set where Eclipse will find the Source file, you can also specify which source files are used and which can be ignored. The next tag is "Projects", which allows you to set the Projects that the current project depends on. In this way, you can set some libraries or public code in a project, and simply include the project from other projects.

The next label is "Libraries", which allows you to add JAR files, Libraries, and class folders to the class path. Finally, you can specify the resources that the project will export, so that the properties of the project can be applied to other projects that import the project.

Eclipse is built in a large source view in the middle, and all the edits are made there. But there are some things to note: Eclipse provides more than just a simple text view. First, there is a small slot on the left of the text. Eclipse uses it to hide the icons that pass useful information. A red "X" is displayed next to lines that cannot be compiled by Eclipse, and a yellow "warning" icon next to the code that Eclipse Deems may have errors, if the import statement is not used (see Figure 1 ).

Second, the problematic code is underlined with appropriate colors. Similarly, red underscores indicate compilation errors, and yellow indicate warnings. Finally, there is another small slot on the right of the scroll bar. Here, the color is used again to convey the message: the red block identifies the wrong code area, and the yellow block identifies the warning code area. Click the color block to move the cursor directly to the problem code. Hover your mouse over the three color entries (icon, underline, or block-shown in Figure 1) to open the description of the problem. Right-click the context menu.

Dynamic Construction

When using Eclipse for Java Development, you first notice how intelligent it is to compile. Go to Preferences (WindowMenu> Preferences) and enable dynamic Build (Workbench> Build Automatically ). Now, every time you save a file, Eclipse will automatically compile the file and the file dependent on the file. Therefore, when you want to run your application, it is basically saved and the latest version. This saves a lot of time when you process large Code bases. If you have to use other ides, the first thing you lose is the simplicity of this feature.

When you use Eclipse, you will feel the underlying principle again and again: IDE understands the code. Eclipse is not only a compiler that can process code and other things on a file-centric basis, it can also view the source code and intelligently process it. Its intelligent compilation capability is proved by its ability to understand the dependencies expressed in import statements.

Smart Search

Eclipse has a very intelligent Search feature (Search Menu> Search) that allows you to Search for any string that appears in a file, entire project, or in a file group. This feature is good, but it is still getting better. Java Search (Search Menu> Java) allows you to limit the Search to only Search for classes, methods, types, or other classes that Java knows. Eclipse can find all the methods that start with "set", and you can easily find all your write access methods. Better, you can click control-click on any method call to enter its implementation. Or click a class name to enter its implementation. In addition, you can right-click the method to find all the places where it is used (References> Project ). Eclipse's understanding of the Code helps it navigate to a large code base, and you will benefit from it.

"TODO" task link Creation

Eclipse also reminds you of the tasks that still need to be executed. Many developers add TODO comments to the Code to remind them that there are still specific tasks to complete or specific situations to handle. Eclipse again uses its knowledge of the Java structure to find any comments starting with TODO, and add it to a special Tasks View (Open Window Menu> Show View> Other> Basic> Tasks to see it ). In this way, Eclipse provides a comprehensive list of tasks to be completed. In addition, you can configure Eclipse to identify other labels you define. Open Preferences (Window Menu> Preferences) and navigate to the "Task Tags" Page (Java> Task Tags ). You can add new tags, delete existing tags, set attributes of Different tags, and specify the default values provided by Eclipse for the code.

Code Writing

You will find that Eclipse can actually write code for you. Right-click the Source file and under the "Source" sub-menu, provide some methods for Eclipse to modify or expand the Code. This will do some boring work and free you from. The most useful code writing capability is the "Generate Getters and Setters" option, which will scan a class to find the domain and Generate appropriate access methods for these domains.

If you select it, a window will pop up asking you to specify the domain for which you want to generate an access method and what access method (get, set, or both) will be generated ). You can also specify the permission (public, private, etc.) for the generated method ). Similarly, Eclipse can generate constructors Based on superclasses and methods to overwrite or encapsulate superclasses.

Reconstruction

One of the most powerful features of Eclipse is its robust support for refactoring. Right-click a method and you will see the "Refactor" sub-menu. If you use this method to change a method name, Eclipse will find all calls to this method and change these calls to use the new method name. You can also change the method signature. The specific method is to add the parameter by adding the parameter, and make Eclipse change all existing calls to add the parameter, using the value you specified. Of course, you can also delete parameters that you think are no longer useful, or rearrange parameters to make the interface more consistent. Refactoring can also work at the class level. You can drag internal classes to their own files or move classes to other packages.

Robust revocation support

Another very good feature is "Local History", which is an extremely simple Local CVS repository. Every time a file is saved, Eclipse will remember this save and allow you to return it to it as needed. By default, it records the last seven days of storage (you can modify this default setting in Window Menu> Preferences> Workbench> Local History ).

When you adopt new features but disrupt unrelated features, the revocation mechanism can recover the situation. You can quickly make a comparison between the two versions to see which changes you have made and return the changes to the previous version or even the previous version. Better, you can only roll back a specific method and keep the modifications in other methods.

JUnit Integration

Eclipse can be easily used with the JUnit framework. If you have a class written according to JUnit standards, you can select a class in the Resources view on the left and Run the Test (Run Menu> Run As> JUnit Test ). Eclipse will automatically find the defined test suite and run all the tests, and use its own custom UI to display the test run and errors. The common JUnit Green Line turns red when the test fails, and Eclipse displays stack tracing information that causes errors.

Let Eclipse do it.

You can see that Eclipse provides so many features to automatically complete some tedious work, making it easier for developers to live. The platform architecture provides you with a great opportunity to find a plug-in to help you complete specific tasks. If you cannot find it, you can use Eclipse to compile it!

Source http://wldj.sys-con.com/read/48887.htm

Introduction: Seth Roby trained representatives from Fortune 500 companies at Parasoft to teach them the automatic Error Prevention method. As an expert service engineer, he has written white papers on the infrastructure and many other theme necessary to test processes, ensure code quality. He also compiled and taught Java and JUnit-centered Unit testing practices. He lives in Costa Mesa in California with his wife Sonja.

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.