Problem Solving and Computing (CSC-103 98S)

[Instructions] [Search] [Current] [Changes] [Syllabus] [Handouts] [Outlines] [Journal] [Problems] [Computing] [SamR Docs] [Tutorial] [API]

Java Style Guide

This document is still under development.

Programming, like writing, provides you some freedom to express the same concept in many different ways. Just as each writer develops his or her own personal style, so do programmers. Important aspects of programming style include

I expect you to follow some basic stylistic conventions in my class. While you will eventually develop your own style, few of you are experienced enough programs to make sufficiently informed decisions. In addition, a uniform style helps us discuss and share code. I will strive to use the same style, but may violate it ocassionally. If you use emacs as your editor, it will automatically enforce some of these rules.


A typical program requires a significant amount of naming of variables, fields, functions, and classes. Strive for informative and distinguishable names. You should rarely use single-letter names (except, possibly, for loop counters). At the same time, you need not go overboard on the length of your names. For most purposes, five to ten characters suffice.

Sun (the developers of Java) recommends a particular capitalization style to help you distinguish the different things that you can name.


Java is whitespace-insensitive (at least in most cases). You can put as few or as many spaces, tabs, and carriage returns as you want in your programs. Hence, you should use whitespace to make your programs more readable, modifiable, and debugable.




// Step through the list of people, printing out all the students.
for (int i = 0; i < REPETITIONS; ++i)
  // If person i is a student then
  if (people[i].getRole().equals("student"))
    // Print out the name of person i
    System.out.println(people[i].getName() + " is a student");
  } // if
} // for

[Instructions] [Search] [Current] [Changes] [Syllabus] [Handouts] [Outlines] [Journal] [Problems] [Computing] [SamR Docs] [Tutorial] [API]

Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.

Source text last modified Fri Jan 16 08:37:24 1998.

This page generated on Thu Apr 2 13:50:18 1998 by SiteWeaver.

Contact our webmaster at