Comprehensive O-O Model Building and C++/Java Development and Training Available
The purpose of this tutorial is to present how-to use the With Class CASE tool to develop Java programs. With Class is a scripting CASE tool which permits the creation of object-oriented diagrams, text specifications, and code generation. To create Java applications, we will follow these steps:
1 - Create a class diagram in With Class.
2 - Generate Java code from the class diagram using a script, e.g. JAVBASIC.SCT.
3 - Open the generated Java code in a Java Editor, e.g. Dick Chase’s Java Editor
4 - Compile the generated code from the Java Editor using the Sun Java Development Kit
5 - Execute the Java code from the Java Development Kit (JDK) or an HTML Web page.
6 - After modifying the Java code in Java Editor, reverse engineer the code in With Class to create a reversed class diagram.
Creating Your First Java Program with a Java Editor and the Java Development Kit (JDK)
You can create a Java development environment by downloading Java tools from various Web sites. You can download the With Class CASE tool demo version from www.microgold.com. You may download a Java editor by searching for Java Editor. One Java Editor is Dick Chase’s Java Editor that can be downloaded from Compuserve in the file javaedit.zip. Another Java Editor is Java Maker by Hee Chang Choi at hcchoi@khgw.info.samsung.co.kr in the file javamake.zip. Another Java Editor is Symantec Café Lite that can be downloaded from www.symantec.com. You may download the Java Development Kit (JDK) from java.sun.com in the file jdk-1_0_.exe. When you execute the file jdk-1_0_.exe several directories, e.g. c:\java and c:\java\bin are created. You must update your autoexec.bat files with these entries:
SET PATH=C:\JAVA;C:\JAVA\BIN;C:\JAVA\INCLUDE;C:\JAVA\LIB
SET CLASSPATH=.;C:\JAVA\LIB
If you get “Cannot Open File” or “Cannot Find File” error messages, you may need to change the CLASSPATH statement so that the JDK can find your files, e.g. SET CLASSPATH=C:\JAVAPROG;C:\JAVA\LIB or SET CLASSPATH=C:\JAVA\LIB\Classes.zip. Do not unzip Classes.zip since the JDK directly uses this file. It is also necessary to have a Windows compression program like WinZip (wnzip.zip) that understands long file names and four character suffixes like program1.java. It is helpful to place DOSKEY in your autoexec.bat file since you may use the DOS command line to compile and execute java programs, e.g. java hello.
To create your first Java program, launch your Java Editor. Configure the editor to be able to find the Java Compiler, e.g. C:\Java\Bin\javac.exe. Enter the following code in the editor.
class Hello {
public static void main ( String args[] ) {
System.out.println ("Hello World");
}
}
Then select the File - Save Document to save the Java file, e.g. hello.java. To compile the file, select Run -Compile Document menu item or click on the Compile icon. In the Dick Chase Java Editor shown below, click the coffee cup icon in the upper toolbar to compile. To execute the program, select Run and enter c:\java\bin\java hello.

[IMAGE Java2.gif]
Once you have created the class diagram, double click on the class to bring up the Class Form shown below.
In the Class Form, click on the Spec Button to update the class specification shown below. The Counter class is a normal class. It is not an abstract or final class. It is not an interface. To indicate packages or classes to be imported select the Include Button to enter a package or class to be imported, e.g. java.util.*.
[IMAGE Java3.gif]
On the Class Form, double click on the attribute to bring up the Attribute Specification. Enter the Attribute Type, e.g. int, Attribute Visibility, e.g. private, and the Attribute Initial Value, e.g. 0.
[IMAGE Java4.gif]
Click on the Code button to bring up the Code Form shown below. Enter Java code for the Increment Operation, e.g. currentValue = currentValue + 1; Later, if you update this code in your Java Editor, you can import the updated code by selecting the Import Java button.
[IMAGE Java5.gif]
Once the class diagram and all specifications have been completed, you may generate Java code by selecting Utilities - Generate Code File per Class shown below. Select Java and the script javbasic.sct.
[IMAGE Java6.gif]
javbasic Script to Generate Java Code
SYSTEM_NAME
[import INCLUDE_FILE;]
CLASS_VISIBILITY CLASS_ABSTRACT CLASS_OR_INTERFACE CLASS_NAME [JAVA_BASE_CLASSES]
SKIP_NEXT_IF_BLANK$implements CLASS_LIBRARY_BASE_CLASS
{
[ATTRIBUTE_ACCESS ATTRIBUTE_FINAL ATTRIBUTE_STATIC ATTRIBUTE_TYPE ATTRIBUTE_NAME = ATTRIBUTE_INITIAL_VALUE; ]
[private ASSOCIATION_ONE_CLASS ASSOCIATION_ONE_NAME = null;]
[private AGGREGATION_ONE_CLASS AGGREGATION_ONE_NAME = new AGGREGATION_ONE_CLASS() ;]
[private Vector ASSOCIATION_MANY_NAME = new Vector();]
[private Vector AGGREGATION_MANY_NAME = new Vector();]
SELECT_WHEN_ONCE OPERATION_IS_ABSTRACT LOGICAL_OR OPERATION_IS_NATIVE
[OPERATION_ACCESS JAVA_OPERATION_ABSTRACT CPP_OPERATION_STATIC OPERATION_SYNCHRONIZED
OPERATION_NATIVE OPERATION_FINAL OPERATION_RETURN_TYPE OPERATION_NAME (CPP_OPERATION_PARAMETERS) ;]
SELECT_THE_REST
[OPERATION_ACCESS JAVA_OPERATION_ABSTRACT CPP_OPERATION_STATIC OPERATION_SYNCHRONIZED
OPERATION_NATIVE OPERATION_FINAL OPERATION_RETURN_TYPE
OPERATION_NAME (CPP_OPERATION_PARAMETERS) {OPERATION_CODE
}]
SELECT_RESET
}
The Counter.java code is shown below. Java code was generated for all classes on the diagram. The code file was opened and compiled in the Java Editor.
Generated Java Code for the Car Class Using javbasic.sct
public class Counter
{
private int currentValue = 0;
public void Increment () {
currentValue = currentValue + 1;
}
public void Decrement () {
}
public void GetValue () {
}
}
[IMAGE java7.gif]
The javall.sct script is shown below. This script generates the maximum amount of Java including constructor, exceptions, and accessor functions. To enter a package name, select Draw - System and enter the package name e.g. package Javacar; in the System Name box. This script implements the 1 to 1 association, e.g. Car to CellularPhone by creating variable currentCellularPhone and setting it to null. This script implements the 1 to 1 aggregation by creating a variable currentMotor and creating a object, e.g. Motor currentMotor = new Motor(). This script implements 1 to many associations and aggregations by creating an object of the Vector class. This script generates accessor methods (get and set) for all variables including variables implementing relationships.
javaall.sct Script to Generate Java Code for the Car Class
SYSTEM_NAME
[import INCLUDE_FILE;]
CLASS_VISIBILITY CLASS_ABSTRACT CLASS_OR_INTERFACE CLASS_NAME [JAVA_BASE_CLASSES]
SKIP_NEXT_IF_BLANK$implements CLASS_LIBRARY_BASE_CLASS
{
[ATTRIBUTE_ACCESS ATTRIBUTE_FINAL ATTRIBUTE_STATIC ATTRIBUTE_TYPE ATTRIBUTE_NAME = ATTRIBUTE_INITIAL_VALUE; ]
[private ASSOCIATION_ONE_CLASS ASSOCIATION_ONE_NAME = null;]
[private AGGREGATION_ONE_CLASS AGGREGATION_ONE_NAME = new AGGREGATION_ONE_CLASS() ;]
[private Vector ASSOCIATION_MANY_NAME = new Vector();]
[private Vector AGGREGATION_MANY_NAME = new Vector();]
public CLASS_NAME() { super();
}
//Constructor with arguments
//Update the argument list to initialize superclass data members
public CLASS_NAME ( SELECT_WHEN LOGICAL_NOT ATTRIBUTE_IS_STATIC LOGICAL_OR ATTRIBUTE_IS_FINAL
[NO_RETURN ATTRIBUTE_TYPE a$ATTRIBUTE_NAME,DELETE_LAST_SYMBOL] )
SELECT_WHEN LOGICAL_NOT ATTRIBUTE_IS_STATIC LOGICAL_OR ATTRIBUTE_IS_FINAL
{ super ();
[ ATTRIBUTE_NAME = a$ATTRIBUTE_NAME; ]
}
public CLASS_NAME get$CLASS_NAME() {
return this;
}
SELECT_WHEN_ONCE OPERATION_IS_ABSTRACT LOGICAL_OR OPERATION_IS_NATIVE
[OPERATION_ACCESS JAVA_OPERATION_ABSTRACT CPP_OPERATION_STATIC OPERATION_SYNCHRONIZED
OPERATION_NATIVE OPERATION_FINAL OPERATION_RETURN_TYPE
OPERATION_NAME (CPP_OPERATION_PARAMETERS)
OPERATION_EXCEPTION_TYPE;
] SELECT_THE_REST
[OPERATION_ACCESS JAVA_OPERATION_ABSTRACT CPP_OPERATION_STATIC OPERATION_SYNCHRONIZED
OPERATION_NATIVE OPERATION_FINAL OPERATION_RETURN_TYPE
OPERATION_NAME (CPP_OPERATION_PARAMETERS) OPERATION_EXCEPTION_TYPE
{ OPERATION_CODE
}] SELECT_RESET
[public final ASSOCIATION_ONE_CLASS get$ASSOCIATION_ONE_CLASS () {
return ASSOCIATION_ONE_NAME ;
}]
[public final AGGREGATION_ONE_CLASS get$AGGREGATION_ONE_CLASS () {
return AGGREGATION_ONE_NAME ;
}]
[public final Vector get$ASSOCIATION_MANY_CLASS () {
return ASSOCIATION_MANY_NAME ;
}]
[public final Vector get$AGGREGATION_MANY_CLASS () {
return AGGREGATION_MANY_NAME ;
}]
[public final void set$ASSOCIATION_ONE_CLASS (ASSOCIATION_ONE_CLASS a$ASSOCIATION_ONE_CLASS) {
ASSOCIATION_ONE_NAME = a$ASSOCIATION_ONE_CLASS ;
}]
[public final void set$AGGREGATION_ONE_CLASS (AGGREGATION_ONE_CLASS a$AGGREGATION_ONE_CLASS) {
AGGREGATION_ONE_NAME = a$AGGREGATION_ONE_CLASS ;
}]
[public final void add$ASSOCIATION_MANY_CLASS (ASSOCIATION_MANY_CLASS a$ASSOCIATION_MANY_CLASS)
throws Exception {
ASSOCIATION_MANY_NAME.addElement(a$ASSOCIATION_MANY_CLASS) ;
}]
[public final void add$AGGREGATION_MANY_CLASS (AGGREGATION_MANY_CLASS a$AGGREGATION_MANY_CLASS )
throws Exception {
AGGREGATION_MANY_NAME.addElement(a$AGGREGATION_MANY_CLASS) ;
}]
[public final void remove$ASSOCIATION_MANY_CLASS (ASSOCIATION_MANY_CLASS a$ASSOCIATION_MANY_CLASS)
throws Exception {
ASSOCIATION_MANY_NAME.removeElement(a$ASSOCIATION_MANY_CLASS) ;
}]
[public final void remove$AGGREGATION_MANY_CLASS (AGGREGATION_MANY_CLASS
a$AGGREGATION_MANY_CLASS ) throws Exception {
AGGREGATION_MANY_NAME.removeElement(a$AGGREGATION_MANY_CLASS) ;
}]
}
Generated Java Code for the Car Class using javall.sct
//package Javacar;
import java.util.*;
public class Car extends Vehicle
{
public int speed = 0;
private static int totalCarsBuilt = 0;
private final static int initialNumber = 1;
private CellularPhone currentCellularPhone = null;
private Motor currentMotor = new Motor() ;
private Vector currentPassengers = new Vector();
private Vector currentTires = new Vector();
public Car() { super(); }
//Constructor with arguments
//Update the argument list to initialize superclass data members
public Car ( int aspeed )
{ super ();
speed = aspeed;
}
public Car getCar() {
return this;
}
public void registerIt () {
}
protected void move () {
}
public void operate (int aSpeed) { //Operation Code
speed = aSpeed;
}
public void makePhoneCall () {
}
public void inflateTire () {
}
public void checkPassengerSeatBelt () {
}
public final CellularPhone getCellularPhone () {
return currentCellularPhone ;
}
public final Motor getMotor () {
return currentMotor ;
}
public final Vector getPassenger () {
return currentPassengers ;
}
public final Vector getTire () {
return currentTires ;
}
public final void setCellularPhone (CellularPhone aCellularPhone) {
currentCellularPhone = aCellularPhone ;
}
public final void setMotor (Motor aMotor) {
currentMotor = aMotor ;
}
public final void addPassenger (Passenger aPassenger) {
currentPassengers.addElement(aPassenger) ;
}
public final void addTire (Tire aTire ) {
currentTires.addElement(aTire) ;
}
public final void removePassenger (Passenger aPassenger) {
currentPassengers.removeElement(aPassenger) ;
}
public final void removeTire (Tire aTire ) {
currentTires.removeElement(aTire) ;
}
}
[IMAGE java8.gif]
Another example of a reversed class diagram from the Animator.java file provided with the JDK and the data dictionary are shown below.
Reversed Class Diagram for the Animator Java Program
[IMAGE java9.gif]
The following are the steps to reverse the Animator.java file distributed with the JDK and to create the data dictionary report.