0% found this document useful (0 votes)
585 views131 pages

Dumps

1. The Iterator pattern involves iterating through a collection in sequential order. 2. The Singleton pattern ensures that only one object of a particular class is ever created. 3. JUnit is an open source framework for unit testing Java applications. It provides annotations to identify test methods and assertions to test expected results.

Uploaded by

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

Dumps

1. The Iterator pattern involves iterating through a collection in sequential order. 2. The Singleton pattern ensures that only one object of a particular class is ever created. 3. JUnit is an open source framework for unit testing Java applications. It provides annotations to identify test methods and assertions to test expected results.

Uploaded by

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

1. How to import all package?

Answer : import java.* 6. class output {


public static void main(String args[]){
2. Which of the following is correct String buffer s1 = new
about junit? StringBuffer("Hello world")
Answer: - It is an open source framework. s1.insert(6,"Good");
- It provides Annotation to identify SOP(s1);
the test methods. }
- It provides Assertions for testing }
Expected results
3. Pattern which follows sequential Answer: Hello Goodworld
order? 7. SOP (‘1’+new integer (2) +3);
Answer : Iterator Answer: 123
4. The pattern involves a single class 8. A team of programmer is involved in
which is responsible to create an reviewing a proposed design for a
object while making sure that only new utility class after some
single object gets created? discussion…….
Answer: Singleton Answer: weak encapsulation
5. class Animal 9. Man dog best friend
{ Answer : class man private dog best
public String noise() friend;
{ 10. Bluemix deploy cloud foundry
return "peep"; Answer: cf push
} 11. Class vector {
} PSVM(String args[])
class Dog extends Animal Vector obj = new vector(4,2);
{ Obj.add element(new Interger(3));
public String noice() Obj.add element(new Interger(2));
{ Obj.add element(new Interger(5));
return "bark"; Obj.removeAll(obj);
} SOP(obj.isEmpty());
} }
class cat extends Animal Answer : True
{ 12. <%@ taglib …………….%>
public String noise() <c:set var = “j” value = “4,3,2,1” />
{ <c:foreach item = “${j}” var = “item”
return "meow"; varstatus = “status”>
} <c:if test = “${status.first}”>
} <c:out value = “${status. Index}” default
}..... = “abc”/>
Animal animal = new Dog(); </c:if>
Cat cat= (Cat)animal; </c:foreach>
SOP(cat.noise()); Answer: 1
Answer : Exception is thrown at the Runtime
13. StringBuffer s1 = new 19. Java.util.enumeration is an example
StringBuffer(“Hello”); of which pattern?
StringBuffer s2 = reverse(s1); Answer : Iterator
SOP(s2); 20. Aggregation represent in UML?
Answer : olleH Answer : hollow diamond on the
14. Chain…cf..whch filter user? collection side
Answer: cf.doFilter() 21. Composition represent in UML?
15. How to access the resultsetobject? Answer : Filled diamond on the side of
Answer : by using special getter the collection
method….. 22. Generalization represent in UML?
16. X= something Answer : hollow triangle shape on the
While(X<10&&x>24) superclass end of the line
Answer : condition false 23. Dependency represent in UML?
Answer : dotted line followed by
17. RunWith(Suit.class) 24. 1..* specify about relationship?
@SuiteClasses({ Answer : At least one instance
annotationTest.class, 25. 0..1 Specify about relationship?
AssertTest.class Answer: Zero or one instance. The
CalculateTest.class, notation n..m indicate n to m instances.
EmployeeTest.class}) 26. The relationship between the object
Public class SuiteTest{ and component parts in UML diagram
//the class remains empty are represented by ----------------.
//used only as a holder for the above Answer : Aggregation
annotaition 27. Class x implements Runnable {
} Public static void main(String args[])
What is the sequence of junit test ? {
Answer : AnnotationTest, AsserTest, /*missing code? */
CalculateTest,EmployeeTest }
18. Public static void main(String args[]) Public void run() {
{ }}
List<string> List = new Which of the following line of code to
ArrayList<string>(); start thread?
//add string Answer : x run = new x();
List.add(“cricket”); Thread t = new Thread(run);
List.add(“football”); t.start();
List.add(“hockey”); 28. PSVM()
Iterator it = List.iterator(); {
While(it.hasNext()) try{
{ int a = 5;
String s = it.next(); int b = 0;
} int c = a/b;
} SOP(“World”);
Which pattern }
Answer : Iterator Catch(exception e)
{ C. Two seconds after thread A is
SOP(“hello”); notified.
}} D. Two seconds after lock B is
Answer : hello released.
29. Int a = 10;
Int b = 0; 38. Invoked only once?
Int c = a/b; Answer : @BeforeClass
SOP(“c”); 39. Invoked before each test?
Output : Answer : @Before
Answer: runtime exception not 40. Invoked after each test?
arithmetic exception Answer : @After
30. Which will contain the body of the 41. Only once invoked finishing all tests?
thread? Answer : @AfterClass
Answer : run() 42. Which of the following represents the
31. Which two of the following methods XML equivalent of this statement
are defined in class thread? <%@ include file=”a.jsp”%> . Select
1. Start() 2. Wait() 3. Notify() 4. Run() the one correct statement
Answer : start() and run()
32. <%@ ……. %> a. <jsp:include file=”a.jsp”/>
<c:foreach var = “item” begin =”0” end b. <jsp:include page=”a.jsp”/>
=”12” step = “3”> c. <jsp:directive.include
Answer: 0,3,6,9,12 file=”a.jsp”/>
33. A user types on URL which method is There is no XML equivalent of include
called? directive.
Anser : get Method 43. What will be proper order of session?
34. The method getWriter return an Answer : loading, instantiation, init,
object of type PrintWriter? service, destroy
Answer: HttpServletResponse 44. Proper order of access modifier
35. To send binary o/p? Answer : private default protected
Answer : getOutputStream public
36. Unit testing? 45. If the options are iterator servlet etc
Answer : Single Entity answer will be iterator.
37. Assume the following method is 46. If the options will be like
properly synchronized and called New class foo{print(………)},
from a thread A on an object B: Answer: new foo(){print(…………)}
wait(2000); 47. Insert(6, “Good”)
Answer : Hello Good Word
After calling this method, when will the 48. Class{
thread A become a candidate to get PSVM
another turn at the CPU? String str = new String( “…..”);
A. After thread A is notified, or }
after two seconds. Do{
B. After the lock on B is released, str = “Hello Stop World ”;
or after two seconds. SOP(str);
} 55. when you want to know attribute has
While(str!=Strong); added removed or replaced?
{ Answer: HttpSessionAttributeListner
……. 56. when you want to know how many
} users are there?
Answer : Hello Stop World Answer: HttpSessionListner
49. When we use command design 57. listener is noticed initialized and
pattern destroyed?
Answer. when history of requests is Answer: ServletContextListner
needed 58. clear(2) in the string of index 2
50. In use case diagram actor represents? Answer : 0134
Answer: An actor represent a roll that 59. Authentication mechanishm in
an outsider takes on when intracting deployment descriptor?
with the business system for instance, Answer: login-config.
an action can be a customer, a business 60.
partner , a supplier or another business 1. interface TestA { String toString(); }
system 2. public class Test {
3. public static void main(String[] args) {
51. In use case diagram actor represents 4. System.out.println(new TestA() {
____? 5. public String toString() { return "test";
Answer: An actor represents a role that }
an outsider takes on when interacting 6. });
with the business system. 7. }
For instance, an actor can be a 8. }
customer, a business partner, a What is the result?
supplier, or another business system. A. test
52. Common mechanisms for session B. null
tracking C. An exception is thrown at runtime.
Ans. D. Compilation fails because of an error
User authorization in line 1.
Hidden fields E. Compilation fails because of an error
URL rewriting in line 4.
Cookies F. Compilation fails because of an error
Session tracking API in line 5.
53. The code snippet below is an example Answer: A
of which of the following? 61. 2+3*5
Long myLong = 21l; Answer 17 integer
A Autoboxing 17 byte
B Autounboxing 25 byte
C Autocasting 25 integer
D Autoinstancing 62. Identify the correct signature of the
Answer: Autoboxing main method?
54. which listener is used to log the… Answer : public static void main(String
Answer: ServletRequestListner args[])
63. public static void main(String[] args) 70. getvalue(IDEAL)
{ SOP(word.subString(0,word.length()-
GenericTest<String> arr[] = new 1)+word.charAt(word.length()-1))
GenericTest[5]; //line 1 Answer: DEAL
arr[0] = new GenericTest("Java"); 71. in javabean reference id define?
//line 2 a. Classname
arr[1] = new GenericTest(1); b. Package
//line 3 c. Instance
arr[2] = (GenericTest<String>)new d. None
GenericTest(1); //line 4 72. Int x=6;
arr[3] = (GenericTest<String>)new Int y = 12;
GenericTest<Integer>(1); //line 5 If(x>y)
for(GenericTest o:arr) {
{ X++;
System.out.println(o); y--;
} }
} SOP(….);
} Answer: 2
Output: Error in Line 1 73. Datatype of the no 9.6352
64. <c:forToken item = “first, second, Answer: float
third, last;” delims = “,” var = double
“current”> Float
<c:out value = “${current}” /> =? Double
Answer: beforelast 74. Answer: RS.CONCUR_UPDATABLE
75. How many thread one from exception
65. Answer: AaBaaaCaaaa mainclass
66. Multiple exception catch block.. Answer : is only 1 thread(main thread)
Answer : superclass exception can not 76. Start same thread two times
be caught first t1.start()
Can we caught either super class or t1.start()
subclass Answer: compilation fails, compile time
67. Filter life cycle error
Answer: init() dofilter() destroy() 77. Behavior of UML diagram?
68. /${3+2-1}:${3+2-1} Answer: a. usecase
Answer: a. /${3+2-1}:4 b. object
b. 4:4 c. profile
c. /4:4
78. Decouples in which design pattern?
69. l.add(2) Answer: Bridge
l.add(5) 79. String s1 = abc;
l.add(8) String s2 = def;
l.add(1) String s3 = s1. concat(s2.UpperCase)
l.reverse(); Answer:: abcdefabcDEF
Answer: 1852 80. HttpServlet supports
a. http SOP(“finally”)
b. https }
c. both }
d. none Output :
81. what is the output of this program Answer if a,b not initialized then error
class output{ and if b = 0; then compile time error
public static void main(String args[]) with finally will work.
{ 85. Current thread
Object obj = new object(); Public class MyRunnable implements
System.out.print(obj.getclass()); runnable {
}} Public void run()
Answer: class java.lang.object {
82. declare array of string //some code
string[]s; }
string s[] }
string []s;b Which of these will create and start this
Answer: ABD thread?
83. class A{ Answer:
int i; new Thread(new MyRunnable()).start();
int j; 86. When we use command desig
A(){ pattern?
I =1; Answer: when history of request is
J=2; needed
} 87. Xyz-xyz instance (pattern)
} Answer: Singleton
Class output{ Abstract
Public static void main(String args[]) Factory
{ 88. To execute in the parameterized
A obj1 = new A(); statement?
SOP(obj1.toString()); Answer: prepared statement
} 89. Design pattern to limit class instaiated
} to one object?
Answer: String associated with obj1 Answer: Singleton
And output will be A@1cde5f 90. Given
84. public void divide(int a, int ) 10 interface Foo{int bar();}
{ 11 public class sprite{
Try{ 12 public int fubar(Foo foo){return
Int c = a/b; foo.bar();}
} 13 public void testFoo(){
Catch(Exception e) 14 fubar(
{ 15 //insert code here
SOP(Exception); 16 );
} 17 }}
Finally{
Answer: new Foo(){public int System.out.println("In the
bar(){return 1;}} loop");
91. A: unit testing is the testing of single a+=2;
entity b-=2;
B: unit testing is the process of checking }
the functionality of the application answer- In the loop
whether it is working as per In the loop
requirements 96. abstract class xyz
Options : {
a. A is true abstract abc (int a, int b) { }
b. B is true }
c. Both are true
d. None of the above - What sort of compilation error you will
What will be the output of this - get ?
- How to fix the compilation error
92. String river = new String("TRAINING"); Answer-- give return type void. and remove
System.out.println(river.length()); empty parenthesys.
answer-8 97. interface ATOB {
String s = "yo";
93. String getValue(String word) public void meth();
{ }
if (word.length() == 1) interface BTOC { }
return "";
else interface C extends ATOB, BTOC {
return getValue( word.substring(0, public void meth();
word.length() - 1) ) + public void meth(int x);
word.charAt(word.length() - 1);
}
}
- Will this compile ?
What is the value of the string answer--- interface can also be extended (when
returned by getValue("DEMOS") inheriting from two interfaces.)
98. int i = -1;
Answer: EMOS int b = 10;
int val = b/ i;
94. public class Question { answer- -10
public static void main(String args[]) { interface Data { public void load(); }
String s1 = "uvw"; abstract class Info { public abstract void
String s2 = "xyz"; load(); }
String s3 = s1.concat(s2.toUpperCase( ) 99. How Can i inherit both the interface
); and abstract class ?
System.out.println(s1+s2+s3); answer= class xyz extends Info implements
}} interface{ void load}
answer: uvwxyzuvwXYZ
95. int a = 9; 100. public class GenericTest<G> {
int b = 14; G g;
while(a<b) { GenericTest(G g){
this.g =g;
} 103. class output {
public static void main(String[] args) public static void main(String args[]){
{ StringBuffer c = new
GenericTest<String> arr[] = new StringBuffer("Hello");
GenericTest[5]; //line 1 StringBuffer c1 = new
arr[0] = new GenericTest("Java"); StringBuffer("World");
//line 2 c.append(c1);
arr[1] = new GenericTest(1); System.out.print(c);
//line 3 }
arr[2] = (GenericTest<String>)new }
GenericTest(1); //line 4 answer-helloworld
arr[3] = (GenericTest<String>)new 104. are resultset updateable?
GenericTest<Integer>(1); //line 5 Answer: yes but only if you indicate a
for(GenericTest o:arr) concurrency strategy when executing
{ the statement and if the driver and
System.out.println(o); database support this option.
} 105. How can you start a database
} transaction in the database
} Answer: by setting the autocommit
Answer-- can not cast <Integer> to <String> property of the connection to false &
line5 execute a statement in the database
106. The object that does not
and default value is null in an array contain the stored procedure itself
but contains only a call to the store
101. class A { procedure?
static String str = Answer: callableStatement
"STRING_IN_A"; 107. To execute a stored procedure
} “total stack” in a database server
class B extends A { which of the following code snipper is
static String str = "STRING_IN_B"; used?
} Answer: callablestatement clbstmnt =
// con.preparecall(“{call totoal stack}”);
in void main cs.executeQuery();
B b1=new B(); 108. Jsp pages have access to
sop b1.str implicit objects that are exposed
// automatically one such object that is
Answer--- will compile fine.bt str is being available is request that request
overwritten in B class. object is an instance of which class?
102. int j=8; Answer: HttpServletRequest
while( (j < 10) && (j > 24)) { 109. Relative path
System.out.println(" Am here"); Answer: c:/test/***
} 110. In class diagram instance are
answer-while() condition is always false represented by using
Answer: Italics SOP(“World”);
111. Which type of driver converts }
jdbc calls into the Network protocol }}
used by the datamanagement Answer: World
system? 120. What get printed when the
Answer: Type 4 following JSTL code program is
112. UML behavior diagram? executed?
Answer: Attribute diagram <%@ taglib uri =
113. SOP(index(i)+index(0)+lastIndex http://java.sun.com/jsp/jstl/core
(i)+lastIndex(0)); prefix = “c” %>
Answer: 6469 <c:forEach var = “item” begin =”0”
114. <c:set var =”j” value = end = “12” step =”3”>
“4,3,2,1”/> ${item}
<c:forEach items = “${j}” var = “item” </c:forEach>
begin=”1” end =”2” Answer: 0,3,6,9,12
Answer: 2 and 3 121. What is the output of this
115. The sendError method defined program?
in the httpservlet class is equivalent Import java.util.*
to invoking the setstatus method with Public static void main(String args[]){
the following parameter. Select the TreeMap obj = new Treemap();
one correct answer: Obj.put(“A”, newInteger(1));
Answer: SC_NOT_FOUND Obj.put(“b”, newInteger(2));
116. When a select statement Obj.put(“c”, newInteger(3));
returns only one record with a single SOP(obj.entrySet());
column of integer datatype on }
invoking resultset getinteger(0) Answer: [A=1,B=2,C=3]
causes_____________ Public class genericstack<E>{
Answer: Stack<E>{
117. A user types the url Stack<E>stk = new stack<E>();
http://www.javaprepare.com/scwd/i }
ndex.html which http request gets }
generated select the one correct 122. Which of the following
answer? describes the purpose of JUnit?
Answer: GET Method A It is a framework to help with
118. Which listener class will close() writing unit tests for your code.
method? B It is a framework to help with
Answer: windowlistner writing code involving unit
119. Class exception_Handling{ conversions.
Public static void main(String args[]){ C It is a framework to help with
Try{ packaging your code into units for
SOP(“Hello”+” ”+1/0); distribution.
} D It is a framework to convert all
Catch(ArithmeticException e) days/dates in your code to June.
{ Answer: A
Answer: getBoolean(),getClob()
123. Which diagram in UML shows a getBlob()
complete or partial view of the 129. class exception_handling {
structure of a modeled system at a public static void main(String args[]) {
specific time? try {
a) Sequence Diagram int a, b;
b) Collaboration Diagram b = 0;
c) Class Diagram a = 5 / b;
d) Object Diagram System.out.print("A");
Answer: d }
catch(ArithmeticException e) {
124. Which of these keywords must System.out.print("B");
be used to monitor for exceptions? }
a) try }
b) finally }
c) throw a) A
d) catch b) B
View Answer c) Compilation Error
Answer: a d) Runtime Error
125. Treemap question and options Ans:B
will be like
(7,9) 130. class A implements foo {
(9,7) 16 foo bar()
17 {
Answer : 7,9 18 Return 1;
126. Testing Amit Gupta and Ravi }
Kumar wala question? }
a) Amit Gupta False Class A implements foo
b)Ravi Kumar False {
c) Amit Gupta False(Expected name 25 foobar()
as Ravi Kumar) 26 {
d)Ravi Kumar False(Expected name as 27 return 2;
Amit Gupta) }
use }
127. Fill in the blank Answer: return 2;
Exception ___________{ If eliminate 16,17,18 return 2
printstack e; If eliminate 25 26 27 return 1
} 131. Which of these handles the
Exception_________{ exception when no catch is used?
printStack e; a. Default handler
} b. Finally
Answer class not found c. Throw handler
Sql exception d. Java run time system
128. Get value from resultset
132. class exception_handling { 134. Why beans are used in J2EE
public static void main(String args[]) { architecture in stead of writing all the
try { code in JSPs ?
int a, b; Answer: (a) Allows separation of roles
b = 0; between web developers and
a = 5 / b; application developers
System.out.print("A"); 135. public class TreeSet {
} public static void main(String args[]){
catch(ArithmeticException e) { //Creating and adding
System.out.print("B"); elements
} TreeSet<Integer>
finally { al=new TreeSet<Integer>();
System.out.print("C"); al.add("7"); //line 5
} al.add(9);
}
} //Traversing elements
a) A Iterator<Integer>
b) B itr=al.iterator();
c) AC while(itr.hasNext()){
d) BC
Answer:BC System.out.println(itr.next());
133. public class Delta }
{ static boolean foo(char c) }
{ }
System.out.print(c);
return true; Answer: compilation error at line 5
}
public static void main( String[] argv 136. Which implementation of set
) would you choose if you want the
{ iterator of set would give you object
int i = 0; in the order it were inserted?
for (foo('A'); foo('B') && (i < 2); LinkedHashSet
foo('C')) TreeSet
{ HashSet
i++; 137. Push(7);
foo('D'); Push(2);
} Pop();
} Push(9);
} Answer: print[7,9]
138. Which operator use to separate
Answer: A. url and attribute?
ABDCBDCB Answer : ?
139. Which operator is used to
separate parameters or attributes?
Anser: & (c) By invoking the method getValue(...),
140. Which method is used to url and cast the result to the desired Java
rewriting? type.
Answer doget method (d) By invoking the special getter methods
141. Delay show in usecase by “Slant on the ResultSet: getString(...),
line” getBoolean (...), getClob(...),...
Answer Slant line for delay
142. (first,two,three,four;,five;) 147. How can you execute DML
delimits(,) statements (i.e. insert, delete, update) in
Answer: firsttwothreefour;five; the database?
(a) By making use of the InsertStatement,
143. Which packages contain the JDBC DeleteStatement or UpdateStatement
classes? classes
(a) java.jdbc and javax.jdbc (b) By invoking the execute(...) or
(b) java.jdbc and java.jdbc.sql executeUpdate(...) method of a normal
(c) java.sql and javax.sql Statement object or a sub-interface
(d) java.rdb and javax.rdb object
thereof
144. Which type of driver provides JDBC (c) By invoking the executeInsert(...),
access via one or more ODBC drivers? executeDelete(...) or executeUpdate(...)
(a) Type 1 driver methods of the
(b) Type 2 driver DataModificationStatement object
(c) Type 3 driver (d) By making use of the execute(...)
(d) Type 4 driver statement of the
DataModificationStatement object
145. Which type of driver converts JDBC
calls into the network protocol used by 148. How do you know in your Java
the database management system program that a SQL warning is generated
directly? as a result of executing a SQL statement
(a) Type 1 driver in
(b) Type 2 driver the database?
(c) Type 3 driver (a) You must catch the checked
(d) Type 4 driver SQLException which is thrown by the
method which executes the statement
146. How can you retrieve information (b) You must catch the unchecked
from a ResultSet? SQLWarningException which is thrown by
(a) By invoking the method get(..., String the method which executes the
type) on the ResultSet, where type is the statement
database type (c) You must invoke the getWarnings()
(b) By invoking the method get(..., Type method on the Statement object (or a sub
type) on the ResultSet, where Type is an interface thereof)
object which represents a database (d) You must query the ResultSet object
type about possible warnings generated by the
database
152. How can you start a database
149. What is, in terms of JDBC, a transaction in the database?
DataSource? (a) By asking a Transaction object to your
(a) A DataSource is the basic service for Connection, and calling the method
managing a set of JDBC drivers begin() on it
(b) A DataSource is the Java (b) By asking a Transaction object to your
representation of a physical data source Connection, and setting the autoCommit
(c) A DataSource is a registry point for property of the Transaction to false
JNDI-services (c) By calling the method
(d) A DataSource is a factory of beginTransaction() on the Connection
connections to a physical data source object
(d) By setting the autoCommit property
150. What is the meaning of of the Connection to false, and execute a
ResultSet.TYPE_SCROLL_INSENSITIVE statement in the database
(a) This means that the ResultSet is
insensitive to scrolling 153. What is the meaning of the
(b) This means that the Resultset is transaction isolation level
sensitive to scrolling, but insensitive to TRANSACTION_REPEATABLE_READ
updates, i.e. not updateable (a) Dirty reads, non-repeatable reads and
(c) This means that the ResultSet is phantom reads can occur
sensitive to scrolling, but insensitive to (b) Dirty reads are prevented; non-
changes made by others repeatable reads and phantom reads can
(d) The meaning depends on the type of occur
data source, and the type and version of (c) Dirty reads and non-repeatable reads
the driver you use with this data source are prevented; phantom reads can occur
(d) Dirty reads, non-repeatable reads and
151. Are ResultSets updateable? phantom reads are prevented
(a) Yes, but only if you call the method
openCursor() on the ResultSet, and if the 154. What statements are correct about
driver and database support this option positioned updates (i.e. cursor updates) in
(b) Yes, but only if you indicate a ResultSets? (2
concurrency strategy when executing the correct answers)
statement, and if the driver and database [a] Using the cursor technique is currently
support this option the only possible way to change the data
(c) Yes, but only if the ResultSet is an in the current row of a ResultSet
object of class UpdateableResultSet, and [b] Insert statements are only supported
if the driver and database support when using scrollable cursors.
thisoption [c] Only scrollable updateable ResultSets
(d) No, ResultSets are never updateable. can use this approach to change the data
You must explicitly execute DML in the current row of a ResultSet
statements (i.e. insert, delete and update) [d] The name of the cursor is specified by
to change the data in the underlying the setCursorName(String name) method
database the Statement object.
155. How can you execute a stored [a] To create a batch of insert and update
procedure in the database? statements, you create an object of type
(a) Call method execute() on a Batch, and call the method
CallableStatement object addStatement(String statement) for each
(b) Call method executeProcedure() on a statement you want to execute in the
Statement object batch
(c) Call method execute() on a [b] Batch insert and updates are only
StoredProcedure object possible when making use of
(d) Call method run() on a parameterized queries.
ProcedureCommand object [c] To do a batched update/insert, you
call addBatch(String statement) on a
156. What happens if you call the method Statement object for each statement you
close() on a ResultSet object? want to execute in the batch
(a) the method close() does not exist for [d] To execute a batched update/insert,
a ResultSet. Only Connections can be you call the executeBatch() method on a
closed. Statement object
(b) the database and JDBC resources are
released 159. What is correct about DDL
(c) you will get a SQLException, because statements (create, grant,...)?
only Statement objects can close (a) DDL statements are treated as normal
ResultSets SQL statements, and are executed by
(d) the ResultSet, together with the calling the execute() method on a
Statement which created it and the Statement (or a sub interface thereof)
Connection from which the Statement object
was retrieved, will be closed and release (b) To execute DDL statements, you have
all database and JDBC resources to install additional support files
(c) DDL statements can not be executed
157. What happens if you call by making use of JDBC, you should use
deleteRow() on a ResultSet object? the native database tools for this.
(a) The row you are positioned on is (d) Support for DDL statements will be a
deleted from the ResultSet, but not from feature of a future release of JDBC
the database.
(b) The row you are positioned on is 160. The JDBC-ODBC Bridge supports
deleted from the ResultSet and from the multiple concurrent open statements per
database connection?
(c) The result depends on whether the a. True
property synchronizeWithDataSource is b. False
set to true or false
(d) You will get a compile error: the 162. Which of the following allows non
method does not exist because you can repeatable read in JDBC Connection?
not delete rows from a ResultSet a. TRANSACTION_READ_UNCOMMITTED
b. TRANSACTION_READ_COMMITTED
158. What statements are correct about c. TRANSACTION_SERIALIZABLE
batched insert and updates? (2 answers) d. TRANSACTION_REPEATABLE_READ
167. Which driver is efficient and always
163. Which of the following statements is preferable for using JDBC applications?
false as far as different type of statements a. Type – 4
is concern in JDBC? b. Type – 1
a. Regular Statement c. Type – 3
b. Prepared Statement d. Type – 2
c. Callable Statement
d. Interim Statement 168. JDBC facilitates to store the java
objects by using which of the methods of
164. Which of the following methods are PreparedStatement
needed for loading a database driver in setObject () 2. setBlob() 3. setClob()
JDBC? a. 1, 2
a. registerDriver() method b. 1,2,3
b. Class.forName() c. 1,3
c. Both A and B d. 2,3
d. getConnection()
169. Which statement is static and
165. Which of the following is false as far synchronized in JDBC API?
as type 4 driver is concern? a. executeQuery()
a. Type 4 driver is “native protocol, pure b. executeUpdate()
java” driver c. getConnection()
b. Type 4 drivers are 100% Java d. prepareCall()
compatible
c. Type 4 drivers uses Socket class to 170. The JDBC-ODBC bridge is
connect to the database a. Three tiered
d. Type 4 drivers can not be used with b. Multithreaded
Netscape c. Best for any platform
d. All of the above
166. To execute a stored procedure
“totalStock” in a database server, which 171. All raw data types (including binary
of the following code snippet is used? documents or images) should be read and
a. Statement stmt = uploaded to the database as an array of
connection.createStatement();stmt.execu a. byte
te("totalStock()"); b. int
b. CallableStatement clbstmnt = c. boolean
con.prepareCall("{call d. char
totalStock}");cs.executeQuery();
c. StoreProcedureStatement 172. The class java.sql.Timestamp has its
stmt=connection.createStoreProcedure("t super class as
otalStock()");spstmt.executeQuery(); a. java.sql.Time
d. PrepareStatement pstmt = b. java.util.Date
connection.prepareStatement("totalStock c. java.util.Time
()");pstmt.execute(); d. None of the above
173. BLOB, CLOB, ARRAY and REF type c. 5
columns can be updated in d. 2
a. JDBC 1.0
b. JDBC 4.0 179. Which method is used to perform
c. JDBC 2.0 DML statements in JDBC?
d. JDBC 3.0 a. execute()
b. executeQuery()
174. Which of the following methods c. executeUpdate()
finds the maximum number of d. executeResult()
connections that a specific driver can
obtain? 180. What is the disadvantage of Type-4
a. Database.getMaxConnections Native-Protocol Driver?
b. Connection.getMaxConnections a. At client side, a separate driver is
c. DatabaseMetaData.getMaxConnections needed for each database.
d. b. Type-4 driver is entirely written in Java
ResultSetMetaData.getMaxConnections c. The driver converts JDBC calls into
vendor-specific database protocol
175. Are prepared statements actually d. It does not support to read MySQL
compiled? data.
a. Yes, they compiled
b. No, they are bound by the JDBC driver 181. import java.util.*;
class TestHashMaps{
176. When the message “No Suitable public static void main(String args[]) {
Driver” occurs? HashMap<Integer,String> hm= new
a. When the driver is not registered by HashMap<Integer,String> ();
Class.forname() method hm.put(100, "John");
b. When the user name, password and hm.put(101, "Paul");
the database does not match hm.put(102, "George");
c. When the JDBC database URL passed is hm.put(103, "Ringo");
not constructed properly for (Map.Entrym: hm.entrySet()) {
d. When the type 4 driver is used System.out.println(m.getKey() + " " +
m.getValue());
177. Which driver is called as thin-driver }
in JDBC? }
a. Type-4 driver }
b. Type-1 driver Answer:
c. Type-3 driver 100 John
d. Type-2 driver 101 Paul
102 George
178. How many transaction isolation 103 Ringo
levels are defined in java.sql.Connection
interface? 182. import java.util.Map;
a. 4 import java.util.TreeMap;
b. 3 public class TestTreeMap {
public static void main(String args[]) { Which four statements are true? (Choose
TreeMap< Integer, String > hm= new four.)
TreeMap< Integer, String > (); A. Raccoon is-a Mammal.
hm.put(100, "John"); B. Raccoon has-a Mammal.
hm.put(102, "Paul"); C. BabyRaccoon is-a Mammal.
hm.put(101, "George"); D. BabyRaccoon is-a Raccoon.
hm.put(103, "Ringo"); E. BabyRaccoon has-a Mammal.
for (Map.Entry m: hm.entrySet()) { F. BabyRaccoon is-a BabyRaccoon.
System.out.println(m.getKey() + " " + Answer: A,B,C,F
m.getValue());
} 185. Which Man class properly represents
} the relationship "Man has a best friend
} who is a Dog"?
Answer A. class Man extends Dog { }
100 John B. class Man implements Dog { }
101 George C. class Man { private BestFriend dog; }
102 Paul D. class Man { private Dog bestFriend; }
103 Ringo E. class Man { private Dog<bestFriend>; }
F. class Man { private BestFriend<dog>; }
183.Given: Answer: D
5. import java.util.*;
6. public class SortOf {
7. public static void main(String[] args) { 186. Given:
8. ArrayList<Integer> a = new
ArrayList<Integer>(); 11. class Alpha {
9. a.add(1); a.add(5); a.add(3); 12. public void foo() {
11. Collections.sort(a); System.out.print("Afoo "); }
12. a.add(2); 13. }
13. Collections.reverse(a); 14. public class Beta extends Alpha {
14. System.out.println(a); 15. public void foo() {
15. } System.out.print("Bfoo "); }
16. } 16. public static void main(String[] args) {
What is the result? 17. Alpha a = new Beta();
A. [1, 2, 3, 5] 18. Beta b = (Beta)a;
B. [2, 1, 3, 5] 19. a.foo();
C. [2, 5, 3, 1] 20. b.foo();
D. [5, 3, 2, 1] 21. }
E. [1, 3, 5, 2] 22. }
F. Compilation fails. What is the result?
G. An exception is thrown at runtime. A. Afoo Afoo
Answer: C B. Afoo Bfoo
C. Bfoo Afoo
184. class BabyRaccoon extends Mammal D. Bfoo Bfoo
{} E. Compilation fails.
F. An exception is thrown at runtime. 189 A company has a business application
Answer: D that provides its users with many
different reports:
187. Given: receivables reports, payables reports,
5. import java.util.Date; revenue projects, and so on. The
6. import java.text.DateFormat; company has just
21. DateFormat df; purchased some new, state-of-the-art,
22. Date date = new Date(); wireless printers, and a programmer has
23. // insert code here been assigned the
24. String s = df.format(date); task of enhancing all of the reports to use
Which code fragment, inserted at line 23, not only the company's old printers, but
allows the code to compile? the new
A. df = new DateFormat(); wireless printers as well. When the
B. df = Date.getFormat(); programmer starts looking into the
C. df = date.getFormat(); application, the programmer
D. df = DateFormat.getFormat(); discovers that because of the design of
E. df = DateFormat.getInstance(); the application, it is necessary to make
Answer: E changes to each
report to support the new printers. Which
188. Given: two design concepts most likely explain
1. public class Base { this situation?
2. public static final String FOO = "foo"; (Choose two.)
3. public static void main(String[] args) { A. Inheritance
4. Base b = new Base(); B. Low cohesion
5. Sub s = new Sub(); C. Tight coupling
6. System.out.print(Base.FOO); D. High cohesion
7. System.out.print(Sub.FOO); E. Loose coupling
8. System.out.print(b.FOO); F. Object immutability
9. System.out.print(s.FOO); Answer: B,C
10. System.out.print(((Base)s).FOO);
11. } } 190.A team of programmers is reviewing
12. class Sub extends Base {public static a proposed API for a new utility class.
final String FOO="bar";} After some discussion,
What is the result? they realize that they can reduce the
A. foofoofoofoofoo number of methods in the API without
B. foobarfoobarbar losing any
C. foobarfoofoofoo functionality. If they implement the new
D. foobarfoobarfoo design, which two OO principles will they
E. barbarbarbarbar be promoting?
F. foofoofoobarbar A. Looser coupling
G. foofoofoobarfoo B. Tighter coupling
Answer: D C. Lower cohesion
D. Higher cohesion
E. Weaker encapsulation
F. Stronger encapsulation A. final
Answer: A B. static
C. native
191. A team of programmers is involved D. public
in reviewing a proposed design for a new E. private
utility class. After F. abstract
some discussion, they realize that the G. protected
current design allows other classes to Answer: A,B,D
access methods in
the utility class that should be accessible 194. Given:
only to methods within the utility class 10. interface Foo { int bar(); }
itself. What design 11. public class Sprite {
issue has the team discovered? 12. public int fubar( Foo foo ) { return
A. Tight coupling foo.bar(); }
B. Low cohesion 13. public void testFoo() {
C. High cohesion 14. fubar(
D. Loose coupling 15. // insert code here
E. Weak encapsulation 16. );
F. Strong encapsulation 17. }
Answer: E 18. }
192. Given: Which code, inserted at line 15, allows
1. public class TestString1 { the class Sprite to compile?
2. public static void main(String[] args) { A. Foo { public int bar() { return 1; }
3. String str = "420"; B. new Foo { public int bar() { return 1; }
4. str += 42; C. new Foo() { public int bar() { return 1; }
5. System.out.print(str); D. new class Foo { public int bar() { return
6. } 1; }
7. } Answer: C
What is the output?
A. 42 195. Given:
B. 420 11. class Animal { public String noise() {
C. 462 return "peep"; } }
D. 42042 12. class Dog extends Animal {
E. Compilation fails. 13. public String noise() { return "bark"; }
F. An exception is thrown at runtime. 14. }
Answer: D 15. class Cat extends Animal {
16. public String noise() { return "meow";
193. Given }
11. public interface Status { 17. } ...
12. /* insert code here */ int MY_VALUE = 30. Animal animal = new Dog();
10; 31. Cat cat = (Cat)animal;
13. } Which three are valid on line 32. System.out.println(cat.noise());
12? What is the result?
(Choose three.) A. peep
B. bark Answer: A
C. meow
D. Compilation fails. 200. Given:
E. An exception is thrown at runtime. 10. interface Jumper { public void jump();
Answer: E } ...
20. class Animal {} ...
196. A programmer has an algorithm that 30. class Dog extends Animal {
requires a java.util.List that provides an 31. Tail tail; 32. } ...
efficient 40. class Beagle extends Dog implements
implementation of add(0, object), but Jumper{
does NOT need to support quick random 41. public void jump() {}
access. What 42. } ...
supports these requirements? 50. class Cat implements Jumper{
A. java.util.Queue 51. public void jump() {}
B. java.util.ArrayList 52. }
C. java.util.LinearList Which three are true?(Choose Three)
D. java.util.LinkedList A. Cat is-a Animal
Answer: D B. Cat is-a Jumper
197. Which Man class properly represents C. Dog is-a Animal
the relationship "Man has a best friend D. Dog is-a Jumper
who is a Dog"? E. Cat has-a Animal
A. class Man extends Dog { } F. Beagle has-a Tail
B. class Man implements Dog { } G. Beagle has-a Jumper
C. class Man { private BestFriend dog; } Answer: B,C,F
D. class Man { private Dog bestFriend; }
E. class Man { private Dog<bestFriend>; } 201. Given:
F. class Man { private BestFriend<dog>; } 10. interface Data { public void load(); }
Answer: D 11. abstract class Info { public abstract
void load(); }
199. A team of programmers is reviewing Which class correctly uses the Data
a proposed API for a new utility class. interface and Info class?
After some discussion, A. public class Employee extends Info
they realize that they can reduce the implements Data {
number of methods in the API without public void load() { /*do something*/ }
losing any }
functionality. If they implement the new B. public class Employee implements Info
design, which two OO principles will they extends Data {
be promoting? public void load() { /*do something*/ }
A. Looser coupling }
B. Tighter coupling C. public class Employee extends Info
C. Lower cohesion implements Data {
D. Higher cohesion public void load(){ /*do something*/ }
E. Weaker encapsulation public void Info.load(){ /*do something*/
F. Stronger encapsulation }
} File obj = new File("/java/system");
D. public class Employee implements Info System.out.print(obj.getName());
extends Data { }
public void Data.load(){ /*do something*/ }
} a) java
public void load(){ /*do something*/ } b) system
} c) java/system
E. public class Employee implements Info d) /java/system
extends Data { Answer:B
public void load(){ /*do something*/ }
public void Info.load(){ /*do something*/ 204. import java.io.*;
} class files {
} public static void main(String args[]) {
F. public class Employee extends Info File obj = new File("/java/system");
implements Data{ System.out.print(obj.getAbsolutePath());
public void Data.load() { /*do }
something*/ } }
public void Info.load() { /*do something*/ Note: file is made in c drive.
} a) java
} b) system
Answer: A c) java/system
d) /java/system
202. Given: View Answer
1. class TestA { Answer: d
2. public void start() { Explanation: None.
System.out.println("TestA"); } Output:
3. } $ javac files.java
4. public class TestB extends TestA { $ java files
5. public void start() { \java\system
System.out.println("TestB"); }
6. public static void main(String[] args) { 205. What is the output of this program?
7. ((TestA)new TestB()).start(); import java.io.*;
8. } class files {
9. } public static void main(String args[]) {
What is the result? File obj = new File("/java/system");
A. TestA System.out.
B. TestB }
C. Compilation fails. }
D. An exception is thrown at runtime. Note: file is made in c drive.
Answer: B a) java
b) system
203. import java.io.*; c) java/system
class files { d) /java/system
public static void main(String args[]) { Answer:D
206. class exception_handling {
public static void main(String args[]) {
try {
int a = args.length;
int b = 10 / a;
System.out.print(a);
try {
if (a == 1)
a = a / a - a;
if (a == 2) {
int c = {1};
c[8] = 9;
}
}
catch (ArrayIndexOutOfBoundException
e) {
System.out.println("TypeA");
}
catch (ArithmeticException e) {
System.out.println("TypeB");
}}}}
a) TypeA
b) TypeB
c) 0TypeA

Important link:
http://javabysri.blogspot.in/2012/06/jdbc
-objective-questions.html
Ques1)When the message"No suitable driver" occurs?

a) When the driver is not registered by Class.forname() method

b) When the user name, password and the database does not match

c) When the JDBC database URL passed is not constructed properly

d) When the type 4 driver is used.

Ques2)Which of the following are needed for loading a database

driver in JDBC?

a)registerDriver() method

b)Class.forName()

c)Both A and B

d)getConnection()

Ques3)BLOB,CLOB,ARRAY and REF type columns can be updated in?

a)JDBC 1.0

b)JDBC 4.0

c)JDBC 2.0

d)JDBC 3.0

Ques4)To execute a stored procedure"Total stock" in a database server

which of the following is used?

a)Statement

b)Callable Statement

c)Stored Procedure Statement

d)Prepare Statement

Ques5)Which of the following is false as far as Type4 driver is concerned?


a)Type 4 driver is “native protocol, pure java” driver.

b)Type 4 drivers are 100% Java compatible.

c) Type 4 drivers uses Socket class to connect to the database.

d) Type 4 drivers can not be used with Netscape.

Ques6)Which statement is static and synchronized in JDBC API?

a)executeQuery()

b) executeUpdate()

c) getConnection()

d) prepareCall()

Ques7)Which of the following stament is false as far as different type is

concern in JDBC?

a)Regular Statement

b)Prepared Statement

c)Callable Statement

d)Interim Statement

Ques8)All raw data types should be read and uploaded to the database

as an array of?

a)byte

b)int

c)boolean

d)char

Ques9)Which are the new features adding in to the JDBC 4.0 ?

(a)Auto-loading of JDBC driver class


(b)Connection management enhancements

(c)Support for RowId SQL type

(d)All of the above

Ques10)Which method is used to perform the DML statement in JDBC?

a)execute()

b)executeQuery()

c)executeUpdate()

d)executeResult()

Ques11)What is the disadvantage of Type-4 Native Protocol Driver?

a)At client side, a separate driver is needed for each database.

b) Type-4 driver is entirely written in Java

c) The driver converts JDBC calls into vendor-specific database protocol

d) It does not support to read MySQL data.

Ques12)JDBC is a ..................... interface, which means that it is used to invoke SQL commands
directly?

A) low-level

B) middle-level

C) higher-level

D) user

Ques13)Which JDBC driver Type(s) can be used in either applet or servlet code?

a) Both Type 1 and Type 2


b) Both Type 1 and Type 3

c) Both Type 3 and Type 4

d) Type 4 only

Ques14)Which JDBC driver Type(s) can you use in a three-tier architecture and if the Web server and
the DBMS are running on the same machine?

a) Type 1 only

b) Type 2 only

c) Both Type 3 and Type 4

d) All of Type 1, Type 2, Type 3 and Type 4

Ques15) ODBC is not appropriate for direct use from java because it uses a ..............

a) C interface

b) C# interface

c) java interface

d) Both A and C

Ques16) Which statements about JDBC are true?

a) JDBC is an API to connect to relational-, object- and XML data sources

b) JDBC stands for Java DataBase Connectivity

c) JDBC is an API to access relational databases, spreadsheets and flat files

d) JDBC is an API to bridge the object-relational mismatch between OO programs and relational

databases

Ques17) Which type of driver converts JDBC calls into the network protocol used by the database
management system

directly?

a) Type 1 driver
b) Type 2 driver

c) Type 3 driver

d) Type 4 driver

Ques18) Which type of Statement can execute parameterized queries?

a) PreparedStatement

b) ParameterizedStatement

c) ParameterizedStatement and CallableStatement

d) All kinds of Statements (i.e. which implement a sub interface of Statement)

Ques19) How can you retrieve information from a ResultSet?

a) By invoking the method get(..., String type) on the ResultSet, where type is the database type

b) By invoking the method get(..., Type type) on the ResultSet,

where Type is an object which represents a database type.

c) By invoking the method getValue(...), and cast the result to the desired Java type.

d) By invoking the special getter methods on the ResultSet: getString(...), getBoolean (...),
getClob(...),...

Ques20) What statements are correct about JDBC transactions?


a) A transaction is a set of successfully executed statements in the database

b) A transaction is finished when commit() or rollback() is called on the Connection object,

c) A transaction is finished when commit() or rollback() is called on the Transaction object

d) A transaction is finished when close() is called on the Connection object.

Ques21) What happens if you call deleteRow() on a ResultSet object?

a) The row you are positioned on is deleted from the ResultSet, but not from the database.

b) The row you are positioned on is deleted from the ResultSet and from the database.

c)The result depends on whether the property synchronizeWithDataSource is set to true or false

d) You will get a compile error: the method does not exist because you can not delete rows from a
ResultSet

Ques22) The JDBC-ODBC Bridge supports multiple concurrent open statements per connection?

a) True

b) False

Ques23) 84. try {

85. ResourceConnection con = resourceFactory.getConnection();

86. Results r = con.query("GET INFO FROM CUSTOMER");

87. info = r.getData();

88. con.close();

89. } catch (ResourceException re) {


90. errorLog.write(re.getMessage());

91. }

92. return info;

Which statement is true if a ResourceException is thrown on line 86?

a) Line 92 will not execute.

b) The connection will not be retrieved in line 85.

c) The resource connection will not be closed on line 88.

d) The enclosing method will throw an exception to its caller

Ques24)Which packages contain the JDBC classes?

a)java.jdbc and javax.jdbc

b)java.jdbc and java.jdbc.sql

c) java.sql and javax.sql

d) java.rdb and javax.rdb

Ques25)How can you execute DML statements (i.e. insert, delete, update) in

the database?

a) By making use of the InsertStatement, DeleteStatement or

UpdateStatement classes

b) By invoking the execute(...) or executeUpdate(...) method of a

normal Statement object or a sub-interface object thereof

c) By invoking the executeInsert(...), executeDelete(...) or

executeUpdate(...) methods of the DataModificationStatement object.

d) By making use of the execute(...) statement of the

DataModificationStatement object.
Ques25)What is, in terms of JDBC, a DataSource?

a) A DataSource is the basic service for managing a set of JDBC drivers.

b) A DataSource is the Java representation of a physical data source.

c) A DataSource is a registry point for JNDI-services.

d) A DataSource is a factory of connections to a physical data source.

Ques26)Are prepared statement actually compiled?

a)Yes,They complied

b)No,they are bound by JDBC driver.

Ques27)What is correct about DDL statements (create, grant,...)

a) DDL statements are treated as normal SQL statements, and are executed by calling the execute()
method on a Statement (or a sub interface thereof) object

b) To execute DDL statements, you have to install additional support files

c) DDL statements can not be executed by making use of JDBC, you should use the native database
tools for this.

d) Support for DDL statements will be a feature of a future release of JDBC’

Ques28)Which of the following allows non repeatable read in JDBC Connection?a

a)TRANSACTION_READ_UNCOMMITTED

b) TRANSACTION_READ_COMMITTED

c) TRANSACTION_SERIALIZABLE

d) TRANSACTION_REPEATABLE_READ

Ques29)The class java.sql.Timestamp has its super class as?

a) java.sql.Time
b) java.util.Date

c) java.util.Time

d) None of the above

Ques30) Which driver is called as Thin-driver in JDBC?

a)TYPE-4

b)TYPE-2

c)TYPE-1

d)TYPE-3
Q 1 - Which of the following is correct about Creational design patterns.

A - These design patterns are specifically concerned with communication between


objects.

B - These design patterns provide a way to create objects while hiding the creation logic,
rather than instantiating objects directly using new opreator.

C - These design patterns concern class and object composition. Concept of inheritance is
used to compose interfaces and define ways to compose objects to obtain new
functionalities.

D - None of the above.

Q 2 - Integer.valueOf is an example of Factory pattern.

A - false

B - true

Q 3 - Which of the following pattern builds a complex object using simple objects and
using a step by step approach?

A - Builder Pattern

B - Bridge Pattern

C - Adapter Pattern

D - Filter Pattern

Q 4 - Which of the following pattern creates a chain of receiver objects for a request?

A - Proxy Pattern

B - Chain of Responsibility Pattern

C - Command Pattern

D - Interpreter Pattern

Q 5 - Which of the following describes the Mediator pattern correctly?

A - This pattern is used to get a way to access the elements of a collection object in
sequential manner without any need to know its underlying representation.
B - This pattern is used to reduce communication complexity between multiple objects or
classes.

C - This pattern is used to restore state of an object to a previous state.

D - This pattern is used when there is one-to-many relationship between objects such as if
one object is modified, its depenedent objects are to be notified automatically.

Q 6 - In which of the following pattern, a class behavior or its algorithm can be changed
at run time?

A - State Pattern

B - Null Object Pattern

C - Strategy Pattern

D - Template Pattern

Q 7 - Which of the following describes the Composite Entity pattern correctly?

A - In this pattern, a visitor class is used which changes the executing algorithm of an
element class.

B - This pattern is used to separate application's concerns.

C - This pattern is used to decouple presentation tier and business tier.

D - This pattern is used in EJB persistence mechanism.

Q 8 - Which of the following pattern creates object without exposing the creation logic to
the client and refer to newly created object using a common interface?

A - Factory Pattern

B - Abstract Factory Pattern

C - Singleton Pattern

D - Transfer Object Pattern

Q 9 - Which of the following pattern is used when we want to pass data with multiple
attributes in one shot from client to server?

A - Factory Pattern

B - Abstract Factory Pattern

C - Singleton Pattern

D - Transfer Object Pattern


Q 10 - Which of the following is the correct list of entities of Composite Entity pattern?

A - Composite Entity, Coarse-Grained Object, Strategies

B - Composite Entity, Dependent Object, Strategies

C - Composite Entity, Coarse-Grained Object, Dependent Object, Strategies

D - Composite Entity, Coarse-Grained Object, Dependent Object

Q 1 - Which of the following describes the Singleton pattern correctly?

A - This pattern creates object without exposing the creation logic to the client and refer
to newly created object using a common interface.

B - In this pattern an interface is responsible for creating a factory of related objects


without explicitly specifying their classes.

C - This pattern involves a single class which is responsible to create an object while
making sure that only single object gets created.

D - This pattern is used when we want to pass data with multiple attributes in one shot
from client to server.

Q 2 - Which of the following describes the Transfer Object pattern correctly?

A - This pattern creates object without exposing the creation logic to the client and refer
to newly created object using a common interface.

B - In this pattern an interface is responsible for creating a factory of related objects


without explicitly specifying their classes.

C - This pattern involves a single class which is responsible to create an object while
making sure that only single object gets created.

D - This pattern is used when we want to pass data with multiple attributes in one shot
from client to server.

Q 3 - Which of the following pattern creates object without exposing the creation logic to
the client and refer to newly created object using a common interface?

A - Factory Pattern

B - Abstract Factory Pattern

C - Singleton Pattern

D - Transfer Object Pattern


Q 4 - In which of the following pattern an interface is responsible for creating a factory of
related objects without explicitly specifying their classes?

A - Factory Pattern

B - Abstract Factory Pattern

C - Singleton Pattern

D - Transfer Object Pattern

Q 5 - Which of the following pattern involves a single class which is responsible to create
an object while making sure that only single object gets created?

A - Factory Pattern

B - Abstract Factory Pattern

C - Singleton Pattern

D - Transfer Object Pattern

Q 6 - Which of the following pattern is used when we want to pass data with multiple
attributes in one shot from client to server?

A - Factory Pattern

B - Abstract Factory Pattern

C - Singleton Pattern

D - Transfer Object Pattern

Q 7 - Which of the following pattern is used when we want to pass data with multiple
attributes in one shot from client to server?

A - Factory Pattern

B - Abstract Factory Pattern

C - Singleton Pattern

D - Transfer Object Pattern

Q 8 - Which type of design patterns provide a way to create objects while hiding the
creation logic, rather than instantiating objects directly using new opreator?

A - Creational Design Patterns

B - Structural Design Patterns

C - Behavioral Design Pattern


D - J2EE Design Patterns

Q 9 - Which type of design patterns concern class and object composition?

A - Creational Design Patterns

B - Structural Design Patterns

C - Behavioral Design Pattern

D - J2EE Design Patterns

Q 10 - Which type of design patterns are specifically concerned with communication


between objects?

A - Creational Design Patterns

B - Structural Design Patterns

C - Behavioral Design Pattern

D - J2EE Design Patterns

Q 11 - Which type of design patterns are specifically concerned with the presentation
tier?

A - Creational Design Patterns

B - Structural Design Patterns

C - Behavioral Design Pattern

D - J2EE Design Patterns

Q 12 - Which of the following describes the Creational pattern correctly?

A - This type of patterns provide a way to create objects while hiding the creation logic,
rather than instantiating objects directly using new opreator

B - This type of patterns concern class and object composition. Concept of inheritance is
used to compose interfaces and define ways to compose objects to obtain new
functionalities.

C - This type of pattern are specifically concerned with communication between objects.

D - This type of pattern are specifically concerned with the presentation tier.

Q 13 - Which of the following describes the Structural pattern correctly?

A - This type of patterns provide a way to create objects while hiding the creation logic,
rather than instantiating objects directly using new opreator
B - This type of patterns concern class and object composition. Concept of inheritance is
used to compose interfaces and define ways to compose objects to obtain new
functionalities.

C - This type of pattern are specifically concerned with communication between objects.

D - This type of pattern are specifically concerned with the presentation tier.

Q 14 - Which of the following describes the Behavioral pattern correctly?

A - This type of patterns provide a way to create objects while hiding the creation logic,
rather than instantiating objects directly using new opreator

B - This type of patterns concern class and object composition. Concept of inheritance is
used to compose interfaces and define ways to compose objects to obtain new
functionalities.

C - This type of pattern are specifically concerned with communication between objects.

D - This type of pattern are specifically concerned with the presentation tier.

Q 15 - Which of the following describes the J2EE pattern correctly?

A - This type of patterns provide a way to create objects while hiding the creation logic,
rather than instantiating objects directly using new opreator

B - This type of patterns concern class and object composition. Concept of inheritance is
used to compose interfaces and define ways to compose objects to obtain new
functionalities.

C - This type of pattern are specifically concerned with communication between objects.

D - This type of pattern are specifically concerned with the presentation tier.

Q 16 - Which of the following is the correct list of entities of MVC pattern?

A - Model, View, Controller

B - Model, Viewer, Control

C - Middle, Viewer, Controller

D - Model, View, Control

Q 17 - Which of the following is the correct list of entities of Business Delegate pattern?

A - Business Delegate, LookUp Service, Business Service

B - Client, Business Delegate, LookUp Service, Business Service

C - Client, LookUp Service, Business Service


D - Client, Business Delegate, Business Service

Q 18 - Which of the following is the correct list of entities of Composite Entity pattern?

A - Composite Entity, Coarse-Grained Object, Strategies

B - Composite Entity, Dependent Object, Strategies

C - Composite Entity, Coarse-Grained Object, Dependent Object, Strategies

D - Composite Entity, Coarse-Grained Object, Dependent Object

Q 19 - Which of the following is the correct list of entities of DAO pattern?

A - Data Access Object Interface, Data Access Object concrete class, Model Object or
Value Object

B - Data Access Object Interface, Model Object or Value Object

C - Data Access Object Interface, Data Access Object concrete class

D - Data Access Object concrete class, Model Object or Value Object

Q 20 - Which of the following is the correct list of entities of Front Controller pattern?

A - Front Controller, Dispatcher, View

B - Front Controller, Dispatcher

C - Controller, Dispatcher, View

D - Front Controller, View

Q 21 - Which of the following is the correct list of entities of Intercepting pattern?

A - Filter, Filter Chain, Target, Client

B - Filter, Target, Filter Manager, Client

C - Filter, Filter Chain, Target, Filter Manager, Client

D - Filter, Filter Chain, Filter Manager, Client

Q 22 - Which of the following is the correct list of entities of Service Locator pattern?

A - Service, Context, Cache, Client

B - Service, Context, Service Locator, Cache, Client

C - Service, Context, Service Locator, Cache, Client

D - Service, Service Locator, Client


Q 23 - Which of the following is the correct list of entities of Transfer Object pattern?

A - Business Object , Transfer Object, Client

B - Service, Context, Service Locator, Cache, Client

C - Business Object , Client

D - Service, Service Locator, Client

Q 24 - In MVC pattern, Model represents an object or JAVA POJO carrying data. It can
also.

A - true

B - false

Q 25 - In MVC pattern, View represents the visualization of the data that model contains.

A - false

B - true

1C
2D
3A
4B
5C
6D
7D
8A
9B
10C
11D
12A
13B
14C
15D
16A
17B
18C
19A
20A
21C
22B
23A
24A
25B

Q 1 - Which of the following describes the Null Object pattern correctly?


A - In this pattern, a class behavior changes based on its state.

B - In this pattern, a null object replaces check of NULL object instance.

C - In this pattern, a class behavior or its algorithm can be changed at run time.

D - In this pattern, an abstract class exposes defined way(s)/template(s) to execute its


methods.

Q 2 - Which of the following describes the Strategy pattern correctly?

A - In this pattern, a class behavior changes based on its state.

B - In this pattern, a null object replaces check of NULL object instance.

C - In this pattern, a class behavior or its algorithm can be changed at run time.

D - In this pattern, an abstract class exposes defined way(s)/template(s) to execute its


methods.

Q 3 - Which of the following describes the Template pattern correctly?

A - In this pattern, a class behavior changes based on its state.

B - In this pattern, a null object replaces check of NULL object instance.

C - In this pattern, a class behavior or its algorithm can be changed at run time.

D - In this pattern, an abstract class exposes defined way(s)/template(s) to execute its


methods.

Q 4 - In which of the following pattern, a class behavior changes based on its state?

A - State Pattern

B - Null Object Pattern

C - Strategy Pattern

D - Template Pattern

Q 5 - In which of the following pattern, a null object replaces check of NULL object
instance?

A - State Pattern

B - Null Object Pattern

C - Strategy Pattern

D - Template Pattern
Q 6 - In which of the following pattern, a class behavior or its algorithm can be changed
at run time?

A - State Pattern

B - Null Object Pattern

C - Strategy Pattern

D - Template Pattern

Q 7 - In which of the following pattern, an abstract class exposes defined


way(s)/template(s) to execute its methods?

A - State Pattern

B - Null Object Pattern

C - Strategy Pattern

D - Template Pattern

Q 8 - Which of the following describes the Visitor pattern correctly?

A - In this pattern, a visitor class is used which changes the executing algorithm of an
element class.

B - This pattern is used to separate application's concerns.

C - This pattern is used to decouple presentation tier and business tier.

D - This pattern is used in EJB persistence mechanism.

Q 9 - Which of the following describes the MVC pattern correctly?

A - In this pattern, a visitor class is used which changes the executing algorithm of an
element class.

B - This pattern is used to separate application's concerns.

C - This pattern is used to decouple presentation tier and business tier.

D - This pattern is used in EJB persistence mechanism.

Q 10 - Which of the following describes the Business Delegate pattern correctly?

A - In this pattern, a visitor class is used which changes the executing algorithm of an
element class.

B - This pattern is used to separate application's concerns.

C - This pattern is used to decouple presentation tier and business tier.


D - This pattern is used in EJB persistence mechanism.

Q 11 - Which of the following describes the Composite Entity pattern correctly?

A - In this pattern, a visitor class is used which changes the executing algorithm of an
element class.

B - This pattern is used to separate application's concerns.

C - This pattern is used to decouple presentation tier and business tier.

D - This pattern is used in EJB persistence mechanism.

Q 12 - In which of the following pattern, a visitor class is used which changes the
executing algorithm of an element class?

A - Visitor Pattern

B - MVC Pattern

C - Business Delegate Pattern

D - Composite Entity Pattern

Q 13 - Which of the following pattern is used to separate application's concerns?

A - Visitor Pattern

B - MVC Pattern

C - Business Delegate Pattern

D - Composite Entity Pattern

Q 14 - Which of the following pattern is used to to decouple presentation tier and


business tier?

A - Visitor Pattern

B - MVC Pattern

C - Business Delegate Pattern

D - Composite Entity Pattern

Q 15 - Which of the following pattern is used in EJB persistence mechanism?

A - Visitor Pattern

B - MVC Pattern

C - Business Delegate Pattern


D - Composite Entity Pattern

Q 16 - Which of the following describes the DAO pattern correctly?

A - This pattern is used to separate low level data accessing API or operations from high
level business services.

B - This pattern is used to provide a centralized request handling mechanism so that all
requests will be handled by a single handler.

C - This pattern is used when we want to do some pre-processing / post-processing with


request or response of the application.

D - This pattern is used when we want to locate various services using JNDI lookup.

Q 17 - Which of the following describes the Front Controller pattern correctly?

A - This pattern is used to separate low level data accessing API or operations from high
level business services.

B - This pattern is used to provide a centralized request handling mechanism so that all
requests will be handled by a single handler.

C - This pattern is used when we want to do some pre-processing / post-processing with


request or response of the application.

D - This pattern is used when we want to locate various services using JNDI lookup.

Q 18 - Which of the following describes the Intercepting pattern correctly?

A - This pattern is used to separate low level data accessing API or operations from high
level business services.

B - This pattern is used to provide a centralized request handling mechanism so that all
requests will be handled by a single handler.

C - This pattern is used when we want to do some pre-processing / post-processing with


request or response of the application.

D - This pattern is used when we want to locate various services using JNDI lookup.

Q 19 - Which of the following describes the Service Locator pattern correctly?

A - This pattern is used to separate low level data accessing API or operations from high
level business services.

B - This pattern is used to provide a centralized request handling mechanism so that all
requests will be handled by a single handler.

C - This pattern is used when we want to do some pre-processing / post-processing with


request or response of the application.
D - This pattern is used when we want to locate various services using JNDI lookup.

Q 20 - Which of the following pattern is used to separate low level data accessing API or
operations from high level business services?

A - DAO Pattern

B - Front Controller Pattern

C - Intercepting Pattern

D - Service Locator Pattern

Q 21 - Which of the following pattern is used to provide a centralized request handling


mechanism so that all requests will be handled by a single handler?

A - DAO Pattern

B - Front Controller Pattern

C - Intercepting Pattern

D - Service Locator Pattern

Q 22 - Which of the following pattern is used when we want to do some pre-processing /


post-processing with request or response of the application?

A - DAO Pattern

B - Front Controller Pattern

C - Intercepting Pattern

D - Service Locator Pattern

Q 23 - Which of the following pattern is used when we want to locate various services
using JNDI lookup?

A - DAO Pattern

B - Front Controller Pattern

C - Intercepting Pattern

D - Service Locator Pattern

Q 24 - Which of the following describes the Factory pattern correctly?

A - This pattern creates object without exposing the creation logic to the client and refer
to newly created object using a common interface.
B - In this pattern an interface is responsible for creating a factory of related objects
without explicitly specifying their classes.

C - This pattern involves a single class which is responsible to create an object while
making sure that only single object gets created.

D - This pattern is used when we want to pass data with multiple attributes in one shot
from client to server.

Q 25 - Which of the following describes the Abstract Factory pattern correctly?

A - This pattern creates object without exposing the creation logic to the client and refer
to newly created object using a common interface.

B - In this pattern an interface is responsible for creating a factory of related objects


without explicitly specifying their classes.

C - This pattern involves a single class which is responsible to create an object while
making sure that only single object gets created.

D - This pattern is used when we want to pass data with multiple attributes in one shot
from client to server.

1B
2C
3D
4A
5B
6C
7D
8A
9B
10C
11D
12A
13B
14C
15D
16A
17B
18C
19D
20A
21B
22C
23D
24A
25B
1 What is the output of the following code?

<% session.setAttribute("name", "John"); %>

<%= session.getAttribute("John") %>

Ans:NULL

2 JavaServer Pages are processed by ?-----JSp container

3 What is the signature of method _jspService of HttpJspPage?----void _jspService(HttpServletRequest, HttpServletResponse) throws


IOException,

ServletException

4statements is incorrect?----HttpServlet.destroy() throws ServletException

5 JavaServer Pages are processed by software on the ?----Servver

6 HttpServlet.service() thrwos ServletException and IOException-----HTML

7 The method _jspService of HttpJspPage should not be overriden by a JSP author-----TRUE

8 Which one of the following is a valid argument for a JSP page directive?----isThreadSafe="yes|no"

9 What is the signature of method jspDestroy of JspPage?---void jspDestroy()

10 What is the output of the following code?

<% session.setAttribute("name", "John"); %>

<%= session.getAttribute("name") %>---john

1 Which of these are legal attributes of page directive. Select the two

correct answers.----errorpage

2 JSP pages have access to implicit objects that are exposed automatically. One such object that is

available is request. The request object is an instance of which class?----HttpServletRequest

3 Which of the following JSP variables are not available within a JSP expression. Select the one

correct answer.------httpsession

4 What is the return type of the getLastModified method of HttpServlet?----long

5 Is the following statement true or false. If the isThreadSafe attribute of the page directive is false,

then the generated servlet implements the SingleThreadModel interface.----TRUE

6 What gets printed when the following JSP code is invoked in a browser. Select the one correct

answer.

<%= if(Math.random() < 0.5) %>

hello

<%= } else { %>

hi

<%= } %>-----The JSP file will not compile.

7 Name the default value of the scope atribute of <jsp:usebean>.---page


8 What gets printed when the following is compiled. Select the one correct answer.

<% int y = 0; %>

<% int z = 0; %>

<% for(int x=0;x<3;x++) { %>

<% z++;++y;%>

<% }%>

<% if(z<y) {%>

<%= z%>

<% } else {%>

<%= z 1%>

<% }%>-----2

9 The methods jspInit and jspDestroy of JspPage may be overriden by a JSP author---TRUE

10-What is the signature of method jspInit of JspPage?----void jspInit()

1> JSP pages have access to implicit objects that are exposed automatically. Name the implicit object

that is of type HttpSession.-----session

2> Is the following JSP code legal? Select the one correct statement.

<%@page info="test page" session="false"%>

<%@page session="false"%>----No. This code will generate syntax errors.

3> true about include directive----When using the include directive, the JSP container treats the file to be included as if it was

part of the original file.

4> When using the include directive, the JSP container treats the file to be included as if it was

part of the original file.---contentType

5> Name the implicit variable available to JSP pages that may be used to access all the other implicit objects.-----pageContext
6> This pageContext object is an instance of type javax.servlet.jsp.PageContext, and provides methods
7> like getPage(), getRequest(), etc. to access other input variables.-----HttpServletRequest
8> In <jsp:getProperty /> which two attributes is necessary----name and property
9> not directive?----scriptlet
10> In <jsp:include> which attributes are used----page and flush
11> Which is true by default?----isThreadSafe
12> correct scopes into JSP----page, request, session, application
13> not attributes of Page directive-----isThreadSafe

14> attributes for <jsp: plugin />

1. code,align, archive,height, hspace, name,

2. nspluginurl, iepluginurl jrevision, type

3. vspace, title, and width------123


14> In <jsp:useBean> which two attributes is necessary-----class and id is necessary

correct for include Action-----It allow dynamic include

15> What is the result of adding following header?

response.addDateHeader("Expires",1);----To ensure the page does not get cached at the client browsers.

16> How you can make jsp page as error page-----isErrorPage ="true"
17> pageContext is an implicit object in jsp.------TRUE
18> config is an implicit object in jsp.-----TRUE

19> Which represents a correct syntax for usebean-----<jsp:usebean id="fruit type ="String"/>
20> A JSP page called test.jsp is passed a parameter name in the URL using http://localhost/test.jsp?

name="John". The test.jsp contains the following code.

<%! String myName=request.getParameter();%>

<% String test= "welcome" + myName; %>

<%= test%>--------------------The program gives a syntax error because of the statement

<%! String myName=request.getParameter();

Ques 1 :

What is the key difference between using a <jsp:forward> and HttpServletResponse.sendRedirect()?

(A) The two methods perform identically.

(B) forward executes on the client while sendRedirect() executes on the server.

(C) forward executes on the server while sendRedirect() executes on the client.

Ans:C

Ques 2 :

How many numbers gets printed when the following JSTL code fragment is executed? Select the one correct answer.

<%@ taglib uri="http://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>

(A) One number gets printed.

(B) Two numbers gets printed.

(C) Three numbers gets printed.

(D) Four numbers gets printed.

Ans:A

Ques 3 :

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="*"/>

(A) The code does not compile as property attribute cannot take * as a value.

(B) The code sets value of all properties of employee bean to "*".

(C) The code sets the values of all properties of employee bean to matrching parameters in request object.

(D) The code does not compile as there is no property attribute of setProperty tag.

Ans:C

Ques 4 :

Which numbers gets printed when the following JSTL code fragment is executed? Select the correct answers.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<c:set var="j" value="4,3,2,1"/>

<c:forEach items="${j}" var="item" begin="1" end="2">


<c:out value="${item}" default="abc"/>

</c:forEach>

(A) 1

(B) 4

(C) 2

(D) abc

Abs:2

Ques 5 :

Which of the following correctly represents the following JSP statement. Select the one correct answer.

(A) x=1;

(B) x=1;

(C) x=1;

(D) x=1;

Ans:

Ques 6 :

Which of the following correctly represents the following JSP statement. Select the one correct answer.

(A) x

(B) x

(C) x

(D) x

Ans:

Ques 7 :

Why beans are used in J2EE architecture in stead of writing all the code in JSPs?

(A) Allows separation of roles between web developers and application developers

(B) Allows integration with Content Management tools

Ans:A

Ques 8 :

Why DB connections are not written directly in JSPs ?

(A) Not a standard J2EE architecture

(B) Load Balancing is not possible


(C) All the above

(D) Both (b) and (c)

Ans:D

Ques 9 :

A JSP page called test.jsp is passed a parameter name in the URL using http://localhost/test.jsp?name="John". The test.jsp contains the
following code.

1 <%! String myName=request.getParameter();%>

2 <% String test= "welcome" + myName; %>

3 <%= test%>

(A) The program prints "Welcome John"

(B) The program gives a syntax error because of the statement 1

(C) The program gives a syntax error because of the statement 2

(D) The program gives a syntax error because of the statement 3

Ans:B

Ques 10 :

What gets printed when the following JSTL code fragment is executed? Select the one correct answer.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<c:set var="item" value="2"/>

<c:forEach var="item" begin="0" end="0" step="2">

<c:out value="${item}" default="abc"/>

</c:forEach>

The JSTL code does not compile as an attribute for forEach tag is not correct.

(A) 0

(B) ABC

(C) 2

(D) Nothing gets printed as c.out statement does not get executed.

Ans:2

Ques 11 :

How many numbers are printed, when the following JSTL code fragment is executed? Select the one correct answer.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


${item}

(A) 1

(B) 5

(C) 6

(D) 11

Ans:6

Ques 12 :

Which of these represent the correct path for the core JSTL library in JSTL version 1.1? Select the one correct answer.

(A) http://java.sun.com/jsp/jstl/core

(B) http://java.sun.com/jsp/core

(C) http://java.sun.com/core

(D) http://java.sun.com/jsp/jstl1.1/core

Ans:A

Ques 13 :

Given that www.example.com/SCWCDtestApp is a validly deployed Java EE web application and that all of the JSP files specified in the requests
below exist in the locations specified.Which two requests, issued from a browser, will return an HTTP 404 error?

(A) http://www.example.com/SCWCDtestApp/test.jsp

(B) http://www.example.com/SCWCDtestApp/Customer/test.jsp

(C) http://www.example.com/SCWCDtestApp/WEB-INF/test.jsp

(D) http://www.example.com/SCWCDtestApp/Customer/Update/test.jsp

Ans:C

Ques 14 :

Which of the following are correct. Select the one correct answer.

(A) JSP scriptlets and declarations result in code that is inserted inside the _jspService method.

(B) The JSP statement <%! int x; %> is equivalent to the statement int x;.

(C) The following are some of the predefined variables that maybe used in JSP expression - httpSession, context.

(D) To use the character %> inside a scriptlet, you may use %\> instead.

Ans:D

Ques 15 :

Which of the following is legal JSP syntax to print the value of i. Select the one correct answer

(A) <%= i; %>


(B) <%int i = 1;%>

(C) <%int i = 1; i; %>

(D) <%int i = 1%>

Ans:D

Ques 16 :

What gets printed when the following is compiled. Select the one correct answer.

<% int y = 0; %>

<% int z = 0; %>

<% for(int x=0;x<3;x++) { %>

<% z++;++y;%>

<% }%>

<% if(z<y) {%>

<%= z%>

<% } else {%>

<%= z - 1%>

<% }%>

(A) 1

(B) 2

(C) 3

(D) The program generates compilation error.

Ans:3

Ques 17 :

Which of the following JSP variables are not available within a JSP expression. Select the one correct answer.

(A) out

(B) httpsession

(C) session

(D) request

Ans:B

Ques 18 :

What gets printed when the following JSTL code fragment is executed? Select the one correct answer.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


<c:set var="item" value="2"/>

<c:if test="${var==1}" var="result" scope="session">

<c:out value="${result}"/>

</c:if>

(A) true

(B) The JSTL code does not compile as attribute for if tag are not correct.

(C) false

(D) Nothing gets printed.

Ans:C

Ques 19 :

What gets printed when the following JSP code is invoked in a browser. Select the one correct answer.

<%= if(Math.random() < 0.5) %>

hello

<%= } else { %>

hi

<%= } %>

(A) The browser will print either hello or hi based upon the return value of random.

(B) The string hello will always get printed.

(C) The string hi will always get printed.

(D) The JSP file will not compile.

Ans:D

Ques 20 :

In JSP, how can you know what HTTP method (GET or POST) is used by client request ?

(A) by using request.setMethod()

(B) impossible to know

(C) by using request.getMethod()

Ans:C

Ques 1 : JSP used for ?

(A) Server Side Programming

(B) Client Side Programming

(C) Both
(D) None of These

Ans:A

Ques 2 : Consider the following code and select the correct statement about it from the options below.

<%! int aNum = 5%>

The value of aNum is <%= aNum%>

(A) It will not flag any compile-time or runtime errors and will not print anything to the output.

(B) It will print "The value of aNum is 5" to the output.

(C) It will flag a compile-time error because of an incorrect declaration.

(D) It will throw a runtime exception while executing the expression.

Ans:A

Ques 3 : Which of the following tags can you use to print the value of an expression to the output stream?

(A) <%@ %>

(B) <%! %>

(C) <% %>

(D) <%= %>

Ans:D

Ques 4 : The following declaration is valid or not?

<%@ page buffer="8kb", session="false" %>

(A) Valid

(B) Invalid

Ans:B

Ques 5 : The following declaration is valid or not?

<%@ page import="org.pskills.dbconnection.* " %>

<%@ page session="true" %>

<%@ page import="java.text.*" %>

(A) Valid

(B) Invalid

Ans: A

Ques 6 : The following declaration is valid or not?


<%@ page bgcolor="navy" %>

(A) Valid

(B) Invalid

Ans:B

Ques 7 : The following declaration is valid or not?

<%@ page buffer="true" %>

(A) Valid

(B) Invalid

Ans:B

Ques 8 : The following declaration is valid or not?

<%@ Page language='java' %>

(A) Valid

(B) Invalid

Ans:B

Ques 9 : Which of the following methods is defined by the JSP engine?

(A) jspInit()

(B) _jspService()

(C) _jspService(HttpServletRequest, HttpServletResponse)

(D) jspDestroy()

Ans:C

Ques 10 : What will be the output of the following code?

<% int x = 5; %>

<%! int x = 10; %>

<%! int y = 50; %>

The value of b multiplied by a is <%= y * x %>

(A) The code will not compile

(B) 30

(C) 250

(D) 500

Ans:C
Ques 11 : What will be the output of the following code?

<% x = 30; %>

<% int x = 200; %>

<%! int x = 300; %>

x = <%= x %>, <%= this.x %>

(A) x = 200, 30

(B) x = 300, 30

(C) x = 30, 30

(D) x = 200, 200

Ans:D

Ques 12 : Which of the following exceptions may be thrown by the _jspService() method?

(A) javax.servlet.jsp.JSPException and java.io.IOException

(B) javax.servlet.jsp.JSPException

(C) javax.servlet.ServletException and javax.servlet.jsp.JSPException

(D) javax.servlet.ServletException and java.io.IOException

Ans:D

Ques 13 : Which are valid and invalid ?

a <%=myObj.m1(); %>

b <% int x=4, y=5; %>

c <%=x=y%>

d <% myObj.m1(); %>

(A) a valid, b,c,and d are invalid

(B) a invalid, b,c adn d are valid

(C) all valid

(D) all invalid

Ans:B

Ques 14 : What will be the output of following code?

<%@ page language='java' %>

<%

int x = 0;
int incr()

return ++x;

%>

The value of x is <%=incr()%>

(A) The value of x is 0

(B) The value of x is 1

(C) The value of x is 2

(D) Error in Code.

Ans:D

Ques 15 : What will be the output of following code?

<% int x = 3; %>

<%! int x = 5; %>

<%! int y = 6; %>

The sum of x and y is <%=x+y%>

(A) The sum of x and y is 11

(B) The sum of x and y is 6

(C) The sum of x and y is 9

(D) The sum of x and y is 3

Ans:C

Ques 16 : How much implicit object in JSP?

(A) 7

(B) 8

(C) 9

(D) None of These.

Ans:9

Ques 17 : Which is not a implicit object in JSP?

a) pageContext

b) pageConfig

c) config

d) context
e) page

f) exception

g) Exception

(A) b,d and f

(B) b,d and g

(C) a,c and g

(D) a,b and e

Ans:A

Ques 18 : What is the term for determining whether a user has access to a particular resource?

(A) Authorization

(B) Authentication

(C) Confidentiality

(D) Secrecy

Ans:A

Ques 19 : Which is not a valid syntax in JSP?

(A) request.authenticate(response)

(B) request.getAttributes("email")

(C) request.getCookies()

(D) None of These

Ans:B

Ques 20 : What will be the output of the following code? (Select one)

<html>

<body>

The value is <%=""%>

</body>

</html>

(A) Compilation error

(B) Runtime error

(C) The value is

(D) The value is null

Ans:C
1.) What programming language(s) or scripting language(s) does Java Server Pages (JSP) support?

Options are:

A.) VB Script

B.) Java only

C.) Any Programming Lanuage Code

D.) Java Script

View Answer

Correct Option: B

2.) What method is used to specify a container's layout in JSP?

Options are:

A.) setConLayout()

B.) setContainerLayout()

C.) setLayout()

D.) layout()

View Answer

Correct Option: C

3.) Which method of the Component class is used to set the position and size of a component in JSP?

Options are:

A.) setPosition()

B.) setBounds()

C.) setSizePosition()

D.) setSize()

View Answer

Correct Option: B

5.) Which class in JSP provides the capability to implement a growable array of objects?

Options are:

A.) Vector Class

B.) Dynamic Array Class

C.) Container Class

D.) Array Class

View Answer

Correct Option: A
6.) In JSP, the classes that allow primitive types to be accessed as objects are known as

Options are:

A.) Object classes

B.) UnBoxing classes

C.) Boxing classes

D.) Wrapped classes

View Answer

Correct Option: D

7.) In JSP, a Canvas object provides access to a Graphics object via one of its method called:

Options are:

A.) getCanvas()

B.) paint()

C.) getPaint()

D.) getGraphics()

View Answer

Correct Option: B

1> correct syntax for usebean-----<jsp:usebean id="fruit type ="String"/>


2> A JSP page called test.jsp is passed a parameter name in the URL using http://localhost/test.jsp?

name="John". The test.jsp contains the following code.

<%! String myName=request.getParameter();%>

<% String test= "welcome" + myName; %>

<%= test%>----------The program gives a syntax error because of the statement

<%! String myName=request.getParameter();%>

3> correct--To use the character %> inside a scriptlet, you may use %> instead.
4> A bean with a property color is loaded using the following statement

<jsp:usebean id="fruit" class="Fruit"/>

What happens when the following statement is executed. Select the one correct answer.

<jsp:setProperty name="fruit" property="*"/>---------

------All the properties of the fruit bean are assigned the values of input parameters of the JSP page

that have the same name.

5> A bean with a property color is loaded using the following statement
<jsp:usebean id="fruit" class="Fruit"/>

Which of the following statements may be used to set the of color property of the bean. Select the one correct

--------<jsp:setProperty name="fruit" property="color" value="white"/>

6> What gets printed when the following JSP code is invoked in a browser. Select the one correct

answer.

<%= if(Math.random() < 0.5) %>

hello

<%= } else { %>

hi

<%= } %>------The JSP file will not compile.

7> Which of JSP variables are not available within a JSP expression.------httpsession

Is the following statement true or false. If the isThreadSafe attribute of the page directive is false,

then the generated servlet implements the SingleThreadModel interface.-----TRUE

8> A bean with a property color is loaded using the following statement

<jsp:usebean id="fruit" class="Fruit"/>

Which of the following statements may be used to print the value of color property of the bean. Select the one

correct answer.

----------<jsp:getProperty name="fruit" property="color"/>

9> Name the default value of the scope atribute of <jsp:usebean>.-------page

1> examples of JSP directive----include


2> Assume that you need to write a JSP page that adds numbers from one to ten, and then print the

output.

<% int sum = 0;

for(j = 0; j < 10; j++) { %>

// XXX Add

j to sum

<% } %>

// YYY Display

ths sum---------<% sum = sum + j; %>

3> A Java bean with a property color is loaded using the following statement

<jsp:usebean id="fruit" class="Fruit"/>


What is the effect of the following statement.

<jsp:setproperty name="fruit" property="color"/>

--------if there is a nonnull

request parameter with name color, then its value gets assigned to color

property of Java Bean fruit.

4> Name the implicit variable available to JSP pages that may be used to access all the other implicit

objects.-----pageContext

5> JSP pages have access to implicit objects that are exposed automatically. One such object that is

available is request. The request object is an instance of which class?-----HttpservletRequest

6> JSP pages have access to implicit objects that are exposed automatically. Name the implicit object

that is of type HttpSession.-----session

7> Which of the following represents the XML equivalent of this statement <%@ include

file="a.jsp"%> .-----<jsp:directive.include file="a.jsp"/>

8> The page directive is used to convey information about the page to JSP container. Which of these

are legal syntax of page directive. Select the one correct statement----<%@ page info="test page" session="false"%>

9> Is the following JSP code legal? Select the one correct statement.

<%@page info="test page" session="false"%>

<%@page session="false"%>----No. This code will generate syntax errors.

10> The default value of isThreadSafe attribute of page directive is true.


11> Which of these are legal attributes of page directive. the one correct answers.-----page
12> A JSP page needs to generate an XML file. Which attribute of page directive may be used to

specify that the JSP page is generating an XML file.---contentType

1> Which of the following phone is when you would get the code in JSP converted to Java ?--translation
2> Can you use the implicit objects in the declaration element of JSP ?---no
3> Which of the following method should not be overriden in JSP---_jspservice
4> What is the name of the JSP Element type looks like----Scriptlet
5> Which is not an implicit object ?----object
6> Should the code in JSP element declaration type end with a semicolon?-----yes
This set of Software Design Multiple Choice Questions & Answers (MCQs) focuses on “UML Class and Object Diagrams”

1. What does a simple name in UML Class and objects consists of ?

a) Letters

b) Digits

c) Punctuation Characters

d) All of the mentioned

View Answer

Answer: d

Explanation: A simple name consists of letters, digits and punctuation characters.

2. What Does a Composite name consists of in a UML Class and object diagram ?

a) Delimiter

b) Simple names

c) Digits

d) All of the mentioned

View Answer

Answer: d

Explanation: Composite name consists of sequence of simple names and simple names already consists of digits.

3. A Class consists of which of these abstractions?

a) Set of the objects

b) Operations

c) Attributes

d) All of the mentioned

e) b, c

View Answer

Answer: d

Explanation: A class is a abstraction of objects, operations and attributes.

4. A class is divided into which of these compartments ?

a) Name Compartment

b) Attribute Compartment

c) Operation Compartment

d) All of the mentioned


View Answer

Answer: d

Explanation: Class is divided into 3 main compartments mentioned)

5. An attribute is a data item held by which of the following ?

a) Class

b) Object

c) All of the mentioned

d) None of the mentioned

View Answer

Answer: c

Explanation: Attribute is a data item held by class or object.

6. What should be mentioned as attributes for conceptual modelling ?

a) Initial Values

b) Names

c) All of the mentioned

d) None of the mentioned

View Answer

Answer: c

Explanation: Initial values along with thier names are used as attributes.

7. An operation can be described as?

a) Object behavior

b) Class behavior

c) Functions

d) a,b

e. None of the mentioned

View Answer

Answer: d

Explanation: An operation is class and object behavior.

8. Which of these are part of class operation specification format ?

a) name

b) parameter list
c) return-type list

d) All of the mentioned

View Answer

Answer: d

Explanation: It consists of all these 3 mentioned format.

9. What among these is true ?

a) Associations may also correspond to relation between instances of three or more classes

b) Association lines may be unlabeled or they may show association name

c) All of the mentioned

d) None of the mentioned

View Answer

Answer : c

Explanation : All the statements mentioned are true with respect to Notations.

10. What is multiplicity for an association?

a) The multiplicity at the target class end of an association is the number of instances that can be associated with a single instance of source
class

b) The multiplicity at the target class end of an association is the number of instances that can be associated with a number instance of source
class

c) All of the mentioned

d) None of the mentioned

View Answer

Answer : a

Explanation : Multiplicity is number of instances associated with single instance to source class.

11. Which among these are the rules to be considered to form Class diagrams?

a) Class symbols must have at least a name compartment

b) Compartment can be in random order

c) Attributes and operations can be listed at any suitable place

d) None of the mentioned

View Answer

Answer : a

Explanation : Compartments can be in order, Attributes and operations must be listed one per line.

12. Which of these are the heuristics ?


a) Name classes, attributes, and roles with noun phrases

b) Name operations and associations with verb phrases

c) Stick to binary associations

d) All of the mentioned

View Answer

Answer : d

Explanation : All the heuristic mentioned are true.

13. An object symbol is divided into what parts ?

a) Top compartment

b) Bottom Compartment

c) All of the mentioned

d) None of the mentioned

View Answer

Answer : c

Explanation : An object is divided into top and bottom compartments.

Which of the following UML diagrams has a static view?

a) Collaboration

b) Use case

c) State chart

d) Activity

View Answer

Answer:b

Which diagram in UML shows a complete or partial view of the structure of a modeled system at a specific time?

a) Sequence Diagram

b) Collaboration Diagram

c) Class Diagram

d) Object Diagram

View Answer

Answer: d

Interaction Diagram is a combined term for

a) Sequence Diagram + Collaboration Diagram

b) Activity Diagram + State Chart Diagram


c) Deployment Diagram + Collaboration Diagram

d) None of the mentioned

View Answer

Answer: a

Structure diagrams emphasize the things that must be present in the system being modeled.

a) True

b) False

View Answer

Answer: a

Which of the following diagram is time oriented?

a) Collaboration

b) Sequence

c) Activity

View Answer

Answer:b

How many diagrams are here in Unified Modelling Language?

a) six

b) seven

c) eight

d) nine

View Answer

Answer:d

Explanation: The nine UML diagrams include use-case, sequence, collaboration, activity, state-chart, deployment, class, object and component.

Class diagram, component diagram, object diagram and deployment diagram are considered as types of

A structural diagrams

B behavioral diagrams

C non-behavioral diagrams

D non structural diagrams

Ans:A

Class diagram, component diagram, object diagram and deployment diagram are considered as types of
A>structural diagrams

B>behavioral diagrams

C>non-behavioral diagrams

D>non structural diagrams

Ans:D

In UML diagrams, relationship between object and component parts is represented by

A> ordination

B> aggregation

C> segregation

D> increment

Ans:B
javaprepare.com - Questions on JSP
A small note here - In the real exam, there will be less questions of type fill in the blanks, as
compared to these set of questions. Also the real exam questions will probably be more difficult
than these questions.

1. Which of the following is legal JSP syntax to print the value of i. Select the one correct
answer
A. <%int i = 1;%>
<%= i; %>
B. <%int i = 1;
i; %>
C. <%int i = 1%>
<%= i %>
D. <%int i = 1;%>
<%= i %>
E. <%int i = 1%>
<%= i; %>

2. A JSP page called test.jsp is passed a parameter name in the URL using
http://localhost/test.jsp?name="John". The test.jsp contains the following code.

<%! String myName=request.getParameter();%>


<% String test= "welcome" + myName; %>
<%= test%>

A. The program prints "Welcome John"


B. The program gives a syntax error because of the statement
<%! String myName=request.getParameter();%>
C. The program gives a syntax error because of the statement
<% String test= "welcome" + myName; %>
D. The program gives a syntax error because of the statement
<%= test%>

3. Which of the following correctly represents the following JSP statement. Select the one
correct answer.
<%=x%>
A. <jsp:expression=x/>
B. <jsp:expression>x</jsp:expression>
C. <jsp:statement>x</jsp:statement>
D. <jsp:declaration>x</jsp:declaration>
E. <jsp:scriptlet>x</jsp:scriptlet>

4. Which of the following correctly represents the following JSP statement. Select the one
correct answer.
<%x=1;%>
A. <jsp:expression x=1;/>
B. <jsp:expression>x=1;</jsp:expression>
C. <jsp:statement>x=1;</jsp:statement>
D. <jsp:declaration>x=1;</jsp:declaration>
E. <jsp:scriptlet>x=1;</jsp:scriptlet>

5. What gets printed when the following JSP code is invoked in a browser. Select the one
correct answer.
<%= if(Math.random() < 0.5) %>
hello
<%= } else { %>
hi
<%= } %>

A. The browser will print either hello or hi based upon the return value of random.
B. The string hello will always get printed.
C. The string hi will always get printed.
D. The JSP file will not compile.

6. Which of the following are correct. Select the one correct answer.
A. JSP scriptlets and declarations result in code that is inserted inside the _jspService
method.
B. The JSP statement <%! int x; %> is equivalent to the statement
<jsp:scriptlet>int x;</jsp:scriptlet%>.
C. The following are some of the predefined variables that maybe used in JSP
expression - httpSession, context.
D. To use the character %> inside a scriptlet, you may use %\> instead.
7. What gets printed when the following is compiled. Select the one correct answer.
<% int y = 0; %>
<% int z = 0; %>

<% for(int x=0;x<3;x++) { %>


<% z++;++y;%>
<% }%>

<% if(z<y) {%>


<%= z%>
<% } else {%>
<%= z - 1%>
<% }%>

A. 0
B. 1
C. 2
D. 3
E. The program generates compilation error.

8. Which of the following JSP variables are not available within a JSP expression. Select
the one correct answer.
A. out
B. session
C. request
D. response
E. httpsession
F. page

9. A bean with a property color is loaded using the following statement

<jsp:usebean id="fruit" class="Fruit"/>


Which of the following statements may be used to print the value of color property of the
bean. Select the one correct answer.

A. <jsp:getColor bean="fruit"/>
B. <jsp:getProperty id="fruit" property="color"/>
C. <jsp:getProperty bean="fruit" property="color"/>
D. <jsp:getProperty name="fruit" property="color"/>
E. <jsp:getProperty class="Fruit" property="color"/>
10. A bean with a property color is loaded using the following statement

<jsp:usebean id="fruit" class="Fruit"/>


Which of the following statements may be used to set the of color property of the bean.
Select the one correct answer.

A. <jsp:setColor id="fruit" property="color" value="white"/>


B. <jsp:setColor name="fruit" property="color" value="white"/>
C. <jsp:setValue name="fruit" property="color" value="white"/>
D. <jsp:setProperty name="fruit" property="color" value="white">
E. <jsp:setProperty name="fruit" property="color" value="white"/>
F. <jsp:setProperty id="fruit" property="color" value="white">

11. A bean with a property color is loaded using the following statement

<jsp:usebean id="fruit" class="Fruit"/>


What happens when the following statement is executed. Select the one correct answer.
<jsp:setProperty name="fruit" property="*"/>

A. This is incorrect syntax of <jsp:setProperty/> and will generate a compilation


error. Either value or param must be defined.
B. All the properties of the fruit bean are initialized to a value of null.
C. All the properties of the fruit bean are assigned the values of input parameters of
the JSP page that have the same name.
D. All the properties of the fruit bean are initialized to a value of *.

12. Is the following statement true or false. If the isThreadSafe attribute of the page directive
is false, then the generated servlet implements the SingleThreadModel interface.

13. Which of the following represents a correct syntax for usebean. Select the two correct
answers.
A. <jsp:usebean id="fruit scope ="page"/>
B. <jsp:usebean id="fruit type ="String"/>
C. <jsp:usebean id="fruit type ="String" beanName="Fruit"/>
D. <jsp:usebean id="fruit class="Fruit" beanName="Fruit"/>

14. Name the default value of the scope atribute of <jsp:usebean>.


A. page
B. application
C. session
D. request

15. Which of the following statements are true for <jsp:usebean>. Select the two correct
answers.

A. The id attribute must be defined for <jsp:usebean>.


B. The scope attribute must be defined for <jsp:usebean>.
C. The class attribute must be defined for <jsp:usebean>.
D. The <jsp:usebean> must include either type or class attribute or both.

16. Which of these are legal attributes of page directive. Select the two correct answers.
A. include
B. scope
C. errorPage
D. session
E. debug

17. Which of the following represents the XML equivalent of this statement <%@ include
file="a.jsp"%> . Select the one correct statement
A. <jsp:include file="a.jsp"/>
B. <jsp:include page="a.jsp"/>
C. <jsp:directive.include file="a.jsp"/>
D. There is no XML equivalent of include directive.

18. Assume that you need to write a JSP page that adds numbers from one to ten, and then
print the output.

<% int sum = 0;


for(j = 0; j < 10; j++) { %>
// XXX --- Add j to sum
<% } %>
// YYY --- Display the sum

Which statement when placed at the location XXX can be used to compute the sum.
Select the one correct statement

A. <% sum = sum + j %>


B. <% sum = sum + j; %>
C. <%= sum = sum + j %>
D. <%= sum = sum + j; %>

19. Now consider the same JSP example as last question. What must be added at the location
YYY to print the sum of ten numbers. Select the one correct statement
A. <% sum %>
B. <% sum; %>
C. <%= sum %>
D. <%= sum; %>

20. JSP pages have access to implicit objects that are exposed automatically. One such object
that is available is request. The request object is an instance of which class?

A. HttpRequest
B. ServletRequest
C. Request
D. HttpServletRequest
21. JSP pages have access to implicit objects that are exposed automatically. Name the
implicit object that is of type HttpSession.

A. session
B. application
C. httpSession
D. httpsession

22. A Java bean with a property color is loaded using the following statement

<jsp:usebean id="fruit" class="Fruit"/>


What is the effect of the following statement.
<jsp:setproperty name="fruit" property="color"/>
Select the one correct answer.

A. An error gets generated because the value attribute of setAttribute is not defined.
B. The color attribute is assigned a value null.
C. The color attribute is assigned a value "".
D. If there is a non-null request parameter with name color, then its value gets
assigned to color property of Java Bean fruit.

23. The page directive is used to convey information about the page to JSP container. Which
of these are legal syntax of page directive. Select the two correct statement
A. <% page info="test page" %>
B. <%@ page info="test page" session="false"%>
C. <%@ page session="true" %>
D. <%@ page isErrorPage="errorPage.jsp" %>
E. <%@ page isThreadSafe=true %>

24. Is the following JSP code legal? Select the one correct statement.
<%@page info="test page" session="false"%>
<%@page session="false"%>
A. Yes. This is legal JSP syntax.
B. No. This code will generate syntax errors.

25. A JSP page needs to generate an XML file. Which attribute of page directive may be
used to specify that the JSP page is generating an XML file.

A. contentType
B. generateXML
C. type
D. outputXML

26. 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 answer.

A. extends
B. import
C. include
D. package
E. classpath

27. Which of these are true. Select the two correct answers.

A. The default value of isThreadSafe attribute of page directive is true.


B. If isThreadSafe attribute of page directive is set to true, then JSP container
dispatches request for the page sequentially.
C. When isThreadSafe attribute of page directive is set to true, a thread is created for
each request for the page.
D. Setting isThreadSage attribute to true for JSP pages, can lead to poor performance.
28. Which of the following are examples of JSP directive. Select the two correct
answers.(?)(not checked yet)
A. include
B. exclude
C. import
D. taglibrary
E. servlet
F. page

29. Which of these is true about include directive. Select the one correct answer.
A. The included file must have jspf extension.
B. The XML syntax of include directive in <jsp:include file="fileName"/> .
C. The content of file included using include directive, cannot refer to variables local
to the original page.
D. When using the include directive, the JSP container treats the file to be included
as if it was part of the original file.

30. Name the implicit variable available to JSP pages that may be used to access all the other
implicit objects.
A. page
B. pageContext
C. context
D. object
E. jspPave

Answers to questions on JSP

1. d. When using scriptlets (that is code included within <% %>), the included code must
have legal Java syntax. So the first statement must end with a semi-colon. The second
statement on the other hand is a JSP expression. So it must not end with a semi colon.
2. b. JSP declarations do not have access to automatically defined variables like request,
response etc.
3. b. The XML syntax for JSP expression is <jsp:expression>Java
expression</jsp:expression>
4. e. The XML syntax for JSP scriptlets is <jsp:scriptlet>Java code</jsp:scriptlet>
5. d. The if statement, else statement and closing parenthesis are JSP scriptlets and not JSP
expressions. So these should be included within <% } %>
6. d. JSP declarations are inserted outside of _jspService method. Hence a is incorrect. The
JSP statement <%!int a;%> is equivalent to <jsp:declaration>int
x;</jsp:declaration>. Hence b is incorrect. The predefined variables that are
available within the JSP expression are session and pageContext, and not httpSession and
context. Hence c is incorrect.
7. c. After the for loop z and y are both set to 3. The else satement gets evaluated, and 2 gets
printed in the browser.
8. e. There is no such variable as httpsession.
9. jsp:getProperty takes two attributes - name and property. The name attribute must match
the id attribute of jsp:usebean.
10. e. The jsp:setProperty takes three attributes - name, property and value. Also the
jsp:setProperty must end with />.
11. c. Using * for property is legal syntax. Bean properties are associated with identically
named input parameters.
12. true. The page directive is defined as <%@page isThreadSafe="false"%>
13. b,c.
14. a. The default scope of the declared bean is page.
15. a,d. The scope and class attributes are not required. But either class or type must be
defined.
16. c,d. The following are legal attributes of page directive - import, isThreadSafe, session,
contentType, autoFlush, extends, info, errorPage, isErrorPage, language.
17. c. <jsp:directive.include> is the XML equivalent of include directive.
18. b. As this is a a Java statement it needs to be included with <% and %>, and it needs to
end in semi-colon.
19. c. As this is a a Java expression it needs to be included with <%= and %>, and it should
not end in semi-colon.
20. d. request is an instance of HttpServletRequest
21. a. Implicit object session is of type HttpSession.
22. d. This is a legal syntax to set a property of JavaBean. The value attribute of setProperty
is optional.
23. b,c. The option a is incorrect because page directive must be included within <%@ . d is
incorrect because the value of isErrorPage attribute must be boolean. e is incorrect
because, the value true is not within quotes.
24. b. Except the import attribute of page directive, all the other attributes of page directive
cannot be specified more than once. In this example session attribute is specified twice.
25. a. contentType attribute is used to generate XML. The syntax will look like -
<%@page contentType="text/xml"/>
26. B. The syntax will look like -
<%@page import="java.util.ArrayList"/>
27. a,c. The default value of isThreadSafe attribute is true. So a is correct. If isThreadSafe is
set to false, then JSP container processes request sequentially, and this leads to poor
performance. Hence b and d are incorrect.
28. a,f. include, taglib and page are examples of JSP directives. The JSP directives have this
syntax -
<%@directive attribute="value" %>
29. d. It is not required that the included file has jspf extension. Hence a is incorrect. The
XML syntax of include directive is <jsp:directive.include>
30. b. This pageContext object is an instance of type javax.servlet.jsp.PageContext, and
provides methods like getPage(), getRequest(), etc. to access other input variables.

Questions on Deployment Descriptor

1. Which of the following files is the correct name and location of deployment descriptor of
a web application. Assume that the web application is rooted at \doc-root. Select the one
correct answer
A. \doc-root\dd.xml
B. \doc-root\web.xml
C. \doc-root\WEB-INF\web.xml
D. \doc-root\WEB_INF\dd.xml
E. \doc-root\WEB-INF\dd.xml
F. \doc-root\WEB_INF\web.xml
G. \doc-root\WEB-INF\lib\dd.xml
H. \doc-root\WEB-INF\classes\dd.xml

2. Which element of the servlet element in the deployment descriptor is used to specify
the parameters for the ServletConfig object. Select the one correct answer.
A. servlet-config
B. init-param
C. load-on-startup
D. filter

3. Which of these is true about deployment descriptors. Select the one correct answer.
A. The order of elements in deployment descriptor is not important. The elements
can follow any order.
B. The elements of deployment descriptor are case insensitive.
C. The servlet-mapping element, if defined, must be included within the servlet
element.
D. The web-app element must include the servlet element.

4. The exception-type element specifies an exception type and is used to handle exceptions
generated from a servlet. Which element of the deployment descriptor includes the
exception-type as a sub-element. Select the one correct answer.
A. error-page
B. servlet
C. exception
D. error-handling

5. Which of these is a correct fragment within the web-app element of deployment


descriptor. Select the one correct answer.
A. <exception> <exception-type> mypackage.MyException</exception-type>
<location> /error.jsp</location> </exception>
B. <error-page> <exception-type> mypackage.MyException</exception-type>
<location> /error.jsp</location> </error-page>
C. <error-page> <exception> mypackage.MyException </exception-type>
<location> /error.jsp </location> </error-page>
D. <error-page> <exception-type> mypackage.MyException</exception-type>
</error-page>
E. <error-page> <servlet-name> myservlet</servlet-name> <exception-type>
mypackage.MyException</exception-type> </error-page>
F. <exception> <servlet-name> myservlet</servlet-name> <exception-type>
mypackage.MyException</exception-type> </exception>

6. Which element of the deployment descriptor of a web application includes the welcome-
file-list element as a subelement. Select the one correct answer.(?)(not checked yet)
A. web-app
B. welcome-file
C. servlet
D. file-list

7. Which of these is a correct fragment within the web-app element of deployment


descriptor. Select the two correct answer.
A. <error-page> <error-code>404</error-code> <location>/error.jsp</location>
</error-page>
B. <error-page> <exception-type>mypackage.MyException</exception-type>
<error-code>404</error-code> <location>/error.jsp</location> </error-page>
C. <error-page> <exception-type>mypackage.MyException</exception-type>
<error-code>404</error-code> </error-page>
D. <error-page> <exception-type>mypackage.MyException</exception-type>
<location>/error.jsp</location> </error-page>

8. Which of these is a correct example of specifying a listener element resented by MyClass


class. Assume myServlet element is defined correctly. Select the one correct answer.
A. <listener>MyClass</listener>
B. <listener> <listener-class>MyClass</listener-class></listener>
C. <listener> <listener-name>aListener</listener-name> <listener-
class>MyClass</listener-class> </listener>
D. <listener> <servlet-name>myServlet</servlet-name> <listener-
class>MyClass</listener-class> </listener>

9. The root of the deployment descriptor is named as


A. web
B. web-app
C. name
D. display-name

10. With in a context-param element of deployment descriptor, which of the following


element is required?
A. param-name
B. name
C. init-param
D. servlet-name

11. Which of these is not a valid top level element in web-app


A. icon
B. listener
C. eror-page
D. security-constraint
E. param-name
12. Which of the follwing are mandatory elements within the filter element. Select two
correct answers.
A. filter-name
B. name
C. value
D. filter-class
E. init-param

13. Which of these is not a valid value for dispatcher element of filter-mapping. Select the
one correct answer.
A. FORWARD
B. RESPONSE
C. INCLUDE
D. ERROR

14. Which of these is not correct about the filter-mapping element of web-app. Select the one
correct answer.
A. filter-name element must be present in the filter-mapping element.
B. Either url-pattern or servlet-name must be present in the filter-mapping element.
C. dispatcher element can be declared zero to three times in the filter-mapping
element.
D. filter-name element in the filter-mapping should be same as the corresponding
filter-name element in the filter element of deployment descriptor.

Answers to questions on Deployment Descriptor

1. C. The deployment descriptor must be called web.xml and be placed in the directory
named WEB-INF
2. B. init-param is used to specify parameters that are accessed using ServletConfig object.
3. A. In the deployment descriptor the elements in the web-app element can come in any
order. B is incorrect because elements are case-sensitive. The servlet-mapping element
should be included within the <web-app> element. So C is incorrect. All the elements
within the web-app element are optional. So D is incorrect.
4. a. error-page element in the element web-app element is used to specify the exception
name.
5. b. The error-page element includes exception-type and location as sub-element. Both
these elements must be defined.
6. A. welcome-file-list is included within the web-app element.
7. A,D. error-page element must include either exception-type or error-code element but not
both. It must also include the location element.
8. B. The element listener-class must be included within the listener element.
9. B. <web-app> element is the root of the deployment descriptor. It has one attribute
named version.
10. A. param-name and param-value are required within the context-param element.

11. E. param-name is a child of context-param element.


12. A and D. filter-name and filter-class are required elements of the filter element.
13. B. The four possible values of the dispatcher element are - FORWARD, INCLUDE,
REQUEST and ERROR. RESPONSE is not a value for the dispatcher element.
14. C. dispatcher element can be declared upto four times.

Questions on tag library


1. When implementing a tag, if the tag just includes the body verbatim, or if it does not
include the body, then the tag handler class must extend the BodyTagSupport class. Is
this statement true of false.

2. Fill in the blanks. A tag handler class must implement the


javax.servlet.jsp.tagext.Tag interface. This is accomplished by extending the class
TagSupport or another class named in one of the options below. Select the one correct
answer.
A. IterationTag
B. TagClass
C. BodyTag
D. BodyTagSupport

3. Is this statement true or false. The deployment descriptor of a web application must have
the name web.xml . In the same way the tag library descriptor file must be called
taglib.xml .
4. A JSP file that uses a tag library must declare the tag library first. The tag library is
defined using the taglib directive - <%= taglib uri="..." prefix="..."%>

Which of the following specifies the correct purpose of prefix attribute. Select the one
correct answer.

A. The prefix defines the name of the tag that may be used for a tag library.
B. The prefix attribute defines the location of the tag library descriptor file.
C. The prefix attribute should refer to the short name attribute of the tag library file
that is defined by the uri attribute of taglib directive.
D. The prefix attribute is used in front of a tagname of a tag defined within the tag
library.

5. A JSP file uses a tag as <myTaglib:myTag>. The myTag element here should be defined
in the tag library descriptor file in the tag element using which element. Select the one
correct answer.
A. tagname
B. name
C. tag
D. prefix

6. Which of the elements defined within the taglib element of taglib descriptor file are
required. Select the two correct answers.
A. tlib-version
B. short-name
C. uri
D. display-name

7. Which of the elements defined within the taglib element of taglib descriptor file are
required. Select the two correct answers.
A. name
B. description
C. validator
D. tag-class
E. display-name

8. Name the element within the tag element that defines the name of the class that
implements the functionality of tag. Select the one correct answer.

A. class-name
B. tag
C. class
D. tag-class
E. tei-class

9. Which of these are legal return types of the doStartTag method defined in a class that
extends TagSupport class. Select the two correct answers.
A. EVAL_PAGE
B. EVAL_BODY
C. EVAL_PAGE_INCLUDE
D. EVAL_BODY_INCLUDE
E. SKIP_PAGE
F. SKIP_BODY
G. SKIP_PAGE_INCLUDE
H. SKIP_BODY_INCLUDE

10. Which of these are legal return types of the doAfterBody method defined in a class that
extends TagSupport class. Select the two correct answers.
A. EVAL_PAGE
B. EVAL_BODY
C. EVAL_PAGE_AGAIN
D. EVAL_BODY_AGAIN
E. SKIP_PAGE
F. SKIP_BODY
G. SKIP_PAGE_AGAIN
H. SKIP_BODY_AGAIN
11. Which of these are legal return types of the doEndTag method defined in a class that
extends TagSupport class. Select the two correct answers.
A. EVAL_PAGE
B. EVAL_BODY
C. EVAL_PAGE_INCLUDE
D. EVAL_BODY_INCLUDE
E. SKIP_PAGE
F. SKIP_BODY
G. SKIP_PAGE_INCLUDE
H. SKIP_BODY_INCLUDE

Answers to questions on tag library

1. false. Such a class should extend the TagSupport class.


2. D. BodyTagSupport extends TagSupport and implements interfaces Tag and IterationTag.
3. false. The tag library descriptor file can have any name. It need not have the name
taglib.xml .
4. d. If the taglib directive directive defines a prefix of test, and a tag is called myTag, then
the tag is used as <test:myTag>.
5. b. The name element inside the tag element defines the tag name to which the prefix of
the taglib is attached. For example <name> myTag </name>
6. a,b. tlib-version and short-name are required elemets within the taglib element of the the
tag library descriptor file.
7. a,d. name and tag-class are required elements within the tag element of tag library
descriptor file.
8. d. tag-class element defines the fully qualified class name of the tag in the TLD file.
9. d,f. EVAL_BODY_INCLUDE, and SKIP_BODY are legal return types of doStartTag.
10. d,f. EVAL_BODY_AGAIN, and SKIP_BODY are legal return types of doAfterBody.
11. a,e. EVAL_PAGE and SKIP_PAGE are legal return types of doEndTag

javaprepare.com - Questions on Servlets


1. The method getWriter returns an object of type PrintWriter. This class has println
methods to generate output. Which of these classes define the getWriter method? Select
the one correct answer.
A. HttpServletRequest
B. HttpServletResponse
C. ServletConfig
D. ServletContext

2. Name the method defined in the HttpServletResponse class that may be used to set the
content type. Select the one correct answer.
A. setType
B. setContent
C. setContentType
D. setResponseContentType

3. Which of the following statement is correct. Select the one correct answer.
A. The response from the dedicated server to a HEAD request consists of status line,
content type and the document.
B. The response from the server to a GET request does not contain a document.
C. The setStatus method defined in the HttpServletRequest class takes an int as an
argument and sets the status of Http response
D. The HttpServletResponse defines constants like SC_NOT_FOUND that may be
used as a parameter to setStatus method.

4. The sendError method defined in the HttpServlet class is equivalent to invoking the
setStatus method with the following parameter. Select the one correct answer.
A. SC_OK
B. SC_MOVED_TEMPORARILY
C. SC_NOT_FOUND
D. SC_INTERNAL_SERVER_ERROR
E. ESC_BAD_REQUEST
5. The sendRedirect method defined in the HttpServlet class is equivalent to invoking the
setStatus method with the following parameter and a Location header in the URL. Select
the one correct answer.
A. SC_OK
B. SC_MOVED_TEMPORARILY
C. SC_NOT_FOUND
D. SC_INTERNAL_SERVER_ERROR
E. ESC_BAD_REQUEST

6. Which of the following statements are correct about the status of the Http response.
Select the one correct answer.
A. A status of 200 to 299 signifies that the request was successful.
B. A status of 300 to 399 are informational messages.
C. A status of 400 to 499 indicates an error in the server.
D. A status of 500 to 599 indicates an error in the client.

7. To send binary output in a response, the following method of HttpServletResponse may


be used to get the appropriate Writer/Stream object. Select the one correct answer.

A. getStream
B. getOutputStream
C. getBinaryStream
D. getWriter

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


used to get the appropriate Writer/Stream object. Select the one correct answer.

A. getStream
B. getOutputStream
C. getBinaryStream
D. getWriter
9. Is the following statement true or false. URL rewriting may be used when a browser is
disabled. In URL encoding the session id is included as part of the URL.

10. Name the class that includes the getSession method that is used to get the HttpSession
object.
A. HttpServletRequest
B. HttpServletResponse
C. SessionContext
D. SessionConfig

11. Which of the following are correct statements? Select the two correct answers.
A. The getRequestDispatcher method of ServletContext class takes the full path of
the servlet, whereas the getRequestDispatcher method of HttpServletRequest
class takes the path of the servlet relative to the ServletContext.
B. The include method defined in the RequestDispatcher class can be used to access
one servlet from another. But it can be invoked only if no output has been sent to
the server.
C. The getRequestDispatcher(String URL) is defined in both ServletContext and
HttpServletRequest method
D. The getNamedDispatcher(String) defined in HttpServletRequest class takes the
name of the servlet and returns an object of RequestDispatcher class.

12. A user types the URL http://www.javaprepare.com/scwd/index.html . Which HTTP


request gets generated. Select the one correct answer.
A. GET method
B. POST method
C. HEAD method
D. PUT method
13. Which HTTP method gets invoked when a user clicks on a link? Select the one correct
answer.
A. GET method
B. POST method
C. HEAD method
D. PUT method

14. When using HTML forms which of the folowing is true for POST method? Select the one
correct answer.
A. POST allows users to bookmark URLs with parameters.
B. The POST method should not be used when large amount of data needs to be
transferred.
C. POST allows secure data transmission over the http method.
D. POST method sends data in the body of the request.

15. Which of the following is not a valid HTTP/1.1 method. Select the one correct answer.
A. CONNECT method
B. COMPARE method
C. OPTIONS method
D. TRACE method

16. Name the http method used to send resources to the server. Select the one correct answer.
A. FTP methodd
B. PUT method
C. WRITE method
D. COPY method

17. Name the http method that sends the same response as the request. Select the one correct
answer.
A. DEBUG method
B. TRACE method
C. OPTIONS method
D. HEAD method
18. Which three digit error codes represent an error in request from client? Select the one
correct answer.
A. Codes starting from 200
B. Codes starting from 300
C. Codes starting from 400
D. Codes starting from 500

19. Name the location of compiled class files within a war file? Select the one correct answer.
A. /META-INF/classes
B. /classes
C. /WEB-INF/classes
D. /root/classes

Answers to questions on Servlets

1. B. The class HttpServletResponse defines the getWriter method.


2. B. setContentType sets the content type of the response being sent to the client.
3. D. The response from the server to a HEAD request does not contain the document,
whereas the response to GET request does contain a document. So A and B are incorrect.
C is incorrect because setStauts is defined in HttpServletResponse.
4. C. sendError(String URL) is equivalent to sending SC_NOT_FOUND (404) response
code.
5. B. sendRedirect(String URL) is equivalent to sending SC_MOVED_TEMPORARILY
(302) response code and a location header in the URL.
6. A. The following table specifies the specific the status code of Http response.

Status Code Purpose


100-199 Informational
200-299 Request was successful
300-399 Request file has moved.
400-499 Client error
500-599 Server error.
7. B. The getOutputStream method is used to get an output stream to send binary data. The
getWriter method is used to get a PrintWriter object that can be used to send text data.
8. D
9. true. The statement about URL encoding is correct.
10. A. The class HttpServletRequest defines the getSession method.
11. A, C.
12. A. GET method gets invoked when a URL is typed.
13. A. GET method gets invoked when user clicks on a link.
14. D. Since POST does not have attributes in the URL, it cannot be used to bookmark the
URL. Since arguments are present in the body of the request, using POST method does
not guarantee security.
15. B. COMPARE is not a valid HTTP method.
16. B. PUT method is used to send resources from client to server.
17. B. TRACE method is used for debugging. It sends the same response as request.
18. C. A status code of 4XX represents a client error.
19. C. Classes are stored in /WEB-INF/classes.

Questions on JSTL and EL


1. What gets printed when the following expression is evaluated? Select the one correct
answer.

${(1==2) ? 4 : 5}
A. 1
B. 2
C. 4
D. 5

2. What gets printed when the following expression is evaluated? Select the one correct
answer.

${4 div 5}
A. 0
B. 0.8
C. 1
D. -1
3. What gets printed when the following expression is evaluated? Select the one correct
answer.

${12 % 4}
A. 0
B. 3
C. 8
D. 16

4. 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="*"/>
A. The code does not compile as there is no property attribute of setProperty tag.
B. The code does not compile as property attribute cannot take * as a value.
C. The code sets value of all properties of employee bean to "*".
D. The code sets the values of all properties of employee bean to matrching
parameters in request object.

5. What is the effect of evaluation of following expression? Select the one correct answer.

${(5*5) ne 25}
A. true
B. false
C. 25
D. The expression does not compile as ne is not a valid operator.

6. What is the effect of evaluation of following expression? Select the one correct answer.

${'cat' gt 'cap'}
A. true
B. false
C. catcap
D. The expression does not compile as gt operator cannot be applied on strings.
7. How many numbers are printed, when the following JSTL code fragment is executed?
Select the one correct answer.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


<c:forEach var="item" begin="0" end="10" step="2">
${item}
</c:forEach>

A. 1
B. 5
C. 6
D. 11

8. What gets printed when the following JSTL code fragment is executed? Select the one
correct answer.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


<c:set var="item" value="2"/>
<c:if test="${var==1}" var="result" scope="session">
<c:out value="${result}"/>
</c:if>

A. The JSTL code does not compile as attribute for if tag are not correct.
B. true
C. false
D. Nothing gets printed.

9. What gets printed when the following JSTL code fragment is executed? Select the one
correct answer.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


<c:set var="item" value="2"/>
<c:forEach var="item" begin="0" end="0" step="2">
<c:out value="${item}" default="abc"/>
</c:forEach>

A. The JSTL code does not compile as an attribute for forEach tag is not correct.
B. 0
C. 2
D. ABC
E. Nothing gets printed as c.out statement does not get executed.
10. How many numbers gets printed when the following JSTL code fragment is executed?
Select the one correct answer.

<%@ taglib uri="http://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>

A. No number gets printed.


B. One number gets printed.
C. Two numbers gets printed.
D. Three numbers gets printed.
E. Four numbers gets printed.

11. Which numbers gets printed when the following JSTL code fragment is executed? Select
the two correct answers.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


<c:set var="j" value="4,3,2,1"/>
<c:forEach items="${j}" var="item" begin="1" end="2">
<c:out value="${item}" default="abc"/>
</c:forEach>

A. 1
B. 2
C. 3
D. 4
E. abc
F. The program does not compile.

12. Which numbers gets printed when the following JSTL code fragment is executed? Select
the two correct answers.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


<c:set var="j" value="4,3,2,1"/>
<c:forEach items="${j}" var="item" begin="1" end="2"
varStatus="status">
<c:out value="${status.count}" default="abc"/>
</c:forEach>
A. 1
B. 2
C. 3
D. 4
E. abc
F. The program does not compile.

13. Which number gets printed when the following JSTL code fragment is executed? Select
the one correct answers.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


<c:set var="j" value="4,3,2,1"/>
<c:forEach items="${j}" var="item" varStatus="status">
<c:if test="${status.first}">
<c:out value="${status.index}" default="abc"/>
</c:if>
</c:forEach>
A. 1
B. 2
C. 3
D. 4
E. abc
F. The program does not compile.

14. Which of these represent the correct path for the core JSTL library in JSTL version 1.1?
Select the one correct answer.
A. http://java.sun.com/jsp/jstl/core
B. http://java.sun.com/jsp/core
C. http://java.sun.com/core
D. http://java.sun.com/jsp/jstl1.1/core

Answers to questions on EL and JSTL

1. D. As 1 is not equal to 2, 5 gets printed.


2. B. div operator is used for dividing in EL.
3. A. % operator gives the remainder after performing division.
4. D. This is a valid syntax for setProperty. All properties of the bean are set from the
corresponding parameter names in the request object.
5. B. The code prints false. ne is a valid operator. Since both left hand side and right hand
side are equal to 25, false gets printed.
6. A. EL considers <cat> to be greater than <cap>, as the letter t comes after the letter p.
7. C. The following numbers get printed - 0, 2, 4, 6, 8, 10.
8. D. if evaluates to false, hence the c.out statement does not get executed.
9. B. The forEach tag gets executed once, and prints zero.
10. B. Only one number gets printed - the number 1.
11. B, C. In this case the forEach tag iterates through two elements of the array named j.
12. B, C. varStatus is set to a class of type LoopTagStatus. This class has a property named
count which is being printed. count is the loop index, beginning with 1. So for two
iterations 1 and 2 get printed. In this case the forEach tag iterates through two elements
of the array named j.
13. A. status.first is true for the first iteration. The index is set to 0 in the first iteration.
14. A. The path of core tag library in JSTL 1.1 is http://java.sun.com/jsp/jstl/core .
jsp, servlet, exceptions, syntaxes

statement = connection.createStatement(
java.sql.ResultSet.TYPE_FORWARD_ONL
Y,
java.sql.ResultSet.CONCUR_READ_ONLY
);
statement.setFetchSize(Integer.MIN_VALUE);

Which isolation level prevents dirty read in JDBC,


connection class.
(A) TRANSACTION_READ_ COMMITTED
(B) TRANSACTION_UNREAD_ COMMITTED

Isolation Level Table-Level Locking


Row-Level Locking

TRANSACTION_READ_UNCOMMITTED Dirty reads, nonre


peatable reads, and phantom reads possible Dirt
y reads, nonrepeatable reads, and phantom reads po
ssible
TRANSACTION_READ_COMMITTED Nonrepeatable reads an
d phantom reads possible Nonrepeatable re
ads and phantom reads possible
TRANSACTION_REPEATABLE_READ Phantom reads not poss
ible because entire table is locked Phantom read
s possible
TRANSACTION_SERIALIZABLE None
None

TYPE_SCROLL_INSENSITIVE:

The result can be scrolled;


its cursor can move both forward and backward relat
ive to the current position,
and it can move to an absolute position. The result
set is insensitive to changes made
to the underlying data source while it is open. It
contains the rows that satisfy the query
at either the time the query is executed or as the
rows are retrieved.
TYPE_SCROLL_SENSITIVE:

The result can be scrolled; its cursor can move


both forward and backward relative
to the current position, and it can move to an ab
solute position. The result set reflects
changes made to the underlying data source while t
he result set remains open.

What is the effect of executing the following JSP


statement, assuming a class with name Employee exi
sts in classes package.

<%@ page import = "classes.Employee" %> <jsp:useBe


an id="employee" class="classes.Employee" scope="s
ession"/> <jsp:setProperty name="employee" propert
y="*"/>

The code does not compile as there is no proper


ty attribute of setProperty tag.
The code does not compile as property attribute
cannot take * as a value.
The code sets value of all properties of employ
ee bean to "*".
Ans) The code sets the values of all properties
of employee bean to matrching parameters in reque
st object.

bookmark is in get.

1. class Animal {
public String noise() {
return "peep";
}
}
class Dog extends Animal {
public String noise() {
return "bark";
}
}
class Cat extends Animal {
public String noise() {
return "meow";
}
}
...
30. Animal animal = new Dog();
31. Cat cat = (Cat)animal;
32. System.out.println(cat.noise());

What is the result?

A. peep
B. bark
C. meow
D. Compilation fails.
E. An exception is thrown at runtime.

Answer: E

1. class A {
2. void foo() throws Exception {
3. throw new Exception();
4. }
5. }
6.
7. class SubB2 extends A {
8. void foo() {
9. System.out.println("B ");
10. }
11. }
12. class Tester {
13. public static void main(String[] args) {
14. A a = new SubB2();
15. a.foo();
16. }
17. }

What is the result?

A. B
B. B, followed by an Exception.
C. Compilation fails due to an error on line 9.
D. Compilation fails due to an error on line 15.
E. An Exception is thrown with no other output

Answer: D
Section: All

Explanation/Reference:
Unhandled exception type Exception

2. legal s3=s2+s1
3. when we are sending data in URl in get method ho
w to separate
parameters? ANs) &
when we are sending data in URl in get method how t
o separate
parameter and separate path? ANs) ?

4. class multithreaded_programing{
public static void main(String args[]){
Thread t = Thread.currentThread();
t.setname("new thread");
System.out.println(t);
}
}

ans- thread[new thread,5,main]

5. current thread
public class MyRunnable implements runnable{
public void run(){
//some code
}}
which of these will create and start this thread?

Ans) new Thread(new MyRunnable()).start();

Description: Becuase the class implements Runnable,

an instance of it has to be passed to the Thread co


nstructor
and then the instance of the Thread has to be start
ed.

6. class Mammal { }

class Raccoon extends Mammal {

Mammal m = new Mammal();

class BabyRaccoon extends Mammal { }

Which four statements are true? (Choose four.)

A. Raccoon is-a Mammal.

B. Raccoon has-a Mammal.

C. BabyRaccoon is-a Mammal.

D. BabyRaccoon is-a Raccoon.

E. BabyRaccoon has-a Mammal.

F. BabyRaccoon is-a BabyRaccoon.

Answer: A,B,C,F

Explanation :Check is-A and Has-A relationship betw


een both classes.

7. What is the output of this program?

import java.io.*;

public class filesinputoutput {

public static void main(String[] args)


{

String obj = "abc";

byte b[] = obj.getBytes();

ByteArrayInputStream obj1 = new Byte


ArrayInputStream(b);

for (int i = 0; i < 2; ++ i) {

int c;

while ((c = obj1.read()) != -1)


{

if (i == 0) {

System.out.print(Charact
er.toUpperCase((char)c)); }}}}}
ans) ABC

8. class output {

public static void main(String args[])

StringBuffer s1 = new StringBuffer("


Hello World");

s1.insert(6 , "Good ");

System.out.println(s1);

a) HelloGoodWorld
b) HellGoodoWorld
c) HellGood oWorld
d) Hello Good World

Answer: d
Explanation: The insert() method inserts one string
into another. It is overloaded
to accept values of all simple types, plus String
and Objects. Sting is inserted into invoking objec
t at
specified position. “Good ” is inserted in “Hello W
orld” T index 6 giving “Hello Good World”.
output:
$ javac output.java
$ java output
Hello Good World

9. string index(i)

10. Which of these keywords cannot be used for a cl


ass which has been declared final?
a) abstract
b) extends
c) abstract and extends
d) None of the mentioned
View Answer
Answer: a
Explanation: A abstract class is incomplete by its
elf and relies upon its subclasses to provide comp
lete
implementation. If we declare a class final then n
o class can inherit that class, an abstract class
needs its subclasses
hence both final and abstract cannot be used for a
same class.

11. import all- import .*

12. abstract class abc{


abstract ...(int a, int b, int c)
Q= method declared right?

13. sos('1'+new integer(2)+3);


ANS-123
14.int a[]=new int[]{1,2,6,4,5};
int b[]=new int[5];
b[2]=a[2];
a[2]=10;
System.out.println(b[2]);
ans: 6

15. GENERICS STRING TAG QUESTION

16. What gets printed when the following JSTL code


fragment is executed? Select the one correct answ
er.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core"


prefix="c" %>
<c:set var="item" value="2"/>
<c:if test="${var==1}" var="result" scope="session"
>
<c:out value="${result}"/>
</c:if>

A.The JSTL code does not compile as attribute f


or if tag are not correct.
B.true
C. false
Ans D. Nothing gets printed.

17. ideal
removin loop
-operations
a)idea
b)deal

18.The sendError method defined in the HttpServlet


class is
equivalent to invoking the setStatus method with th
e following
parameter. Select the one correct answer.
4.
A. SC_OK
B. SC_MOVED_TEMPORARILY
C. SC_NOT_FOUND Ans) C
D. SC_INTERNAL_SERVER_ERROR
E. ESC_BAD_REQUEST
5. The sendRedirect method defined

The sendRedirect method defined in the HttpServlet


class is
equivalent to invoking the setStatus method with th
e following
parameter and a Location header in the URL. Select
the one
correct answer.
A. SC_OK
B. SC_MOVED_TEMPORARILY Ans) B
C. SC_NOT_FOUND
D. SC_INTERNAL_SERVER_ERROR
E. ESC_BAD_REQUEST

19.doget is in which? a)request.httpresponse ? b)re


sponse.http?
20.jsp-attributes: differentiate a), b)& c)?
21. independently vary=bridge
22. factory set

23. A team of programmers is involved in reviewing


a proposed design for a new utility class.
After some discussion, they realize that the curre
nt design allows other classes to access
methods in the utility class that should be access
ible only to methods within the utility class itse
lf.

What design issue has the team discovered?

A. Tight coupling
B. Low cohesion
C. High cohesion
D. Loose coupling
E. Weak encapsulation
F. Strong encapsulation

Answer: E
24. instanceof

25. man dog best friend ans:class man{private dog b


est friend;}

26. push pop stack


27. blue mmix deploy cloud foundry ans)cf push
28. 1..*At least one instance
29. window if class=underline
30. abstract class- italics
31. slant line for delay
32. hollow diamond on collection side for aggregat
ion, filled for composition and hollow triangle fo
r generalization.
33. jstl
34. arrow towards mammal
35. iterator question
36. hasnext(), traverse
37. junit testing in which order
38. scroll insensitive
39. What is the output of this program?

import java.util.*;

class vector {

public static void main(String args[])


{

Vector obj = new Vector(4,2);

obj.addElement(new Integer(3));

obj.addElement(new Integer(2));

obj.addElement(new Integer(5));

obj.removeAll(obj);

System.out.println(obj.isEmpty());
}

a) 0
b) 1
c) true
d) false
View Answer
Answer: c
Explanation: firstly elements 3, 2, 5 are entered
in the vector obj, but when obj.removeAll(obj); is
executed all the elements are deleted and vector
is empty, hence obj.isEmpty() returns true.
Output:
$ javac vector.java
$ java vector
true

40. import java.util.*;

class Array {

public static void main(String args[])


{

int array[] = new int [5];

for (int i = 5; i > 0; i--)

array[5 - i] = i;

Arrays.sort(array);

for (int i = 0; i < 5; ++i)

System.out.print(array[i]);;

} Ans) 12345
41. What is the output of this program?
import java.util.*;

class Maps {

public static void main(String args[])


{

TreeMap obj = new TreeMap();

obj.put("A", new Integer(1));

obj.put("B", new Integer(2));

obj.put("C", new Integer(3));

System.out.println(obj.entrySet());

a) [A, B, C]
b) [1, 2, 3]
c) {A=1, B=2, C=3}
d) [A=1, B=2, C=3]
Answer: d
Explanation: obj.entrySet() method is used to obta
in a set that contains the entries in the map. Thi
s method provides set view of the invoking map.
Output:
$ javac Maps.java
$ java Maps
[A=1, B=2, C=3]

42. What is the output of this program?

import java.util.*;

class Bitset {
public static void main(String args[])
{

BitSet obj = new BitSet(5);

for (int i = 0; i < 5; ++i)

obj.set(i);

obj.clear(2);

System.out.print(obj);

a) {0, 1, 3, 4}
b) {0, 1, 2, 4}
c) {0, 1, 2, 3, 4}
d) {0, 0, 0, 3, 4}
View Answer
Answer: a
Explanation: None.
Output:
$ javac Bitset.java
$ java Bitset
{0, 1, 3, 4}

43. What is the output of this program?

import java.util.*;

class Array {

public static void main(String args[])


{

int array[] = new int [5];

for (int i = 5; i > 0; i--)


array[5-i] = i;

Arrays.fill(array, 1, 4, 8);

for (int i = 0; i < 5 ; i++)

System.out.print(array[i]);

advertisements
a) 12885
b) 12845
c) 58881
d) 54881
View Answer
Answer: c
Explanation: array was containing 5,4,3,2,1 but wh
en method Arrays.fill(array, 1, 4, 8) is called it
fills the index location starting with 1 to 4 by
value 8 hence array becomes 5,8,8,8,1.
Output:
$ javac Array.java
$ java Array
58881

44. prefix uri


45. last; or;last
46. What is the output of this program?

import java.util.*;

class Collection_Algos {

public static void main(String args[])


{

LinkedList list = new LinkedList();


list.add(new Integer(2));

list.add(new Integer(8));

list.add(new Integer(5));

list.add(new Integer(1));

Iterator i = list.iterator();

Collections.reverse(list);

Collections.shuffle(list);

while(i.hasNext())

System.out.print(i.next() + " ");

a) 2 8 5 1
b) 1 5 8 2
c) 1 2 5 8
d) Any random order

Answer: d
Explanation: shuffle – randomizes all the elements
in a list.
Output:
$ javac Collection_Algos.java
$ java Collection_Algos
1 5 2 8
(output will be different on your system)

47.What is the output of this program?

import java.util.*;

class Collection_Algos {
public static void main(String args[])
{

LinkedList list = new LinkedList();

list.add(new Integer(2));

list.add(new Integer(8));

list.add(new Integer(5));

list.add(new Integer(1));

Iterator i = list.iterator();

Collections.reverse(list);

Collections.sort(list);

while(i.hasNext())

System.out.print(i.next() + " ");

a) 2 8 5 1
b) 1 5 8 2
c) 1 2 5 8
d) 2 1 8 5

Answer: c
Explanation: Collections.sort(list) sorts the give
n list, the list was 2->8->5->1 after sorting it b
ecame 1->2->5->8.
Output:
when reverse 1 5 8 2
but sorting 1 2 5 8 ans is C
48. URL from a remote location protocol http is use
d. a)http b)https c)both d)none [Ans. c]
49. <%@ taglib uri="http://java.sun.com/jsp/jstl/co
re"
prefix="c" %>
<c:set var="item" value="2"/>
<c:forEach var="item" begin="0" end="0" step="2">
<c:out value="${item}" default="abc"/>
</c:forEach>
The JSTL code does not compile as an attribute for
forEach
tag is not correct. Ans A
A. 0
B. 2
C. ABC
D. Nothing gets printed as c.out statement does not
get executed.

50.<%@ taglib uri="http://java.sun.com/jsp/jstl/cor


e"
prefix="c" %>
<c:set var="j" value="4,3,2,1"/>
<c:forEach items="${j}" var="item" varStatus="statu
s">
<c:if test="${status.first}">
<c:out value="${status.index}" default="abc"/>
</c:if>
</c:forEach>
A. 1
B. 2
C. 3
D. 4
E. abc
F. The program does not compile

51.What is the output of this program?

import java.util.*;

public class genericstack <E> {


Stack <E> stk = new Stack <E>();

public void push(E obj) {

stk.push(obj);

public E pop() {

E obj = stk.pop();

return obj;

class Output {

public static void main(String args[])


{

genericstack <String> gs = new gene


ricstack<String>();

gs.push("Hello");

System.out.print(gs.pop() + " ");

genericstack <Integer> gs = new gen


ericstack<Integer>();

gs.push(36);

System.out.println(gs.pop());

a) Error
b) Hello
c) 36
d) Hello 36

Answer: d
Explanation: None.
Output:
$ javac Output.java
$ java Output
Hello 36

52. class output {

public static void main(String args[])

StringBuffer c = new StringBuffer(


"Hello");

StringBuffer c1 = new StringBuffer


(" World");

c.append(c1);

System.out.println(c);

a) Hello
b) World
c) Helloworld
d) Hello World Ans-d.

53.class output {

public static void main(String args[])

{
StringBuffer s1 = new StringBuffer("
Hello");

s1.setCharAt(1,'x');

System.out.println(s1);

a) xello
b) xxxxx
c) Hxllo
d) Hexlo
View Answer
Answer: c
Explanation: None.
Output:
$ javac output.java
$ java output
Hxllo

54. switch case


55. array of string
56. "welcome.trim()"= when compiled ans) equals

57. builder pattern


58. Question on this:

Calendar calendar = new GregorianCalendar();

int year = calendar.get(Calendar.YEAR);


int month = calendar.get(Calendar.MONTH);
int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH
); // Jan = 0, not 1
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK)
;
int weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR
);
int weekOfMonth= calendar.get(Calendar.WEEK_OF_MONT
H);
int hour = calendar.get(Calendar.HOUR);
// 12 hour clock
int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY)
; // 24 hour clock
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
int millisecond= calendar.get(Calendar.MILLISECOND)
;

59. class output {

public static void main(String args[])

String s1 = "one";

String s2 = s1 + " two";

System.out.println(s2);

a) one
b) two
c) one two
d) compilation error
View Answer
Answer: c

60. Total number of users using listners - ans. ht


tpsessionlistner

61. class exception_handling {

public static void main(String args[])


{
try {

System.out.print("Hello" + " "


+ 1 / 0);

catch(ArithmeticException e) {

System.out.print("World");

a) Hello
b) World
c) HelloWorld
d) Hello World

Answer: b

62. class output {

public static void main(String args[])

char c[]={'a', '1', 'b' ,' ' ,'A' ,


'0'};

for (int i = 0; i < 5; ++i)

if(Character.isDigit(c[i]))

System.out.println(c[i]+
" is a digit");

if(Character.isWhitespace(c[
i]))

System.out.println(c[i]+
" is a Whitespace character");

if(Character.isUpperCase(c[i
]))

System.out.println(c[i]+
" is an Upper case Letter");

if(Character.isLowerCase(c[i
]))

System.out.println(c[i]+
" is a lower case Letter");

i=i+3;

a) a is a lower case Letter


is White space character
b) b is a lower case Letter
is White space character
c) a is a lower case Letter
A is a upper case Letter
d) a is a lower case Letter
0 is a digit
View Answer
Answer:c

62. Two questions on these.


Interfaces for Event Listeners-
Session Serialization--HttpSession
Request Lifecycle Event--ServletRequestListener

Session Attribute Binding--HttpSessionAttribute


Listener
Session LifecycleEvent--HttpsessionListener
Web Application Lifecycle Event--ServletContext
Listener

63. Which of the following describes the correct


sequence of the steps involved in making a connect
ion with a database.
1. Loading the driver
2. Process the results.
3. Making the connection with the database.
4. Executing the SQL statements.
(A) 1,2,3,4
(B) 1,3,4,2
(C) 2,1,3,4
(D) 4,1,2,3
Answer : 1,3,4,2

64. import java.io.*;


class filesinputoutput {
public static void main(String args[])

InputStream obj = new FileInputStre


am("inputoutput.java");
System.out.print(obj.available());
}
}
Note: inputoutput.java is stored in the disk.
a) true
b) false
c) prints number of bytes in file
d) prints number of characters in the file
View Answer
Answer: c
Explanation: obj.available() returns the number of
bytes.
Output:
$ javac filesinputoutput.java
$ java filesinputoutput
1422
(Output will be different in your case

65.import java.io.*;
public class filesinputoutput {
public static void main(String[] args)
{
String obj = "abc";
byte b[] = obj.getBytes();
ByteArrayInputStream obj1 = new Byte
ArrayInputStream(b);
for (int i = 0; i < 2; ++ i) {
int c;
while((c = obj1.read()) != -1) {

if(i == 0) {
System.out.print(Charact
er.toUpperCase((char)c));
obj2.write(1);
}
}
System.out.print(obj2);
}
}
}
a) AaBaCa
b) ABCaaa
c) AaaBaaCaa
d) AaBaaCaaa

Answer: d
Explanation: None.
Output:
$ javac filesinputoutput.java
$ java filesinputoutput
AaBaaCaaa

66. Which of these methods are used to read in from


file?
a) get()
b) read()
c) scan()
d) readFileInput()
View Answer
Answer: b

67. tostring question

68. SC_OK

69. Which of the following allows non repeatable re


ad in JDBC Connection?
a. TRANSACTION_READ_UNCOMMITTED
b. TRANSACTION_READ_COMMITTED
c. TRANSACTION_SERIALIZABLE
d. TRANSACTION_REPEATABLE_READ Ans. D

70. dirty unread- ans)read.

71.package pkg;

class output {

public static void main(String args[])

StringBuffer s1 = new StringBuffer(


"Hello");

s1.setCharAt(1, x);

System.out.println(s1);

}
a) xello
b) xxxxx
c) Hxllo
d) Hexlo

Answer: c
72.public class Test8 {
public static void main (String args[]) {
Number numberRef = new Integer(0);
Double doubleRef = (Double)numberRef;
}
}

It shows me exception at runtime:

Exception in thread "main" java.lang.ClassCastExcep


tion:
java.lang.Integer cannot be cast to java.lang.Dou
ble

73. command design pattern ans)d (history...)

74. Which of these is not a valid value for dispatc


her element of filtermapping.
Select the one correct answer.

A. FORWARD
B. RESPONSE Ans) B
C. INCLUDE
D. ERROR

75. Which of the following is legal JSP syntax to p


rint the value of i.
Select the one correct answer

A. <%int i = 1;%>
<%= i; %>

B. <%int i = 1;
i; %>

C. <%int i = 1%>
<%= i %>

D. <%int i = 1;%>
<%= i %>
E. <%int i = 1%>
<%= i; %>

Ans) D.

76. <% int sum = 0;


for(j = 0; j < 10; j++) { %>
// XXX --- Add j to sum
<% } %>
// YYY --- Display ths sum. What must be added at
the location YYY to print the sum of ten numbers.
Select the one correct statement

A. <% sum %>


B. <% sum; %>
C. <%= sum %>
D. <%= sum; %> ANS) C.

77. <%@ taglib uri="http://java.sun.com/jsp/jstl/co


re"
prefix="c" %>
<c:set var="j" value="4,3,2,1"/>
<c:forEach items="${j}" var="item" begin="1" end="2
">
<c:out value="${item}" default="abc"/>
</c:forEach>
A. 1
B. 2
C. 3
D. 4
E. abc
F. The program does not compile.
Which numbers gets pri

Ans) 2,3

78. Which number gets printed when the following JS


TL code
fragment is executed? Select the one correct answer
s.
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"
prefix="c" %>
<c:set var="j" value="4,3,2,1"/>
<c:forEach items="${j}" var="item" varStatus="statu
s">
<c:if test="${status.first}">
<c:out value="${status.index}" default="abc"/>
</c:if>
</c:forEach> Ans)A
A. 1
B. 2
C. 3
D. 4
E. abc
F. The program does not compile.

79. Which of the following is not a valid HTTP/1.1


method. Select the
one correct answer.
15.
A. CONNECT method
B. COMPARE method
C. OPTIONS method
D. TRACE method
Name the http method used

answer: B

80. Name the location of compiled class files withi


n a war file? Select
the one correct answer.
19.
A. /META-INF/classes
B. /classes
C. /WEB-INF/classes
D. /root/classes
Answers- web inf

81. What get printed when the following JSTL code f


ragment 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>

options
A)0,3,6,9,12
B)3,6,9,12
C)0,6,9,12
D)0,3,6,9

http://www.sanfoundry.com/java-questions-answers-fr
eshers-experienced/

The four techniques used in session tracking are:

Java Language Keywords

Here is a list of keywords in the Java programming


language. You cannot use any of the following as
identifiers in your programs. The keywords const a
nd goto are reserved, even though they are not cur
rently used. true, false, and null might seem like
keywords, but they are actually literals; you can
not use them as identifiers in your programs.
abstract continue for new switch
assert*** default goto* package synchro
nized
boolean do if private this
break double implements protected throw
byte else import public throws
case enum**** instanceof return transient
catch extends int short try
char final interface static void
class finally long strictfp** volatile
const* float native super while
* not used
** added in 1.2
*** added in 1.4
**** added in 5.0

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy