文档介绍:×÷Õߣºjeru
email: jeru@
ÈÕÆÚ£º8/9/2001 6:12:34 PM
Good Java Style: Part 2
By Thornton Rose
Introduction
This is the conclusion of a two-part series on Java coding style. In Good Java Style: Part 1
, I introduced my case for writing Java code using good habits, explained why we should care about the way our code looks, and illustrated some general elements of good Java style. In this part, I illustrate more elements of good style and bring my case to a conclusion.
Source Files
There are many ways that a Java source file can anized. Here is one that works well:
File ment (optional).
Package declaration.
Blank line or other separator.
Import statements.
Blank line or other separator.
Class(es).
Example 1. Bad anization.
.rotpad;
import .*;
import .*;
.javacogs.*;
import .*;
import .*;
class Foo {
...
}
public class RotPad extends JFrame {
...
}
Example 2. Good anization.
.rotpad;
// Java classes
import .*;
import .*;
import .*;
import .*;
// JavaCogs classes
.javacogs.*;
/**
RotPad is a simple GUI application for performing rotation ciphers on plain
text.
*
***@author Thornton Rose
***@version
*/
public class RotPad extends JFrame {
...
}
//-----------------------------------------------------------------------------
/**
Foo is ...
*