The Standalone Java Program Template
The minimum standalone Java program template is as follows:
public class YourClassName
{
public static void main(String[] args)
{
// This is where the program starts.
}
}
You store the above in a text file named YourClassName.java
A. You supply the YourClassName.
B. Capitalization of the YourClassName must match the capitalization of the YourClassName part of the file name.
C. Everything else you type exactly (see "Line continuation and indenting formatting note" that follows) as you see it above.
Line continuation and indenting formatting note: Java is very flexible when it comes to line continuation and indenting. Consider the positioning of curly braces. Their placement is a matter of formatting style and does not effect the outcome of the program. For example the open curly brace may appear at the end of a line in examples you encounter. This is also true of all the words on the lines you see in the example. Each could be on a separate line. As well all the code could appear on the left margin. Following a format style will help you detect errors quicker, make code more readable and provide a better grade in the course.
Correct Example
// The HelloWorld.java file
public class HelloWorld
{
public static void main(String[] args)
{
// This is where the program starts.
}
}
// The Helloworld.java file
public class HelloWorld
{
public static void main(String[] args)
{
// This is where the program starts.
}
}
Correct Example
// The Tester.java file
public class Tester
{
public static void main(String[] args)
{
// This is where the program starts.
}
}
// The Tester.java file
public class HelloWorld
{
public static void main(String[] args)
{
// This is where the program starts.
}
}
// The HelloWorld.java file
public class HelloWorld
{
public static void Main(String[] args)
{
// This is where the program starts.
}
}
// The HelloWorld.java file
public class HelloWorld
{
public static void main(string[] args)
{
// This is where the program starts.
}
}
Correct Example With Exaggerated Poor Line Continuation and Indenting Formatting
// The Tester.java file
public
class Tester
{
public static
void main(String[]
args)
{
// This is where the program starts.
}
}
Correct Example With No Indenting Formatting
// The Tester.java file
public class Tester
{
public static void main(String[] args)
{
// This is where the program starts.
}
}