Set your own Eclipse code style (internal) and eclipse code

Source: Internet
Author: User

Set your own Eclipse code style (internal) and eclipse code

After several code submissions, we found that many people's code styles are not standardized. I personally think it is necessary to set the code specifications.

In general, there are three code styles, two of which are similar to the following:

 

public void function(){  //function body}

 

Obviously, the Code becomes hard to read when multiple layers of code blocks are nested.

The programmer should remember that the code is written to others, and it is absolutely necessary to avoid writing only (write-only) the code. A good code style will inevitably take advantage of two points: indent and appropriate line breaks.

My code style is as follows:

public void function(){       //function body}

Note that brace pair must be aligned for the following reasons:

public void function1(){       for(int i = 0; i < 10; i ++){                for(int j = 0; j < 10; j ++){                            //some code                }       }}
public void function2(){       for(int i = 0; i < 10; i++)       {                for(int j = 0; j < 10; j++)                {                         //some code                }       }}

 

Which one do you mean is easy to see and which one looks more comfortable?

 

Okay: I am not talking much about it. Next I will explain how to set my own code style in Eclipse:

 

Step one: Window> Preferences on the menu

 

Step two: Enter the code in the search box

 

Step three: Select Java-> Formatter and click New... Button (below Eclipse [built-in)

 

Step four: enter your favorite name in Profile name. Here, MyJavaStyle is used as an example:

 

Step five: On the Indentation tab, select Statements within 'Switch 'body"

 

Step six: On the Braces tab, except for Anonymous class declaration, select Next Line

Step seven: On the Control Statements tab, select:

 

Step eight: Apply-> OK-OK ......

 

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.