Agile Javaв„ў: Crafting Code with Test-Driven Development

To execute the Hello application from the command line, enter:

java Hello

Make sure that Hello is capitalized as shown.

If you entered the command correctly, you should see the output:

hello world

Problems Executing Hello

  • If you see:

    'java' is not recognized as an internal or external command, ...

    or

    java: Command not found.

    then you either have not installed Java or the Java bin directory is not part of your path statement. Refer to the section Checking Your Java Installation for some assistance.

  • If you see:

    [View full width]

    Exception in thread "main" java.lang.NoClassDefFoundError: hello (wrong name: Hello) ...

    then you entered the wrong case, for example:

    java hello

    Correct the command and try again.

  • If you see:

    [View full width]

    Exception in thread "main" java.lang.NoClassDefFoundError: Hello /class

    then you entered the .class portion of the name. Correct the command and try again.

Each time you compile the source file, the Java compiler will replace any associated class file that already exists.

Only where pertinent in this book (for example, when I discuss classpath) do I demonstrate use of the javac and java commands. I highly recommend that you familiarize yourself with command-line compilation and execution. The Java compiler and VM work virtually the same across all platforms. If you have difficulty compiling and executing code within your IDE, you will have to refer to the documentation for your IDE.

Категории