Web services test code generator
Klaus Berg has recently released a test-code generator for JUnit-based Web service clients. If you're developing Web services using Axis2 and XMLBeans this wizard could turn your JUnit test client coding into a powerful code generation process. It also has uses for those using GUI-based testing tools like soapUI.

Newsletter sign-up

Sign up for our technology specific newsletters.

Enterprise Java
View all newsletters

Email Address:

User interfaces for object-oriented systems, Part 6: The RPN calculator

The RPN-calculator application demonstrates object-oriented UI principles

This month we continue the process begun in the January Java Toolbox by completing the RPN (Reverse Polish Notation) calculator application. The RPN calculator is a small but nontrivial application that demonstrates some of the important object-oriented UI principles we've looked at in previous Java Toolbox articles, specifically the visual-proxy design pattern. This application isn't just a toy; I use it virtually every day -- every time I need a calculator, in fact.

A word of warning: the following discussion will be incomprehensible if you haven't read the earlier installments of this series.

TEXTBOX: TEXTBOX_HEAD: Build user interfaces for object-oriented systems: Read the whole series!

Reverse Polish Notation was championed for years by Hewlett-Packard, though I've been told that their most recent calculators don't support it anymore (a pity). It is one of those things that are difficult to learn but wonderful to use once you understand them. The RPN's basic notion is built around an arithmetic stack. Numbers, when entered, are pushed on the stack, and all operations use stack items as operands.

For example, when you press the add (+) key, the two items closest to the top of the stack are popped and added together, and the resulting sum is pushed, effectively replacing the original operands. Although that might seem like a strange way to do things, you never need to use parentheses, and once you get used to it, you'll probably rather like it. I've been using my PalmPilot as a handheld calculator, using Russ Webb's great RPN calculator (see Resources), but I wanted one for my computer too. Being a programmer, I thought building one was the easiest way to get exactly what I wanted.

Resources
  • The code
  • All the code for this article (and past articles) is available on my Website. Click Articles on the site's navigation bar. You can find an index to all my previous JavaWorld articles on the same page
    http://www.holub.com.
  • An example RPN calculator
  • Russ Webb's RPN calculator provides a good example of Reverse Polish Notation for the PalmPilot platform
    http://www.nthlab.com
  • UML resources
  • The Unified Modeling Language (UML) notation is gradually winning the notation wars. UML is an emerging standard, with the Object Management Group (OMG) in charge of the process. Get more information from OMG at
    http://www.omg.org/uml
  • UML Distilled, by Martin Fowler and Kendall Scott (Addison-Wesley, 2000), is my favorite quick introduction to UML
    http://www1.fatbrain.com/asp/BookInfo/BookInfo.asp?theisbn=020165783X&from=NCN454
  • The UML specification can be downloaded from
    http://www.rational.com/uml/resources/documentation
  • A word of warningThe foregoing link is to the Rational Web site because the principal designers of UMLGrady Booch, James Rumbaugh, and Ivor Jacobsen all work for Rational. Nonetheless, Rational Rose, their object-oriented CASE tool, is one of the weakest -- though most popular -- of the object-oriented CASE tools available. For one thing, Rose supports only a small subset of UML and doesn't do a particularly good job of it. The drawings in this article were created using Visio (which I'm also not ecstatic about) using templates of my own devising. You can get these templates from my Website in the Object-Oriented Design subsection of the Goodies section.
    http://www.holub.com.
  • Design patterns
  • Swing architecture