[Next Example | Main Tutorial Page]
Message queue: Example 1 of 3
Use the following as an example for your program.
//////////////////////////////////////////////////////////////////////////////////
//
// Example using the Message Queue function of the AS/400 Toolbox for Java
//
//////////////////////////////////////////////////////////////////////////////////
//
// This source is an example of AS/400 Toolbox for Java "Message Queue".
// IBM grants you a nonexclusive license to use this as an example
// from which you can generate similar function tailored to
// your own specific needs.
//
// This sample code is provided by IBM for illustrative purposes
// only. These examples have not been thoroughly tested under all
// conditions. IBM, therefore, cannot guarantee or imply
// reliability, serviceability, or function of these programs.
//
// All programs contained herein are provided to you "AS IS"
// without any warranties of any kind. The implied warranties of
// merchantability and fitness for a particular purpose are
// expressly disclaimed.
//
// AS/400 Toolbox for Java
// (C) Copyright IBM Corp. 1999
// All rights reserved.
// US Government Users Restricted Rights -
// Use, duplication, or disclosure restricted
// by GSA ADP Schedule Contract with IBM Corp.
//
//////////////////////////////////////////////////////////////////////////////////
package examples; 1
import java.io.*;
import java.util.*;
import com.ibm.as400.access.*; 2
public class displayMessages extends Object
{
public static void main(String[] parameters) 3
{
displayMessages me = new displayMessages();
me.Main(parameters); 4
System.exit(0); 5
}
void displayMessage()
{
}
void Main(String[] parms)
{
try 6
{
// Toolbox code goes here
}
catch (Exception e)
{
e.printStackTrace(); 7
}
}
}
- This class is in the 'examples' packages. Java uses packages to avoid name conflicts
between Java class files.
- This line makes all of the AS/400 Toolbox for Java classes in the access package
available to this program. The classes in the access package
have the common prefix com.ibm.as400. 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.
- This class has a main method; therefore, it can be run as an application.
To invoke the program, you run java examples.displayMessages. Note that case
must match when running the program. Because an AS/400 Toolbox for Java class is used,
jt400.zip must be in the classpath environment variable.
-
The main method (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 Main. The Main()
method can call any other method in the displayMessages object.
-
The AS/400 Toolbox for Java creates threads on behalf of the application to carry out AS/400
Toolbox for Java activity. If the program does not issue System.exit(0)
at termination time, the program may not terminate normally. For example,
suppose this program was run from a Windows 95 DOS prompt. Without this
line, the command prompt would not return when the program finished. The
user would have to enter Ctrl-C to get a command prompt.
-
The AS/400 Toolbox for Java code throws exceptions that your program must catch.
-
This program displays the text of the exception while the program is performing error
processing. Exceptions thrown by the AS/400 Toolbox for Java are translated, so the text
of the exception will be the same as the language of the workstation.