Click this widget to change the font size.
Click this widget to change contrast.
Skip to content

Home Page 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | Links | Search | Bio | Faculty

Guide to Object-oriented Programming With Java (Buffalo State College Version)

Chapter 3: Naming Packages and Classes

Naming Conventions

A Java package is a "container" for your Java classes. Your packages should be named as follows (your-last-name should be all lowercase with no space or apostrophes):


(depending on whether its an exercise or an assignment ;-))

So, the first line of every .java file should be:

package edu.buffalostate.cis425.fa10.exercises.assignments.your-last-name;
package edu.buffalostate.cis425.fa10.exercises.exercises.your-last-name;

Each Java program can contain only one (1) class method. The name of the class must begin with an Uppercase letter. The name of your .java file should be the same as the name of your class. For example, the file HelloWorld would have a public class HelloWorld { } statement.

A Sample java Program

Every Java program should start with the package line. Next you would have any import statements, the class line, any class variables, then class methods, and finally the main() method.

package edu.buffalostate.cis425.fa10.exercises.assignments.your-last-name;

 * File:
 * This is a sample Java Application
 * It prints a short statement to the standard out
 * @author Your Name Here

import java.util.Scanner;
import java.text.DecimalFormat;

public class MyFirstApplication {
  * The main() is the entry point for a Java program when executed
  * public means it is publicly accessible (required)
  * static means there is no object defined yet at start of program
  * void means it does not return anything
  * @param string array - command line arguments passed to program
  * @return none

  public static void main(String[] args) {
  // print to the console
    System.out.println("I've coded, compiled, and run my first Java program!.");

Figure 3-1: Sample Code
I've coded, compiled, and run my first Java program!

Figure 3-2: Sample Java Program Output