22-03-2014, 02:45 PM
Java Code Conventions
Code Conventions.pdf (Size: 59.25 KB / Downloads: 11)
Why Have Code Conventions
Code conventions are important to programmers for a number of reasons:
80% of the lifetime cost of a piece of software goes to maintenance.
Hardly any software is maintained for its whole life by the original author.
Code conventions improve the readability of the software, allowing engineers to
understand new code more quickly and thoroughly.
If you ship your source code as a product, you need to make sure it is as well packaged
and clean as any other product you create
Wrapping Lines
When an expression will not fit on a single line, break it according to these general principles:
Break after a comma.
Break before an operator.
Prefer higher-level breaks to lower-level breaks.
Align the new line with the beginning of the expression at the same level on the previous
line.
If the above rules lead to confusing code or to code that’s squished up against the right
margin, just indent 8 spaces instead.
Comments
Java programs can have two kinds of comments: implementation comments and
documentation comments. Implementation comments are those found in C++, which are
delimited by /*...*/, and //. Documentation comments (known as “doc comments”) are
Java-only, and are delimited by /*...*/. Doc comments can be extracted to HTML files
using the javadoc tool.
Implementation comments are mean for commenting out code or for comments about the
particular implementation. Doc comments are meant to describe the specification of the code,
from an implementation-free perspective. to be read by developers who might not necessarily
have the source code at hand.
Comments should be used to give overviews of code and provide additional information that is
not readily available in the code itself. Comments should contain only information that is
relevant to reading and understanding the program. For example, information about how the
corresponding package is built or in what directory it resides should not be included as a
comment.