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

Java Uml Steps PDF

This tutorial demonstrates how to generate Java source code from a UML class diagram model in Eclipse using Visual Paradigm for UML. The steps include creating a phone book project in Eclipse, drawing a UML class diagram with classes like PhoneBook and Category, adding attributes and operations to the classes, and clicking the "Update Code" button to generate the Java source files from the model. The user can then modify the generated code and click "Update UML Model" to synchronize changes back to the diagram.

Uploaded by

prasath67
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
186 views

Java Uml Steps PDF

This tutorial demonstrates how to generate Java source code from a UML class diagram model in Eclipse using Visual Paradigm for UML. The steps include creating a phone book project in Eclipse, drawing a UML class diagram with classes like PhoneBook and Category, adding attributes and operations to the classes, and clicking the "Update Code" button to generate the Java source files from the model. The user can then modify the generated code and click "Update UML Model" to synchronize changes back to the diagram.

Uploaded by

prasath67
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Visual Paradigm for UML Generate Java source from UML class diagram Eclipse

Tutorial

Generate Java source from UML class diagram Eclipse


Written Date : January 18, 2010 You can perform round-trip engineering in Eclipse, to keep Java source code and class model in sync. In this tutorial, we will see how to create a class model and eventually generating source code from model. 1. Create a Java project Phone Book in Eclipse.

2.

Right click on the project node in Package Explorer and select Open VP-UML from the popup menu.

http://www.visual-paradigm.com/product/vpuml/tutorials/sdeeccodegen.jsp

Page 1 of 7

Visual Paradigm for UML Generate Java source from UML class diagram Eclipse

Tutorial

3.

In Diagram Navigator, right click on Class Diagram and select New Class Diagram from the popup menu.

4.

A new diagram is created. You are asked to enter a package header on top of the diagram. Enter myapp and press Enter.

5.

You are asked to provide the diagram name. Enter Domain Model and press Enter.

6.

Select Class from the diagram toolbar. Click on the diagram to create a class and name it as PhoneBook.

http://www.visual-paradigm.com/product/vpuml/tutorials/sdeeccodegen.jsp

Page 2 of 7

Visual Paradigm for UML Generate Java source from UML class diagram Eclipse

Tutorial

7.

We need to create a new class Category with association to PhoneBook. Move the mouse cursor of the class PhoneBook. Press on the resource icon Aggregation->Class.

8.

Drag to the right of the class PhoneBook and release the mouse button. Name the new class Category.

9.

Follow the previous steps to create class Contact, associated by class Category.

10.

There are two kinds of contact: friend and relative. Create two subclasses from class Contact through the resource icon Generalization->Class, and name them as Friend and Relative.

The diagram should look like this:

http://www.visual-paradigm.com/product/vpuml/tutorials/sdeeccodegen.jsp

Page 3 of 7

Visual Paradigm for UML Generate Java source from UML class diagram Eclipse

Tutorial

11.

It is time to add attributes to classes. Right click on class PhoneBook and select Add > Attribute from the popup menu.

12.

Enter owner : String to name the attribute as owner, and set the type as String.

13.

Press Enter to proceed to the next attribute. Enter createDate : java.util.Date as attribute name and type. Click on diagram to confirm editing.

Note that the package of type Date, which is java.util, will not be shown by default. If you want to show fully qualified name you can right click on diagram background and select Presentation Options > Type > Fully Qualified from the popup menu. 14. Let's continue with creating operation. Right click on the class PhoneBook and select Add > Operation from the popup menu. Enter createPhoneBook(owner : String) : PhoneBook to create a public operation createPhoneBook with parameter owner, and return an object in type PhoneBook.

15.

16.

Follow the previous steps create attribute and operations in the remaining classes as listed below: Class Attributes Operations createCategory(title : String, desc : String) : Category

Category title : String desc : String Contact name : String address : String age : int

createContact(name : String) : Contact createContact(name : String, age : int) : Contact

http://www.visual-paradigm.com/product/vpuml/tutorials/sdeeccodegen.jsp

Page 4 of 7

Visual Paradigm for UML Generate Java source from UML class diagram Eclipse

Tutorial

gender : char Friend firstMet : String

Relative relationship : String The diagram should look like this:

17.

We almost complete modeling. Let's set the role names. Double click on the Category end of the connector between class PhoneBook and Category. Name the role cats. Set multiplicity as 0..*. These changes will affect the attribute of category that will be generated in the class PhoneBook.

http://www.visual-paradigm.com/product/vpuml/tutorials/sdeeccodegen.jsp

Page 5 of 7

Visual Paradigm for UML Generate Java source from UML class diagram Eclipse

Tutorial

18.

Similarly edit the connector between Category and Contact by setting the role names of the two ends to cat and contacts, and multiplicities to 1 and 0..* respectively. This is the completed diagram.

19. 20.

Press Ctrl-S to save. Now comes the code generation. Click on the Update Code button on toolbar.

21.

Check the Package Explorer. You should see a list of generated file. You can open them to fill in the code body.

http://www.visual-paradigm.com/product/vpuml/tutorials/sdeeccodegen.jsp

Page 6 of 7

Visual Paradigm for UML Generate Java source from UML class diagram Eclipse

Tutorial

22.

This is the end of the tutorial. Instead of closing Eclipse now, you may try something more by editing the code like to add, rename or delete class, attributes and operations, and click the Update UML Model button, which is the one next to the Update Code button, and observe the changes that will make in the class model. Enjoy!

Visual Paradigm for UML home page


(http://www.visual-paradigm.com/product/vpuml/)

UML tutorials
(http://www.visual-paradigm.com/product/vpuml/tutorials.jsp)

Visual Paradigm home page


(http://www.visual-paradigm.com/)

http://www.visual-paradigm.com/product/vpuml/tutorials/sdeeccodegen.jsp

Page 7 of 7

You might also like