Page 802 - Introduction to Programming with Java: A Problem Solving Approach
P. 802

                768 Appendix 5 Java Coding-Style Conventions
Class Organization
1. Each of your classes may contain the following items (in the following order):
a) class prologue section b) import statements
c) constant class variables
d) non-constant class variables
e) instance variables f) abstract methods
g) constructors
h) instance methods
i) class methods
2. Normally you should place a main method and any of its helper methods in its own separate driver class. But it’s sometimes appropriate to include a short main method within the class it drives as an embedded testing tool. Put such a method at the end of the class definition.
Sample Java Program
 /*****************************************************************
*
Student.java
Dean & Dean
*
Apago PDF Enhancer
*
*
This class handles processing of a student's name.
*****************************************************************/
import java.util.Scanner;
public class Student
{
private String first = ""; // student's first name
private String last = ""; // student's last name
//**************************************************************
public Student()
{}
// This constructor verifies that each passed-in name starts
// with an uppercase letter and follows with lowercase letters.
public Student(String first, String last)
{
}
setFirst(first);
setLast(last);
Figure A5.1a
Student class, used to illustrate coding conventions—part A




























































   800   801   802   803   804