119 lines
5.7 KiB
HTML
119 lines
5.7 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="reference" />
|
||
|
<meta name="DC.Title" content="Example: Using message queues (part 1 of 3)" />
|
||
|
<meta name="abstract" content="" />
|
||
|
<meta name="description" content="" />
|
||
|
<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="tutorl1" />
|
||
|
<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>Example: Using message queues (part 1 of 3)</title>
|
||
|
</head>
|
||
|
<body id="tutorl1"><a name="tutorl1"><!-- --></a>
|
||
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
|
<h1 class="topictitle1">Example: Using message queues (part 1 of 3)</h1>
|
||
|
<div><p></p>
|
||
|
<div class="section"><p>[ <a href="tutorl2.htm#tutorl2">Next part</a> ]</p>
|
||
|
<p>Use
|
||
|
the following as an example for your program.</p>
|
||
|
<div class="note"><span class="notetitle">Note:</span> Read the <a href="codedisclaimer.htm#codedisclaimer">Code
|
||
|
example disclaimer</a> for important legal information.</div>
|
||
|
<pre>//////////////////////////////////////////////////////////////////////////////////
|
||
|
//
|
||
|
// Example using the Message Queue function of the IBM Toolbox for Java
|
||
|
//
|
||
|
// This source is an example of IBM Toolbox for Java "Message Queue".
|
||
|
//
|
||
|
//////////////////////////////////////////////////////////////////////////////////
|
||
|
|
||
|
package examples; <a href="#tutorl1__dup0002">Note 1</a>
|
||
|
|
||
|
|
||
|
import java.io.*;
|
||
|
import java.util.*;
|
||
|
|
||
|
import com.ibm.as400.access.*; <a href="#tutorl1__dup0003">Note 2 </a>
|
||
|
|
||
|
public class displayMessages extends Object
|
||
|
{
|
||
|
|
||
|
public static void main(String[] parameters) <a href="#tutorl1__dup0004">Note 3 </a>
|
||
|
{
|
||
|
displayMessages me = new displayMessages();
|
||
|
me.Main(parameters); <a href="#tutorl1__dup0005">Note 4 </a>
|
||
|
|
||
|
System.exit(0); <a href="#tutorl1__dup0006">Note 5 </a>
|
||
|
}
|
||
|
|
||
|
|
||
|
void displayMessage()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
|
void Main(String[] parms)
|
||
|
{
|
||
|
try <a href="#tutorl1__six">Note 6 </a>
|
||
|
{
|
||
|
|
||
|
// IBM Toolbox for Java code goes here
|
||
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
|
e.printStackTrace(); <a href="#tutorl1__seven">Note 7 </a>
|
||
|
}
|
||
|
}
|
||
|
}</pre>
|
||
|
</div>
|
||
|
<div class="section"><ol><li id="tutorl1__dup0002"><a name="tutorl1__dup0002"><!-- --></a>This class is in the 'examples' package. Java™ uses
|
||
|
packages to avoid name conflicts between Java class files.</li>
|
||
|
<li id="tutorl1__dup0003"><a name="tutorl1__dup0003"><!-- --></a>This line makes all of the IBM<sup>®</sup> Toolbox for Java classes in the access package available
|
||
|
to this program. The classes in the access package have the common prefix <strong>com.ibm.as400</strong>.
|
||
|
By using an import statement, the program can refer to a class using just
|
||
|
its name, not its fully-qualified name. For example, you can reference the
|
||
|
AS400 class by using AS400, instead of com.ibm.as400.AS400.</li>
|
||
|
<li id="tutorl1__dup0004"><a name="tutorl1__dup0004"><!-- --></a>This class has a <strong>main</strong> method; therefore, it can be
|
||
|
run as an application. To invoke the program, you run <strong>java examples.displayMessages</strong>.
|
||
|
Note that case must match when running the program. Because an IBM Toolbox for Java class
|
||
|
is used, jt400.zip must be in the classpath environment variable.</li>
|
||
|
<li id="tutorl1__dup0005"><a name="tutorl1__dup0005"><!-- --></a>The main method mentioned in Note 3 is static. One of the
|
||
|
restrictions of static methods is that static methods can call only other
|
||
|
static methods in their class. To avoid this restriction, many java programs
|
||
|
create an object, and then do initialization processing in a method called <strong>Main</strong>.
|
||
|
The Main() method can call any other method in the displayMessages object.</li>
|
||
|
<li id="tutorl1__dup0006"><a name="tutorl1__dup0006"><!-- --></a>The IBM Toolbox for Java creates threads on behalf of the application
|
||
|
to carry out IBM Toolbox
|
||
|
for Java activity.
|
||
|
If the program does not issue <strong>System.exit(0)</strong> at termination time,
|
||
|
the program may not terminate normally. For example, suppose this program
|
||
|
was run from a Windows<sup>®</sup> 95 DOS prompt. Without this line, the command
|
||
|
prompt does not return when the program finished. The user has to enter Ctrl-C
|
||
|
to get a command prompt.</li>
|
||
|
<li id="tutorl1__six"><a name="tutorl1__six"><!-- --></a>The IBM Toolbox for Java code throws exceptions that your program
|
||
|
must catch.</li>
|
||
|
<li id="tutorl1__seven"><a name="tutorl1__seven"><!-- --></a>This program displays the text of the exception while the program
|
||
|
is performing error processing. Exceptions thrown by the IBM Toolbox for Java are
|
||
|
translated, so the text of the exception will be the same as the language
|
||
|
of the workstation.</li>
|
||
|
</ol>
|
||
|
<p>[ <a href="tutorl2.htm#tutorl2">Next part</a> ]</p>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
</body>
|
||
|
</html>
|