86) Benefit of using Java Beans to separate Business Logic from presentation markup within the JSP environment
87) correct JSP compilation sequence
Answer:
JSP page looks like a HTML page but is a servlet. When presented with JSP page the JSP engine does the following 7 phases.
1. Page translation: -page is parsed, and a java file which is a servlet is created.
2. Page compilation: page is compiled into a class file
3. Page loading : This class file is loaded.
4. Create an instance :- Instance of servlet is created
5. jspInit() method is called
6. _jspService is called to handle service calls
7. _jspDestroy is called to destroy it when the servlet is not required.
2. Page compilation: page is compiled into a class file
3. Page loading : This class file is loaded.
4. Create an instance :- Instance of servlet is created
5. jspInit() method is called
6. _jspService is called to handle service calls
7. _jspDestroy is called to destroy it when the servlet is not required.
88) union will select distinct values say true or false
Ans: true
89) advantage of preparedStatement
Ans: reduces execution time, same statement can be used by supplying different values
90) Not true about forward
91) Options true while subclassing
92) What does reset method on an ActionForm perform
Answer
There is a reset() method on ActionForm that is called *before* Struts does the auto-populate trick. The contract is that this method should reset all relevant attributes for this particular form to default values.
void | reset(ActionMapping mapping, javax.servlet.http.HttpServletRequest request) Reset bean properties to their default state, as needed. |
void | reset(ActionMapping mapping, javax.servlet.ServletRequest request) Reset all bean properties to their default state. |
93) Various scope in JSP
application
session
request
page
94) If you have created a custom Action Mapping subclass with the property “service”, you can initialize the value to “select Record” using which
All the below
<init prop name=”service” value=”select Record”/>
<set prop property=”service” value=”select Record”/>
<put field key=”service” value=”select Record”/>
95)
1.statement stmt=con.createstmt()
2.
3.Resultset rs=stmt.executequery(“Select * from”);
4.
5.while(rs.next()){
6.string somevalue=rs.getString(“form name”);
7}
In which line data get retrived
a. 5 b. none c.3 d.6
96) public class test{
int i=1,j=1;
try{
i++;
j--;
if(i/j>1)
i++
catch(ArithmeticException e)
s.o.p(0);
}
Catch(ArrayIndexoutofBoundsexception e)
s.o.p(1)
}
Catch(Exception e)
s.o.p(2)
}
finally{
s.o.p(3)
}
s.o.p(4)
Ans: 0 3 4
97) Statements true
constructors not inherited
parental constructor can be invoked
any method can contain a call to this or super
constructor can be overridden
Ans : a,b
98) Resource bundles are convenient way to
Answer:
Resource Bundle is the portion of a piece of software that holds application data (but not user data) separate from the program itself. Typical resources include icons, window positions, dialog box definitions, program text, and menus. The resource bundle is a convenient way to modify and update various aspects of the user interface without having to recompile the software. In particular, by putting all text used in the program into the resource bundle, it becomes enormously easier to translate the software into another language.
Depending on the operating system (OS) and programming language environments, developers can use a variety of mechanisms to identify and separate culturally sensitive or locale-dependent objects from their source code. Windows programmers have their resource (RC) files and resource-only dynamic link libraries (DLLs). Macintosh developers have their resource forks and similar concepts. Of course, Java developers have a method too--the resource bundle.
Resource Bundles
The most obvious type of localizable object is a text string, but resource bundles can store any Java object. Whatever you choose to store, you'll put it into some form of java.util.ResourceBundle.
To create a concrete class you must subclass ResourceBundle and implement two methods: handleGetObjects and getKeys. Directly subclassing ResourceBundle like this is a distraction from the main purpose of a bundle, which is to store localizable objects, not to write a lot of code logic. Fortunately, the Java Development Kit (JDK) provides two subclasses, ListResourceBundle and PropertyResourceBundle, that allow you to concentrate on providing the data for the file instead of writing code.
99) Characteristics of java bean
100) Filenotfoundexception---output
101) class.forName return in JDBC
Ans: class object of the driver manager
102) 10 not null values 5 null values what will give count(name)
Ans: 10
103) true about transient modifier
104) service(),doPost(),doGet() are thread safe?
1. What if the Java driver is not compatible with the JDBC?
Ans: exception is thrown at runtime
2. Role of result set (2 ques on result set)
3. Flow of JSP
a. loading->compiled->generate response
b. if not loaded->compiled->again load->generate response
4. public class sample{
psvm{ sysout(“100”+10);}}
ANS: 10010
5. Taglib descriptor……….
c. TLD is coded in Java
6. Application resources……………….
d. application
e. application resources
f. resources
g. methods
7. J2SE 3.1………………..
h. Hot spot……………..
8. Redirect and forward
9. JSP vs. Servlets
10. JSP latest version
i. 1.1
j. 1.2
k. 2.1 - Answer
l. 2.0
11. Action form in servlet
12. Action class is called by………………..
m. name
n. page
o. path
13. abstract class MineA{
String str; method();}
Class Mine extends MineA{
Psvm{
Int[] s=new int[5];
Sysout(………..);
}}
a. compilation error: class Mine should be declared abstract
b. runtime error: AIOOB
c. compilation error:
d. runtime error:
Ans: a
14. java bean syntax
p. <java: id, name, value>
q. <java: name, value>
r. <java: id, value>
15. sessions…………
16. Which method is not available in servlet config?
s. getServletContext()
t. getInitParameter()
u. gerInitParameterNames()
v. addInitParameter() - Answer
Interface ServletConfig
All Known Implementing Classes:
GenericServlet
public interface ServletConfig
A servlet configuration object used by a servlet container used to pass information to a servlet during initialization.
Method Summary | |
java.lang.String | getInitParameter(java.lang.String name) Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist. |
java.util.Enumeration | getInitParameterNames() Returns the names of the servlet's initialization parameters as an Enumeration of String objects, or an empty Enumeration if the servlet has no initialization parameters. |
ServletContext | getServletContext() Returns a reference to the ServletContext in which the caller is executing. |
java.lang.String | getServletName() Returns the name of this servlet instance. |
17. Format of path specified in HTML:
w. GET/………./index.html1.1/HTTP
x. GET/………./index.html HTTP/1.1
y. GET ………./index.html1.1/HTTP
18. sun java naming standards
19. Can an anonymous class extend another class and implement an interface?
20. To read data which is superior?
z. input stream
aa. file reader
Ans: buffered reader
21. Reset in HTML?
22. What is reason for separating business logic and presentation in JSP?
23. What is the tag to make output of a jsp to appear in the output of another jsp?
24. Command to get sequence of steps that takes place in the execution of a java program?
25. subclassing…………………….
26. Class composition is a better alternative than defining alternative subclass… (T/F)
Ans: true(if the superclass is going to change)
27. What will server flag in J2SE 1.3 do?
28. Creating a new thread requires fewer resources than creating a new process. (T/F)
Ans: true
29. How can struts populate a form in struts 1.1?
30. xml page can be created using jsp. (T/F)
31. Various phases in jsp container?
32. each process must have a thread .true or falseeee?
Ans: true
33. driver manager is used to
a)manage all connections.
b)to manage jdbc drivers
Ans: manage connections and mange jdbc drivers
34. which of the following will allow control flow
a)try wit handled exception (not sure )
b)try wit unhandled exception
c)all above
d)try wit no xceptionnnnnnnnn
35. inheritance disadvantage
Ans: child class becomes dependent on parent class causing tight coupling
36. difference between redirect and forword
You can pass control from one JSP page to another using one of two options: Including a <jsp:forward> standard action tag or passing the redirect URL to response.sendRedirect() in a scriptlet.
The <jsp:forward> option is faster and more efficient. When you use this standard action, the forwarded target page is invoked internally by the JSP runtime, which continues to process the request. The browser is totally unaware that the forward has taken place, and the entire process appears to be seamless to the user.
When you use sendRedirect(), the browser actually has to make a new request to the redirected page. The URL shown in the browser is changed to the URL of the redirected page. In addition, all request scope objects are unavailable to the redirected page because redirect involves a new request.
Use a redirect only if you want the URL to reflect the actual page that is being executed in case the user wants to reload the page.
37. latest version of JSP? 2.1
Given
Float i=4.4f,j=8.5f;
sop((-i==~i+1)+”,”+(-j==~j+1));
wat is output?
a)compilation error
b)true,false
c)false,true
d)true,true
38. which is used to identify the resource but not tell how to reach that resource?
a)URI
b)URL
c)URI or URL
A URL (Uniform Resource Locator, previously Universal Resource Locator) - usually pronounced by sounding out each letter but, in some quarters, pronounced "Earl" - is the unique address for a file that is accessible on the Internet
A Uniform Resource Identifier (URI), is a compact string of characters used to identify or name a resource. A URI can be classified as a locator or a name or both. A Uniform Resource Locator (URL) is a URI that, in addition to identifying a resource, provides means of acting upon or obtaining a representation of the resource by describing its primary access mechanism or network "location". For example, the URL http://www.wikipedia.org/ is a URI that identifies a resource (Wikipedia's home page) and implies that a representation of that resource (such as the home page's current HTML code, as encoded characters) is obtainable via HTTP from a network host named www.wikipedia.org. A Uniform Resource Name (URN) is a URI that identifies a resource by name in a particular namespace. A URN can be used to talk about a resource without implying its location or how to dereference it. For example, the URN urn:isbn:0-395-36341-1 is a URI that, like an International Standard Book Number (ISBN), allows one to talk about a book, but doesn't suggest where and how to obtain an actual copy of it.
39. when we do reset in form page…………………..
It wil set to initial values or it will get all the requests againnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn……………
40. Inner join operation will give all the values in the first table even though there are no matching data between two tables. True or false?
Ans: false
41. Question on the syntax of the setting a property name in JSP
42. What is the best scope among the following for maintain the data efficiently
Options are : request, session, page request, application request
Ans: request
1. Approximate time for retrieving
a)1 value b) 100 values from data base is.
same
cannot say
None
Ans: ‘a’ requires less time than ‘b’
2.
A) var NoofRows = 1;
B) var NoofRows = 100;
for(i=0;i< NoofRows;i++){
INSERT INTO SOMETABLE VALUES(SOMECOLUMN)
}
Same time.
B little longer than A
A takes 100 times B
d)
Ans :b
3. Public class A{
String s;
void amethod(){
System.out.println(s);
}
Public static void main(String[] args){
A obj=new A();
Obj.amethod();
}
}
Output?
Ans: null
Since s is an instance var, automatically initialized to null, hence the output
4. public class A {
A(){
class B{
void method(){
System.out.println("No arg");
}
}
}
A(int i){
class B{
void method(){
System.out.println("arg");
}
}
}
public static void main(String[] args) {
A obj=new A(1);
}
}Ans: Runtime error.
4. What is the output of the following
5. <HTML><BODY>The output is <%=“”%></BODY></HTML>
Ans: The output is What ever is inside the “” will be printed.
6. flow how a jsp works when it gets a request..
JSP Processing
Just as a web server needs a servlet container to provide an interface to servlets, the server needs a JSP container to process JSP pages. The JSP container is responsible for intercepting requests for JSP pages. To process all JSP elements in the page, the container first turns the JSP page into a servlet (known as the JSP page implementation class). The conversion is pretty straightforward; all template text is converted to println( ) statements similar to the ones in the handcoded servlet shown in Example 3-1, and all JSP elements are converted to Java code that implements the corresponding dynamic behavior. The container then compiles the servlet class.
Converting the JSP page to a servlet and compiling the servlet form the translation phase. The JSP container initiates the translation phase for a page automatically when it receives the first request for the page. Since the translation phase takes a bit of time, the first user to request a JSP page notices a slight delay. The translation phase can also be initiated explicitly; this is referred to as precompilation of a JSP page. Precompiling a JSP page is a way to avoid hitting the first user with this delay. It is discussed in more detail in Chapter 16.
The JSP container is also responsible for invoking the JSP page implementation class (the generated servlet) to process each request and generate the response. This is called the request processing phase. The two phases are illustrated in Figure 3-3.
Figure 3-3: JSP page translation and processing phases
As long as the JSP page remains unchanged, any subsequent request goes straight to the request processing phase (i.e., the container simply executes the class file). When the JSP page is modified, it goes through the translation phase again before entering the request processing phase.
get the request, check for the servlet, if servlet present ....
7. class parent{
void method(){
sysout(“parent”)
}
}
class child extends parent{
void method(){
sysout(“Child”)
}
}
Parent obj new child();
What is the output?
Ans: Child
8. transient modifier for 1)method variables
local methods
method definitons
Ans: instance variables
9. For shopping cart which will you prefer?
a.application
b.session
c.page
d.request
answer: session
10. send redirect on request obj is sent to the browser...
a.true
b.false
When a sendRedirtect method is invoked, it causes the web container to return to the browser indicating that a new URL should be requested. Because the browser issues a completely new request any object that are stored as request attributes before the redirect occurs will be lost. This extra round trip a redirect is slower than forward.
11. Question frm localization in struts,
Entire specification is done.....
Creates specific resource for each request
Either i or ii
Neither i nor ii
Only i
Only ii
12.some question about action mapping...
13. -jsp tag libs
14. Given some coding using tag interfaces …….. Asked me to debug it.
15. Given four class names and asked me to pick appropriate one taking Sun java coding standards into consideration.
16. JSP flow……….
17. Four options will be having the jdbc connection code… question will be which is correct? The difference was where they place the conn.close() stmt. Conn.close stmt should be in finally block.
18. Jsp declarations syntax
19. Read carefully the following topics:
redirect and forward
IN command in SQL
Got one question regarding sub queries in SQL
Coding regarding type casting in java ( implicit type casting)
Javax.servlet and javax.servlet.pagecontext packages.
20. What are the methods in HTTP?
1.GET
2.HEAD
3.RETRIEVE
4.POST
Answer : 1,2,4
GET,HEAD,POST,PUT,DELETE,TRACE,CONNECT are the methods in HTTP 1.1
21.What is the output of the following?
<@ page language="java">
out.print("Hello");
out.print("World")
etc(I don't remember it exactly)
22. Advantages of jsp…. Seperation of presentation logic from business logic so that few people can work on presentation and others can work on the other logic..
23.A question on ActionServlet
24. If connection is not fully compliant what happens? Ans: Driver Manager won’t register it.
25. While (rs.next ()){
Integer x=s.getInt(c);
---
}
Ans: No error
26. How to make servlet implement single thread model.
Ans: By setting isThreadsafe=False
27.Difference Between <%@Include %> and <jsp=include>
Ans: <%@Include %> - related to compile time
<jsp=include> - related with request time
28.Which two are equal
Ans: <jsp:scriplet>---------;</jsp:scriplet> and <%--------;%>
29.what method used to initiate servlet
Ans: void init(ServletConfig)
30.When to use forward and when to use redirect.
Ans: redirect – client side -- forward server side
31.How to maintain sessions:
Ans: save in secret field,url rewriting,cookies … In short All of the above ;)
32. Can inner classes implement interface and extend another class..
Ans : Nooo
33. Non static methods can over ride Non Static methods
34. 19.int i=o;
Boolean b = false
If(b&&(i++>0))
{
empty
}
System.out.println(i);
Ans: 0
35. public class A{
public static void main(String[] args){
boolean b=false;
String s;
s = (b=!b)?"hello": (b=!b)?"world":"World";
System.out.println(s);
}
}
Output: hello
36. What identifies in an action uniquely..?
Ans: path
37. In init parameter ………..
Ans:Application
38. In MVC perspective , struts provides ..?
Ans: Controller
39. If methods in older versions of java are used then what happens ..?
Ans: deprecated
40. whats a correct interface name..?
Ans: ModelInterface
41. Issues in sublassing.
Ans: All of the above.
42. Initial attribute values can be set from deployment descriptor.
Ans False
43. whats the output…?
<html>
<body>
Value is
<%= ” ” %>
</body></html> Ans: value is
44.When does JVM exit ..?
Ans: System.exit() is called
45. Something about flush…
46. Relating to implicit objects
47.What represents an identifier name for a resource but not have to locate/path to it ..?
Ans:URI
48. <%@page isErrorpage=”true”%>
bb. Session object is available to pages that have isErrorpage set to true
cc. Exception object is available to pages that have isErrorpage set to true
dd. Used to mark the current JSP page as error page
ee. None of the above
49. Some static data is available for entire application what to do
a. create a singleton object to share the data
b. create the application object to share the data (not sure if D is correct but B is surely correct)
c. use some caching mechanisms
d. all the above
50. <bean:write> what this tag will do
51. To initialize the servlet, servlet container call on………
e. Benefit of using Java Beans to separate Business Logic from presentation markup within the JSP environment
f. correct JSP compilation sequence
g. Not true about forward
h. Options true while subclassing
i. What does reset method on an ActionForm perform
52. If you have created a custom Action Mapping subclass with the property “service”, you can initialize the value to “select Record” using which
All the below
<init prop name=”service” value=”select Record”/>
<set prop property=”service” value=”select Record”/>
<put field key=”service” value=”select Record”/>
53. Resource bundles are convenient way to –refer above
54. flow how a jsp works when it gets a request.. –refer above
i. get the request, check for the servlet, if servlet present ..
55. About implicit variable
can’t be used in bean and servlet
can be used in jsp
56.int arr[]=new int[2]
print arr[2]
Ans: ArrayIndexOutOfBoundsException
57.using forward in jsp
redirect and forward in servlet
servlet context
jsp in relation to servlet
58. send redirect on request obj is sent to the browser...
m. true b.false
1. Question frm localization in struts,
ii. Entire specification is done.....
iii. Creates specific resource for each request
a. Either i or ii
2. Neither i nor ii
3. Only i
4. Only ii
2. what will happen when init() is called?
3. To specify an ActionMapping to use when a request doesn't match any other mapping, you can
Use an asterisk for the path property
Set the “default” property of the mapping to true
Set the “unknown” property of the mapping to true
Set the “missing” init-param of the ActionServlet to the mapping’s path.
4. jsp tag libs
5. Given some coding using tag interfaces …….. Asked me to debug it.
6. JSP flow………. Don’t take it easy question it will be very confusing I don’t remember the options
7. Jsp declarations syntax
8. Read carefully the following topics:
redirect and forward
IN command in SQL
Got one question regarding sub queries in SQL
Coding regarding type casting in java ( implicit type casting)
Javax.servlet and javax.servlet.pagecontext packages.
9. Difference Between <%@Include %> and <jsp=include>
Ans: <%@Include %> - related to compile time
<jsp=include> - related with request time
10. Which two are equal
Ans: <jsp:scriplet>---------;</jsp:scriplet> and <%--------;%>
11. what method used to initiate servlet
Ans: void init(ServletConfig)
12. When to use forward and when to use redirect.
Ans: redirect – client side -- forward server side
13. How to maintain sessions:
Ans: save in secret field,url rewriting,cookies … In short All of the above ;)
14. What identifies in an action uniquely..?
Ans: path
15. In init parameter
Ans: Application
16. In MVC perspective , struts provides ..?
Ans: Controller
17. Initial attribute values can be set from deployment descriptor.
Ans False
18. Arrays in java are objects
19. Relating to implicit objects
1. using forward in jsp
2. redirect and forward in servlet
3. servlet context
4. jsp in relation to servlet
5. For shopping cart which will you prefer?
n. application
o. session
p. page
q. request
answer: session
6. send redirect on request obj is sent to the browser...
a. true
b. false
7. Question frm localization in struts,
i) Entire specification is done.....
ii) Creates specific resource for each request
a. Either i or ii
b. Neither i nor ii
c. Only i
d. Only ii
8. Difference Between <%@Include %> and <jsp=include>
Ans: <%@Include %> - related to compile time
<jsp=include> - related with request time
9. Which two are equal
Ans: <jsp:scriplet>---------;</jsp:scriplet> and <%--------;%>
10. what method used to initiate servlet
Ans: void init(ServletConfig)
11. When to use forward and when to use redirect.
Ans: redirect – client side -- forward server side
12. How to maintain sessions:
Ans: save in secret field,url rewriting,cookies … In short All of the above ;)
13. What identifies in an action uniquely..?
Ans: path
14. In init parameter
Ans: Application
15. In MVC perspective , struts provides ..?
Ans: Controller
16. Initial attribute values can be set from deployment descriptor.
Ans False
17. what’s the output…?
<html>
<body>
Value is
<%= ” ” %>
</body></html> Ans: value is
18. Relating to implicit objects
19. What represents an identifier name for a resource but not have to locate/path to it ..?
Ans: URI
20. what are the methods in HTTP?
1. GET
2. HEAD
3. RETRIEVE
4. POST
21. What is the output of the following?
<@ page language="java">
out.print("Hello");
out.print("World")
etc (I don't remember it exactly)
22. Advantages of jsp…. Separation of presentation logic from business logic so that few people can work on presentation and others can work on the other logic..
1) Which of the following types of inheritances do java support?
a.single inheritance
b.multiple inheritance
c.multilevel inheritance
d.hybrid
e.Only single and multiple inheritance
Ans: single and multilevel
2.) import library.*
Public class Myprogram{}
What should be the name of the java file containing this program?
a.Library.java
Ans: b.Myprogram.java
3.) which of the following are the valid comment stmt in java?
a.//
b./**/
c.!---!
d./** **/
Ans: a,b,d
4)An object should never directly manipulate the internal data of another object.
This reflects which of the following..
a.encapsulation
b.abstraction
c.polymorphism
d.inheritance
Ans: encapsulation