Concurrent Programming with Java
Lab Manual, Version 1.0, F. Astha Ekadiyanto,
2002.
Lab 1: Introduction to Lab. Environment and Object Orientation
Hello World is probably the most popular program ever made by programmers (especially Java programmers since it has been used in many Java learning/tutorial literature).
To write this simple program, you need:
The JavaTM 2 Platform, Standard Edition.
You can download the SDK from http://java.sun.com and consult the installation instructions.
You can check your java installation by using a command prompt and run the java.exe (in Win32 systems).C:\Program Files\jdk1.3\bin> java -version java version "1.3.1-04 " Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-04) Java HotSpot(TM) Client VM (build 1.3.1-04, mixed mode)In order to compile your programs you will need at least the java compiler javac.exe (in Win32 system) listed in PATH and the API class libraries indicated by the environment variable CLASS_PATH (or the option -classpath when running the compiler).
SET JAVA_HOME="C:\Program Files\jdk1.3" SET PATH=%JAVA_HOME%\bin;%PATH% SET CLASS_PATH=.;%JAVAHOME%\lib\tools.jar;%JAVAHOME%\jre\classesA text editor.
In this example, we'll use NotePad, the simple editor included with the Windows platforms. To find NotePad, from the Start menu select Programs Accessories NotePad. You can easily adapt these instructions if you use a different text editor. Optionally, there are bunch of IDE (Integrated Development Tool) to help you write your programs, but some books recommend not to use them unless you know "a little bit" about Java Programming.
Your first program (probably), HelloWorldApp, will simply display the greeting "Hello world!". To create this program, you will: Create a source file. A source file contains text, written in the Java programming language, that you and other programmers can understand. You can use any text editor to create and edit source files named HelloWorldApp.java
/** * The HelloWorldApp class implements an application that * displays "Hello World!" to the standard output. */ public class HelloWorldApp { public static void main(String[] args) { // Display "Hello World!" System.out.println("Hello World!"); } }
Compile the source file into a bytecode file. The compiler, javac, takes your source file and translates its text into instructions that the Java Virtual Machine (Java VM) can understand. The compiler converts these instructions into a bytecode file.
C:\userfile>javac HelloWorldApp.java C:\userfile>dir Directory of C:\userfile 11.11.2002 11:22 432 HelloWorldApp.class 11.11.2002 11:22 287 HelloWorldApp.java 2 File(s) 719 bytes
Run the program contained in the bytecode file. The Java interpreter
installed on your computer implements the Java VM. This interpreter takes your
bytecode file and carries out the instructions by translating them into instructions
that your computer can understand.
C:\userfile>java HelloWorldApp Hello World!