S8333: Java User Experience: Confessions of and old COBOL Programmer
SHARE Technical Conference, February 23, 1999



An old COBOL programmer will share his experiences learning the Java language. Over the past year the speaker has programmed in Java using the Sun compiler, the Microsoft Visual Java++ integrated development environment, and VisualAge for Java from IBM. This session will include working Java applications that illustrate encapsulation, polymorphism, and inheritance in a way the author hopes will assist COBOL programmers to make that "aha" leap to a fuller understanding of object concepts.
The handout will include code examples including: programs to process Apache server logs, , a utility that dumps an input file (not a hex dump, but will print all ASCII characters), and a file editor that reads its edit commands from a file.
You are welcome to check the author's website, www.jsrsys.com, for a preview of his presentation as it is being developed, including code examples.


Steve Ryder, Senior Director
JSR Systems (SHARE Code: JSR)
2 Margranita Crescent
Austin, Texas 78703-1717

The speaker has been developing COBOL code since 1968. Other "languages" he has used include: Univac 1050 assembler, IBM 360 assembler, CDC Cyber assembler, AutoCoder, Algol, PL/I, Fortran, Pascal, C, C++, Java, and HTML!
Clients for whom the speaker has developed code include:

The University of Texas at Austin


Texas Education Agency


Houston Ind. School District


Conroe Ind. School District


United States Navy


Capitol Appraisal Group, Inc.





The development "environments" I tried included:
I began my adventure in Java by studying "Teach Yourself Java in 21 Days" by Laura Lemay. I highly recommend this book, and this approach. The particular book came with a CD-ROM version of Sun’s JDK 1.02, and all the examples were also on the CD-ROM. After working thru most of the examples in this book, I decided to get Microsoft Visual Java++. This IDE would be ideal if you are using Microsoft’s C++ IDE. The JsrDump utility actually began by using the applet wizard, however I found the code generated by the wizard to be overly complex, and eventually whittled most of it out of the program.
I installed the NetRexx to Java utility, hoping at I could code some simple NetRexx programs, then inspect the generated Java code. I quickly learned that the generated Java code was not meant to be read by humans, and that was the end of that adventure.
I downloaded the JDK 1.1 from javasoft mainly for the documentation. Since I have been writing code since 1964, I knew what I wanted to do, I just did not know the class names, properties, and methods.
I was quite impressed by the two day Visual Age for Java tutorial I took at SHARE a year ago. I purchased the software, and have worked thru about half the examples in their excellent and very slim "Getting Started" book. I had hoped to be farther along in time for this presentation. However, things have been very busy back at the ranch! Yes, there is lots of demand for old COBOL programmers, though I expect we will be doing most of our new development using the Visual Age for Java Enterprise edition next year. Of course Y2K updates could delay that estimate.
Here is my own "hybrid IDE" using Microsoft Visual Java++ components, with DOS command J*.BAT files, and the Programmer’s File Editor (PFE) freeware which I discovered thru PC World’s Tipworld.

jdoc.txt -- Document JSR Systems "IDE"
** j.bat follows:
rem j.bat -- change directory to java
rem jc.bat - compile java
rem jcr.bat compile and run java
rem je.bat - edit java with pfe
rem jj.bat - exec java class
cd \jsr\java
** jc.bat follows:

REM jc.bat parm2 = options -g full debug -O optimize -verbose
c:\jdk1.1.7B\bin\javac.exe %2 %1.java

** jcr.bat follows:

c:\jdk1.1.7B\bin\javac.exe %2 %1.java

Pause press any key to continue...
jview %1 %2 %3 %4 %5 %6 %7 %8 %9
** je.bat follows:
C:\pfe\pfe32.exe %1.java
** jj.bat follows:
C:\WINDOWS\jview %1 %2 %3 %4 %5 %6 %7 %8 %9
** dump.bat follows:
c:\windows\jview.exe JsrDump %1
** End of JSR Systems "IDE"


I have organized my directory structure so that I develop my Java code in the jsr/java directory. Completed source is placed in the jsr/java/source directory, and completed class files are placed in jsr/java/bin, which is included in my CLASSPATH list. I have found the default error messages to be sufficient to determine any errors, and have not really had to do much with the -debug options.
Now is the time to demonstrate some of my utilities. If you wish to run these on your own system at home, feel free to download the JsrClass.zip, and the JsrJava.zip files from my website, www.jsrsys.com/jsrsys/java. You are free to use these programs as long as you abide by the www.jsrsys.com/copyright conditions.
(invokes) JsrDump. Demonstrate use from command line, from the SendTo menu, and using file dialog.
with jsrSHARE.txt "command" file.
and LogSplit with access.bat and client.bat.


Coding Issues

Now you have seen some of the types of applications you can easily do in Java. Let's look at the code to answer the question, how can you do that?

30: static final int maxChar = 78;

31: static final int maxLine = 10;
32: static final String scaleLine =
33: ....+....1....+....2....+....3/5....+....6....+....7....+678";

211: DataInputStream inFileStream =

212: new DataInputStream
(new FileInputStream ( inputFile));
213: DataOutputStream outFileStream =
214: new DataOutputStream(new
215: DataInput inFile = inFileStream;
216: DataOutput outFile = outFileStream;
217: String line;
218: try { while ((line = inFile.readLine()) != null)
234: } catch (EOFException eEOF)

{System.out.println("EndOfFile!: "+ inputFile); }
235: catch ( IOException eIO )
{System.out.println("I/OError! "); }
236: inFileStream.close(); // free up resource prior to rename
237: outFileStream.close();
238: } catch (FileNotFoundException eFNF)
239: catch ( IOException eIO )
{System.out.println("I/O or Output! "); }


241: File inFD = new File(inputFile);

242: File bakFD = new File(bakFile);
243: File tempFD = new File(tempFile);
244: System.out.println("copy " +inputFile+ " to " +tempFile+ " rename to " +bakFile);
245: if (bakFD.exists() == true)
246:     System.out.println("delete " + bakFD+"=" + bakFD.delete());
247: System.out.println("rename "+inFD+ " to "+ bakFD+"=" + inFD.renameTo(bakFD));
248: System.out.println("rename "+tempFD+" to " +inFD+"=" + tempFD.renameTo(inFD));

21: { JsrList JsrListC = new JsrList();

65:           JsrListC.copyFile(listFiles[i], outFile, jsrTitle));

8: import JsrDebug;

9: import JsrSortString;
22:     JsrDebug debug = new JsrDebug();
23:     debug.Display("JsrList--"+copyright);

24: if (args.length < 2)

25: { debug.Display("JsrList--must contain two arguments:");
26:   debug.Display("---------arg 1: file suffix (i.e., java)");
27:   debug.Display("---------arg 2: target file for output.");
28:   return;
29: }

36: if (nLines > maxScreen)

37:    Accept(displayString);
38: else
39:    System.out.println(displayString);
Accept will pause if screen is full. If user enters "q", all further Display requests will be ignored.
120: Integer intCount = new Integer(htmCount[i]);

// convert integer to String
121: String strCount = intCount.toString();
122: while (strCount.length() < 10) strCount = " "+strCount;
// pad to 10 bytes
123:    countArray[i] = strCount +" accesses to: "+htmName[i];

51: linesin++;

52: lines100++;
53: if (lines100 == 100)
54: {
55:   lines100 = 0;
56:   System.out.print("Reading line: "+linesin+"\r");
57:   System.out.flush();
58: }

24:   String.padLeft(String.parmString, int.parmLen)
25:   {
26:      String.tempString = parmString;
27:      if (tempString.length() > parmLen)
28:         tempString = tempString.substring(tempString.length()- parmLen,
29:           tempString.length());
30:      else
31:      {
32:         while (tempString.length() < parmLen)
33:           tempString = " "+tempString;
34:      }
35:      return.tempString;
36:   }
38:   String.padLeft(int.parmInt, int.parmLen)
39:   {
40:      Integer.tempInt = new.Integer(parmInt);
41:      String tempString = tempInt.toString();
42:      return.padLeft(tempString, parmLen);
43:   }





Other Reminders

181: if (endFrom == '=')

171: if (to.equals("*delete*") && where != -1)
Note also that "&&" is logical AND, "||" is logical OR, "!" is NOT.

159: int lenFrom = from.length();

162: char endFrom = from.charAt(lenFrom-1);
167: where = oldString.indexOf(from);
178: newSB = newSB+oldString.substring(last,where)+to;

I hope these examples will help you to get started. I am quite high on Java, and expect that we all will be doing more Java and less COBOL (and no C++). IMHO, Java is what C++ wanted to be. Unfortunately C++ has become "bloatware", while Java has become truly modular and portable.


Return to JSR Systems Services.
Return to JSR Systems' home page.
Copyright © 1999, JSR Systems, All rights reserved.