129 lines
8.5 KiB
HTML
129 lines
8.5 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE html
|
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html lang="en-us" xml:lang="en-us">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<meta name="security" content="public" />
|
|
<meta name="Robots" content="index,follow" />
|
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
|
<meta name="DC.Type" content="task" />
|
|
<meta name="DC.Title" content="Create, compile, and run a HelloWorld Java program" />
|
|
<meta name="abstract" content="Creating the simple, Hello World Java program is a great place to start when becoming familiar with the IBM Developer Kit for Java." />
|
|
<meta name="description" content="Creating the simple, Hello World Java program is a great place to start when becoming familiar with the IBM Developer Kit for Java." />
|
|
<meta name="DC.Relation" scheme="URI" content="getstart.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="install.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="runfirst.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="dkmap.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="crtjdir.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="crtedit.htm" />
|
|
<meta name="copyright" content="(C) Copyright IBM Corporation 2006" />
|
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" />
|
|
<meta name="DC.Format" content="XHTML" />
|
|
<meta name="DC.Identifier" content="crtcmrun" />
|
|
<meta name="DC.Language" content="en-us" />
|
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
|
<!-- US Government Users Restricted Rights -->
|
|
<!-- Use, duplication or disclosure restricted by -->
|
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
|
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
|
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
|
<title>Create, compile, and run a HelloWorld Java program</title>
|
|
</head>
|
|
<body id="crtcmrun"><a name="crtcmrun"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">Create, compile, and run a HelloWorld Java program</h1>
|
|
<div><p>Creating the simple, Hello World Java™ program is a great place to start when
|
|
becoming familiar with the IBM<sup>®</sup> Developer Kit for Java.</p>
|
|
<div class="section"><p>To create, compile, and run your own Hello World Java program,
|
|
perform the following steps:</p>
|
|
</div>
|
|
<ol><li><span><a href="dkmap.htm">Map a network drive to your iSeries™ server</a>.</span></li>
|
|
<li><span><a href="crtjdir.htm">Create a directory on your iSeries server</a> for
|
|
your Java applications.</span></li>
|
|
<li><span>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<sup>®</sup> Notepad to code your Java application.</span><ol type="a"><li class="substepexpand"><span>Name your text file <samp class="codeph">HelloWorld.java</samp>. For more
|
|
information about how you can create and edit your file, see <a href="crtedit.htm">Create
|
|
and edit Java source files</a>.</span></li>
|
|
<li class="substepexpand"><span>Make sure that your file contains this source code: </span> <pre> class HelloWorld {
|
|
public static void main (String args[]) {
|
|
System.out.println("Hello World");
|
|
}
|
|
}</pre>
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
<li><span>Compile the source file.</span><ol type="a"><li><span>Enter the Work with Environment Variable (WRKENVVAR) command
|
|
to check the CLASSPATH environment variable. If the CLASSPATH variable does
|
|
not exist, add it and set it to '.' (the current directory). If the CLASSPATH
|
|
variable does exist, make sure that the '.' is at the beginning of the path
|
|
name list. For details about the CLASSPATH environment variable, see <a href="classpth.htm">Java classpath</a>.</span></li>
|
|
<li><span>Enter the Start Qshell (STRQSH) command to start the Qshell
|
|
Interpreter.</span></li>
|
|
<li><span>Use the change directory (cd) command to change the current
|
|
directory to the integrated file system directory that contains the <samp class="codeph">HelloWorld.java</samp> file.</span></li>
|
|
<li><span>Enter <samp class="codeph">javac</samp> followed by the name of the file
|
|
as you have it saved on your disk. For example, enter <samp class="codeph">javac HelloWorld.java</samp>.</span></li>
|
|
</ol>
|
|
</li>
|
|
<li><span>Set the <a href="fileauth.htm">file authorities on the class
|
|
file in the integrated file system</a>.</span></li>
|
|
<li><span>Optimize the Java application.</span><ol type="a"><li class="substepexpand"><span>On the <em>QSH Command Entry</em> line, type: </span> <pre> system "CRTJVAPGM '/<em>mydir</em>/<em>myclass</em>.class' OPTIMIZE(20)"</pre>
|
|
where <em>mydir</em> is the path name of the directory in which your Java application
|
|
is saved, and where <em>myclass</em> is the name of your compiled Java application.
|
|
<p><strong>Note:</strong> You can specify an optimization level of up to 40.
|
|
An optimization level of 40 increases the efficiency of the Java application,
|
|
but it also limits debug capabilities. In the early stages of developing a Java application,
|
|
you may want to set your optimization level at 20 so you can more easily debug
|
|
your application. See the <a href="../cl/crtjvapgm.htm" target="_blank">CRTJVAPGM</a> command and the OPTIMIZE parameter for more
|
|
information.</p>
|
|
</li>
|
|
<li class="substepexpand"><span>Press the <strong>Enter</strong> key.</span> <p>A message appears,
|
|
stating that a Java program has been created for your class.</p>
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
<li><span>Run the class file.</span><ol type="a"><li><span>Ensure that your <a href="classpth.htm">Java classpath</a> is
|
|
set up correctly.</span></li>
|
|
<li><span>On the Qshell command line, type <samp class="codeph">java</samp> followed
|
|
by <samp class="codeph">HelloWorld</samp> to run your <samp class="codeph">HelloWorld.class</samp> with
|
|
the Java virtual
|
|
machine. For example, enter <samp class="codeph">java HelloWorld</samp>. You can also
|
|
use the <a href="../cl/runjva.htm" target="_blank">Run Java (RUNJVA)
|
|
command</a> on your iSeries server to run <samp class="codeph">HelloWorld.class</samp>.</span></li>
|
|
<li><span><samp class="codeph">"Hello World"</samp> prints to your screen if everything
|
|
was entered correctly. The shell prompt (by default, a $) appears, indicating
|
|
that the Qshell is ready for another command. </span></li>
|
|
<li><span>Press F3 (Exit) or F12 (Disconnect) to return to the command
|
|
entry display.</span></li>
|
|
</ol>
|
|
</li>
|
|
</ol>
|
|
<div class="section"><p>You can also easily compile, optimize, and run your Java application
|
|
using iSeries Navigator,
|
|
a graphical user interface for performing tasks on your iSeries server.
|
|
For instructions, see <a href="opsnav.htm#opsnav">iSeries Navigator commands that are supported by Java</a>. For more information
|
|
on iSeries Navigator,
|
|
including installation information, see <a href="../rzaj2/rzaj2overview.htm" target="_blank">Getting to know iSeries Navigator</a>.</p>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="getstart.htm" title="If you have not yet used IBM Developer Kit for Java, follow these steps to install it, configure it, and practice running a simple Hello World Java program.">Install and configure IBM Developer Kit for Java</a></div>
|
|
</div>
|
|
<div class="relconcepts"><strong>Related concepts</strong><br />
|
|
<div><a href="crtjdir.htm" title="You must create a directory on your iSeries server where you can save your Java applications.">Create a directory on your iSeries server</a></div>
|
|
</div>
|
|
<div class="reltasks"><strong>Related tasks</strong><br />
|
|
<div><a href="install.htm" title="Installing IBM Developer Kit for Java allows you to create and run Java programs on your iSeries server.">Install IBM Developer Kit for Java</a></div>
|
|
<div><a href="runfirst.htm" title="This topic will help you to run your first program.">Run your first Hello World Java program</a></div>
|
|
<div><a href="dkmap.htm" title="To map a network drive, complete the following steps.">Map a network drive to your iSeries server</a></div>
|
|
</div>
|
|
<div class="relref"><strong>Related reference</strong><br />
|
|
<div><a href="crtedit.htm" title="You can create and edit Java source files in a number of ways.">Create and edit Java source files</a></div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html> |