import java.lang.annotation.Annotation; import javax.ejb.Entity; public class GetAnnotation { public static void main(String[] args) { Annotation[] as = Person.class.getAnnotations(); for(int i=0;i<as.length;i++){ System.out.println(as[i].annotationType()); } Annotation a =Person.class.getAnnotation(Entity.class); System.out.println(a); Annotation[] das = Person.class.getDeclaredAnnotations(); for(int i=0;i<das.length;i++){ System.out.println(das[i].annotationType()); } } } /// import javax.ejb.Entity; import javax.ejb.AccessType; import javax.ejb.Id; import javax.ejb.GeneratorType; import java.io.Serializable; @Entity(access = AccessType.FIELD) public class Person implements Serializable { @Id(generate = GeneratorType.AUTO) Integer id; String name; }