File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mock exam questions

 
Ranjani Theyagarajan
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am going to take up my exam within couple of days.
It would be gr8 if you guys help me for the answer of the following questions.

1)
test.jsp
===============

<% String str="hello"; %>
<%= str %>
<jsp:include page="another.jsp" flush="true" />
<% str+=" World";
out.println(str);
%>


another.jsp
===========
<% String str="hi";
out.println(str); %>


What is the output for the test.jsp file?

==========================================================================


2) Select the EL fragment which will produce compilation erro? select two choices


a) ${1+'1'}
b) ${varDoesntExist+1}
c) ${sessionScope * 2}
d) ${2/varDoesntExist}
e) ${2/ varContainingZero }
f) ${varDoesntExist1 <varDoesntExist2}
g) ${!true - !false}

======================================================================

3) Acme Inc decides to develop a Swing application to acces the central office data from branches all
over the world. The central office would enter business data using this application and the
branches would mostly read these data over the networl. te application would use EJB for
accessing the enterprise data. one of the primary goal of the application is to provide faster
response time both at central and branch office.

The other goal is to reduce the application dev time by devloping the business and UI Compenents
in parallel without waiting for each other.

Given this scneario which of the following j2EE design would solve the problem effectively?
select two choices.


a) Intercepting Filter
b) MVC
c) Front controller
d) Servive Locator
e) Business delegate
f) Value object

==========================================================================

4) PostTest.html
===============

<html>
<body>
<form method="POST" action="/servlet/PostTest">
val1=<input type="text" name="value1"><br>
val2=<input type="text" name="value2"><br>
<input type="submit" name="AddButton">
</form>
</body>
</html>



PostTest.java
==============


public void doPost(HttpServletRequest req,HttpServletResponse res){
BufferedReader inReader=req.getReader();
PrintWriter out=res.getWriter();

String val1Str=inReader.readLine();
String val2Str=inReader.readLine();

out.println("Value obtained manually =" val1Str);
out.println("Value obtained manually =" val2Str);

out.println("Value obtained again is =" req.getParameter("Value1"));
out.println("Value obtained again is =" req.getParameter("Value2"));

}

The values entered are value1=500 and value2=600. what is the o/p?

a) compilation error

b) value obationed manually = null
value obationed manually = null
value obationed again is = 500
value obationed again is = 600

c) value obationed manually =

value1=500 &&value2=600&&AddButton=Submit+Query
value obatained again manually is = null
value obationed again is = 500
value obationed again is = 600


d) value obationed manually =

value1=500 &&value2=600&&AddButton=Submit+Query
value obatained again manually is = null
value obationed again is = null
value obationed again is = null


==========================================================================

5) what is the o/p?

<% sesson.setAttribute("varCents","20");
%>
$100.${varCents}

1) compliation error
2) classcastException
3) prints $100.20
4) prints $100.$20

===============================================================


6) can a userdefined identifier be named sessionScope in a jsp file?


Thanks in Advance.

Warm Regards,
Ranjani
 
Yati Tan
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
r they frm hfsj ?
[ February 16, 2006: Message edited by: Yati Tandon ]
 
Ranjani Theyagarajan
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope... these question are from a mock exam...
 
Sandhya Lever
Ranch Hand
Posts: 90
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.hello hello world
2.c,g
3.e
4.b I think
5.3
6.yes
 
shanthisri mocherla
Ranch Hand
Posts: 119
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the answer for question 1 is
hello hi helloWorld.
"hi " from another.jsp will be included there in the ouput .




6.when I used sessionScope as a variable in setAttribute method and then used it in EL expression I got this output
org.apache.commons.el.ImplicitObjects$3@162d950


<% session.setAttribute("sessionScope",20); %>
$100.${sessionScope}

Shanthi
[ February 16, 2006: Message edited by: shanthisri mocherla ]
 
vu ngoc thanh
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
4. The answer is D
This is because when you use inReader.readLine(), data of request will be read only once. So when you use req.getParameter("Value1") after using readLine(), the value is null
 
P Chittaranjan
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answere for Q4 should be compilation error.

public void doPost(HttpServletRequest req,HttpServletResponse res){
this is missing the throws clause(throws ServletException,IOException).
 
Ranjani Theyagarajan
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's assume that doPost method declares IOException and ServletException.. then what would be the result.
 
P Chittaranjan
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your program don't have any compile time error the output will be

d) value obationed manually =

value1=500 &&value2=600&&AddButton=Submit+Query
value obatained again manually is = null
value obationed again is = null
value obationed again is = null
 
vu ngoc thanh
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you overide a method, you needn't declare throws clause in methods of parent class or interface it implements. So the method
public void doPost(HttpServletRequest req,HttpServletResponse res) still run
 
Narendra Dhande
Ranch Hand
Posts: 951
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to answer your queries.


1)
test.jsp
===============

<% String str="hello"; %>
<%= str %>
<jsp:include page="another.jsp" flush="true" />
<% str+=" World";
out.println(str);
%>


another.jsp
===========
<% String str="hi";
out.println(str); %>
What is the output for the test.jsp file?


The answer should be "hi hello World" If the writer is buffered, Otherwise it will "hello hi hello World", as if the out is not buffered it will not flushed


==========================================================================


2) Select the EL fragment which will produce compilation erro? select two choices


a) ${1+'1'}
b) ${varDoesntExist+1}
c) ${sessionScope * 2}
d) ${2/varDoesntExist}
e) ${2/ varContainingZero }
f) ${varDoesntExist1 <varDoesntExist2}
g) ${!true - !false}

======================================================================
My Answers are C and G
The outpu of other options are
a) 2 b) 1 d) Infinity e) Infinity f) false

3) Acme Inc decides to develop a Swing application to acces the central office data from branches all
over the world. The central office would enter business data using this application and the
branches would mostly read these data over the networl. te application would use EJB for
accessing the enterprise data. one of the primary goal of the application is to provide faster
response time both at central and branch office.

The other goal is to reduce the application dev time by devloping the business and UI Compenents
in parallel without waiting for each other.

Given this scneario which of the following j2EE design would solve the problem effectively?
select two choices.


a) Intercepting Filter
b) MVC
c) Front controller
d) Servive Locator
e) Business delegate
f) Value object

I go for B and E

==========================================================================

4) PostTest.html
===============

<html>
<body>
<form method="POST" action="/servlet/PostTest">
val1=<input type="text" name="value1"><br>
val2=<input type="text" name="value2"><br>
<input type="submit" name="AddButton">
</form>
</body>
</html>



PostTest.java
==============


public void doPost(HttpServletRequest req,HttpServletResponse res){
BufferedReader inReader=req.getReader();
PrintWriter out=res.getWriter();

String val1Str=inReader.readLine();
String val2Str=inReader.readLine();

out.println("Value obtained manually =" val1Str);
out.println("Value obtained manually =" val2Str);

out.println("Value obtained again is =" req.getParameter("Value1"));
out.println("Value obtained again is =" req.getParameter("Value2"));

}

The values entered are value1=500 and value2=600. what is the o/p?

a) compilation error

b) value obationed manually = null
value obationed manually = null
value obationed again is = 500
value obationed again is = 600

c) value obationed manually =

value1=500 &&value2=600&&AddButton=Submit+Query
value obatained again manually is = null
value obationed again is = 500
value obationed again is = 600


d) value obationed manually =

value1=500 &&value2=600&&AddButton=Submit+Query
value obatained again manually is = null
value obationed again is = null
value obationed again is = null

My answer is A. The doPost must throws the IOException and Servlet Exception or hanldle internally.
If the methods signature is properly defined The answer will be D

==========================================================================

5) what is the o/p?

<% sesson.setAttribute("varCents","20");
%>
$100.${varCents}

1) compliation error
2) classcastException
3) prints $100.20
4) prints $100.$20

===============================================================
Here is typo in session speling , otherwise the output is 3


6) can a userdefined identifier be named sessionScope in a jsp file?


Yes, as long as it is not used in EL


Hope it help
Thanks
 
Vishal Chugh
Ranch Hand
Posts: 177
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
once again , very nice link . I have also checked ansers myself


Thank you Narendra Dhande!!

I have doubt about below :
3) Acme Inc decides to develop a Swing application to acces the central office data from branches all
over the world. The central office would enter business data using this application and the
branches would mostly read these data over the networl. te application would use EJB for
accessing the enterprise data. one of the primary goal of the application is to provide faster
response time both at central and branch office.

The other goal is to reduce the application dev time by devloping the business and UI Compenents
in parallel without waiting for each other.

Given this scneario which of the following j2EE design would solve the problem effectively?
select two choices.


a) Intercepting Filter
b) MVC
c) Front controller
d) Servive Locator
e) Business delegate
f) Value object
quote:

I go for B and E

Howcome for E??? B is fine.


and about below :
${sessionScope * 2}
${!true - !false} i got compiler error , is it beacuse i used keywords(sessionScope and true/false) in wrong contexts?? (true/false not treated as 0 or 1 as unknowns , nulls , infinity are treated )
 
Abdul Rahman
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, the answer is as below for the above questions:

1 - hello hi hello World
2- c and g will give compilation error.
3- My bet will be b and f. since the data will be read over the n/w, and the response time should be faster the value object should be the ideal choice.
4 - answer: b
5 - answer: 3
6 - yes you can but its generally a bad idea and should be avoided in real time scenario.

All the best Ranjani.
 
manojreddy yaram
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



1) hello hello hi world
2) e, g
3) a, d
4) c
5) 4
6) yes

















thank's
Ranjani Theyagarajan
 
Abdul Rahman
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi manoj,

can you explain your answers ?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic