Java语言编程规范——排版规范

对于排版的规范,可能大家很多都知道用ctrl+shift+f一键格式化,那么这个一键格式化遵循了什么样的规则呢?当然很多公司也有自己的一个formatting.xml 格式化规范文件。今天我们就来具体了解下这个一键格式化到底包括哪些内容。
- 程序块要采用缩进风格编写,缩进1个TAB键。
- 较长的语句、表达式或参数(>120字符)要分成多行书写,长表达式要在低优先级操作符处划分新行,操作符放在新行之首,划分出的新行要进行适当的缩进,使排版整齐,语句可读。
示例:

if (filename != null 
     && new File(logPath + filename).length() < LogConfig.getFileSize())
{
    ... // program code
}   
public static LogIterator read(String logType, Date startTime, Date endTime,
                                 int logLevel, String userName, int bufferNum)
  • 不允许把多个短语句写在一行中,即一行只写一条语句
    示例:如下例子不符合规范。
LogFilename now = null;        LogFilename that = null;

应如下书写:

LogFilename now = null;
LogFilename that = null;
  • if, for, do, while, case, switch, default 等语句自占一行,且if, for, do, while等语句的执行语句无论多少都要加括号{}。
    示例:如下例子不符合规范。
if(writeToFile)           writeFileThread.interrupt();

应如下书写:

if(writeToFile)
{
     writeFileThread.interrupt();
}
  • 相对独立的程序块之间、变量说明之后必须加空行。
    示例:如下例子不符合规范。
if(log.getLevel() < LogConfig.getRecordLevel())
{
    return;
}
LogWriter writer;

应如下书写:

if(log.getLevel() < LogConfig.getRecordLevel())
{
     return;
}
//空一行
LogWriter writer;
int index;
  • 对齐只使用TAB键,不使用空格键。
  • 在两个以上的关键字、变量、常量进行对等操作时,它们之间的操作符之前、之后或者前后要加空格。
    说明:采用这种松散方式编写代码的目的是使代码更加清晰。
    示例:
    (1)逗号、分号只在后面加空格。
int a, b, c; 

(2)比较操作符, 赋值操作符"="、 "+=",算术操作符"+"、"%",逻辑操作符"&&"、"&",位域操作符"<<"、"^"等双目操作符的前后加空格。

if (current_time >= MAX_TIME_VALUE) 
a = b + c;
a *= 2;
a = b ^ 2;

(3)"!"、"~"、"++"、"--"、"&"(地址运算符)等单目操作符前后不加空格。

flag =! isEmpty; // 非操作"!"与内容之间
i++;             // "++","--"与内容之间

(4)"."前后不加空格。

p.id = pid;     // "."前后不加空格

(5)if、for、while、switch等与后面的括号间应加空格,使if等关键字更为突出、明显。

if (a >= b && c > d)
  • 类属性和类方法不要交叉放置,不同存取范围的属性或者方法也尽量不要交叉放置。
    格式:
类定义
{
     类的公有属性定义
     类的保护属性定义
     类的私有属性定义
     类的公有方法定义
     类的保护方法定义
     类的私有方法定义
}

##最后
以上规范并不完整,欢迎大家补充。

本文作者:Rance935本文出处:Java语言编程规范——排版规范转载请在开头注明作者详细信息和本文出处
欢迎关注我的微信公众号和QQ群,分享Android 开发和互联网内容
Android技术分享:群号534813930
微信号:androidparks
公众号:AndroidParks

评论

  • reklama lubin回复

    Excellent blog! Do you have any helpful hints for
    aspiring writers? I'm planning to start my own blog soon but I'm a little lost on everything.
    Would you recommend starting with a free platform like WordPress or go for a paid option? There are
    so many options out there that I'm totally overwhelmed ..
    Any tips? Thanks!

  • VladilenGergo回复

    try it viagra overnigh

    [url=http://viagraomz.com/]online viagra[/url]

    <a href="http://viagraomz.com/">cheap viagra online</a>

    buy viagra for premature

  • VladilenGergo回复

    forum viagra sur le net

    <a href=http://viagraomz.com/>generic viagra online</a>

    <a href="http://viagraomz.com/">online viagra</a>

    levitra 20 mg o viagra

  • CheplanovaGergo回复

    viagra basel

    http://viagralms.com/ - canadian viagra

    <a href="http://viagralms.com/">online viagra</a>

    online can canadians viagra

  • read me回复

    Greate post. Keep writing such kind of information on your blog.
    Im really impressed by your site.
    Hello there, You've done an excellent job.
    I'll certainly digg it and in my opinion recommend to my
    friends. I'm confident they'll be benefited from this site.

  • MakritskayaGergo回复

    gay tabs host buy viagra

    <a href=http://viagraoail.com/>buy viagra online</a>

    <a href="http://viagraoail.com/">buy viagra</a>

    viagra shop hollan

  • Grupo Coral回复

    I quite like looking through a post that will make men and women think. Also, many thanks for permitting me to comment!|

  • CheplanovaGergo回复

    viagra in uk low price

    http://viagralms.com/ - generic viagra online

    <a href="http://viagralms.com/">buy viagra</a>

    viagra by cipla review

  • Bob回复

    Have actually been taking little over a month.

  • MakritskayaGergo回复

    what viagra to take

    <a href=http://viagraoail.com/>viagra cheap</a>

    <a href="http://viagraoail.com/">viagra online</a>

    online standard viagra

  • CheplanovaGergo回复

    herb viagra 6800mg review

    http://viagralms.com/ - buy viagra

    <a href="http://viagralms.com/">generic viagra online</a>

    generic viagra mg price

  • MakritskayaGergo回复

    comparaison viagra cialis

    [url=http://viagraoail.com/]viagra online[/url]

    <a href="http://viagraoail.com/">buy generic viagra</a>

    viagra cialis pills

  • 我看到它落下了两张照片回复

    Heya i'm for the primary time here. I came across this
    board and I to find It truly useful & it helped me
    out much. I'm hoping to provide one thing back and aid others like you
    aided me.

  • CheplanovaGergo回复

    viagra ablauf patent

    http://viagralms.com/ - cheap viagra

    <a href="http://viagralms.com/">buy viagra</a>

    viagra levitra same day

  • VladilenGergo回复

    can you get viagra samples

    <a href=http://viagraomz.com/>online viagra</a>

    <a href="http://viagraomz.com/">cheap viagra</a>

    strongman viagra

  • MakritskayaGergo回复

    how long for viagra to work

    <a href=http://viagraoail.com/>online viagra</a>

    <a href="http://viagraoail.com/">buy viagra</a>

    viagra bremen

  • Yatango Andy Taylor回复

    I've been exploring for a bit for any high-quality articles or blog posts in this kind of area .
    Exploring in Yahoo I finally stumbled upon this website. Studying this information So i'm
    happy to show that I've a very good uncanny feeling I discovered exactly what I needed.
    I most for sure will make certain to do not overlook this web site and give it a look regularly.

  • Yatango Andy Taylor回复

    Good site you've got here.. It's difficult to
    find high-quality writing like yours these days.
    I really appreciate individuals like you! Take care!!

  • biological dentist回复

    I'm really enjoying the theme/design of your blog.
    Do you ever run into any browser compatibility issues?
    A couple of my blog readers have complained
    about my blog not operating correctly in Explorer but looks
    great in Chrome. Do you have any tips to help fix this issue?

  • CheplanovaGergo回复

    le viagra rembourse

    http://viagralms.com/ - online viagra

    <a href="http://viagralms.com/">viagra online</a>

    migliore prezzo di viagra

  • VladilenGergo回复

    viagra generico mas bajo

    [url=http://viagraomz.com/]buy viagra online[/url]

    <a href="http://viagraomz.com/">viagra cheap</a>

    try it viagra overnigh

  • CheplanovaGergo回复

    viagra by cipla review

    http://viagralms.com/ - viagra online

    <a href="http://viagralms.com/">buy viagra</a>

    viagra law uk

  • VladilenGergo回复

    buy viagra on ebay

    <a href=http://viagraomz.com/>buy viagra online</a>

    <a href="http://viagraomz.com/">buy viagra online</a>

    viagra rezeptfrei frau

  • &****回复

    Nice post. I was checking constantly this blog and I'm inspired!
    Extremely helpful information particularly the closing phase :
    ) I take care of such info a lot. I used to be looking for this particular information for a long time.

    Thank you and good luck.

  • VladilenGergo回复

    viagra kaufen basel

    <a href=http://viagraomz.com/>generic viagra online</a>

    <a href="http://viagraomz.com/">buy viagra</a>

    viagra dor nas costas

  • culinary回复

    I've been surfing online more than 3 hours today, yet I never found any interesting article like yours. It’s pretty worth enough for me. Personally, if all web owners and bloggers made good content as you did, the internet will be a lot more useful than ever before.

  • Attorney At Law回复

    Great tremendous issues here. I am very satisfied to peer your article. Thanks so much and i'm having a look forward to contact you. Will you please drop me a e-mail?

  • Barrister回复

    I would like to voice my love for your kind-heartedness giving support to those who actually need assistance with this theme. Your very own commitment to passing the solution along appears to be especially invaluable and have in most cases permitted workers much like me to attain their goals. Your entire insightful advice indicates a lot to me and additionally to my colleagues. Best wishes; from everyone of us.

  • Schools回复

    Wonderful work! This is the kind of info that are supposed to be shared across the internet. Disgrace on the seek engines for no longer positioning this submit upper! Come on over and talk over with my web site . Thanks =)

  • Lélio Vieira Carneiro Junio回复

    I think that everything posted made a great deal of sense. However, what about this? suppose you typed a catchier post title? I mean, I don't wish to tell you how to run your website, but suppose you added a headline that grabbed a person's attention? I mean %BLOG_TITLE% is a little plain. You could peek at Yahoo's home page and watch how they create news headlines to grab people interested. You might add a video or a related pic or two to grab people interested about what you've got to say. In my opinion, it might make your posts a little bit more interesting.|

  • AdamGergo回复

    comprar cialis generico foro

    http://canadianiucialis.com/ - generic cialis

    <a href="http://canadianiucialis.com/">cialis</a>

    efectos cialis alcoho

  • Law School回复

    I¡¦ll right away take hold of your rss as I can not to find your e-mail subscription link or e-newsletter service. Do you have any? Kindly allow me recognize so that I could subscribe. Thanks.

  • short escape回复

    Normally I don't learn article on blogs, however I would like to say that this write-up very forced me to check out and do it! Your writing style has been amazed me. Thank you, very nice post.

  • outdoor activities回复

    Awsome info and right to the point. I am not sure if this is in fact the best place to ask but do you folks have any ideea where to hire some professional writers? Thanks in advance 😊

  • VladilenGergo回复

    viagra pill cost in india

    <a href=http://viagraomz.com/>buy viagra</a>

    <a href="http://viagraomz.com/">buy viagra online</a>

    viagra tablets duration

  • class rings回复

    Aw, this was an exceptionally nice post. Spending some time and actual effort to make a top notch
    article… but what can I say… I hesitate a whole lot and never manage to
    get anything done.

  • Luther回复

    Have actually been taking little over a month.

  • AdamGergo回复

    comprar cialis levitra

    http://canadianiucialis.com/ - canadian cialis

    <a href="http://canadianiucialis.com/">buy cialis</a>

    cialis sublingual mist canada

  • Nonton Anime Subtitle Indonesia回复

    Definitely believe that which you stated. Your favorite justification seemed to
    be on the net the simplest thing to be aware of. I say to you, I certainly get irked while people think about worries that they plainly
    do not know about. You managed to hit the nail upon the top as well as defined
    out the whole thing without having side-effects , people could take a signal.

    Will likely be back to get more. Thanks

  • kelleher international reviews回复

    My developer is trying to convince me to move to .net from PHP.

    I have always disliked the idea because of the costs. But he's tryiong none the less.
    I've been using Movable-type on various websites for about a year and am concerned about switching to
    another platform. I have heard great things about blogengine.net.
    Is there a way I can import all my wordpress posts into it?
    Any kind of help would be really appreciated!

  • LenaGergo回复

    how to get sample viagra

    <a href=http://norxcheapviagraf.com/>buy viagra online</a>

    <a href="http://norxcheapviagraf.com/">generic viagra</a>

    viagra 50mg online kaufen

  • Brook回复

    Hi there, can you aid me on this? I adhered to all the steps pointed out however it
    really did not end up fairly like yours. Many thanks

  • adidas ultra boost uncaged回复

    I intended to put you one little bit of word just to say thanks a lot again for these amazing pointers you have shown on this site. It has been strangely open-handed with people like you to convey extensively just what many of us might have marketed as an ebook to get some bucks for their own end, most importantly considering that you could possibly have tried it if you ever considered necessary. The concepts additionally worked to become a easy way to be certain that other people have the identical dreams much like mine to grasp more on the topic of this matter. I'm certain there are a lot more pleasant opportunities up front for individuals that view your site.

  • AdamGergo回复

    cialis online best place

    http://canadianiucialis.com/ - generic cialis

    <a href="http://canadianiucialis.com/">canadian cialis</a>

    cialis und wikipedia

  • freshly squeezed sugarcane juice回复

    Hi great blog! Does running a blog such as this take a large amount of work?
    I've very little knowledge of computer programming but I
    was hoping to start my own blog soon. Anyway, if
    you have any suggestions or tips for new blog owners please share.
    I know this is off subject but I just needed to
    ask. Thanks!

  • AdamGergo回复

    online cialis kauf

    [url=http://canadianiucialis.com/]buy cialis[/url]

    <a href="http://canadianiucialis.com/">cialis</a>

    enter site take cialis

  • AdamGergo回复

    visit web site cialis 5 mg buy

    http://canadianiucialis.com/ - order cialis online

    <a href="http://canadianiucialis.com/">cialis</a>

    purchase cialis from us

  • Sugarcane Juice Victoria回复

    obviously like your web-site but you need to check the spelling on quite a few of your posts.

    Many of them are rife with spelling problems and I find it very troublesome to inform the truth then again I will definitely come again again.