Witscale Test Center

1.2 The Java class > 1.2.4 UML notation for class


1.2.4 UML notation for class

Java constructs are often shown using the UML (Unified Modeling Language) notations in diagrams.

 

The UML notations are used to pictorially convey software design. Java application designs are no exception. Though the exam itself does not require knowledge of UML, it is useful to know the basic notations while answering diagram-based questions as the diagrams in such questions often use UML notations.

 

Let us start with UML notation for Java class. Figure 1.2 shows a class diagram for the Account class (see listing 1.1).  The Account class is represented with a rectangle with three sub-sections. The top-most section contains the class’s name. The middle section contains the member variables of the class and bottom section shows the methods.

 


Figure 1.2 UML notation for a simple Account class

 

The three sub-sections may be absent altogether. This is especially true when the Class diagram is being used to illustrate special relationships (such as inheritance, generalization) among the classes. For instance, in the banking application we have been discussing Account class is extended to have a subclass named CheckingAccount. You can illustrate this relationship using UML notation for class.  Figure 1.3 shows the CheckingAccount extends from the Account class using a block arrow connector. 

 


Figure 1.3 UML notation for Account class and its subclass CheckingAccount which implements the interface Auditable

 

The figure also illustrates the class CheckingAccount implements an interface Auditable with the help of a dashed line as a connector. You might have noticed that an interface is represented as a rectangle just like a class. However, it has additional phrase <<interface>> along with interface name.

With this section, we finished the nitty-gritty details of class and interface declarations. In the following two sections, we will discuss the member declarations within class.