This set of Advanced Java Multiple Choice Questions & Answers (MCQs) on “Java Beans”.
1. Which of the following is not an Enterprise Beans type?
a) Doubleton
b) Singleton
c) Stateful
d) Stateless
Answer: a
Clarification: Stateful, Stateless and Singleton are session beans.
2. Which of the following is not true about Java beans?
a) Implements java.io.Serializable interface
b) Extends java.io.Serializable class
c) Provides no argument constructor
d) Provides setter and getter methods for its properties
Answer: b
Clarification: java.io.Serializable is not a class. Instead it is an interface. Hence it cannot be extended.
3. Which file separator should be used by MANIFEST file?
a) /
b)
c) –
d) //
Answer: a
Clarification: MANIFEST file uses classes using / file separator.
4. Which of the following is correct error when loading JAR file with duplicate name?
a) java.io.NullPointerException
b) java.lang.ClassNotFound
c) java.lang.ClassFormatError
d) java.lang.DuplicateClassError
Answer: c
Clarification: java.lang.ClassFormatError: Duplicate Name error is thrown when .class file in the JAR contains a class whose class name is different from the expected name.
5. Java Beans are extremely secured?
a) True
b) False
Answer: b
Clarification: JavaBeans do not add any security features to the Java platform.
6. Which of the following is not a feature of Beans?
a) Introspection
b) Events
c) Persistence
d) Serialization
Answer: d
Clarification: Serialization is not the feature of Java Beans. Introspection, Customization, Events, Properties and Persistence are the features.
7. What is the attribute of java bean to specify scope of bean to have single instance per Spring IOC?
a) prototype
b) singleton
c) request
d) session
Answer: b
Clarification: Singleton scope of bean specifies only one instance per spring IOC container. This is the default scope.
8. Which attribute is used to specify initialization method?
a) init
b) init-method
c) initialization
d) initialization-method
Answer: b
Clarification: init-method is used to specify the initialization method.
<bean id = "helloWorld" class = "com.bean.HelloWorld" init-method = "init" />
9. Which attribute is used to specify destroy method?
a) destroy
b) destroy-method
c) destruction
d) destruction-method
Answer: b
Clarification: destroy-method is used to specify the destruction method.
<bean id = "helloWorld" class = "com.tutorialspoint.HelloWorld" destroy-method = "destroy" />
10. How to specify autowiring by name?
a) @Qualifier
b) @Type
c) @Constructor
d) @Name
Answer: a
Clarification: Different beans of the same class are identified by name.
-
@Qualifier("student1")
-
@Autowired
-
Student student1;