Java Code Conventions
Download Link :
Indian Users : Java Coding Conventions
International Users : Java Coding Conventions
Alternate Link : Java Coding Conventions
For reading scroll down.
Indian Users : Java Coding Conventions
International Users : Java Coding Conventions
Alternate Link : Java Coding Conventions
For reading scroll down.
1.1 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.
2 - File Names
This section lists commonly used file suffixes and names.
2.1 File Suffixes
JavaSoft uses the following file suffixes:
Java source : .java
Java bytecode
:
.class
2.2 Common File Names
Frequently used file names include:
GNUmakefile The preferred name for makefiles.We use gnumake to build our software.
README
The preferred
name for the file that summarizes the contents of a particular directory.
3 - File Organization
A file consists of
sections that should be separated by blank lines and an optional comment
identifying each section. Files longer than 2000 lines are cumbersome and
should be avoided.
3.1 Java Source Files
Each Java source file
contains a single public class or interface. When private classes and
interfaces are associated with a public class, you can put them in the same
source file as the public class. The public class should be the first class or
interface in the file.
Java source files have the following ordering:
• Beginning comments
• Package and Import
statements; for example:
import java.applet.Applet;
import java.awt.*;
import java.net.*;
• Class and interface
declarations
3.1.1 Beginning Comments
All source files should begin with a c-style comment that lists the programmer(s), the date, a
copyright notice, and
also a brief description of the purpose of the program. For example:
/*
* Classname
*
* Version info
*
* Copyright
notice
*/
3.1.2 Package and Import Statements
The first non-comment
line of most Java source files is a package statement. After that,
import statements can
follow. For example:
package java.awt;
import
java.awt.peer.CanvasPeer;
3.1.3 Class and Interface Declarations
The following table describes the parts of a class or interface declaration, in the order that they
should appear. See
“Java Source File Example” on page 19 for an example that includes
comments.
Part of
Class/Interface
Declaration Notes
1 Class/interface
documentation
See “Documentation Comments” on page 9 for
comment
(/**...*/)
information on what should be in this comment.
2 class or interface
statement
3 Class/interface
implementation
This
comment should contain any class-wide or
comment (/*...*/), if
necessary
interface-wide information that wasn’t appropriate
for the class/interface documentation comment.
4 Class (static)
variables
First the public class variables, then the protected,
and then the private.
5 Instance variables
First public, then protected, and then private.
6 Constructors
7 Methods
These methods should be grouped by functionality
rather than by scope or accessibility. For example, a
private class method can be in between two public
instance methods. The goal is to make reading and
understanding the code easier.
Download for reading complete document :
Download Link :
Indian Users : Java Coding Conventions
International Users : Java Coding Conventions
Alternate Link : Java Coding Conventions

No comments:
Post a Comment