Dumps
Dumps
Important link:
http://javabysri.blogspot.in/2012/06/jdbc
-objective-questions.html
Ques1)When the message"No suitable driver" occurs?
b) When the user name, password and the database does not match
driver in JDBC?
a)registerDriver() method
b)Class.forName()
c)Both A and B
d)getConnection()
a)JDBC 1.0
b)JDBC 4.0
c)JDBC 2.0
d)JDBC 3.0
a)Statement
b)Callable Statement
d)Prepare Statement
a)executeQuery()
b) executeUpdate()
c) getConnection()
d) prepareCall()
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
a)execute()
b)executeQuery()
c)executeUpdate()
d)executeResult()
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?
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
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
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
a) PreparedStatement
b) ParameterizedStatement
a) By invoking the method get(..., String type) on the ResultSet, where type is the 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(...),...
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
88. con.close();
91. }
Ques25)How can you execute DML statements (i.e. insert, delete, update) in
the database?
UpdateStatement classes
DataModificationStatement object.
Ques25)What is, in terms of JDBC, a DataSource?
a)Yes,They complied
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
c) DDL statements can not be executed by making use of JDBC, you should use the native database
tools for this.
a)TRANSACTION_READ_UNCOMMITTED
b) TRANSACTION_READ_COMMITTED
c) TRANSACTION_SERIALIZABLE
d) TRANSACTION_REPEATABLE_READ
a) java.sql.Time
b) java.util.Date
c) java.util.Time
a)TYPE-4
b)TYPE-2
c)TYPE-1
d)TYPE-3
Q 1 - Which of the following is correct about Creational design patterns.
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.
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
C - Command Pattern
D - Interpreter Pattern
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.
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
C - Strategy Pattern
D - Template Pattern
A - In this pattern, a visitor class is used which changes the executing algorithm of an
element class.
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
C - Singleton 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
C - Singleton Pattern
A - This pattern creates object without exposing the creation logic to the client and refer
to newly created object using a common interface.
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.
A - This pattern creates object without exposing the creation logic to the client and refer
to newly created object using a common interface.
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
C - Singleton Pattern
A - Factory Pattern
C - Singleton 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
C - Singleton 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
C - Singleton 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
C - Singleton 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?
Q 11 - Which type of design patterns are specifically concerned with the presentation
tier?
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.
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.
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.
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 17 - Which of the following is the correct list of entities of Business Delegate pattern?
Q 18 - Which of the following is the correct list of entities of Composite Entity pattern?
A - Data Access Object Interface, 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?
Q 22 - Which of the following is the correct list of entities of Service Locator pattern?
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
C - In this pattern, a class behavior or its algorithm can be changed at run time.
C - In this pattern, a class behavior or its algorithm can be changed at run time.
C - In this pattern, a class behavior or its algorithm can be changed at run time.
Q 4 - In which of the following pattern, a class behavior changes based on its state?
A - State 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
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
C - Strategy Pattern
D - Template Pattern
A - State Pattern
C - Strategy Pattern
D - Template Pattern
A - In this pattern, a visitor class is used which changes the executing algorithm of an
element class.
A - In this pattern, a visitor class is used which changes the executing algorithm of an
element class.
A - In this pattern, a visitor class is used which changes the executing algorithm of an
element class.
A - In this pattern, a visitor class is used which changes the executing algorithm of an
element class.
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
A - Visitor Pattern
B - MVC Pattern
A - Visitor Pattern
B - MVC Pattern
A - Visitor Pattern
B - MVC Pattern
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.
D - This pattern is used when we want to locate various services using JNDI lookup.
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.
D - This pattern is used when we want to locate various services using JNDI lookup.
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.
D - This pattern is used when we want to locate various services using JNDI lookup.
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.
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
C - Intercepting Pattern
A - DAO Pattern
C - Intercepting Pattern
A - DAO Pattern
C - Intercepting Pattern
Q 23 - Which of the following pattern is used when we want to locate various services
using JNDI lookup?
A - DAO Pattern
C - Intercepting Pattern
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.
A - This pattern creates object without exposing the creation logic to the client and refer
to newly created object using a common interface.
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?
Ans:NULL
ServletException
8 Which one of the following is a valid argument for a JSP page directive?----isThreadSafe="yes|no"
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
3 Which of the following JSP variables are not available within a JSP expression. Select the one
correct answer.------httpsession
5 Is the following statement true or false. If the isThreadSafe attribute of the page directive is false,
6 What gets printed when the following JSP code is invoked in a browser. Select the one correct
answer.
hello
hi
<% z++;++y;%>
<% }%>
<%= z%>
<%= z 1%>
<% }%>-----2
9 The methods jspInit and jspDestroy of JspPage may be overriden by a JSP author---TRUE
1> JSP pages have access to implicit objects that are exposed automatically. Name the implicit object
2> Is the following JSP code legal? Select the one correct statement.
3> true about include directive----When using the include directive, the JSP container treats the file to be included as if it was
4> When using the include directive, the JSP container treats the file to be included as if it was
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
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?
Ques 1 :
(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.
<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>
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.
</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
Ans:A
Ques 8 :
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.
3 <%= test%>
Ans:B
Ques 10 :
What gets printed when the following JSTL code fragment is executed? Select the one correct answer.
</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.
(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
Ans:D
Ques 16 :
What gets printed when the following is compiled. Select the one correct answer.
<% z++;++y;%>
<% }%>
<%= z%>
<%= z - 1%>
<% }%>
(A) 1
(B) 2
(C) 3
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.
<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
Ans:C
Ques 19 :
What gets printed when the following JSP code is invoked in a browser. Select the one correct answer.
hello
hi
<%= } %>
(A) The browser will print either hello or hi based upon the return value of random.
Ans:D
Ques 20 :
In JSP, how can you know what HTTP method (GET or POST) is used by client request ?
Ans:C
(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.
(A) It will not flag any compile-time or runtime errors and will not print anything to the output.
Ans:A
Ques 3 : Which of the following tags can you use to print the value of an expression to the output stream?
Ans:D
(A) Valid
(B) Invalid
Ans:B
(A) Valid
(B) Invalid
Ans: A
(A) Valid
(B) Invalid
Ans:B
(A) Valid
(B) Invalid
Ans:B
(A) Valid
(B) Invalid
Ans:B
(A) jspInit()
(B) _jspService()
(D) jspDestroy()
Ans:C
(B) 30
(C) 250
(D) 500
Ans:C
Ques 11 : What will be the output of the following code?
(A) x = 200, 30
(B) x = 300, 30
(C) x = 30, 30
Ans:D
Ques 12 : Which of the following exceptions may be thrown by the _jspService() method?
(B) javax.servlet.jsp.JSPException
Ans:D
a <%=myObj.m1(); %>
c <%=x=y%>
Ans:B
<%
int x = 0;
int incr()
return ++x;
%>
Ans:D
Ans:C
(A) 7
(B) 8
(C) 9
Ans:9
a) pageContext
b) pageConfig
c) config
d) context
e) page
f) exception
g) Exception
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
(A) request.authenticate(response)
(B) request.getAttributes("email")
(C) request.getCookies()
Ans:B
Ques 20 : What will be the output of the following code? (Select one)
<html>
<body>
</body>
</html>
Ans:C
1.) What programming language(s) or scripting language(s) does Java Server Pages (JSP) support?
Options are:
A.) VB Script
View Answer
Correct Option: B
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:
View Answer
Correct Option: A
6.) In JSP, the classes that allow primitive types to be accessed as objects are known as
Options are:
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
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
What happens when the following statement is executed. Select the one correct answer.
------All the properties of the fruit bean are assigned the values of input parameters of the JSP page
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
6> What gets printed when the following JSP code is invoked in a browser. Select the one correct
answer.
hello
hi
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,
8> A bean with a property color is loaded using the following statement
Which of the following statements may be used to print the value of color property of the bean. Select the one
correct answer.
output.
// XXX Add
j to sum
<% } %>
// YYY Display
3> A Java bean with a property color is loaded using the following statement
request parameter with name color, then its value gets assigned to color
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
6> JSP pages have access to implicit objects that are exposed automatically. Name the implicit object
7> Which of the following represents the XML equivalent of this statement <%@ include
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.
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”
a) Letters
b) Digits
c) Punctuation Characters
View Answer
Answer: d
2. What Does a Composite name consists of in a UML Class and object diagram ?
a) Delimiter
b) Simple names
c) Digits
View Answer
Answer: d
Explanation: Composite name consists of sequence of simple names and simple names already consists of digits.
b) Operations
c) Attributes
e) b, c
View Answer
Answer: d
a) Name Compartment
b) Attribute Compartment
c) Operation Compartment
Answer: d
a) Class
b) Object
View Answer
Answer: c
a) Initial Values
b) Names
View Answer
Answer: c
Explanation: Initial values along with thier names are used as attributes.
a) Object behavior
b) Class behavior
c) Functions
d) a,b
View Answer
Answer: d
a) name
b) parameter list
c) return-type list
View Answer
Answer: d
a) Associations may also correspond to relation between instances of three or more classes
View Answer
Answer : c
Explanation : All the statements mentioned are true with respect to Notations.
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
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?
View Answer
Answer : a
Explanation : Compartments can be in order, Attributes and operations must be listed one per line.
View Answer
Answer : d
a) Top compartment
b) Bottom Compartment
View Answer
Answer : c
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
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
a) Collaboration
b) Sequence
c) Activity
View Answer
Answer:b
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
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
Ans:D
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.
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; %>
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
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
11. A bean with a property color is loaded using the following statement
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"/>
15. Which of the following statements are true for <jsp:usebean>. Select the two correct
answers.
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.
Which statement when placed at the location XXX can be used to compute the sum.
Select the one correct statement
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
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.
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
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.
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
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
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.
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.
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
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.
A. getStream
B. getOutputStream
C. getBinaryStream
D. getWriter
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.
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
${(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.
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.
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.
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.
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.
11. Which numbers gets printed when the following JSTL code fragment is executed? Select
the two correct answers.
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.
13. Which number gets printed when the following JSTL code fragment is executed? Select
the one correct answers.
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
statement = connection.createStatement(
java.sql.ResultSet.TYPE_FORWARD_ONL
Y,
java.sql.ResultSet.CONCUR_READ_ONLY
);
statement.setFetchSize(Integer.MIN_VALUE);
TYPE_SCROLL_INSENSITIVE:
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());
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. }
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);
}
}
5. current thread
public class MyRunnable implements runnable{
public void run(){
//some code
}}
which of these will create and start this thread?
6. class Mammal { }
Answer: A,B,C,F
import java.io.*;
int c;
if (i == 0) {
System.out.print(Charact
er.toUpperCase((char)c)); }}}}}
ans) ABC
8. class output {
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)
17. ideal
removin loop
-operations
a)idea
b)deal
A. Tight coupling
B. Low cohesion
C. High cohesion
D. Loose coupling
E. Weak encapsulation
F. Strong encapsulation
Answer: E
24. instanceof
import java.util.*;
class vector {
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
class Array {
array[5 - i] = i;
Arrays.sort(array);
System.out.print(array[i]);;
} Ans) 12345
41. What is the output of this program?
import java.util.*;
class Maps {
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]
import java.util.*;
class Bitset {
public static void main(String args[])
{
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}
import java.util.*;
class Array {
Arrays.fill(array, 1, 4, 8);
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
import java.util.*;
class Collection_Algos {
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())
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)
import java.util.*;
class Collection_Algos {
public static void main(String args[])
{
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())
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.
import java.util.*;
stk.push(obj);
public E pop() {
E obj = stk.pop();
return obj;
class Output {
gs.push("Hello");
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
c.append(c1);
System.out.println(c);
a) Hello
b) World
c) Helloworld
d) Hello World Ans-d.
53.class output {
{
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
String s1 = "one";
System.out.println(s2);
a) one
b) two
c) one two
d) compilation error
View Answer
Answer: c
catch(ArithmeticException e) {
System.out.print("World");
a) Hello
b) World
c) HelloWorld
d) Hello World
Answer: b
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;
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
68. SC_OK
71.package pkg;
class output {
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;
}
}
A. FORWARD
B. RESPONSE Ans) B
C. INCLUDE
D. ERROR
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.
Ans) 2,3
answer: B
${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/