Compiling Hello World


Either use your IDE to compile Hello (if your IDE requires explicit compilation[3]) or compile it from the command line:

[3] Some IDEs require you to explicitly trigger a build. Other IDEs, such as Eclipse, automatically compile the necessary source files each time you save an edit change.

 javac Hello.java 

See the sidebar for more information about the javac command.

You should be in the directory where you saved Hello.java. If all went well, you will see no messages from the compiler. If you mistyped something, you will likely receive compilation errors. For example, you might see:

 Hello.java:4: ';' expected    }    ^ 1 error 

This specific error means that you forget to type the semicolon (;) at the end of the third line of text.

You might see multiple errors, depending on what you mistyped. Correct any errors and try to compile the file again. If you still have problems, make sure your code looks exactly as it appears above. Finally, see the section Still Stuck? at the end of this chapter.

A successful compilation of Hello.java will produce the file Hello.class. Execute a dir or ls command to produce a directory listing and ensure that Hello.class exists. Hello.class is the binary compiled version of the source codethe class file. Hello.class is what the Java VM will read and interpret in order to execute the code you typed in Hello.java.



Agile Java. Crafting Code with Test-Driven Development
Agile Javaв„ў: Crafting Code with Test-Driven Development
ISBN: 0131482394
EAN: 2147483647
Year: 2003
Pages: 391
Authors: Jeff Langr

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net