Modeling Java Annotations
You can model Java Annotations in UML modeling. It is designed to enhance the development process by empowering users to model Java annotations in a UML environment and ensure smooth transformations between UML representations and Java source code.
Java Annotation is a tag that represents the metadata, that is, attached with class, interface, methods or fields to indicate some additional information. Annotations can be leveraged to create cleaner, more maintainable, and efficient Java applications.
It is worth highlighting that:
- Annotations are placed prior to the code element they apply to (for example, a method, class, interface or method)
- Annotations use the @ symbol followed by the annotation name and optional attributes
- Annotations do not change the code's logic but provide metadata for tools and frameworks.
In UML model, apply the "JavaAnnotation" stereotype by following below steps:
- Select the model element (for example, a method, class, interface or method)
- Goto Properties view and open Stereotypes tab.
- Click Apply Stereotypes… button
- Choose JavaAnnotation stereotype from the list
- Click on OK button.
Follow the syntax guidelines for adding diverse types of annotations:
- Marker Annotations: @AnnotationName
- Single Member Annotation: @AnnotationName("value")
- Normal Annotation: @AnnotationName(param1 = "value1", param2 = "value2")
- Import statement: com.example.AnnotationName
You can add necessary details of the annotations in the stereotype properties.

Note:
It is important to recognize situations not considered issues during Java Annotation Modeling and Transformation. For example:
- Changes Between Source Code and UML Transformations: When performing Java to UML transformations, it is normal to observe changes between the source code and UML representations. This is a part of the transformation process and is intended to prompt users to align values manually. The tool will highlight discrepancies, allowing users to review and synchronize annotations as needed.
- Valid Java Annotation Syntax: During Java to UML transformations, users are expected to enter valid Java annotation syntax. If users provide incorrect syntax, the tool will flag these entries but will also offer an option to correct the annotations. This interactive prompt ensures that users can easily rectify any syntax errors and maintain consistency between the UML representations and Java source code.