Rules and Standards |
CAA V5 Java Code PresentationPresentation conventions to improve the readability of Java code |
Technical Article |
AbstractThis article gives you information on how to program Java classes and interfaces as regards code layout. CAA Use Cases are expected to respect these conventions. |
Each Java source contains a single class or interface.
The code presentation must obey the following order:
// COPYRIGHT DASSAULT SYSTEMES 2000 |
/* ----------------------------------------- * creation: 04/01/2000 by egr * modification: 13/02/2000 by egr to add the dump method * modification: 23/05/2000 by egr. IR A234789. to treat the case when the file does not exist. ---------------------------------------------*/ |
package com.dassault_systemes.ENOVDesktop.ENOVDtpCommand; |
// PortalBase Framework import com.dassault_systemes.catweb.base.catlet.CSO // to manage current selection import com.dassault_systemes.catweb.base.catlet.CATlet // to retrieve the CSO import com.dassault_systemes.catweb.base.event.CSOListener // to subscribe to CSO // PortalApplications Framework import com.dassault_systemes.catweb.databackend.dataType/Driver2 // to implement the interface |
/** * Class which manages the current selection. * <br><b>Role</b>: This class stores a list of the currently selected elements. * Each CATlet has one and only one instance of a CSO object. * To get this instance, call the {@link ICATlet#getCSO()} method. * Use this class to add or remove elements from the selection. * This class dispatches {@link CSOEvent} when the selection is modified. * Implement the {@link CSOEventListener} interface to subscribe to this events. */ |
public class CSO |
[Top]
Indentation
When an expression will not fit on a single line, break it after a comma
or before an operator.
Align the new line with the beginning of the expression at the same level on
the previous line, or if it is too far on the right, use an indentation
twice as big as usual.
MyMethod(longArg1, longArg2, longArg3, longArg4, longArg5); longName1 = longName2 * (longName3 + longName4 - longName5) + 4 * longname6; |
int level; // indentation level int size; // size of table |
however, the following declarations are acceptable:
int x, y, z; // point coordinates |
In the same way, do not use embedded assignments (ex: a=b=c).
Air out, use spaces:
for (expr1; expr2; expr3) { a = b / (c + d) * e++ + (int) l; myVar.myMethod(a, b, c); } |
if-else
or for
statements even if there is only one line.
class Sample extends Object { int var; void Print(int i, int j) { if (condition) { statement1; } else { statement1; statement2; } } ... } |
Use parentheses liberally in expressions involving mixed operators to avoid operator precedence problems.
if (a == b) && (c == d) |
But avoid them in a return
statement unless they make the
return value more obvious in some way.
return; return myDisk.size(); return (size ? size : defaultSize); |
for
loop as counter values. Use
static final variables instead.
if (MAX_LENGTH == lg) |
[Top]
run(), runFast()
.V
property should be getV
and setV
. e.g., setPriority
V
should be named
isV
, e.g., isInterrupted
F
should be named toF
, e.g., toString
.As regards the other variables, using a prefix is optional.
The usually used prefixes are:
and, as for classes, an abbreviation of three or four characters is often used as a prefix:
[Top]
All the exposed entities (class, interface, public and protected methods and
fields) must be preceded by a comment in the javadoc style. See Documenting Your
Interfaces and Classes. But even the not exposed entities should be commented in
the same way, particularly in the CAA use cases.
Moreover, C++ style comments should be used to give overviews of code and
provide additional information to make the code easier to understand. However,
redundant information must be avoided.
Comments are written at the third singular person (e.g., creates).
[Top]
Version: 1.0 [Sep 2000] | Document created |
[Top] |
Copyright © 2000, Dassault Systèmes. All rights reserved.