OO design and analysis aspects of Java programs ( in
Advanced Java: Idioms, Pitfalls, Styles, and Programming Tips by
Chris Laffra - PART I, Idioms and Programming Tips)
how to implement callbacks ( in
Advanced Java: Idioms, Pitfalls, Styles, and Programming Tips by
Chris Laffra - PART I, Idioms and Programming Tips)
the range of meta-programming techniques in Java ( in
Advanced Java: Idioms, Pitfalls, Styles, and Programming Tips by
Chris Laffra - PART I, Idioms and Programming Tips)
security aspects ( in
Advanced Java: Idioms, Pitfalls, Styles, and Programming Tips by
Chris Laffra - PART I, Idioms and Programming Tips)
Java pitfalls and "gotchas" ( in
Advanced Java: Idioms, Pitfalls, Styles, and Programming Tips by
Chris Laffra - PART I, Idioms and Programming Tips)
the strengths and limitations of multi-threaded programming ( in
Advanced Java: Idioms, Pitfalls, Styles, and Programming Tips by
Chris Laffra - PART I, Idioms and Programming Tips)
OO analysis and design for Java ( in
Advanced Java: Idioms, Pitfalls, Styles, and Programming Tips by
Chris Laffra - PART I, Idioms and Programming Tips)
multithreaded application development ( in
Advanced Java: Idioms, Pitfalls, Styles, and Programming Tips by
Chris Laffra - PART I, Idioms and Programming Tips)
naming of classes and interfaces ( in
Advanced Java: Idioms, Pitfalls, Styles, and Programming Tips by
Chris Laffra - PART I, Idioms and Programming Tips)
optimization techniques ( in
Advanced Java: Idioms, Pitfalls, Styles, and Programming Tips by
Chris Laffra - PART I, Idioms and Programming Tips)
equality testing ( in
Advanced Java: Idioms, Pitfalls, Styles, and Programming Tips by
Chris Laffra - PART I, Idioms and Programming Tips)
exception handling techniques ( in
Advanced Java: Idioms, Pitfalls, Styles, and Programming Tips by
Chris Laffra - PART I, Idioms and Programming Tips)
floating point limitations ( in
Advanced Java: Idioms, Pitfalls, Styles, and Programming Tips by
Chris Laffra - PART I, Idioms and Programming Tips)
reflection in Java ( in
Advanced Java: Idioms, Pitfalls, Styles, and Programming Tips by
Chris Laffra - PART I, Idioms and Programming Tips)
hashtables ( in
Advanced Java: Idioms, Pitfalls, Styles, and Programming Tips by
Chris Laffra - PART I, Idioms and Programming Tips)
implementing callbacks ( in
Advanced Java: Idioms, Pitfalls, Styles, and Programming Tips by
Chris Laffra - PART I, Idioms and Programming Tips)
the cost of garbage collection ( in
Advanced Java: Idioms, Pitfalls, Styles, and Programming Tips by
Chris Laffra - PART I, Idioms and Programming Tips)
accessing methods of unconstructed objects
( in
Advanced Java: Idioms, Pitfalls, Styles, and Programming Tips by
Chris Laffra - PART I, Idioms and Programming Tips)
The Java convention appears to be that the open brace is to be put on the line following the owner of the
block and that the closing brace should be indented one level. The important thing, as pointed out by
Laffra ( in
Advanced Java: Idioms, Pitfalls, Styles, and Programming Tips by
Chris Laffra - PART I, Idioms and Programming Tips)
is that your organization choose an indentation style and stick to it. My (Scott W. Ambler) advice is to use the
same indentation style that your Java development environment uses for the code that it generates.
(in
2.4 TECHNIQUES FOR WRITING CLEAN CODE 2.4.2 Paragraph Your Code in AmbySoft Inc.
Java Coding Standards by
Scott W. Ambler, v. July 10, 1997, p. 10
)
The import statement allows the use of wildcards when indicating the names of classes. For example, the
statement
import java.awt.*;
brings in all of the classes in the package java.awt at once. Actually, that's not completely true. What
really happens is that every class that you use from the java.awt package will be brought into your code
when it is compiled, classes that you don't use won't be. Although this sounds like a good feature, it
reduces the readability of your code. A better approach is to fully qualify the name of the classes that your
code uses ( in
Advanced Java: Idioms, Pitfalls, Styles, and Programming Tips by
Chris Laffra - PART I, Idioms and Programming Tips)
(also in The NASA
Coding Standards for C, C++, and Java, Vision 2000). A better way to import classes is shown in the example below:
import java.awt.Color;
import java.awt.Button;
import java.awt.Container;
(in 7.2 IMPORTING CLASSES in AmbySoft Inc.
Java Coding Standards by
Scott W. Ambler, v. July 10, 1997, p. 32
)
One way to make your classes easier to understand is to declare them in a consistent manner. The
common approach in Java is to declare a class in the following order:
(NPS , 1996)
(see the NPS'
Navy Java Style Guide)
- public methods
- public attributes
- protected methods
- protected attributes
- private methods
- private attributes
Laffra ( in
Advanced Java: Idioms, Pitfalls, Styles, and Programming Tips by
Chris Laffra - PART I, Idioms and Programming Tips)
points out that constructors and finalize() should be listed first, presumably because these
are the first methods that another developer will look at first to understand how to use the class.
(quoted from 6.1 STANDARDS FOR CLASSES 6.1.3 Class Declarations in AmbySoft Inc.
Java Coding Standards by
Scott W. Ambler, v. July 10, 1997, p. 27
)