Set your own Eclipse code style (internal)

Source: Internet
Author: User

After these several code submissions, found that many people's code style is not standardized. Personally, it is necessary to impose a code specification.

Overall, there are three code styles, two of which are similar to this:

 Public void function () {  //function Body}

Obviously, the code becomes difficult to read in cases where multiple blocks of code are nested.

The programmer must remember that the code is written for others to read, absolutely absolutely avoid writing (write-only) code. A good code style is bound to use two points: indentation (indent) and proper line wrapping.

The style of my code is this:

 Public void function () {       //function Body}

Note that the curly brace pair (brace pair) is aligned for a simple reason:

 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 <, i++)       {                for (int
     j = 0; J < 10; J + +)                {                         //Some code                }        }}

Which one would you say is easy to see and which looks comfortable?

Okay, don't say much, let's talk about how to set your own code style in eclipse:

Step One: window->preferences on the menu

Step: Enter code in the search box

Step Three: Select Java->formatter, click New ... button (i.e. under Eclipse [built-in])

Step Four: Enter your preferred name in Profile name. Here take Myjavastyle as an example:

Step Five: In the Indentation tab, tick "statements within ' switch ' body"

Step Six: In the Braces tab, except for anonymous class declaration, the other select all next line

Step Seven: In the Control Statements tab, TICK:

Step Eight:apply->ok-ok ...

Set your own Eclipse code style (internal)

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.