How to Generate Sequence Diagram from Java?

Since source code is in text form, it is complex and is hard for human to read or analyze, especially when the logic is complicated and involves a large number of classes. "A picture is worth a thousand words", by visualizing source code with diagram, you can easily realize the classes involve as well as their relationship in run time. In order to help you with that, Visual Paradigm enables you to reverse your Java source code into UML sequence diagram, so that you can gain a better understanding of Java source code by reading diagram instead of looking to a possibly thousand lines of source code. This is very beneficial for both analysis and communication.

November 10, 2014
Views: 263,073
PDF Download
  1. Download Sample.zip for this tutorial and extract the zip file to any directory.
  2. Study the source code. Read the register method in RegisterController.java to see how it works.
    Java source code
  3. Create a new project by selecting Project > New from the application toolbar. In the New Project window, enter Account Registration as the project name and click Create Blank Project.
    New project
  4. Select Tools > Code > Instant Reverse Java to Sequence Diagram... from the toolbar.
  5. In the Instant Reverse Java to Sequence Diagram window, click the Add Source Folder... button.
  6. Select the extracted source folder, `src`. Click the Next button.
  7. Select the method to visualize: src > RegisterController.java > register(String, int). Click the Next button.
    Instant Reverse Java to Sequence Diagram window
  8. You need to select a diagram to visualize the interaction. The Create new sequence diagram option is selected, and a diagram name is entered by default. Click the Finish button.
    Create new sequence diagram
  9. As a result, a UML sequence diagram is formed. Let's study the diagram.
    Sequence diagram formed
    When the `register` method of `RegisterController` is invoked (message 1), it creates an `Account` object (message 1.1). After that, the controller sets the ID, name, and age of the `Account` object (messages 1.2, 1.3, 1.4) and adds the object to an account list (message 1.5). The invocation ends with a return message (message 1.6).