Java Reference
In-Depth Information
Constant Naming Conventions
Constants are always written in all capital letters, with individual words separated by under-
scores. An example might be the constant DIRECTOR_LENGTH , which would be set to the
maximum size of the director's name stored in our database.
File Layout
A Java class or interface always consists of the following standard layout:
1. Beginning comments
2. Package and import statements
3. Class or interface declarations
The Sun Code Conventions state that two blank lines should appear between each of these
major sections. That is, there should be two blank lines between the beginning comments and
the package statement. Similarly, there should be two blank lines between the import state-
ments and the class or interface declarations. In all other cases where a blank line will help
readability (say, between method declarations), you would normally only have a single blank
line. A simple example is shown in the following code snippet:
1 /*
2 * HelloWorld.java version 1.0.0 date 2005-06-20
3 * Copyright © Andrew Monkhouse & Terry Camerlengo 2005
4 *
5 * This is a version of the hello world program
6 * The beginning comment, has two blank lines following it
7 */
8
9
10 package com.example.javaExamples;
11
12 import java.util.Date;
13
14
15 public class HelloWorld {
16 public static void main(String[] args) {
17 sayHello();
18 }
19
20 public static void sayHello() {
21 System.out.println("Hello, world at " + new Date() + "\n");
22 }
23 }
As shown here, there are two blank lines between each of the major sections: lines 8 and 9
separate the beginning comments from the package and import statements, and lines 13 and
Search WWH ::




Custom Search