More Java using JZOS Toolkit
Part Three - Challenge #07


A weird problem exists resulting from previous challenge Java program execution

Below is a repeat of what you read in challenge 6. However, it is worth reading a second time. Even an experienced Java programmer would have a very difficult time completing the challenge because the syntax is compiler acceptable and the logic 'appears' to be perfect. You will learn appearances can sometime be misleading.

  • Enter oedit
      Your Unix subdirectory with file names is displayed
  • Edit e to the left of to view the Java source code
  • Line 1 imports the IBM JZOS Toolkit
  • Line 7 shows the data to be read is from JCL DDNAME //RECIN
  • Line 10 declares variable nRead as an integer
     nRead declared variable is significant in resolving syntax error during compile
  • Line 12 reads a text line into string variable rec
  • Line 13 replaces Who said this   with Albert Einstein
  • Line 13 variable newRec has the modified text
  • Line 14 writes the content of newRec
  • Line 15 results in reading the next text line

Challenge Situation

The Java program reads text, parses the text looking for text string 'Who said this ', then replaces it with text string 'Albert Einstein'. However, the Java execution did not replace the string. 'Who said this '.

View of member #06 in P3.OUTPUT will show the string replacement did not occur.

You will find the issue is not the program logic but involves the specific string of data being replaced.

Remember what you learned about hexadecimal values. You will need it.

Challenge Description

You will be guided to why the Java program did not replace the sting. You will need to make a modification to the Java source code to correct the problem. You will compile and execute the Java program using JCL to prove the old string was replaced by the new string,


Use Java program to replace old string of text with a new string of text
  • Enter oedit
      Your Unix subdirectory with file names is displayed
  • Edit e to the left of to view the Java source code
  • Enter hex on
  • Very carefully look at the hex values associated with the old string "Who said this "
  • From ISPF Command Shell panel =6, enter obrowse '/z/public'
  • View v file quote
  • Enter hex on and carefully look at hex values associated with the second line
  • The java program is reading '/z/public/quote'

Carefully reviewing old string hex values is the key to solving the problem

You do not need to be Java programmer or a programmer to identify the problem.

Hint - Make the string in the Java program match the string in '/z/public/quote'

Get new copy of JCL to compile and execute modified Java source code
  • dslist jcl
  • Select s new member name zjava
  • copy 'zos.public.jcl(zjava)'
  • change //STDOUT to write output to member #07 in p3.output

Last task to get full credit

NOTE: Remember copy and paste is available to help eliminate typing mistakes.

  • dslist p3.output
  • edit e member name #07
  • copy '/z/z#####/' after the last line in member #07
      Substitute your ID for z##### on the above copy command
  • Press F3 or enter end;return

What did you just learn?

Programs process data. Problems can exist as a result of making assumptions about the data.

Next: Challenge #08