public class SimpleProgs
1: // Most of our programs will start with the line below:
2: import java.util.Scanner;
4: // Next comes the "javadoc" comments -- the comments explaining the class.
5: // They start with a "/**" and end with a "*/".
6: // Every line starts with a " *".
7: // The javadoc includes a short description of the class.
8: // It also includes an "author tag" to identify the author.
10: /**
11: * An application that's just here for you to look at the comments.
12: *
13: * @author Mark Young (A00000000)
14: */
16: // Our programs will have one "class" defined -- the name of the class being
17: // the same as the name of the file (except the file has ".java" added).
18: public class SimpleProgs {
20: // At this point we are inside the class definition.
21: // Everything is indented four spaces.
22: // What usually appears in the class definition are constants and methods.
24: // First thing inside the class definition are the constants.
25: // Each one starts with the words "public static final"
26: public static final int ANSWER = 42;
27: public static final double PI = 3.14159;
28: public static final String GREETING = "Hello, World!";
30: // Our simplest programs will have only one method -- the main method.
31: // The main method always starts like this:
32: public static void main(String[] args) {
33: // At this point we are inside the method definition.
34: // Everything is indented /another/ four spaces (eight in total).
35: // What usually appears inside the method definition are commands:
36: System.out.println();
37: System.out.println("Simple Programs Program");
38: System.out.println("-----------------------");
39: System.out.println();
40: System.out.println("This program doesn't do much -- look at the code");
41: System.out.println("to see the comments about it!");
42: System.out.println();
43: System.out.println("By the way, I created three constants:");
44: System.out.println(" ANSWER (" + ANSWER + ")");
45: System.out.println(" PI (" + PI + ")");
46: System.out.println(" GREETING (" + GREETING + ")");
47: System.out.println();
49: // Now we come to the end of the method -- the closing brace.
50: // It is indented four spaces (not eight spaces) because it's not
51: // /inside/ the method definition.
52: }
54: // And now we come to the end of the class definition -- the closing brace.
55: // It is not indented at all, because it's not /inside/ the class
56: // definition.
57: }
59: // And now we are outside the class definition.
60: // Normally, nothing will appear here.
61: // If you put anything here (other than comments, like this one),
62: // the compiler will usually complain about it!