JAVA Tutorial


Java Program Development With Class

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.

Using With Class to Create a Class Diagram and Generate Java Code

To create your first Java program in With Class, launch With Class and set the Utilities - Preferences to Java. Create the class diagram, counter.omt. Select the class icon or Draw - Class. Place the class on the diagram. Enter the class name Counter. Enter the attribute currentValue. Enter the operation names Increment, Decrement, and GetValue. To generate Java code select Utilities - Generate Code per File. Select Java. If neceßsary, select Browse to find the script file javbasic.sct. To view the generated code counter.java, select File - Edit File and open counter.java. Then open the Java editor and open counter.java. Compile counter.java in the Java Editor to create counter.class. Then run the program from the Java Editor. Alternatively, run the program from the DOS command prompt with the command java counter.

[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 () {
}
}

Using With Class to Generate Java Code for All Major Java Features



To show you a more complex example, the following is the class diagram for a Car Transportation System. This diagram shows all major object-oriented relationships, e.g. inheritance, 1 to 1 association, 1 to 1 aggregation, 1 to many association, and 1 to many aggregation. This class diagram shows the Unified Method class diagram symbols: arrow - inheritance, line - association, diamond - aggregation, * - 1 to many, - private, + public, # protected, and $ static. The box enclosing the Vehicle class indicates an abstract class.

Class Diagram Showing All Major Relationships

[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) ;
}
}

Using With Class to Reverse Engineer Java Code

After you compile and update your generated Java code in your Java Editor, you may reverse engineer the code into a class diagram. Select Utilities - Preferences to select Java. Select Utilities - Reverse Directory. Select the Java files to be reversed. Select OK. With Class reads the Java files and creates the class diagram. You may reverse any Java code that successfully compiles. Below is the reversed class diagram from the Car Transportation System. This diagram shows the Unified Method graphic symbols. The trailing $, e.g. Car$, indicate an overloaded function name.

[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.

Summary Guidelines to Use With Class to Develop Java Applications

The following are some guidelines to create class diagrams and to generate Java code.
- Select Utilities - Preferences select Java as the language. Enter Java types if desired.
- Enter the package name in the System Name, e.g. package XYZPackage; Select Draw - System.
- Enter class information in the Class Specification, e.g. interface, final, and abstract.
- Enter attribute information in the Attribute Specification, e.g. constant, static, and final.
- Enter operation information in the Operation Specification, e.g. abstract, synchronized, final, and native
- To generate Java code, select a Java script, e.g. javbasic.sct or javall.sct. javbasic.sct may be used to generate code for interfaces.
- After changing the Java code, import the changed code from the Operation Specification - Code Form.
- To create a class diagram from existing Java code, select Utilities - Reverse Directory.
- Additionally, Java code may be generated from a state diagram with the script javstate.sct and a Java message table may be generated from an object interaction diagram with the script tabobj.sct.


Comments and suggestions on this tutorial and the Java code generation scripts are requested - Richard Felsinger RCF Associates, 960 Scottland Dr, Mt Pleasant, SC 29464 Telephone 803-881-3648 e-mail 71162.755@compuserve.com

buy cialis cialisfunsurforg cialisfunsurforg onlinehtml site cialis and back pain cialis levitra vs combine viagra and cialis allowed black buy casino cialis diet gambling health jack phentermine poker tag viagra xhtml canada over the counter cialis viagra cialis generic viagra cialis viagra levitra prices women take cialis drug buy cialis tadalafil cialis drinking alcohol cialis online usa levitra vs cialis vs viagra brand name cialis cheapest soft cialis cialis get viagra cialis viagra taking cialis with viagra buy cialis where cialis drugs cialis over dose lowest price generic cialis buy cialis generic ciales web site marketing cialis interaction precautions cialis western open add cialis link new buying generic cialis cialis free cialis suggest url valium detox buy cialis pharmacy cialis experience cialis pills online cialis buy cialis dream pharmaceutical cialis and oral sex cialis lawyer columbus compare viagra cialis levitra viagra cialis levitra buy cialis shop tadalafil cialis fast heart rate cialis online pharmacy online pharmacy cialis seychelles buy cialis ebay find tadalafil cheap cialis cialis injury attorney cincinnati cialis uk similar drugs for cialis buy cialis online submit=buy cialis online cialis dose it work cialis no prescription needed generic cialis muncie indiana buy cialis genericf hostingcom link cialis cheap no prescription cialis injury attorney cleveland cialis versus viagra 20mg cialis canada cialis deals cialis forum cialis free consultation cialis sample price viagra cialis levitra buy cialis link onlineinttc cialis class action lawsuit cialis levitra combine cialis and levitra viagra allowed black buy casino cialis diet gambling jack low online order phentermine poker tag viagra xhtml can cialis and viagra be taken together cialis free sample coupon cialis soft tab online consultation purchase cialis buy cialis online us cialis commercial cialis line differences viagra cialis levitra allowed black casino cialis diet gambling health jack phentermine poker tag viagra xhtml can i get cialis in canada cialis free samples cialis samples sale without prescription cialis in detroit area buy cialis cialis drug prescription cialis on second attempt generic viagra cialis levitra best cialis price canadian perscription of cialis cialis free trial cialis site suggest samples of viagra cialis levitra buy cialis now cialis cheap cialis injury lawyer ohio cialis viagra vs valium buying online buy discount cialis cialis effects side cialis online discount cialis soft allowed black buy casino cialis diet gambling jack online order phentermine poker tag viagra xhtml by cialis comment post posted cialis for sale on line cialis prescription las posas de ciales buy canada cialis cheap generic cialis cialis generic price cialis soft tab prescription cialis on line buy cialis online viagra cialis compare levitra cialis link online suggest discount generic cialis . buy tadalafil cialis cialis for sale cialis open western lowest cialis levitra prices buy cialis dosage effects online side warning cheap cialis generic cialis free sample cialis soft tab online consultation usa side effects of cialis buy cialis link suggest cialis attorney columbus cialis information pamphlet cialis stories viagra cialis generica buy cialis viagra cialis compared to viagra cialis new viagra dangers of taking cialis allowed cialis tag viagra xhtml canada cialis cialis for woman cialis overnight hypertension treatment using cialis buy cheap cialis canadian cialis cialis for women cialis price order cialis submit=order cialis buy cialis in the uk cheapest cialis generic cialis generic cialis sale review cialis levitra viagra buy cialis link onlinenew pharminfo cialis and liver disease cialis how to avoid backache cialis soft tabs penis pump plus cialis buy cialis online cialis comparison levitra viagra cialis icos lily online cialis tadalafil swflash 1.cab buy cialis online dreampharmaceuticals cialis co drug eli impotence lilly cialis julilatiwaveprohostingcom link onlinehtml cialis samples submit=cialis samples mixing cialis and viagra buy cialis without prescription cheap cialis submit=cheap cialis cialis female view cialis review lawsuits involving blindness caused by cialis buy cialis generic online canada cialis line cialis female opinion cialis online submit=cialis online generic cialis submit=generic cialis buy cialis link onlinenettc can you mix cialis and viagra cialis fda approval cialis online buy generic cialis 20 mg best price cialis buy viagra cialis levitra cialis erectile dysfunction cialis official website erection does not go down after taking cialis black casino cialis diet followup gambling health jack phentermine poker post viagra cialis 20mg cialis generic link suggest cialis woman sitemap2 add cialis link buy generic cialis cialis dosage cialis melt packs buy generic cialis online