Set Java

Astah supports modeling in Java, C++, and C#. If you are modeling in Java, set so in Astah first.

  1. Select a root package on a tree and check [Java] in the bottom pane.
    Set Java


  2. Then Java options in [Language] tab become available for Classes, Attributes, and Operations.
    Java Options

TIPS – Set Java to a project by default

You can set Java as your default programming language to Astah from [Tools] – [System Properties] – [Project].

section divider

Import Java Source Code

You can import Java source code files and generate Class diagrams with the reversed models.

  1. Go to [Tools] – [Java] – [Import Java].
    Import Java Menu


  2. Choose .java files you want to import and click [OK]. Make sure you select the right encoding.
    Import Java Box

  3. Choose attributes that you want to import as associations.
    Import as Attributes

  4. Imported models are added to the tree.
    Imported Java Classes
section divider

Auto-generate Class Diagram

You can auto-create a Class diagram with the imported models.

  1. Right-click on a package or class and choose [Auto Create Class Diagram].
    Please refer to “Auto Create Class Diagrams” for more details and available options.
    Auto Create Diagram Options

  2. The generated diagram is opened in the Diagram Editor.
    Auto Create Class Diagram


TIPS – Use Auto-layout

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

section divider

Use Reverse Plug-in


Astah’s Easy Code Reverse Plug-in is the easiest way to reverse source code from Github, Bitbucket, and Gooogle Project Hosting into a UML class diagram just by drag-and-dropping the URL a repository or the .java source code files directly on to Astah!

  1. Install Astah’s Easy Code Reverse Plug-in
  2. Directly drag the link of the .java file from online repository.
    Easy Code Reverse

  3. The imported model would appear on the diagram.
    Reversed Class
section divider

Generate Java source code

“Export Java” is used to generate Java Skeleton Code from selected Diagram Elements.
The Definitions of Classes and Operations are exported as Documentation Comments.

  1. Go to [Tools] – [Java] – [Export Java] from Main Menu.
    Import Java Menu

  2. Select the models you want to export to source code.
    Export Java Option

  3. .java files would be generated.
    If the .java files with the same name already exist, the source code files would be completely replaced with what you last export.
    If you do not want the latest export to overwrite the whole source code and you want to keep any modifications you’ve made to the .java files, check [When overwriting, keep the information of existing code that is not in the model.] option.
    Export-Java-option

Sample source code

Sample UML Class Diagram
Exported Java source code