Skip to main content

Course Package 1

Hello.java

 /* File: Hello.java
 
    This is a simple sample standalone text-based Java application.
    Output is generated to StdOut (Standard Out), which in this case is the user's console.
 
    In a Java application, execution begins with the main() method (defined below).
 
    If you're working from the command line (such as on mislab)
    compile and execute this program with the commands:
 
      javac Hello.java                   (creates Hello.class)
      java  Hello                        (runs the JVM to execute byte code)
 
    (Note: The file names in these commands are case-sensitive.)
 
    javac.exe is the Java compiler. javac translates source code (stored in
    a .java file) into platform-independent byte code (stored in a .class
    file). Byte code is interpreted and executed by a JVM (Java Virtual Machine).
 
    java.exe is a JVM. Some consumer electronics are hardware JVM's (their electronics can
    actually interpret and execute Java byte code). A JVM is platform-dependent.
    That is, you must have a JVM that runs in your environment.
 
    The main method must be defined as it is in the example below. The only
    thing that you can change is the name of the parameter (args).
 
    The main method receives an Array of String objects.
 
     Some elements of programming style which are demonstrated here:
    1. the class name begins with an upper-case letter
    2. corresponding curly braces are aligned
    3. statements within a body of code are indented
    4. blank lines are used to enhance readability
    5. comments are used to enhance readability and understandability
 
 */
 




 public class Hello                              // Hello class header
 {                                               // the body of the class is enclosed in curly braces,
                                                 // which are aligned to enhance readability
 
   public static void main(String[] args)        // main() method header; execution begins here
   {                                             // the body of the method is enclosed in curly braces
 
     System.out.println("Hello world");          // call the println method to generate output
                                                 // to StdOut
   }
 
 }
 // You should type this program, compile it, and execute it to test your Java environment.