Set Java

Astah supports modeling in Java, C++, and C#. If you are modeling in Java, set the project language to Java first:

  1. Select the root package in the Structure Tree and check [Java] in the bottom pane.
    Setting the project language to Java
  2. With Java set, you can edit Java-specific options for Classes, Attributes, and Operations in the [Language] tab.
    Java options in the Language tab

TIPS – Set Java to a project by default

You can set Java as the default programming language for new projects in [Tools] – [System Properties] – [Project].

section divider

Import Java Source Code

You can import Java source code files and create class diagrams from the reverse-engineered models.

  1. Go to [Tools] – [Java] – [Import Java].
    Import Java menu
  2. Choose the .java files you want to import and click [OK]. Make sure you select the correct encoding.
    Import Java dialog
  3. Choose the attributes you want to import as associations.
    Choosing attributes to import as associations
  4. The imported models are added to the tree.
    Imported Java classes in the Structure Tree
section divider

Auto-generate Class Diagram

You can automatically create a class diagram from the imported models. For details and options, see Auto Create Class Diagrams.

  1. Right-click a package or class and choose [Auto Create Class Diagram].
    Auto Create Class Diagram options
  2. The generated diagram opens in the Diagram Editor.
    Automatically created class diagram

TIPS – Use Auto-layout

After generating a diagram, you can lay out the models vertically or horizontally from the [Alignment] – [Auto Layout] menu.

section divider

Use Reverse Plug-in

With the Easy Code Reverse Plug-in, you can reverse-engineer Java source code into a UML class diagram by dragging a repository URL or .java files directly onto Astah.

  1. Install the Easy Code Reverse Plug-in.
  2. Drag the link to a .java file in an online repository onto Astah.
    Dragging a .java file link onto Astah
  3. The imported model appears on the diagram.
    Reverse-engineered class on the diagram
section divider

Generate Java source code

[Export Java] generates Java skeleton code from the selected diagram elements. The definitions of classes and operations are exported as documentation comments.

  1. Go to [Tools] – [Java] – [Export Java] in the main menu.
    Java menu with Export Java
  2. Select the models you want to export as source code.
    Export Java dialog
  3. The .java files are generated. If files with the same names already exist, they are completely replaced by the latest export. To keep modifications you’ve made to existing .java files, check the [When overwriting, keep the information of existing code that is not in the model.] option.
    Option to keep existing code when overwriting

Sample source code

Sample UML class diagram
Java source code exported from the sample class diagram