X

Geertjan's Blog

  • February 23, 2006

UML and NetBeans IDE (Part 2)

Geertjan Wielenga
Product Manager
Yesterday I looked at how to use NetBeans IDE to create a UML model from an existing application. Today, I went through this tutorial: UML Modeling: Developing Applications. I did this because this time I wanted to start from the other side—without an application. My question going in was: "How much code will the IDE be able to generate for me?" I was quite amazed, really. I had assumed that I would have to build the whole UML model, that I would then have to choose a menu item that says something like: "Generate application" and that then the whole application would be generated from the model. How wrong I was! I started by having to create a Java Project and a UML Project. While creating the UML Project, there was a cool little checkbox that set the magic in motion: "Generate Code". This forced me to select an existing project (again, unfortunately, like yesterday, one that had to be open in the IDE). Then, the first "wow" moment came right near the start of the tutorial—I dragged a "Class" item from the Palette into the Diagram Editor (i.e., the Diagram Editor is in the same spot as where the Source Editor normally is), and then I renamed the class. Take a look at what was then added to my Java Project:

In other words, a "BankAccount" class was created, with a constructor. Then, I added an attribute, balance, to the diagram (by right-clicking in the diagram and choosing "Insert Attribute"), which resulted in the balance field being created, as well as a getter and setter. Then I right-clicked in the diagram again and chose "Insert Operation" and then added the withdraw operation. Doing this—all right inside the diagram, i.e., graphically— resulted in code being generated each step of the way:

Continuing like this, I added an interface (Bank.java), a superclass (Checking.java), and a test class (AccountTest.java). The relationships between these classes were done via the items in the Palette. The package was created the same way, with items in the palette being used to connect all the classes to the package.

Switching from the visual representations to the actual code is easy:

What is called "round trip engineering" is totally cool—changes you make in the code are reflected in the diagram; changes you make in the diagram are reflected in the code. Again, the code is generated whenever you add something to the diagram, how cool is that? So, you can see the effect immediately in the Java project in the Projects window.

And this is what the application looked like right at the end (notice the addition of a main method in AccountTest.java, I added that in the code, not in the diagram, but, as soon as I had made the addition to the code, it was added to the diagram by the IDE):

The whole thing was a really cool experience—working at a higher level, yet seeing code being generated for you on the fly. The only bug I encountered was this one—when the diagram needs to be saved (indicated by the asterisk below), the Save button in the IDE isn't activated (but you can workaround this by right-clicking on the tab and choosing "Save Document" there). Here's the proof—asterisk is visible in the tab, but Save button in the IDE cannot be clicked:

Aside from the above, the UML toolset in the IDE is really cool. Now, I wonder if this stuff can also be used in other areas, such as web applications and plug-in modules...

Join the discussion

Comments ( 13 )
  • legolas woodlan Thursday, February 23, 2006
    I like NetBeans 5 look and feel, but Netbeans 5.5 enterprise edition look like to have netbeans 4.1 LAF.
    am i correct ?
  • Kovica Thursday, February 23, 2006
    Now try to add a note to the diagram and enter some non-Latin1 characters... See a bug now ? :)
  • Aswin Anand T H Friday, February 24, 2006
    Cool! im downloading 5.5 right away :)
  • Matthew Ryan Wednesday, July 5, 2006
    Hi,
    I've been using NetBeans 5.5beta and a Daily build from about a week ago and I don't have UML support in either of them. Not bundled. And in the Update Centre I don't see any Modules to pull down.
    At present I work in NetBeans but do all my modeling in another tool I won't mention. It would be great to fire up this functionality in my NetBeans.
  • Geertjan Wednesday, July 5, 2006
    You need NetBeans Enterprise Pack, although there's no guarantee it will work with NetBeans IDE 5.5 Beta, as far as I am aware.
  • Geertjan Wednesday, July 5, 2006
    Sorry, wrong link. Here it is:
    http://www.netbeans.org/products/enterprise/index.html
  • Matthew Ryan Wednesday, July 5, 2006
    I just re-read your post. Somehow in the excitement my eyes glossed over it, amazed by the following screenshots, and I missed this little detail. ;-)
    Thanks
  • Geertjan Wednesday, July 5, 2006
    Cool. Looks like you've got some interesting articles in your blof, about the NetBeans Platform. Neat! Pretty cool to discover how simple yet powerful the NetBeans Platform is, isn't it? Really blew me away when I first got into it and even still it's a really cool and fun set of tools for rapid (and maintainable and extendable!) creation of Swing apps.
  • Geertjan Wednesday, July 5, 2006
    "blof" should be "blog"
  • Matthew Ryan Wednesday, July 5, 2006
    A lot of people visit my Blog for the 'Quickstart an MDI application using NetBeans 5.0' post.
    http://florecista.blogspot.com/2006/01/quickstart-mdi-application-using.html
    I've used NetBeans for a while and am always surprised when I meet developers who haven't looked at it and found all the fantastic features. So if I have time to sit with them I show them and if I don't I write a little tutorial and send them the link.
  • David Sunday, July 15, 2007
    Hi!
    Just to ask if it is possible to use UML for Netbeans platform development?
    Is there a sample to look? Thank you!
  • shalin Monday, October 13, 2014

    Net-Beans is a fabulous IDE. But I would like to create class diagrams and import to net-beans


  • Creately Tuesday, April 7, 2015

    Can these uml diagrams (OOP) concepts directly converted in to java code?


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.