[go: up one dir, main page]

0% found this document useful (0 votes)
51 views15 pages

Modified Ass M

The document contains multiple choice questions related to Java programming concepts like JSP, Servlets, JDBC, JUnit etc. It asks about topics like number of outputs from a JSTL code snippet, ResultSet functionality, Servlet lifecycle management, Java Stream API methods and more. The correct answers to the questions are also provided as options to select from.

Uploaded by

Uttara B
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views15 pages

Modified Ass M

The document contains multiple choice questions related to Java programming concepts like JSP, Servlets, JDBC, JUnit etc. It asks about topics like number of outputs from a JSTL code snippet, ResultSet functionality, Servlet lifecycle management, Java Stream API methods and more. The correct answers to the questions are also provided as options to select from.

Uploaded by

Uttara B
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

1.How many numbers get printed when the following JSTL code fragment is executed?

<%@ tagliburi=https://java.sun.com/jsp/jstl/core prefix=”c%”>


<c:set var=”item”value=”2”/>
<c:choose>
<c:when test=”${item>0}”>
<c:out value=”1”/>
</c:when>
<c:when test=”${item==2}”>
<c:out value=”2”/>
</c:when>
<c:when test=”${item<2}”>
<c:out value=”3”/>
</c:when>
<c:otherwise>
<c:out value=”4”/>
</c:otherwise>
</c:choose>

Options :
1. No Number gets printed
2. One number gets printed
3. Two numbers gets printed
4. Three numbers gets printed

You want all clients using XYZ to use the same instance (only one) of class XYZ , what
should you do to achieve this goal?
1. Mark class XYZ final
2. Mark class XYZ abstract
3. Apply the Singleton design pattern to class XYZ
4. Apply the Factory Method design pattern to class XYZ
2.What gets printed when the following JSTL code fragment is executed ?
%@taglib uri=”http://java.sun.com/jsp/jstl/core”prefix=”c”%
<c:forEach var=”item”begin=”0” end=”12”step=”3”>
${item}
</c:forEach>
1. 0,3,6,9,12
2. 3,6,9,12
3. 0,6,9,12
4. 0,3,6,9

This example of prepared statement interface that _________________


PreparedStatementstmt=con.prepareStatement(“select *from emp”);
ResultSetrs=stmt.executeQuery();
While(rs.next()){
System.out.println(rs,getInt(1)+” “+rs.getString(2));
}

1. Deletes the record


2. Retrieves the record
3. Updates the record
4. Inserts the record

Which type of Statement can execute parameterized queries ?


1. PreparedStatement
2. Parameterized Statement
3. ParameterizedStatement and Callable Statement
4. All kinds of Statements

Which of the following means that the ResultSet can only read ?
1. ResultSet.CONCUR_READ_ONLY
2. ResultSet.CONCUR_UPDATABLE
3. ResultSet.READ_ONLY
4. ResultSet.UPDATABLE
In the Snippet below, what line of code needs to be added to move the cursor to the 3 rd
row in the resultset?
Class.forName(“oracle.jdbc.driver.OracledDriver”);
Connectioncon=DriverManager.getConnection(“jdbc:oracle:thin@localhost:1521:xe”,”syst
em”,”oracle”);
Statement
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDAT
ABLE);
ResultSetrs=stmt.executeQuery(“select*from emp765”);

1. Rs.move(3);
2. Rs.next(3);
3. Rs.absolute(3);
4. Rs.getstring(3);

What happens if you call the method close() on a ResultSet object?


1. The method close() does not exist for a ResultSet. Only Connections can be closed.
2. The database and JDBC resources are released.
3. You will get a SQLException , because only Statement objects can close ResultSets
4. The ResultSet , together with the statement which created it and the connection
from which the statement was retrieved Closall(), will be closed and released
database and JDBC resources

How do you know in your Java program that an SQL warning generated as a result of
executing and SQL statement in the database?
1. You must catch the checked SQLException which is thrown by the method which
executes the statement.
2. You must Catch the unchecked SQLWarningException which is thrown by the
method
3. You must invoke the getWarnings() method on the statement object (or a sub
interface thereof)
4. You must query the ResultSet object about possible warnings generated by the
database
You are creating a class diagram using UML and you need to show that one of your classes
is an abstract clas. How would you do that ?
1. Underline the name of the class In the diagram
2. Draw a dotted line between it and the other classes
3. Use italics for the name of the class
4. Draw an arrow with a hallow diamond head between it and the other classes.

You should use the sequence diagram to ________


1. Indicate how objects interact and in what order in a given situation
2. Describe how objects related with each other
3. Represent what actions external users can perform by interacting with the system
and it’s environment
4. Indicate the overall structure of a system and their dependencies and interfaces
2.You need to provide a way to access the elements of an aggregate object sequentially,
without exposing the underlying representation, should you apply?
1. Builder
2. Iterator
3. Observer
4. Command

3.The sendError method defined in the HttpServletResponse class is equivalent to


invoking the setStatus method using which one of the following parameters?

1. SC_OK
2. SC_CREATED
3. SC_NOT_FOUND
4. SC_CONTINUE
4. If in test.jsp:
\${3+2-1:}${3+2-1}
What is the Output?

1. \${3+2-1}:4
2. \$4:4
3. 4:4
4. \4:4
5.The Lifecycle of a servlet is managed by:
1. Servlet context
2. Servlet container
3. The Supporting protocol (such as http or https)
4. None of the above

6. A JSP page uses the java.util.ArrayList class many times. Instead of referring the class by
its complete package name each time, we want to just use ArrayList. Which attribute of
page directive must be specified to achieve this? Select the one correct

1. Extends
2. Include
3. Package
4. Import
7. Which of the following does not include getAttribute () method?
1. Httpsession
2. ServletRequest
3. ServletContext
4. ServletConfig

8. To send text output in a response, which of the following method of HttpServletResponse


may be used to get the appropriates Writer/Stream object

1. getOutputStream
2. getBinaryStream
3. getWriter
4. getStream

9. Which file is used for servlet Configuration?


1. Config.xml
2. Web.xml
3. System.xml
4. Servlet.xml
10. You can only use a servlet if it is installed on _____________
1. Internet
2. Client
3. Server
4. Browser

11. Identify the Location of compiled class files within a war file ?
1. /META-INF/classes
2. /classes
3. /WEB-INF/classes
4. D,/root/classes

12. Which of the following cannot be used as the scope when using a JavaBean with JSP?
1. Application
2. Session
3. Response
4. Request

13. What is the effect of executing the following JSP statement , assuming a class with
name Employee exists in classes package?

%@page import = “classes.Employee”%


<jsp:useBean id = “employee”class=”classes.Employee “scope=”session”/>
<jsp:setProperty name=”employee” property=”*”/>

1. The code does not compile as there is no property attribute of setProperty tag.
2. The code does not compile as the property attribute cannot take * as a value
3. The code sets value of all properties of employee bean to “*”.
4. The code sets the values of all properties of employee bean matching parameters in
request object
14. What are the mechanisms available in ServletContextListener Interface?
1. contextInt().contextService(),contextDestroy()
2. contextInitialized(),contextDestroy()
3. contextInitialized(),contextService(),ContextDestroyed()
4. contextInitialized(), contextService()

15. Which listener is used to process context creation and destruction?


1. ServletContextListener
2. ServletContextAttributeListener
3. HttpContextListener
4. All of the above

16. The task authentication blocking of requests ,data compression, logging and auditing
are performed by _________

1. Servlet filter
2. Servlet Config
3. Servlet Context
4. Servlet Container
17. What is the output of following code?

Public class NameRuleTest {


@Rule
Public TestName name = new TestName();

@Test
Public void testA() {
System.out.println(name.getMethodName());
assertEquals(“testA”, name .getMethodName());
}

@Test
Public void testB() {
System.out.println(name.getMethodName());
assertEquals(“testB”,name.getMethodName());
}
}

1. TestA,testB
2. testBtestA
3. testA compile error
4. testB compile error

18. Which of the following annotations causes that method run once before any of the
test methods in the class ?

1. @Test
2. @Before
3. @BeforeClass
4. @AfterClass
19. Pick the correct Java Stream API’s?

1. Stream.allMatch
2. Stream.noneMatch
3. Stream.anyMatch
4. All the above

20. What is the command line tool introduced for JS engine in Java 8?
1. Jjs
2. Jss
3. Jfs
4. Jbd
31. Which class is introduced in Java 8 to get the current milliseconds?
a) Clock
b) Current Time
c) Date Time
d) Time
32. Which is the correct Java code snippet to be used to create a Functional Interface ?
a) Interface MyFunctionalInterface implements Functional {
b) “@FunctionalInterface interface MyFunctionalInterface {“
c) “@Functional interface MyFunctionalInterface {“
33. Pick the class that is NOT part of Java collection framework.
a) Map
b) List
c) Queue
d) Struct
34. In Java, Which of these class types supports sequential and parallel processing of data?
a) Queue
b) Lambda
c) ExecutorService
d) Streams
35. Which Java Set implementation is sorted and synchronized?
a) TreeSet
b) LinkedHashSet
c) HashSet
d) ConcurrentSkipListSet
36. Which of the following statements is NOT correct for JVM?
a) JVM acts as a translator that translates different Machine code (on the basis of Host
Machine) for a common Byte Code.
b) JVM is a Virtual Machine that acts as a intermediary between Java Application and Host
Operating System.
c) JVM reads Byte Code and generates Machine Code.
d) JVM reads Source Code and generates Byte Code.

37. Is the following a valid Java code Snippet?


Optional < String >aValue = Optional.of (“Not Empty”);
If (aValue.ifPresent()) {
System.out.print1n( “Got Not Empty”);
}
a) True
b) False

38. Java Stream does NOT store the elements. It simply performs the aggregate operations
to get the desired stream of data.
a) True
b) False

39. Which Java class is used to apply reduction or aggregate functions on streams?
a) Filters
b) Reduction
c) Collectors
40. Java system properties can be set or modified at runtime.
a) True
b) False

41. Identify the parts of lambda expression in Java.


i. Name
ii. Parameter list
iii. Body
iv. Return Type
a) i
b) iv
c) i and iv
d) ii and iii

42. Which of the following statements are true about Java?


i. A finally block is executed, only after the catch block is executed.
ii. A finally block is executed whether an exception is thrown or not.
iii. A finally block is NOT mandatory.
iv. A finally block is executed, only if an exception occurs.
a) i
b) iv
c) i and iv
d) ii and iii

43. What is the basis for equality state in Java IdentityHashmap?


a) HashCode and equals
b) Name
c) Reference

44. Which of the following terminologies are typically used with regards to AOP?
A. Concerns
B. Advice
C. Float
D. Pointcut
a) A, B, and D
b) A, C, and D
c) A, B, and C
d) B, C, and D
45. Fill in the blank.
The use of Autodiscovery and Autowire will reduce the amount of ___________.
a) Java code generated
b) Methods generated
c) XML Spring configurations
d) <bean> elements

46. Which of these is a standard Java Interface?


a) Serializable
b) Long
c) System
d) Collections
47. Dependency Injection (DI) or Inversion of Control (IOC) is based on which Hollywood
principle ?
a) Do not call us. We will call you.
b) Understand the problem first.
c) The customer is always right.
d) What you see is what you get.

48. From where does the Spring container gets its instructions?
A. Properties File
B. Spring JARS
C. XML File
D. Annotations
a) A and C
b) C and D
c) B and D
d) A and D

49. Fill in the blank.


The use of the prototype scope is recommended for ______________ type of beans.
a) Stateless
b) Stateful
c) Restless
d) Restful

50. Which is the alternative to create, load, and manage beans in a Spring Application?
a) ApplicationFactory
b) ContextFactory
c) BeanFactory
d) SpringBeanFactory

51. The Dependency Lookup is a methodology where we get the resource after demand.
There can be various ways to get the resource. Types of Dependency Lookup include:
a) Factory Method
b) JNDI Method
c) Key Word Method
d) All of the above

52. To use java.util.List,what is the Spring Collections element that you need?
a) <list>
b) <List>
c) <lists>
d) <util:list>

53. Fill in the blanks:


Java- based configuration allows bean definition and Spring configuration to move out of
_________.
a) XML files
b) Java code
c) Property files
d) All of the above

54. Which one of these statements about XML declaration of transaction manager bean is
NOT true?
a) The tx namespace provides JTA transaction manager declaration shortcut syntax.
b) The Id of the bean has to be transactionManager.
c) Depending on the application persistence technology, the HibernateTransactionManager
or the DataSourceTranasctionManager could be used as bean class.
d) A default transaction timeout could be given.

55. Which one of the following is one of the challenge of Traditional Transaction
Management?
a) Transaction Management at Database Connection Level
b) Programmatic Management of Transactions
c) Error-Prone Connection Management
d) All of the above

56. What does the JDBC Template users to connect to the database?
a) A simple java bean with connection properties
b) A data source bean configuration
c) An XML with DB connection parameters
d) A jdbc connection object

58. How many types of autowiring modes are supported in Spring?


a) Three
b) Five
c) Six
d) Four
59. In the following example, what type of autowire will be used?
@Autowired(required=false)
Public EmployeeAutowiredByConstructorService(@Qualifier(“employee”) Employee
emp) {
This.employee=emp;
}
a) ByName
b) ById
c) @Autowired
d) Constuctor

60. What annotation wiring element is added to scan packages to find and register beans
within the Application Context?
a) <context:annotation-config/>
b) <context:annotation-scan/>
c) <context:component-config/>
d) <context:component-scan>

You might also like