QUALITY ASSURANCE DOCUMENTATION

ELITECORE

TECHNOLOGIES

LT D

QU A LI T Y A S S U RA NC E D O C U M EN TAT IO N
JAVA CODING STANDARDS
DATE: OCTOBER 19, 2010 REVISION 1.0.0

ELITECORE TECHNOLOGIES LTD

1

1

2 .0 July 29. 2003 Vaibhavi Shah Changes made in Class Names 0.QUALITY ASSURANCE DOCUMENTATION DOCUMENT REVISION HISTORY SR.2 July 28.1 July 14. 3 . 4 . 0. 2003 Lomesh Contractor Sapana Shah Changes made in method names. 1.2003 Sapana Shah Draft version VERSION NO DATE AUTHOR REVISION COMMENTS variable names Format has been changed Some extra points are removed ELITECORE TECHNOLOGIES LTD 2 2 . 1 . NO.0.1 July 29. 2003 1.

.............QUALITY ASSURANCE DOCUMENTATION TA B L E O F C O N T E N T S 1.. Block Comments.................................2.................................................................................... Use of Threads........3...1...................................................2.........2..................................5 3................................. Java Source Files..... Variable Assignments.....................2 1...............3................................................................. Declarations-------------------------------------------------------------------------------------------------8 5................. Coding Style-------------------------------------------------------------------------------------------------7 4...........................................................5 3...... Providing Access to Instance and Class Variables............................ General.7 4............ MISCELLANEOUS-------------------------------------------------------------------------------------------11 7.........................................................................1......................3 1...1.9 6.............................7 5..............4........................................2..2.................................... Initializing Variables........................ Naming Convention---------------------------------------------------------------------------------------2 1.....3 2........8 6............................................................................................................. Constants............3............. General............................12 ELITECORE TECHNOLOGIES LTD 1 1 ..... Method Names.6 4........ Comments for a Method.....................11 7.............................................................................................................. File Names....................................5 3................. Points to be considered..........................1.............................................................................. End of Line Comments...............8 5.. Comments---------------------------------------------------------------------------------------------------5 3........4 3........... Variable Names.... Wrapping Lines...................................................................1.........................2................................................7 4.............................................1...................... File Organization-------------------------------------------------------------------------------------------4 2............................4.....2 1........3.............................................................1......8 5.....3........9 7...............................................................................9 6.6 3..................5........ Placement... Number Per Line........3....................... Good Programming Practice------------------------------------------------------------------------------9 6............................................ Line Length........................11 7......... Referring to Class Variables and Methods......... Comments for a Class ........ Security Feature of Java..................

StaffDelegateFactory 1.java extension.doc” for more detail ELITECORE TECHNOLOGIES LTD 2 2 .g.g.explanatory. CreateStaffAction Delegates should be identified by assigning suffix as “Delegate” E. StaffAction Action class for operations will have suffix as “Operation” E. Name File name: Cccccccccc. StaffDelegate Delegate Factory “DelegateFactory” should be identified by assigning suffix as     E. Refer to “Constant Range.g.QUALITY ASSURANCE DOCUMENTATION 1.  Servlet should be identified by assigning suffix as “Servlet” E. Use uppercase for the first letter of the functionality as well as for the first letter. int final LOGIN_SUCCESS = 1. NAMING CONVENTION 1. StaffServlet Action class should be identified by assigning suffix as “Action” E.g.g.  FILE NAMES The Java files must have . The names should be self.1. Write comments with each constant. Underscore can be used to separate meaningful words. Note: Constant range is fixed for each module.2.     CONSTANTS Constants should be written in upper case letters only.Meaningful class name First few letters are to be used for describing file functionality.Java Ccccccccc . E.g.

dateDeactivate. etc.. dPrice. 13. 7. 3. strMessage. chActive. etc. htbCustInfo. bAutoCommit. iCustomerCount. dateCustCreate. 8. etc. etc. 4. SR. strText. 2. iSize. start the method name with lowercase and the keyword to start with uppercase (Hungarian Notation) Example: toString(). bDistributedLoaded... 1. etc. 10. 1. htbRategroupInfo.QUALITY ASSURANCE DOCUMENTATION 1. iLength.) . 11. dateCustExpire.3. chUnlimitedDay. METHOD NAMES For all methods. etc.).4. sbText. etc. 12. 5. etc. sbMessage. NO. vctUserNames. fPrice.. etc. getValues (. vctCustInfo. fAmount.. strUserName. 9. getAccountNumber (. VARIABLE NAMES TYPE Integer Number Double Float Boolean Date String StringBuffer Vector Hashtable Char Enumeration Iterator Collection PREFIX (LOWERCASE) i d f b date str sb vct htb ch enum iter coll EXAMPLE iCount. enumElements. 6. strHelp. dAmount. etc. enumRows. enumServices etc iterServices collServices Figure 1: Variable Naming convention ELITECORE TECHNOLOGIES LTD 3 3 .

When private classes and interfaces are associated with a public class. FILE ORGANIZATION A file consists of sections that should be separated by blank lines and optional comments identifying each section. The public class should be the first class or interface in the file.QUALITY ASSURANCE DOCUMENTATION 2. The order of these variables should be public. 2. Java source files should have the following ordering      Package statements Import statements Beginning Comments Class and interface declarations Class (static) variables.1. protected and then private Constructors   ELITECORE TECHNOLOGIES LTD 4 4 . protected and then private Instance variables. The order of these variables should be public. these can be put in the same source file as the public class. JAVA SOURCE FILES Each Java source file contains a single public class or interface.

GENERAL Use the javadoc format of /** Comments */.  javadoc generates documentation only for variables and methods with public. This enables a documentation of the class in HTML format to be carried out by running the javadoc documentation tool provided by JDK. External Methods Called: Start Date: Modification log: */ 3. protected or private protected access. Please refer appendix 1for more details on documentation using javadoc 3. Any comments relating to private or default package variables and methods are not translated to the output documentation.3.QUALITY ASSURANCE DOCUMENTATION 3. Any algorithms used or books referred. COMMENTS 3.1. This is in keeping with the object oriented methodology where only what is accessible to other classes should be revealed. COMMENTS FOR A CLASS Following should be incorporated just above the class definition /* @author: Functionality description: What it is supposed to do. COMMENTS FOR A METHOD Just above a method explain the following /** *DESCRIPTION *@param <name of param> description *@return description of the return value */ ELITECORE TECHNOLOGIES LTD 5 5 .2.

5.4. END OF LINE COMMENTS Use the //comment delimiter to put in comments at the end of a line. Block comments should be formatted as follows /* * This is a block comment */ 3. This should not be used to comment out multiple lines of code. BLOCK COMMENTS A blank line to set it apart from the rest of the code should precede a block comment.QUALITY ASSURANCE DOCUMENTATION 3. ELITECORE TECHNOLOGIES LTD 6 6 .

. Method1(longExpression1.3.1.g. LINE LENGTH Avoid line longer than 80 characters as readability becomes an issue. CODING STYLE 4.. Void myFn (.) { } Whatever the convention is followed. LongExpression4. longExpression3. break it according to these general principles • • • • E.QUALITY ASSURANCE DOCUMENTATION 4.2. longExpression2. the code must be aligned properly. the previous line ELITECORE TECHNOLOGIES LTD 7 7 . 4. just indent 8 spaces instead. Var2 = longName1 + longName2 – longName3 * (longName4 + LongName5) Break after a comma Break before an operator Align the new line with the beginning of the expression at the same level on If the above rules lead to confusing code. longExpression5). GENERAL The style followed must be readable. Use the same tab size for all the files. The same style has to be followed through out the class and application. WRAPPING LINES When an expression will not fit on a single line. 4.

ELITECORE TECHNOLOGIES LTD 8 8 . String strName .//Name of Person String strType. int. E. But all classes that have the Object class to be the parent are initialized to null.2.g. when an instance of a String. They must be initialized as follows String strName= new String(). DECLARATIONS 5.1. Boolean. NUMBER PER LINE One declaration per line is recommended since it encourages commenting.QUALITY ASSURANCE DOCUMENTATION 5. INITIALIZING VARIABLES Java initializes the standard data type variables viz. it can lead to confusion 5.3. // Type of Participant 5. Don’t wait to declare variables before their first use. or instance of a Vector or Hash table are used. So care must be taken to initialize these variables first. E. PLACEMENT Put declarations only at the beginning of blocks. char. float etc.g.

fChar = barFoo. It is hard to read.1.classMethod(). For example: classMethod(). Example: fooBar. Often. // AVOID! Do not use the assignment operator in a place where it can be easily confused with the equalityoperator.  VARIABLE ASSIGNMENTS Avoid assigning several variables to the same value in a single statement. Use a class name instead.classMethod(). } should be written as if ((c++ = d++) != 0) {  ELITECORE TECHNOLOGIES LTD 9 9 .3. Case where the class is essentially a data structure. In other words. //OK anObject. //AVOID! 6. instance variables don’t need to be explicitly set or gotten—often that happens as a side effect of method calls.g. if you would have used a struct instead of a class (if Java supported struct).2.. Example: if (c++ = d++) { // AVOID! Java disallows . //OK AClass. E. with no behavior.QUALITY ASSURANCE DOCUMENTATION 6.lchar = 'c'. then it’s appropriate to make the class’s instance variables public.. GOOD PROGRAMMING PRACTICE 6. 6. PROVIDING ACCESS TO INSTANCE AND CLASS VARIABLES Don’t make any instance or class variable public without proper reason. REFERRING TO CLASS VARIABLES AND METHODS Avoid using an object to access a class (static) variable or method.

d = a + r.  ELITECORE TECHNOLOGIES LTD 10 10 . This is the job of the compiler.QUALITY ASSURANCE DOCUMENTATION . it rarely actually helps.. // AVOID! should be written as a = b + c. Example: d = (a = b + c) + r. } Do not use embedded assignments in an attempt to improve run-time performance. and besides..

There can be only one security manager in an application. If done at the end it can cause multiple problems. it is resident in memory. To implement a security policy. In Java the switch .setSecurityManager. SECURITY FEATURE OF JAVA The security manager makes decisions about access to sensitive resources. must be subclassed. overriding the methods to determine resource access according to policies that are defined. SR. Restrict nested If’s to three levels by using the fall through logic 2. The security manager doesn’t have all the information that it needs to do a good job of resource tracking. Import the entire package only when a large number of classes from that package are going to be used. the SecurityManager. Under this circumstance it may be required to write nested If statements.1. there could be many subtle implications which must be investigated. bytes and ints. Multiple decisions 3. if too many static classes are present it could affect the performance of the system or if multiple instances of the same applet exists it could result in overwriting the contents of the static class as in the case of any global variable. MISCELLANEOUS 7. For instance when the checkAccess(Threadgroup) method is called. The implementation of the SecurityManager class that is part of the core Java library is not very useful because it is an implementation that denies everything no matter what the source. This ensures that a full testing of all classes is carried out using the packaging.2. Once a security manager has been set using System. which is an instance of the SecurityManager class. But override only methods that are required. 4.case statement can handle only chars. NO 1. Creation Packages of It is advisable to create packages at the outset of coding classes. Use of Static Class 7. By allowing access. POINTS TO BE CONSIDERED POINT Import of Classes DESCRIPTION Import only the classes that are required from a package. it is always a security violation to try to set a new security manager. ELITECORE TECHNOLOGIES LTD 11 11 .QUALITY ASSURANCE DOCUMENTATION 7.

QUALITY ASSURANCE DOCUMENTATION the security manager doesn’t know whether a thread is being created or an entire thread group is being destroyed. But some of the points to take into consideration before using threads. 7.  The memory requirements of a thread include the memory for its Thread object and perhaps Runnable object. ELITECORE TECHNOLOGIES LTD 12 12 . A thread may require kernel resources from the underlying operating system The more threads. it makes better sense to decrease the threads or do the entire application in a single thread. Not only can the use of threads increase the resource requirements of an application. USE OF THREADS Java incorporates threads into its design.3. In that case. they can also decrease its performance. the more the system has to manage An application can be paralleled only by the number of available processors     A thread is a resource that should be used carefully. the more chances there are for subtle errors and performance problems. On a low level. It may very well turn out that a multithreaded application will be spending much of its time synchronizing rather than doing work. The more threads there are that need to cooperate with one another. a thread has memory for its execution stack associated with it. An application that can be split among very independent threads is much easier to create than one where the threads require much interaction between them.

Sign up to vote on this title
UsefulNot useful