Make Eclipse conform to Java programming specifications

Source: Internet
Author: User

Programming specifications are very important, so that the code of the team can be easily read and maintained, and the function can be extended in the future.

To do this, you must first sharpen your tools! As a Java programmer, dealing with Eclipse may be a matter of a lifetime. Setting Eclipse to conform to the company's programming specifications will save us a lot of time.

All users who use Eclipse know the function of pressing Ctrl + F, which is to automatically typeset the written code and make it easy to read.

When I first entered the company, the old programmer told me not to use this shortcut key, because it will cause code accidents, such as automatically sorting different parameters of a long method into different lines. What he does not know is that Ctrl + F is based on certain rules, and these rules can be set by themselves.

After setting Eclipse according to the company's programming specifications, after writing the code, a Ctrl + F page will become neat and nice. The same is true when reading other people's code.

Here we will not talk about formal programming specifications, but how to set up Eclipse step by step according to the programming specifications.

1. Set the JDK version and encoding format

The basic settings in Eclipse are all set in Windows> Preferences. Java programming's personalized settings are located in Windows-> Preferences-> Java.

(1) JDK version

For Java Development, you must first set the JDK version. MyEclipse has its own Jdk, but eclipse does not.

Follow these steps to set the custom JDK.

First, in Java-> Complier, set the Compiler compliance level to 1.6.

Then, in the right Directory of Java-> Installed JREs, you can see the JDK address and add JDK. you can locate the JDK folder by adding-> Stankard VM-> Next-> Directory, finish!

 

(2) encoding format

Preferences-> General click workspace, there is a Text file encoding on the right, click Other, select Utf-8, after the new project is UTF-8 encoded.

 

Window-> Preferences-> Java-> Code Style contains a large number of Code Style settings. The annotation template is set in Code Style-> Code Templates.

(1) File Header JavaDoc template settings:

Comments-> Files, click Edit... on the right to overwrite the JavaDoc example of the company's file header, as shown below:

/**

* Copyright <year> Xxx Inc.

*/

(2) JavaDoc template settings such as class/interface and method are similar to the above:

Similarly, Comments-> type setting class/interface JavaDoc template and Methods Setting method.

 

You can set your own Formatter as needed.

In the Code Style option, select Formatter and create your own Formatter. Click "New..." to set the name.

Then jump.

The following describes in detail the tabs on the Fomatter style settings page.

(1) set the tab key in Eclipse to 4 spaces, which is troublesome.

First, there is a Tab policy option under the first Tab Indentation. Select spaces only to save.

Then, use spaces to replace TAB, window-> preference-> General-> Editors-> Text Editors, and insert space for tabs on the right. Select and save the settings;

 

(2) Indentation on the first tab is set to indent. After selection, the Preview on the right changes directly and you can observe it.

The Statements within 'switch' body option should be checked.

 

(3) The second tab Braces is to set whether to wrap the brackets.

Generally, except class/Interface and array (the first and last) are set to Same Line, other values are set to Next Line.

 

(4) The third tab, White Space, sets spaces.

Generally, a comma must be left blank, all operators, and assignments must be left blank, and all keywords and other keywords and non-keywords must be left blank.

The configuration is too cumbersome and will not be listed here. It is very simple.

 

(5) The fourth tab, Blank Lines, is set to empty rows.

 

(6) The fifth tab, New Lines, is used to set a line break in braces.

 

(7) Control Statements on the sixth tab sets the Control statement format.

Insert new Line before 'else' in an 'if' statement is usually checked.

 

(8) The seventh tab Line Wrapping is a set of specific values for Line spacing, indentation, and maximum Line length.

Here, in order to avoid line breaks during Automatic formatting, you can set Maximum line width to a larger value and I will set it to 500 directly.

 

(9) Comments on the eighth tab sets the comment format.

 

(10) The ninth tab Off/On Tags sets the label switch in the comment.

 

We know that in Eclipse, you can use Shift + F2 to open its API documentation for a class. However, for various reasons, it is often hard to open, but in fact this can be set. As follows:

(1) Window-> Preferences-> Java-> Installed JREs

Select an existing JDK and click Edit on the right.

There is a JRE system libraries list in the center of the dialog box, which contains 9 jar packages.

 

(2)open a jar package with 2 files, one is the source file src.zip, and the other is the javadoc location :( none). All we need to do is replace this empty address with the actual address of the API document on our hard disk. Select javadoc location, click the Javadoc Location... option on the right, Click Browse... in the pop-up box, and enter the actual address of the API document on the hard disk.

 

(3) set each jar package one by one. Finally, when we select a JDK class, Shift + F2, you can open the corresponding API documentation in eclipse.

 

In addition to the preceding settings related to programming specifications, many personalized settings make Eclipse easier to use.

Preferences-> General-> Appearance-> Colors and Fonts right-side list select Java-> Java Editor Text Font, click Edit... to change the java Font.

The font settings here do not affect the fonts of xml, txt, properties, and other files. The fonts for initializing xml, txt, and properties files are usually very small and difficult to observe. See the settings below.

 

Preferences-> General-> Appearance-> Colors and Fonts select Basic-> Text font in the list on the right, and click Edit... to change the font.

Sometimes I think the font of the console is not eye-catching. If I want to change the font, I can use the following method.

 

Preferences-> Appearance-> colors and fonts right-side list select debug-> console font, click Edit... to change the font.

Other font settings are similar.

For a long time, the white color will make the programmer's eyes dizzy, and the attention cannot be concentrated. Setting the background color can alleviate this problem.

 

Select preferences-> Editors-> Text Editors. The Panel on the right has an Appearance color options to set the color of various modules.

Select Background color, remove the System Default check box on the right, and click Color to set the color.

The background colors recommended by ophthalmologists are: Tone 85, saturation 123, and brightness 205. After the settings are complete, the elegant light green will appear.

 

Certificate ------------------------------------------------------------------------------------------------------------------------------------------------------------

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.