Running a Java program, JavaDemo.java

  1. Make a directory for Java. mkdir Java
  2. Make a directory for each Java program (this keeps them organized)
    mkdir JavaDemo
  3. Create the file for JavaDemo.java (same name as the class)
    vi JavaDemo.java
  4. To compile the file: javac JavaDemo.java (this creates JavaDemo.class)
  5. To run the file: java JavaDemo (this runs the JavaDemo.class file)
  6. Make sure the text file "sampleFile.txt" is in the same directory