Experiment 10
Experiment: Perform Reverse Engineering in Java (Code
to Model Conversion)
Objective
To understand and demonstrate reverse engineering — the
process of converting existing Java code into its
corresponding UML class diagram or model. This technique
helps in understanding legacy code, documentation, and
system maintenance.
Theory
Reverse Engineering in software engineering is the process
of analyzing software to extract design and architectural
information. Unlike forward engineering (model → code),
reverse engineering does the opposite: code → model.
This is particularly useful when:
Source code exists but documentation is missing
One needs to refactor or improve system design
Understanding complex legacy systems
Steps Involved:
1. Analyze the existing source code.
2. Identify classes, attributes, methods, and relationships.
3. Create UML models (typically class diagrams) based on
code structure.
Java Code for Reverse Engineering
public class Employee {
private String name;
private int id;
public Employee(String name, int id) {
this.name = name;
this.id = id;
}
public void displayDetails() {
System.out.println("Name: " + name);
System.out.println("ID: " + id);
}
}
public class Manager extends Employee {
private String department;
public Manager(String name, int id, String department) {
super(name, id);
this.department = department;
}
public void displayDetails() {
super.displayDetails();
System.out.println("Department: " + department);
}
}
UML Class Diagram Representation
We will reverse engineer the above code into the following UML
structure:
Classes:
Employee
o - name: String
o - id: int
o + Employee(String, int)
o + displayDetails(): void
Manager (inherits from Employee)
o - department: String
o + Manager(String, int, String)
o + displayDetails(): void
Tools to Perform Reverse Engineering Automatically
1. IntelliJ IDEA / Eclipse + UML Plugin
o Many IDEs can generate UML from Java code using
plugins.
o Example: ObjectAid (Eclipse), SimpleUML (IntelliJ)
2. StarUML / Visual Paradigm
o Import source code and auto-generate diagrams.
3. Online Tools
o draw.io (manual creation)
Conclusion
Reverse engineering helps developers visualize the structure of
existing codebases. This aids in documentation, debugging,
refactoring, and onboarding new developers to the project.