Application Development Using Java
Part Three - Challenge #05


The IBM Z hardware architecture is the best performing environment for Java.

These capabilities include

  • zIIP - dedicated processors for Java workload
  • SIMD - Single Instruction, Multiple Data
  • SIMT - Single Instruction, Multiple Threads
  • SMT - Simulatenous Multithreading
  • CPACF - CP Assist for Cryptographic Function

Java 8 exploits IBM Z new SIMD vector hardware instructions for the Java libraries and numerous frequently used functions. Benchmarks exploiting SIMD vector hardware instructions improved by between 2X and 60X.

In the z/OS environment, the unix shell, JCL, and middleware such as CICS is available to execute Java where Java APIs exist to read from and write to any combination of z/OS data sources.

Java can read and write any z/OS data source. The challenge explores the very powerful Java SQL API and its ability to select, insert and update relational database tables.

A Java driver (JDBC - Java Database Connectivity) enables relational database connectivity capability.

Java program execution requires a JVM, or Java Virtual Machine. The JVM enables java program execution on any operating system without a recompile. The executable java program used in the challenge could be binary transferred to your workstation. Successful workstation execution which returns the result set from the remote relational database to the workstation requires the JDBC driver in the workstation CLASSPATH. If you want to try it, db2jcc.jar, db2jcc_license_cisuz.jar, and favorite.class must be binary transferred to your workstation. The workstation path containing favorite.class and the jar files must be made accessible by the workstation JVM using the CLASSPATH variable. Also, Java must be installed on the workstation.

You are given Java language code to compile. The program connects to z/OS relational database table and processes a SQL statement to count the number of records in the DB2 relational database table.

If you participated in 2016 Master the Mainframe Part 3, you may remember the table used in the challenge. The table required each contestant to insert a record with their favorite color, month, and time of day, dusk or dawn.

Java language constructs:

  • // is a comment line
      comments are helpful
  • { } curly braces identifies a "section" of code with a limited scope
      { some_code }
      { statements }
      { content of a java class }
      { method bodies }
  • ( ) parentheses have 2 purposes:
      control order of operations in an expression
      supply parameters to a constructor or method
  • [ ] square brackets are used to index into an array


Completion of the challenge requires more virtual storage for the TSO session:

  • Re logon to TSO, =x, logon
    when prompted, enter your ID
  • Modify the Size value on TSO/E LOGON panel
      Size ===> 32786
      Size ===> 327686
Copy java source code from a partitioned data set to a unix file
  ** Be sure to replace z99999 below with your personal ID
  Jump to ISPF Command Shell panel =6 and enter:

oputx 'zos.mtm2017.public.source(favorite)' /z/z99999/ mode(700)

Start a z/OS Unix shell, enter:

From the z/OS Unix shell prompt enter:
The file should be listed

Edit unix file as follows:

Quickly review the Java source, then exit edit session

Compile as follows:

Compile of creates favorite.class, a JVM executable.
Invoke the JVM environment and execute favorite.class as follows:
java favorite
Note: You may need to press enter key a 2nd time for results to be written to display

The Java program displays the following:
Total number of records = 1061

Completion of the challenge is to modify to display each specific color total using a SQL statement operand
WHERE COLOR = 'the specific color'.

The display format with a total count for each color must be as follows:

Total number of records = 1061
Total number of red     = 
Total number of blue    = 
Total number of green   = 
Total number of purple  = 
Total number of orange  = 
Total number of yellow  =
Total number of white   =
Total number of black   = 


  • Observe java while loop statement following the SQL statement is returning each line from the SQL statement execution.
  • Execution of additional SQL SELECT statements can be accomplished by replicating a "section" of java code.
  • Variables rs1 and sql1 are used for SQL statement execution and storing the result set from table MTM2017.FAVORITE.
  • Use different variables, such as rs2 and sql2, to execute, store, and print additional result sets.
  • Include rs#.close() for each new SQL query before }catch(SQLExpection se),
  • Try getting result set for one color first, then the other colors.
Once the java program displays the requested report, then enter the following to execute the java program and redirect the output to a unix file with file name result:
java favorite > result

Copy the result unix file name to hlq.P3.OUTPUT(#05) as follows:
cp result "//p3.output(#05)"
exit, then enter to return to ISPF panels.

Review of hlq.P3.OUTPUT(#05) should contain the requested output.

Note: The output record format only needs 1 space between each word, the = symbol, and the total to get credit.

Next: Challenge #06

In the event an original copy of is needed to start over:

Copy java source code from a partitioned data set to a unix file
  ** Be sure to replace z99999 below with your personal ID
  Jump to ISPF Command Shell panel =6 and enter:

oputx 'zos.mtm2017.public.source(favorite)' /z/z99999/ mode(700)