java examples
Home Java Examples Resources Java Interview Questions
Brainpower SEO

How to annotate a class or method?

This example show you how to use the HelloAnno annotation on the previous example code, How to create a simple annotation?. We add the HelloAnno annotation to our class and its methods.

package com.javacoderanch.example.annotation;

@HelloAnno(value = "Good Morning", greetTo = "Universe")
public class HelloAnnoExample {
    public static void main(String[] args) {
        HelloAnnoExample example = new HelloAnnoExample();


    @HelloAnno(value = "Hi there", greetTo = "Alice")
    public void sayHi() {

    @HelloAnno(value = "Hello there", greetTo = "Bob")
    public void sayHello() {