0% found this document useful (0 votes)
46 views

Software Engineering exp9

The document outlines an experiment on forward engineering in Java, demonstrating the conversion of a UML class model into source code. It explains the process of transforming UML diagrams into Java classes, including attributes, methods, and relationships, and provides an example with a Person and Student class. The conclusion emphasizes the benefits of forward engineering for clarity and maintainability in software development.

Uploaded by

lput4439
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Software Engineering exp9

The document outlines an experiment on forward engineering in Java, demonstrating the conversion of a UML class model into source code. It explains the process of transforming UML diagrams into Java classes, including attributes, methods, and relationships, and provides an example with a Person and Student class. The conclusion emphasizes the benefits of forward engineering for clarity and maintainability in software development.

Uploaded by

lput4439
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Experiment 9

Experiment: Perform Forward Engineering in Java


(Model to Code Conversion)
Objective
To demonstrate the process of forward engineering, i.e.,
generating source code (Java) from a UML class model. This
experiment illustrates how object-oriented designs can be
translated into functional code structures.
Theory
Forward Engineering is the process of transforming a design
or model (like a UML diagram) into actual code. In object-
oriented programming, it often begins with creating UML class
diagrams that outline:
 Classes
 Attributes
 Methods
 Relationships (inheritance, association, etc.)
Using these diagrams, developers can then implement Java
classes with constructors, getters, setters, and business logic.
Example UML Class Diagram
Let’s assume a simple UML model with the following:
Classes:
1. Person
o name: String
o age: int
o +displayInfo()
2. Student (inherits from Person)
o rollNo: int
o +displayInfo() (overridden)

UML diagram

Generated Java Code (from UML Model)


// Base Class
public class Person {
protected String name;
protected int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public void displayInfo() {
System.out.println("Name: " + name);
System.out.println("Age: " + age);
}
}

// Derived Class
public class Student extends Person {
private int rollNo;
public Student(String name, int age, int rollNo) {
super(name, age);
this.rollNo = rollNo;
}

@Override
public void displayInfo() {
super.displayInfo();
System.out.println("Roll No: " + rollNo);
}
}

// Main Program
public class Main {
public static void main(String[] args) {
Student s = new Student("Alice", 20, 101);
s.displayInfo();
}
}

Steps to Perform Forward Engineering


1. Draw UML class diagram with tools like:
o draw.io
o StarUML
2. Identify class structures:
o Attributes, Methods, Access Specifiers, Inheritance
3. Write Java code:
o Create classes and implement logic as per diagram
4. Compile and run:
o Use IDE (Eclipse, IntelliJ) or command line (javac,
java)

Conclusion
Forward engineering ensures systematic, traceable, and model-
driven development. Translating UML diagrams to Java code
supports clarity, maintainability, and real-world object mapping.

You might also like