| Snaprecruit.com

| Snaprecruit.com

Interview question based on skill :

Take as many assements as you can to improve your validate your skill rating

Total Questions: 20

1. Which one is the default scope of the beans?

Correct Answer is : Singleton

2. Which scope creates a new bean instance each time when requested?

Correct Answer is : Prototype

3. Session Creates a single bean instance per HTTP request, only valid in the context of a web application?

Correct Answer is : FALSE

4. Which of the following are considered valid beans?

Correct Answer is : All of the mentioned

5. What will be the output? public class ShoppingCart { private List items = new ArrayList(); public void addItem(Product item) { items.add(item); } public List getItems() { return items; } }     import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Main { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml"); Product aaa = (Product) context.getBean("aaa"); Product cdrw = (Product) context.getBean("cdrw"); Product dvdrw = (Product) context.getBean("dvdrw"); ShoppingCart cart1 = (ShoppingCart) context.getBean("shoppingCart"); cart1.addItem(aaa); cart1.addItem(cdrw); System.out.println("Shopping cart 1 contains " + cart1.getItems()); ShoppingCart cart2 = (ShoppingCart) context.getBean("shoppingCart"); cart2.addItem(dvdrw); System.out.println("Shopping cart 2 contains " + cart2.getItems()); } }

Correct Answer is : Shopping cart 1 contains (AAA 2.5, CD-RW 1.5)

6. In above question if scope of shoppingCart named bean is prototype, then what will be the output? What will be the output?

Correct Answer is : Shopping cart 1 contains (AAA 2.5, CD-RW 1.5)

7. Which interface is used to perform initialization of beans?

Correct Answer is : InitializingBean

8. Which interface is used to perform destruction of beans?

Correct Answer is : Disposablebean

9. Alternate way of initialization method is:-

Correct Answer is : init-method attribute

10. Alternate way of destruction method is:-

Correct Answer is : destroy-method attribute

11. Which annotation is used as a substitute of initialization method?

Correct Answer is : @PostConstruct

12. .Which annotation is used as a substitute of destroy method?

Correct Answer is : @PreDestroy

13. Which configuration can be used for Dependency Injection?

Correct Answer is : All of the mentioned

14. To validate Java beans in a web application using annotations.

Correct Answer is : All of the mentioned

15. JSR-303 or bean validation can access beans through annotations.

Correct Answer is : TRUE

16. For validating beans Spring supports.

Correct Answer is : all of the mentioned

17. JSR-303 can’t access java beans directly.

Correct Answer is : FALSE

18. Annotation which indicates a field cannot be a null.

Correct Answer is : @NotNull

19. Annotation used to indicate a field has to have a minimum of 2 characters.

Correct Answer is : @Size

20. Annotation which receives a value in the form regexp=”[email protected]+\\.[a-z]+”.

Correct Answer is : @Pattern