Using ChatGPT and PlantUML to Generate UML Diagrams from Java Pseudocode
This article demonstrates how to leverage ChatGPT's ability to produce textual code snippets together with PlantUML to automatically create various UML diagrams—such as sequence, class, flow, state, and use‑case diagrams—from Java‑style pseudocode, providing a step‑by‑step workflow and example prompts.
Although ChatGPT cannot directly output images, it can generate structured textual outputs like tables, code, and mathematical formulas, including text‑based graphic description languages that allow the creation of visual diagrams without a graphical editor.
The article introduces PlantUML, an open‑source tool that uses plain text to describe UML diagrams (class, sequence, use‑case, etc.), highlighting its advantages: human‑readable syntax, free usage, automatic layout, rapid updates, and high customizability.
For each diagram type, the article provides a Java‑style pseudocode example, the corresponding PlantUML code generated by ChatGPT, and the rendered diagram image. The examples cover:
Sequence diagram of a simple e‑commerce order flow.
Class diagram of a personnel system with Person, Teacher, and Student classes.
Flowchart of a shopping process with conditional branches for stock, discounts, and payment.
State diagram illustrating order state transitions (New, Shipped, Delivered, Closed).
Use‑case diagram for a library management system showing Librarian and Reader interactions.
Each PlantUML snippet is shown inside tags to preserve the exact code, for example:
public class User {
private String name;
private String email;
// ...
public void placeOrder(Order order) {
// order logic
}
}
public class Order {
private User user;
private String orderId;
public void process() {
OrderProcessor orderProcessor = new OrderProcessor();
orderProcessor.processOrder(this);
}
}
// ... other classes ...The corresponding PlantUML for the sequence diagram is:
@startuml
actor User
participant Order
participant OrderProcessor
participant NotificationService
User -> Order: placeOrder(order)
activate Order
Order -> OrderProcessor: process()
activate OrderProcessor
OrderProcessor -> NotificationService: processOrder()
activate NotificationService
NotificationService --> User: sendNotification()
deactivate NotificationService
deactivate OrderProcessor
deactivate Order
@endumlAfter generating the PlantUML code, the user copies it into the PlantUML online editor (https://www.plantuml.com) to preview and export the diagram image.
The article concludes with a concise workflow: provide Java code to ChatGPT, specify the desired UML diagram type, let ChatGPT produce PlantUML code, and finally render the diagram using the PlantUML web service. It also supplies a reusable prompt template for generating any UML diagram from code.
Sohu Tech Products
A knowledge-sharing platform for Sohu's technology products. As a leading Chinese internet brand with media, video, search, and gaming services and over 700 million users, Sohu continuously drives tech innovation and practice. We’ll share practical insights and tech news here.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.