Step 3: Generating Java Source Code from the Class Model

Previous topic
Previous
Next topic
Next

This task takes you through the steps required to generate Java source code from the class model you have created. Once you have generated the Java source code you will update the code and observe the effect this has on the diagram. This shows how JDeveloper synchronizes the code and class model.

To generate source code from a class diagram:

  1. First you will generate Java source code for the Java interface OrderObservable and the Java class Order. Select OrderObservable, and holding down the CTRL key, select Order so that they both have visible handles. Choose Generate | Java from the context menu. Notice that these Java classes now appear in the Navigator as OrderObservable.java and Order.java.
  2. Next, examine the Java source code that has been generated for these classes by double-clicking the file's node in the Navigator.
  3. In the code view of the Order Java class, add the method isPacked(), and make the return type boolean. Go back to the class diagram and see how this change is reflected in the diagram.

Now that you have generated source code from the class diagram, you are ready to proceed to the last part of the tutorial, Step 4 - Extending the Model by Reverse-Engineering an Existing Class, which describes how to extend the model by adding an existing class to the project and adding it to the diagram.