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

评论

  • how to lose belly fat回复

    I'll immediately snatch your rss feed as I can't to find
    your email subscription hyperlink or e-newsletter service.
    Do you've any? Please allow me realize in order
    that I could subscribe. Thanks.

  • CheplanovaGergo回复

    osu viagra rezept

    http://viagralms.com/ - canadian viagra

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

    i use it herbal viagra

  • POLYTRONGLASS回复

    Do you have a spam issue on this site; I also am a blogger, and I was wondering your situation; we have
    developed some nice practices and we are looking to trade solutions
    with others, why not shoot me an e-mail if interested.

  • Graphic Desig回复

    What i do not realize is actually how you are not really a lot
    more neatly-favored than you may be right now.

    You're so intelligent. You understand therefore considerably with regards to this matter, produced me for my part imagine it
    from numerous varied angles. Its like men and women don't seem to be interested unless it's something to do with Girl gaga!
    Your individual stuffs outstanding. At all times maintain it up!

  • Ada回复

    Have actually been taking little over a month.

  • nmd回复

    I just wanted to send a simple word so as to say thanks to you for all the great tricks you are placing here. My considerable internet search has finally been paid with incredibly good know-how to talk about with my co-workers. I would claim that we readers actually are definitely endowed to dwell in a notable network with many brilliant professionals with beneficial tips. I feel extremely privileged to have discovered your website and look forward to plenty of more exciting moments reading here. Thank you once again for all the details.

  • CheplanovaGergo回复

    only here best price viagra

    http://viagralms.com/ - viagra online

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

    generisk viagra super active

  • VladilenGergo回复

    safe maximum viagra dosage

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

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

    comprar genericos de viagra

  • Jose Wilame Araujo Rodrigues回复

    Fascinating blog! Is your theme custom made or did you download it from somewhere? A theme like yours with a few simple tweeks would really make my blog shine. Please let me know where you got your design. Thanks|

  • Invention回复

    Very well written information. It will be valuable to everyone who usess it, including myself. Keep up the good work - i will definitely read more posts.

  • Interior Home Design回复

    Hiya, I'm really glad I've found this info. Today bloggers publish just about gossips and net and this is really irritating. A good blog with exciting content, this is what I need. Thank you for keeping this web site, I'll be visiting it. Do you do newsletters? Can't find it.

  • Pool Fence回复

    I was just looking for this info for a while. After 6 hours of continuous Googleing, at last I got it in your site. I wonder what is the lack of Google strategy that don't rank this kind of informative websites in top of the list. Generally the top web sites are full of garbage.

  • Public School回复

    whoah this weblog is fantastic i like studying your articles. Stay up the good work! You already know, many individuals are hunting round for this info, you can aid them greatly.

  • celebrities回复

    I enjoy you because of all of the labor on this website. My mum take interest in going through internet research and it is simple to grasp why. Almost all hear all concerning the powerful way you render priceless suggestions via this web site and even welcome response from website visitors on the content while our favorite child is always discovering so much. Take pleasure in the remaining portion of the new year. You have been doing a very good job.

  • Living and Gardening回复

    Well I truly liked reading it. This post procured by you is very constructive for accurate planning.

  • Nora回复

    Hi there, You've done an excellent job. I will certainly digg it and personally recommend to my friends.
    I'm confident they will be benefited from this site.

  • CheplanovaGergo回复

    date patent viagra

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

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

    date patent viagra

  • MakritskayaGergo回复

    viagra kansas

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

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

    best pill splitter viagra

  • CheplanovaGergo回复

    where to buy viagra in chicago

    http://viagralms.com/ - online viagra

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

    recreational uses of viagra

  • Eldon回复

    You may also have special needs just like a family or pet friendly
    which is created from easy to clean material etc. Before buying large tiles, you should ensure your floor is completely flat.
    Westchester is often a country positioned in New York in United States, as well as the place is best referred
    to as Westchester Country.

  • Find Carl Kruse on Vator回复

    I don't even understand how I finished up here, but
    I believed this put up was good. I do not recognise who
    you're but certainly you're going to a well-known blogger in the event you are not
    already. Cheers!

  • A Daily Update Of Stock回复

    Hurrah! At last I got a blog from where I be able to in fact get
    helpful data concerning my study and knowledge.

  • dietas para Adelgazar Rapido回复

    Whoa! This blog looks just like my old one! It's on a
    completely different subject but it has pretty much the same page layout and design.
    Great choice of colors!

  • Odessa回复

    I was wondering if you ever thought of changing the structure of your website?
    Its very well written; I love what youve got to say.
    But maybe you could a little more in the way of content so people
    could connect with it better. Youve got an awful lot of text for only having 1 or two images.

    Maybe you could space it out better?

  • CheplanovaGergo回复

    viagra pour femme dangereux

    http://viagralms.com/ - viagra online

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

    viagra generic london

  • adidas gazelle sale回复

    This is the appropriate blog for anyone who wants to search out out about this topic. You notice so much its nearly hard to argue with you (not that I actually would want匟aHa). You undoubtedly put a new spin on a topic thats been written about for years. Great stuff, just great!

  • Despedidas De Soltero En Madrid回复

    Hello, i think that i saw you visited my site thus i came to “return the favor”.I am attempting to
    find things to enhance my site!I suppose its ok to use some of your ideas!!

  • CheplanovaGergo回复

    viagra mastercard espaA±a

    http://viagralms.com/ - viagra online

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

    where to get viagra

  • гурта回复

    Outstanding post however , I was wanting to know if you could write
    a litte more on this topic? I'd be very grateful if you could elaborate a little bit further.
    Thank you!

  • CheplanovaGergo回复

    comprar viagra uruguay

    [url=http://viagralms.com/]canadian viagra[/url]

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

    viagra dealers bangalore

  • Alannah回复

    Choosing the suitable shipping companies per kind of freights require some research.
    Forbes declared Japan is a vital section of the global supply chain so when supplying chain is disrupted, it's going
    to customize the U. The education system of
    Spain is significantly higher and as well as 30 European countries it aims to
    create a European Higher Education Space.

  • Indonesia furniture exporter回复

    If you've had these worries yourself, it is important which you realize which you will find things
    you can do to cut back the danger. And if employees find
    some modifications in their role in the job tenure, they're going to then require high level of corporate experience.
    WHAT IS THIS VORTEX REALLY AND HOW CAN IT HELP YOU BUILD YOUR NETWORK MARKETING BUSINESS.

  • VladilenGergo回复

    wow)) viagra uk purchase

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

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

    link for you viagra best buy

  • talking about vator回复

    hello there and thank you for your information – I
    have certainly picked up something new from right here.
    I did however expertise some technical issues using this site,
    as I experienced to reload the web site lots of
    times previous to I could get it to load correctly.
    I had been wondering if your web hosting is OK?

    Not that I'm complaining, but slow loading instances
    times will sometimes affect your placement in google and can damage your high quality score if ads and marketing with Adwords.
    Anyway I am adding this RSS to my e-mail and could look out for much more
    of your respective interesting content. Make sure you update this again soon.

  • Scale Your Business回复

    It is not my first time to pay a quick visit this website, i am visiting
    this web site dailly and obtain fastidious information from here all the time.

  • MakritskayaGergo回复

    achat viagra non generiqu

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

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

    viagra pharmacy online generic

  • CheplanovaGergo回复

    wholesale viagra in india

    [url=http://viagralms.com/]viagra cheap[/url]

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

    farmaci generici come viagra

  • CheplanovaGergo回复

    mejor precio de viagra au

    http://viagralms.com/ - online viagra

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

    viagra til m?nd

  • VladilenGergo回复

    lowest price viagra in oc ca

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

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

    viagra in costa rica

  • CheplanovaGergo回复

    should i take two viagra

    http://viagralms.com/ - buy viagra

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

    generic viagra super force