Creating, compiling, and running a HelloWorld Java program
Creating the simple Hello World Java™ program is a great place to start when becoming familiar with the IBM® Developer Kit for Java.
To create, compile, and run your own Hello World Java program, perform the following steps:
- Map a network drive to your system.
- Create a directory on your server for your Java applications.
- On the command line, type:
CRTDIR DIR('/mydir')
where mydir is the name of the directory you are creating.
Press the Enter key.
- On the command line, type:
- Create the source file as an American Standard Code for
Information Interchange (ASCII) text file in the integrated file system.
You can either use an integrated development environment (IDE) product
or a text-based editor such as Windows Notepad
to code your Java application.
- Name your text file
HelloWorld.java
. - Make sure that your file contains this source code:
class HelloWorld { public static void main (String args[]) { System.out.println("Hello World"); } }
- Name your text file
- Compile the source file.
- Enter the Start Qshell (STRQSH) command to start the Qshell Interpreter.
- Use the change directory (cd) command to change the
current directory to the integrated file system directory that contains
the
HelloWorld.java
file. - Enter
javac
followed by the name of the file as you have it saved on your disk. For example, enterjavac HelloWorld.java
.
- Set the file authorities on the class file in the integrated file system.
- Run the class file.
- Ensure that your Java classpath is set up correctly.
- On the Qshell command line, type
java
followed byHelloWorld
to run yourHelloWorld.class
with the Java virtual machine. For example, enterjava HelloWorld
. You can also use the Run Java (RUNJVA) command on your system to runHelloWorld.class
:RUNJVA CLASS(HelloWorld) "Hello World"
prints to your screen if everything was entered correctly. If running in the Qshell environment, the shell prompt (by default, a $) appears, indicating that the Qshell is ready for another command.- Press F3 (Exit) or F12 (Disconnect) to return to the command entry display.