IntroCS Chapter 1.1 Introduction

San Skulrattanakulchai

September 19, 2016

Topics

Program Development

Here are the classic steps to develop a Java program:

  1. Use a text editor to edit a source file SOURCEFILE.java

  2. Compile the source file by typing

    javac SOURCEFILE.java

    This produces a class file SOURCEFILE.class. If there are errors during compilation, then go back to the previous step.

  3. Run the class file by typing

    java SOURCEFILE

    If there are errors during interpretation like not getting the expected output, then go back to the previous step.

Terms

Anatomy of a Java source file

/* Prints "Hello, World". */

public class HelloWorld {
    // This is line comment
    public static void main(String[] args) {
        System.out.println("Hello, World");
    }
}

Comandline Arguments

This program shows how to process commandline arguments.

/*************************************************************************
 *  Prints "Hi, Bob. How are you?" where "Bob" is replaced by the
 *  command-line argument.
 *************************************************************************/

public class UseArgument {
    public static void main(String[] args) {
        System.out.print("Hi, ");
        System.out.print(args[0]);
        System.out.println(". How are you?");
    }
}

Program Errors (Bugs)

is called a program error (or bug).

Error Examples

Input & Output