Java MCQ Number 01100

Java MCQ Set 1

1. PointCut definitions can’t be reused again
a) True
b) False

Answer

Answer: b [Reason:] Like many other AOP implementations, AspectJ also allows you to define a pointcut independently to be reused in multiple advices.

2. Annotation used to refer poincuts?
a) @Pointcut
b) @PointcutExecution
c) @PointcutBefore
d) None of the mentioned

Answer

Answer: a [Reason:] In an AspectJ aspect, a pointcut can be declared as a simple method with the @Pointcut annotation.

3.

   package com.apress.springrecipes.calculator;
   import org.aspectj.lang.annotation.Aspect;
   import org.aspectj.lang.annotation.Pointcut;
   @Aspect
   public class CalculatorPointcuts 
   {
	@Pointcut("execution(* *.*(..))")
public void loggingOperation() {}
   }
 
   package com.apress.springrecipes.calculator;
   @Aspect
public class CalculatorLoggingAspect 
{
   ...
   @Before("CalculatorPointcuts.loggingOperation()")
   public void logBefore(JoinPoint joinPoint) 
   {
   ...
   }
   @AfterReturning(
   pointcut = "loggingOperation()",
   returning = "result")
   public void logAfterReturning(JoinPoint joinPoint, Object result)
   {
   throw new IllegalArgumentException();
   }
   @AfterThrowing(
   pointcut = "CalculatorPointcuts.loggingOperation()",
   throwing = "e")
   public void logAfterThrowing(JoinPoint joinPoint, IllegalArgumentException e)
   {
   ...
   }
   @Around("CalculatorPointcuts.loggingOperation()")
   public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable 
   {
   ...
   }
}

Output?
a) Runtime Error
b) IllegalArgument Exception
c) BeanCreation Exception
d) None of the mentioned

Answer

Answer: c [Reason:] When you refer to this pointcut, you have to include the class name as well. If the class is not located in the same package as the aspect, you have to include the package name also.

4. Language used to set various kinds of join points
a) AspectJ pointcut language
b) Java pointcut language
c) XML pointcut language
d) None of the mentioned

Answer

Answer: a [Reason:] The AspectJ pointcut language is a powerful expression language that can match various kinds of join points.

5. Spring AOP only supports method execution join points for the beans in its IoC container
a) True
b) False

Answer

Answer: a [Reason:] If you use a pointcut expression out of this scope, an IllegalArgumentException will be thrown.

6. Is the following pointcut expression correct?
execution(* ArithmeticCalculator.*(..))
a) Yes
b) No
c) If every target class is in same package
d) Depends where target class is located

Answer

Answer: c [Reason:] You can omit the package name if the target class or interface is located in the same package as this aspect.

7. The annotations must be added to the implementation class but not the interface
a) True
b) False

Answer

Answer: a [Reason:] Annotations must be added to the implementation class but not the interface, as they will not be inherited.

8. Which of the following pattern is used to match bean name?
a) bean(*Calculator)
b) bean(Calculator)
c) bean(com.appress.spring.Calculator)
d) None of the mentioned

Answer

Answer: a [Reason:] The following pointcut expression matches beans whose name ends with Calculator.

9. Bean name patterns are supported by all configurations(XML,Java,AspectJ)
a) True
b) False

Answer

Answer: b [Reason:] This pointcut type is supported only in XML-based Spring AOP configurations, not in AspectJ annotations.

10. Expressions which returns Parameters of pointcuts?
a) target
b) args
c) none of the mentioned
d) all of the mentioned

Answer

Answer: d [Reason:] The expressions target() and args() capture the target object and argument values of the current join point and expose them as pointcut parameters.

11. Are logical operators valid in pointcut expressions?
a) Yes
b) No

Answer

Answer: a [Reason:] In AspectJ, pointcut expressions can be combined with the operators && (and), || (or), and ! (not).

12. Method which checks if all target classes are matched
a) matches()
b) pair()
c) matchTargetClass()
d) none of the mentioned

Answer

Answer: a [Reason:] If the matches() method always returns true, all target classes will be matched.

13. Spring supports operations on pointcuts:-
a) notably
b) union
c) intersection
d) all of the mentioned

Answer

Answer: d [Reason:] Union means the methods that either pointcut matches.
Intersection means the methods that both pointcuts match.
Union is usually more useful.

14. Pointcuts can be composed using:-
a) org.springframework.aop.support.Pointcuts class
b) composablePointcut class
c) all of the mentioned
d) none of the mentioned

Answer

Answer: c [Reason:] Using the static methods in the org.springframework.aop.support.Pointcuts class, or using the ComposablePointcut class in the same package.

15. Pointcut used to parse an AspectJ pointcut expression string
a) org.springframework.aop.aspectj.AspectJExpressionPointcut
b) org.springframework.aop.aspectj.AspectJExpressionPointcutString
c) org.springframework.aop.aspectj.AspectJExpressionString
d) org.springframework.aop.aspectj.AspectJPointcuttoString

Answer

Answer: a [Reason:] Since 2.0, the most important type of pointcut used by Spring is org.springframework.aop.aspectj.AspectJExpressionPointcut. This is a pointcut that uses an AspectJ supplied library to parse an AspectJ pointcut expression string.

Java MCQ Set 2

1. Spring supports most of the popular ORM (or data mapper) frameworks.
a) Hibernate
b) JDO
c) JPA
b) All of the mentioned

Answer

Answer: d [Reason:] Spring supports most of the popular ORM (or data mapper) frameworks, including Hibernate, JDO, iBATIS, and the Java Persistence API (JPA).

2. ORM which isn’t supported by Spring:-
a) Hibernate
b) JDO
c) TopLink
b) All of the mentioned

Answer

Answer: d [Reason:] Classic TopLink isn’t supported starting from Spring 3.0 (the JPA implementation’s still supported, of course).

3. An ORM framework persists your objects according to the mapping metadata you provide.
a) True
b) False

Answer

Answer: a [Reason:] XML- or annotation-based, such as the mappings between classes and tables, properties and columns, and so on.

4. Database Engine which uses low memory consumption and easy configuration.
a) SQL
b) MySQL
c) Apache Derby
d) None of the mentioned

Answer

Answer: c [Reason:] Derby is an open source relational database engine provided under the Apache License and implemented in pure Java.

5. Mode which Derby prefers to run in:-
a) embedded
b) client/server
c) all of the mentioned
d) none of the mentioned

Answer

Answer: c [Reason:] Derby can run in either the embedded mode or the client/server mode.

6. For testing purposes, the client/server mode is more appropriate.
a) True
b) False

Answer

Answer: a [Reason:] It allows you to inspect and edit data with any visual database tools that support JDBC—for example, the Eclipse Data Tools Platform (DTP).

7. To start the Derby server in the client/server mode.
a) startNetworkServer java file
b) startNetworkServer script
c) startNetwork script
d) all of the mentioned

Answer

Answer: b [Reason:] To start the Derby server in the client/server mode, just execute the startNetworkServer script for your platform (located in the bin directory of the Derby installation).

8. JDBC Properties for Connecting to the Application Database.
a) Driver Class
b) URL
c) Username
d) All of the mentioned

Answer

Answer: d [Reason:] JDBC Properties for Connecting to the Application Database
Property Value
Driver class org.apache.derby.jdbc.ClientDriver
URL jdbc:derby://localhost:1527/vehicle;create=true
Username app
Password app

9. The general purpose of the Data Access Object (DAO) pattern is to avoid these logic related problems by separating data access logic from business logic and presentation logic.
a) True
b) False

Answer

Answer: a [Reason:] This pattern recommends that data access logic be encapsulated in independent modules called data access objects.

10. To access the database with JDBC:-
a) DAO interface
b) DAO Class
c) DataAccess interface
d) None of the mentioned

Answer

Answer: a [Reason:] Because your DAO implementation has to connect to the database to execute SQL statements, you may establish database connections by specifying the driver class name, database URL, username, and password.

11. Standard interface defined by the JDBC specification that factories Connection instances.
a) javax.sql.DataAccess
b) javax.sql.DataSource
c) javax.sql.Data
d) javax.sql.DataSourceAccess

Answer

Answer: b [Reason:] The javax.sql.DataSource interface is a standard interface defined by the JDBC specification that factories Connection instances.

12. Data source implementations provided by different vendors and projects.
a) C3PO
b) Apache Commons DBCP
c) All of the mentioned
d) None of the mentioned

Answer

Answer: c [Reason:] C3PO and Apache Commons DBCP are popular open source options, and most applications servers will provide their own implementation.

13. Spring also provides several convenient but less powerful data source implementations.
a) DriverManagerDataSource
b) DriverManagerData
c) DriverManagerDataAccess
d) DriverManagerDataSourceAccess

Answer

Answer: a [Reason:] The simplest one is DriverManagerDataSource, which opens a new connection every time one is requested.

14. SingleConnectionDataSource (a DriverManagerDataSource subclass). As its name indicates, this maintains only a single connection.
a) True
b) False

Answer

Answer: a [Reason:] Another data source implementation provided by Spring is SingleConnectionDataSource (a DriverManagerDataSource subclass). As its name indicates, this maintains only a single connection that’s reused all the time and never closed.

15. Which DataSource is not stable in MultiThreaded Environment?
a) DriverManagerDataSource
b) SingleConnectionDataSource
c) All of the mentioned
d) None of the mentione

Answer

Answer: c [Reason:] As its name indicates, this maintains only a single connection that’s reused all the time and never closed. Obviously, it is not suitable in a multithreaded environment.

Java MCQ Set 3

1. Which of the following is used to convert property values to text Values?
a) property Editor
b) property setter
c) property getter
d) none of the mentioned

Answer

Answer: a [Reason:] A property editor is a feature of the JavaBeans API for converting property values to and from text values.

2. Which property editor is used to specify a URL String for a propertyof the URL type?
a) java.net.*
b) java.io.*
c) java.net.URL
d) none of the mentioned

Answer

Answer: c [Reason:] Spring will automatically convert the URL string into a URL object and inject it into your property.

3. Which interface is used to create your own property editors?
a) CustomEditorConfigurer
b) RegisterCustomEditor
c) PropertyEditorConfigurer
d) None of the mentioned

Answer

Answer: a [Reason:] The CustomEditorConfigurer is implemented as a bean factory post processor for you to register your custom property editors before any of the beans get instantiated.

4. Which of the following property editors are registered by Spring?
a) CustomNumberEditor
b) FileEditor
c) CustomDateEditor
d) CustomNetEditor

Answer

Answer: b [Reason:] ClassEditor, FileEditor, LocaleEditor, and URLEditor are preregistered by Spring, so you don’t need to register them again.

5. What are the ways to create custom Property Editors?
a) implement PropertyEditor interface
b) extend PropertyEditorSupport Class
c) none of the mentioned
d) all of the mentioned

Answer

Answer: d [Reason:] You can write custom property editors by implementing the java.beans.PropertyEditor interface or extending the convenient support class java.beans.PropertyEditorSupport.

6. Method which converts property into a string value
a) getAsText
b) setAsText
c) regText
d) None of the mentioned

Answer

Answer: a [Reason:] The getAsText() method converts a property into a string value.

7. Method that converts string into a property value
a) getAsText
b) setAsText
c) regText
d) None of the mentioned

Answer

Answer: b [Reason:] The setAsText() method converts a string back into a property.

8. The property value is retrieved by:-
a) getValue method
b) setValue method
c) none of the mentioned
d) all of the mentioned

Answer

Answer: d [Reason:] The property value is retrieved and set by calling the getValue() and setValue() methods.

9. For a property editor to be searched correctly, it must be located in the same package as the target class, and the name must be Editor’s name
a) True
b) False

Answer

Answer: b [Reason:] The name must be target class name with Editor as its suffix.

10. Which package is used for periodic work
a) java.lang.Thread
b) java.util.TimerTask
c) java.util.Timer
d) java.util.concurrent

Answer

Answer: b [Reason:] Java 1.3 saw the introduction of java.util.TimerTask to support doing some sort of work periodically.

11. Which subinterface provides functionality for managin Threads and their events
a) ExecutorService
b) ThreadService
c) All of the mentioned
d) None of the mentioned

Answer

Answer: a [Reason:] ExecutorService, a subinterface, provides more functionality for managing threads and providing support for raising events to the threads, such as shutdown().

12. Method provided by ExectuorService which returns a Future < T >
a) submit
b) publish
c) addService
d) registerService

Answer

Answer: a [Reason:] ExecutorService, a subinterface, provides more functionality for managing threads and providing support for raising events to the threads, such as shutdown().

13. Which method provided by ExecutorService is used to check whether job is finshed or cancelled
a) Future.isDone()
b) Future.isCancelled()
c) None of the mentioned
d) All of the mentioned

Answer

Answer: d [Reason:] You can call Future.isDone() or Future.isCancelled() to determine whether the job is finished or cancelled, respectively.

14. The Quartz intergration and message driven POJO container doesn’t needs TaskExec utor Services
a) True
b) False

Answer

Answer: b [Reason:] The TaskExecutor interface is used quite a bit internally in the Spring framework.

15. Which of the following class’s instance is used by TimerTaskExecutor for managing jobs
a) java.util.Timer
b) java.util.Date
c) java.util.HashMap
d) none of the mentioned

Answer

Answer: a [Reason:] TimerTaskExecutor uses a java.util.Timer instance and manages jobs (java.util.concurrent.Callable or java.lang.Runnable instances) for you by running them on the Timer.

Java MCQ Set 4

1. Which of the following is used to convert property values to text Values?
a) property Editor
b) property setter
c) property getter
d) none of the mentioned

Answer

Answer: a [Reason:] A property editor is a feature of the JavaBeans API for converting property values to and from text values.

2. Which property editor is used to specify a URL String for a propertyof the URL type?
a) java.net.*
b) java.io.*
c) java.net.URL
d) none of the mentioned

Answer

Answer: c [Reason:] Spring will automatically convert the URL string into a URL object and inject it into your property.

3. Which interface is used to create your own property editors?
a) CustomEditorConfigurer
b) RegisterCustomEditor
c) PropertyEditorConfigurer
d) None of the mentioned

Answer

Answer: a [Reason:] The CustomEditorConfigurer is implemented as a bean factory post processor for you to register your custom property editors before any of the beans get instantiated.

4. Which of the following property editors are registered by Spring?
a) CustomNumberEditor
b) FileEditor
c) CustomDateEditor
d) CustomNetEditor

Answer

Answer: b [Reason:] ClassEditor, FileEditor, LocaleEditor, and URLEditor are preregistered by Spring, so you don’t need to register them again.

5. What are the ways to create custom Property Editors?
a) implement PropertyEditor interface
b) extend PropertyEditorSupport Class
c) none of the mentioned
d) all of the mentioned

Answer

Answer: d [Reason:] You can write custom property editors by implementing the java.beans.PropertyEditor interface or extending the convenient support class java.beans.PropertyEditorSupport.

6. Method which converts property into a string value
a) getAsText
b) setAsText
c) regText
d) None of the mentioned

Answer

Answer: a [Reason:] The getAsText() method converts a property into a string value.

7. Method that converts string into a property value
a) getAsText
b) setAsText
c) regText
d) None of the mentioned

Answer

Answer: b [Reason:] The setAsText() method converts a string back into a property.

8. The property value is retrieved by:-
a) getValue method
b) setValue method
c) none of the mentioned
d) all of the mentioned

Answer

Answer: d [Reason:] The property value is retrieved and set by calling the getValue() and setValue() methods.

9. For a property editor to be searched correctly, it must be located in the same package as the target class, and the name must be Editor’s name
a) True
b) False

Answer

Answer: b [Reason:] The name must be target class name with Editor as its suffix.

10. Which package is used for periodic work
a) java.lang.Thread
b) java.util.TimerTask
c) java.util.Timer
d) java.util.concurrent

Answer

Answer: b [Reason:] Java 1.3 saw the introduction of java.util.TimerTask to support doing some sort of work periodically.

11. Which subinterface provides functionality for managin Threads and their events
a) ExecutorService
b) ThreadService
c) All of the mentioned
d) None of the mentioned

Answer

Answer: a [Reason:] ExecutorService, a subinterface, provides more functionality for managing threads and providing support for raising events to the threads, such as shutdown().

12. Method provided by ExectuorService which returns a Future < T >
a) submit
b) publish
c) addService
d) registerService

Answer

Answer: a [Reason:] ExecutorService, a subinterface, provides more functionality for managing threads and providing support for raising events to the threads, such as shutdown().

13. Which method provided by ExecutorService is used to check whether job is finshed or cancelled
a) Future.isDone()
b) Future.isCancelled()
c) None of the mentioned
d) All of the mentioned

Answer

Answer: d [Reason:] You can call Future.isDone() or Future.isCancelled() to determine whether the job is finished or cancelled, respectively.

14. The Quartz intergration and message driven POJO container doesn’t needs TaskExec utor Services
a) True
b) False

Answer

Answer: b [Reason:] The TaskExecutor interface is used quite a bit internally in the Spring framework.

15. Which of the following class’s instance is used by TimerTaskExecutor for managing jobs
a) java.util.Timer
b) java.util.Date
c) java.util.HashMap
d) none of the mentioned

Answer

Answer: a [Reason:] TimerTaskExecutor uses a java.util.Timer instance and manages jobs (java.util.concurrent.Callable or java.lang.Runnable instances) for you by running them on the Timer.

Java MCQ Set 5

1. Attribute used by Spring to refresh beans
a) refresh-check-interval
b) refresh-check-delay
c) refresh-delay
d) none of the mentioned

Answer

Answer: b [Reason:] Spring is able to refresh a scripted bean definition from its source once you have specified the checking interval in the refresh-check-delay attribute.

2. Spring IoC container refreshes the script periodically according to the interval period specifed
a) True
b) False

Answer

Answer: a [Reason:] When a method is called on that bean, Spring will check the script source if the specified checking interval has elapsed. Then, Spring will refresh the bean definition from the script source if it has been changed.

3. Default value of refresh-check-delay attribute
a) Zero
b) Negative
c) Positive
d) None of the mentioned above

Answer

Answer: b [Reason:] By default, the refresh-check-delay attribute is negative, so the refresh checking feature is disabled. You can assign the milliseconds for refresh checking in this attribute to enable this feature.

4. XML Element to define an inline script
a) lang:inlinescript
b) lang:inline_script
c) lang:
d) lang:inline-script

Answer

Answer: d [Reason:] You can define an inline script source in the lang:inline-script element of a scripted bean to replace a reference to an external script source file by the script-source attribute.

5. Refresh checking feature is not applicable for an inline script
a) True
b) False

Answer

Answer: a [Reason:] Spring IoC container only loads the bean configuration once, at startup.

6. To prevent the characters in your script from conflicting with the reserved XML characters
a) Use ![CDATA[…]] tag
b) Use ![DATA[…]] tag
c) Use ![CDATA(…)] tag
d) None of the mentioned

Answer

Answer: a [Reason:] You no longer have to specify the reference to the external script source file in the script-source attribute.

7. Dynamic-language-backed bean with some configurations
a) Refreshable bean
b) Beanshell
c) Scripting Beans
d) Inline Script

Answer

Answer: a [Reason:] A refreshable bean is a dynamic-language-backed bean that with a small amount of configuration, a dynamic-language-backed bean can monitor changes in its underlying source file resource, and then reload itself when the dynamic language source file is changed.

8. To quickly add a Spring Validator implementation to a Spring MVC Controller
a) Use inline-script
b) lang:inline-script
c) All of the mentioned
d) None of the mentioned

Answer

Answer: c [Reason:] If we put to one side the issues surrounding whether it is good practice to define dynamic language source inside a Spring configuration file, the lang:inline-script/ element can be useful in some scenarios.

9. Spring can detect and refresh changes from the script source files
a) True
b) False

Answer

Answer: a
Exlanation: Using Refreshing Inline script.

10. Script’s location is specified by attribute
a) script-source
b) xml-source
c) script-annotation
d) none of the mentioned

Answer

Answer: a [Reason:] Specifying the script’s location in the script-source attribute.

ed010d383e1f191bdb025d5985cc03fc?s=120&d=mm&r=g

DistPub Team

Distance Publisher (DistPub.com) provide project writing help from year 2007 and provide writing and editing help to hundreds student every year.