Contents

  1. ./First.java
  2. ./Hello.java
  3. ./HelloPreview.java

./First.java 1/3

[
top][prev][next]
/**
 * This class demonstrates some basic Java syntax.
 * Note that this code is "overcommented".  I am trying to explain
 * the code to you.  You should not need this many comments in your code.
 * However, if the comments are helpful to you, you can continue with them.
 *
 * All code in a Java program must belong to a class.
 * There is typically one class per file, and the file name is ClassName.java
 * Compile this code using
 *     javac First.java
 * Run the compiled bytecode First.class using
 *     java First
 *
 * @author Sara Sprenkle
 */
public class First {  // File must be saved as First.java
  
   /**
    * Called when user runs 
    *  java First
    */
   public static void main(String[] args) { // Blocks start/end with {}
       System.out.println("This is my first Java program!"); // Statements end with ;
   }
}

./Hello.java 2/3

[
top][prev][next]
/**
 * Our first Java class
 *
 * All code in a Java program must belong to a class.
 * There is typically one class per file, and the file name is ClassName.java
 * Compile this code using
 *     javac Hello.java
 * Run the compiled bytecode Hello.class using
 *     java Hello
 * 
 * @author Sara Sprenkle
 */
public class Hello {  //File must be saved as Hello.java
  
   /**
    * Called when user runs 
    *  java Hello
    */
   public static void main(String[] args) { // Blocks start/end with {}
       System.out.print("Hello, World!"); // Statements end with ;
       System.out.println("More stuff!"); // Statements end with ;
   }
}

./HelloPreview.java 3/3

[
top][prev][next]
/**
 * Demonstrates new feature _previewed_ in Java 21
 * Need to compile and run using 
 *      javac --source 21 --enable-preview HelloPreview.java
 *      java --source 21 --enable-preview HelloPreview.java

 *
 * @author Sara Sprenkle
 */
public class HelloPreview {

    public void main() {
        System.out.println("Hello!");
    }
    
}

Generated by GNU Enscript 1.6.5.90.