Guide to Object-oriented Programming With Java (University at Buffalo 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):
buffalo.edu.fa23.assignments.your-last-name;
or
buffalo.edu.fa23.exercises.your-last-name;
(depending on whether its an exercise or an assignment )
So, the first line of every .java
file should be:
package buffalo.edu.fa23.assignments.your-last-name
;
or
package buffalo.edu.fa23.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.
/**
* File: MyFirstApplication.java *
* 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.io.*;
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!.");
}
}
MyFirstApplication.java
Code
<terminated>
I've coded, compiled, and run my first Java program!