// CustomAnnotation.java

package sample;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface CustomAnnotation {
    int value();
}


//SampleClass.java

package sample;

public class SampleClass {

    @CustomAnnotation(1)
    public void firstMethod(){
        System.out.println(toString() + "_first");
    }

    @CustomAnnotation(2)
    public void secondMethod(){
        System.out.println(toString() + "_second");
    }
}


//SampleApp.java 

package sample;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class SampleApp {
    public static void main(String[] args) {
        SampleClass sample = new SampleClass();
        Method[] methods = sample.getClass().getMethods();
        for (Method method : methods) {
            CustomAnnotation annotation = method.getAnnotation(CustomAnnotation.class);
            if (annotation != null) {
                System.out.println("Annotated with value: " + annotation.value());
                try {
                    method.invoke(sample);
                } catch (IllegalAccessException | InvocationTargetException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

//Output

> Task :SampleApp.main()

Annotated with value: 1
sample.SampleClass@14ae5a5_first
Annotated with value: 2
sample.SampleClass@14ae5a5_second

//End