Professional Documents
Culture Documents
Approved by :
(Signature)
Name
Role
Date
Amendment
1
2
4-Sep-01
28-Sep-01
10-Oct-01
2-Jun-03
Baseline Document
Document name in the footer is
changed
Spelling and grammatical
corrections
Company name has been
changed to
Approved
By
Ver. No.
Remove
Page
Insert
Page
1.0
1.1
All
All
1.2
All
All
1.3
All
All
21-Sep-02
TSQM/JAVA/STD/01
Java Standards
Ver.: 1.4
Page 2 of 15
Objective..................................................................................................................4
2.0
Files.........................................................................................................................4
3.0
Indentation..............................................................................................................4
4.0
5.0
Declarations............................................................................................................7
6.0
Statements...............................................................................................................8
7.0
White Spaces...........................................................................................................9
8.0
Naming Conventions............................................................................................10
I.
Packages................................................................................................................10
II.
III.
Methods............................................................................................................10
IV.
Variables...........................................................................................................11
V.
Constants..............................................................................................................11
VI.
Objects..............................................................................................................12
VII.
Components......................................................................................................12
9.0
TSQM/JAVA/STD/01
Java Standards
Ver.: 1.4
Page 3 of 15
1.0
Objective
The objective of this manual is to provide a set of standards for JAVA'
Programming to produce software that is:
Maintainable
Reliable
Portable
Consistent
Re-usable
2.0
Files
3.0
When private classes and interfaces are associated with a public class, they
should be put in the same source file as the public class.
The public class should be the first class or interface in the file. All source
files should have the following comment style that lists the Class
Description, Version no, Date Created, Last Modified Date, and
Modification Log.
The comments should also include the Private class names as well as
interfaces (if any) along with their description. (Can be included in a
tabular format like the Modification Log).
/*
* Class Description:
* Hierarchy Structure
* Version No:
* Date Created:
* Last Modified Date:
* Modification Log:
* SNo | Change Date | Changed By | Change Description
* Private Class Names
*/
Indentation
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.
TSQM/JAVA/STD/01
Java Standards
Ver.: 1.4
Page 4 of 15
Examples:
var = someMethod1(longExpression1,
someMethod2(longExpression2,
longExpression3));
4.0
TSQM/JAVA/STD/01
Java Standards
Ver.: 1.4
Page 5 of 15
}
Very short comments should appear on the same line as the code they
describe, but should be shifted far enough to separate them from the
statements. If more than one short comment appears in a chunk of code,
they should all be indented to the same tab setting.
if (a == 2)
{
return TRUE;
/* special case */
} else
{
return isPrime(a);
/* works only for odd a */
}
The // comment delimiter can comment out a complete line or only a
partial line. It shouldn't be used on consecutive multiple lines for text
comments; however, it can be used in consecutive multiple lines for
commenting out sections of code. Examples of all three styles follow:
if (foo > 1)
{
// Do a double-flip.
...
}
else
{
return false;
// Explain why here.
}
//if (bar > 1) {
//
// // Do a triple-flip.
// ...
//}
TSQM/JAVA/STD/01
Java Standards
Ver.: 1.4
Page 6 of 15
C style
Single line
TSQM/JAVA/STD/01
Java Standards
Usage
Example
/**
Customer A customer is
any person or organization
that we sell services and
products to.
5.0
Declarations
6.0
Statements
TSQM/JAVA/STD/01
Java Standards
Ver.: 1.4
Page 8 of 15
7.0
White Spaces
TSQM/JAVA/STD/01
Java Standards
Ver.: 1.4
Page 9 of 15
8.0
Naming Conventions
I. Packages
The packages should be named with the prefix of meaningful names and
then followed by the class name in lower case.
Example:
patientcare.fileoperations
drug.dbconnect
TSQM/JAVA/STD/01
Java Standards
Ver.: 1.4
Page 10 of 15
}
Exception classes are not precisely part of the main architecture of a
program and naming them in this manner enables them to stand out
relative to the other classes.
III. Methods
Methods should be verbs, in mixed case with the first letter
lowercase, with the first letter of each internal word capitalized. All
private variables whose values might be set or used by external programs
should have SET and GET methods, to set and read the value respectively.
TSQM/JAVA/STD/01
Java Standards
Ver.: 1.4
Page 11 of 15
Ver.: 1.4
Page 12 of 15
TSQM/JAVA/STD/01
Java Standards
Ver.: 1.4
Page 13 of 15
JTree
9.0
Don't make any instance or class variable public without good reason.
Use local variables for performing only one functionality, avoid reuse.
Numerical constants (literals) should not be coded directly, except for -1,
0, and 1, which can appear in a for loop as counter values. For others
constants should be used.
Avoid assigning several variables to the same value in a single statement.
Import only the classes required form a package instead of importing the
whole package.
Eg:
Instead of
import java.util.*;
Use the following:
import java.util.HashTable;
When checking for equality against a constant value, have the constant
value on the RightHandSide of the equality check statement.
Eg:
Instead of
(ABC).equals(Str)
use the following:
(Str).equals(ABC)
In for statements, when checking the automatic values against other
values, assign those values to variables and use those variables in the
checks.
Eg:
Instead of:
Vector v = new Vector();
for (int i=0; i < v.length(); i++)
{
}
use the following:
Vector v= new Vector();
int length = v.length();
for (int i=0; i< length; i++)
{
TSQM/JAVA/STD/01
Java Standards
Ver.: 1.4
Page 15 of 15