You use the classes from the JCICS library like normal Java classes. Your applications declare a reference of the required type and a new instance of a class is created using the new operator.
Do not use finalizers in CICS Java programs. For an explanation of why finalizers are not recommended, see the Java Diagnostics Guide.
Do not end CICS Java programs by issuing a System.exit() call. When Java applications run in CICS, the public static void main() method is called through the use of another Java program called the Java wrapper. When you use the wrapper CICS initializes the environment for Java applications and, more importantly, cleans up any processes that are used during the life of the application. Terminating the JVM, even with a clean return code of 0, prevents this cleanup process from running, and might lead to data inconsistency. Using System.exit() when the application is running in a JVM server terminates the JVM server and quiesces CICS immediately.
// Define a package name for the program package unit_test; // Import the JCICS package import com.ibm.cics.server.*; // Declare a class for a CICS application public class JCICSTSQ { // The main method is called when the application runs public static void main(CommAreaHolder cah) { try { // Create and name a Temporary Storage queue object TSQ tsq = new TSQ(); tsq.setName("JCICSTSQ"); // Delete the queue if it exists try { tsq.delete(); } catch(InvalidQueueIdException e) { // Absorb QIDERR System.out.println("QIDERR ignored!"); } // Write an item to the queue String transaction = Task.getTask().getTransactionName(); String message = "Transaction name is - " + transaction; tsq.writeItem(message.getBytes()); } catch(Throwable t) { System.out.println("Unexpected Throwable: " + t.toString()); } // Return from the application return; } }