Java - Interview Questions and Answers for 'Annotations' | Search Java Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com
Share

Search Java Interview Questions


 2098 questions in repository.
 There are more than 200 unanswered questions.
Click here and help us by providing the answer.
Label / Company      Label / Company / Text

   



Interview Questions and Answers for 'Annotations' - 26 question(s) found - Order By Newest

 Q1. What are concepts introduced with Java 5 ?Core Java
Anonymous
Ans. Generics , Enums , Autoboxing , Annotations and Static Import.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java5   generics   enum   autoboxing   annotations   static import        rare

Try 1 Question(s) Test


 Q2. Which annotations are used in Hibernate ?Hibernate
admin
info@buggybread.com
Ans. @Entity
@Table
@Id
@Column
@Temporal
@Basic
@Enumerated
@Access
@Embeddable
@Lob
@AttributeOverride
@Embedded
@GeneratedValue
@ElementCollection
@JoinTable
@JoinColumn
@CollectionId
@GenericGenerator
@OneToOne
@OneToMany
@ManyToOne
@ManyToMany
@NotFound

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     hibernate   annotations


 Q3. What are meta Annotations ?
Anonymous
Ans. Annotations that apply to other annotations are called meta-annotations.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   annotations   meta annotations


 Q4. How to create a Junit to make sure that the tested method throws an exception ?
admin
info@buggybread.com
Ans. Using annotation Test with the argument as expected exception.

@Test (expected = Exception.class)

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     junit   junit annotations


 Q5. What is the use of @GeneratedValue annotation in Hibernate?Hibernate
Admin
info@buggybread.com
Ans. This annotation is added to the auto increment column with the strategy to increment the column value. Usually this is added to the surrogate primary key column and specified with the Database Sequence.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     hibernate   hibernate annotations   @generatedvalue   database sequence


 Q6. Explain Annotations ?
Anonymous
Ans. Annotations, a form of metadata, provide data about a program that is not part of the program itself. Annotations have no direct effect on the operation of the code they annotate. Annotations have a number of uses, among them:
• Information for the compiler — Annotations can be used by the compiler to detect errors or suppress warnings.
• Compile-time and deployment-time processing — Software tools can process annotation information to generate code, XML files, and so forth.
• Runtime processing — Some annotations are available to be examined at runtime.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   annotations      basic        frequent


 Q7. Give an Example of Annotations ?
Anonymous
Ans. Suppose that a software group traditionally starts the body of every class with comments providing important information:
public class Generation3List extends Generation2List {

// Author: John Doe
// Date: 3/17/2002
// Current revision: 6
// Last modified: 4/12/2004
// By: Jane Doe
// Reviewers: Alice, Bill, Cindy

// class code goes here

}
To add this same metadata with an annotation, you must first define the annotation type. The syntax for doing this is:
@interface ClassPreamble {
String author();
String date();
int currentRevision() default 1;
String lastModified() default "N/A";
String lastModifiedBy() default "N/A";
// Note use of array
String[] reviewers();
}
The annotation type definition looks similar to an interface definition where the keyword interface is preceded by the at sign (@) (@ = AT, as in annotation type). Annotation types are a form of interface, which will be covered in a later lesson. For the moment, you do not need to understand interfaces.
The body of the previous annotation definition contains annotation type element declarations, which look a lot like methods. Note that they can define optional default values.
After the annotation type is defined, you can use annotations of that type, with the values filled in, like this:
@ClassPreamble (
author = "John Doe",
date = "3/17/2002",
currentRevision = 6,
lastModified = "4/12/2004",
lastModifiedBy = "Jane Doe",
// Note array notation
reviewers = {"Alice", "Bob", "Cindy"}
)
public class Generation3List extends Generation2List {

// class code goes here

}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   annotations


 Q8. What are few of the Annotations pre defined by Java?
Anonymous
Ans. @Deprecated annotation indicates that the marked element is deprecated and should no longer be used. The compiler generates a warning whenever a program uses a method, class, or field with the @Deprecated annotation.

@Override annotation informs the compiler that the element is meant to override an element declared in a superclass.

@SuppressWarnings annotation tells the compiler to suppress specific warnings that it would otherwise generate.

@SafeVarargs annotation, when applied to a method or constructor, asserts that the code does not perform potentially unsafe operations on its varargsparameter. When this annotation type is used, unchecked warnings relating to varargs usage are suppressed.

@FunctionalInterface annotation, introduced in Java SE 8, indicates that the type declaration is intended to be a functional interface, as defined by the Java Language Specification.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java8   annotations   pre defined annotations


 Q9. Name few meta-annotations ?
Anonymous
Ans. @Retention annotation specifies how the marked annotation is stored:

@Documented annotation indicates that whenever the specified annotation is used those elements should be documented using the Javadoc tool. (By default, annotations are not included in Javadoc.)

@Target annotation marks another annotation to restrict what kind of Java elements the annotation can be applied to.

@Inherited annotation indicates that the annotation type can be inherited from the super class. (This is not true by default.) When the user queries the annotation type and the class has no annotation for this type, the class' superclass is queried for the annotation type. This annotation applies only to class declarations.

@Repeatable annotation, introduced in Java SE 8, indicates that the marked annotation can be applied more than once to the same declaration or type use. For more information, see Repeating Annotations.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java8   annotations   meta annotations



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q10. What entries we make in the hibernate config file if we are not using hbm files but Annotations ?Hibernate
Admin
info@buggybread.com
Ans. We configure Entity classes having annotated mappings.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     hibernate   hibernate annotations


 Q11. What is the difference between these 2 annotations ?

@Entity

@Entity ( name="EMPLOYEES" )
Hibernate
admin
info@buggybread.com
Ans. The first annotation will try to map the Class with the Table as of same name as Class whereas the second annotation will specify the Entity name as "EMPLOYEES" and hence will try to map with Table Name "EMPLOYEES".

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     hibernate   hibernate annotations   entity annotations


 Q12. What is the difference between these 2 annotations ?

@Entity ( name ="EMPLOYEES")
@Entity @Table ( name=""EMPLOYEES"" )

@Entity ( name="EMP")
@Table ( name="EMPLPYEES" )
Hibernate
Admin
info@buggybread.com
Ans. First Annotation will set the Entity name as EMPLOYEES and hence will try to map with the same Table name.

The second annotation will make the Entity mapped to table EMPLOYEES irrespective of the Entity Name ( which is class name in this case ).

Third Annotations will set the different names for Enitity and Table and will explicitly map them.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     hibernate   hibernate annotations   entity annotation   table annotation


 Q13. What are the different ID generating strategies using @GeneratedValue annotation ?Hibernate
Admin
info@buggybread.com
Ans. Auto , Identity , Sequence and Table.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     hibernate   generatedvalue annotations   architecture


 Q14. How to do Eager loading in Hibernate ?Hibernate
Admin
info@buggybread.com
Ans. Using

lazy = false in hibernate config file

or

@Basic(fetch=FetchType.EAGER) at the mapping

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     hibernate   lazy loading hibernate   basic annotation hibernate   architecture


 Q15. What are the annotations used in Junit with Junit4 ?
Admin
info@buggybread.com
Ans. @Test

The Test annotation indicates that the public void method to which it is attached can be run as a test case.

@Before

The Before annotation indicates that this method must be executed before each test in the class, so as to execute some preconditions necessary for the test.

@BeforeClass

The BeforeClass annotation indicates that the static method to which is attached must be executed once and before all tests in the class.

@After

The After annotation indicates that this method gets executed after execution of each test.

@AfterClass

The AfterClass annotation can be used when a method needs to be executed after executing all the tests in a JUnit Test Case class so as to clean-up the set-up.

@Ignores

The Ignore annotation can be used when you want temporarily disable the execution of a specific test.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   junit   jnuit4   junit annotations


 Q16. Name few annotations related classes and interfaces ?
Admin
info@buggybread.com
Ans. http://www.buggybread.com/2015/01/java-annotations-classes-and-interfaces.html

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   annotations


 Q17. What is the difference betweeen @Inject and @Autowired ?Spring
Admin
info@buggybread.com
Ans. @Autowired and @Inject are similar in terms of functionality they achieve. @Inject is part of a new Java technology called CDI that defines a standard for dependency injection whereas @Autowired is a Spring specific annotation for dependency injection.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     spring   web frameworks   dependency injection   autowired   inject   spring annotations   ioc


 Q18. What is the use of Deprecated annotation ?2016-06-23 13:40:01

Ans. Deprecated annotation is for documentation purpose only. It doesn't enforce anything but would mark the method name as crossed to signify that the client should refrain from using it.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     Deprecated annotation


 Q19. Does Deprecated annotation enforces anything ?2016-06-23 13:40:38

Ans. No. It just marks the method and hence signals the client to refrain from using it.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     Deprecated annotation



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q20. If you are supposed to deprecate the method , Will you deprecate the method in the implementation class or will you deprecate the abstract declaration within interface or abstract class ?2016-06-23 13:42:05

Ans. Deprecating the interface / or declaration doesn't make much sense as the implementation is deprecated and not the interface.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     Deprecated annotation


 Q21. What is the use of Annotations in Java ?Core Java2017-05-05 21:40:54

Ans. Annotations are used to specify meta information about the code.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     Annotations


 Q22. Are Annotations better than using XML configs ?Core Java2017-05-05 21:41:52

Ans. Yes , as both code and its meta information reside in the same file, it promotes better readability and maintenability.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     Annotations


 Q23. What is the use of @Bean annotation in Spring ?Spring2017-05-16 19:35:49

Ans. There are 2 ways to specify dependencies in Spring, one by the way of specifying beans in config files and other is by specifying annotations like @Bean, @Component , @Service etc to let spring know of the dependencies.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     spring bean annotation  spring annotations


 Q24. Which of following annotation is used to initialize objects before executing set of tests ?Junit
a. @Test
b. @Ignore
c. @After
d. @Before

Ans.d. @Before

 Q25. Which of the following is not an Hibernate AnnotationHibernate
a. @Id
b. @JoinTable
c. @ManyToMany
d. @Autowired

Ans.d. @Autowired

 Q26. Which of following is not Spring MVC annotation ?Spring
a. @Autowired
b. @Controller
c. @JoinColumn
d. @Transactional

Ans.c. @JoinColumn



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus
 

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked:
         

X Close this

X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   


Questions Asked: