14. Where were inner classes introduced into the Java programming language syntax?--B
A. | 1.0 |
B. | 1.1 |
C. | 1.2 |
D. | 1.3 |
E. | 1.4 |
15.
16.
1. What do you have to do to make an instance variable into a JavaBean property? ---B
A. | Declare the instance variable public and static. |
B. | Define a get method and a set method for the variable. |
C. | Drop the Bean into the BeanBox property sheet. |
D. | Declare the instance variable private and let the BeanBox define get and set methods for the variable. |
2. An application builder tool can analyze how JavaBeans work. Which mechanism does the tool use? ---C
A. | Persistence |
B. | Method customization |
C. | Introspection |
D. | Event delegation |
3. Properties control what aspects of a JavaBean? ---B
A. | The communication between JavaBeans. |
B. | A JavaBean's appearance and behavior. |
C. | How a JavaBean is compiled and dropped into the BeanBox (or other tool). |
D. | The tools you can use to customize a JavaBean. |
4. JavaBean methods are all ---D
A. | Events |
B. | Properties |
C. | Event listeners |
D. | Identical to methods of other Java classes |
5. A source Bean is a JavaBean that fires an event, while the Bean that receives the event is called a ---A
A. | Listener Bean |
B. | Receiver Bean |
C. | Enterprise JavaBean |
D. | EventHandler Bean |
6. JavaBeans and widgets are both considered to be reusable software components. However, JavaBeans differ from widgets because Beans ---B
A. | Can be reused more rapidly than widgets. |
B. | Define a design-time interface that tools can query. |
C. | Take up less storage space that widgets. |
D. | Can be run by more tools on more platforms than widgets. |
7. The BeanBox is a JavaBean testing tool that comes with the Bean Developer's Kit. The BeanBox has the following windows: ---A
A. | ToolBox, BeanBox, and Properties windows. |
B. | ToolBox, BeanBox, and Garage windows. |
C. | BeanBox, ToolBox, and Windows98 windows. |
D. | Properties and ToolBox windows. |
8. JavaBeans communicate with each other using events, such as action events. You establish the connection between Beans by: ---D
A. | Writing a special adapter class. |
B. | Using the BeanBox Edit -> Events menu and resulting dialog box to hook up one Bean to another. |
C. | Having the BeanBox generate the special adapter class. |
D. | Any of the above choices. |
9. You use the Property sheet in the BeanBox tool to ---C
A. | Add new properties to a Bean. |
B. | Delete a Bean's property. |
C. | Change the value of a Bean's property. |
D. | All of the above. |
10. The properties of a Bean ---D
A. | May be inherited by the Bean from its superclass. |
B. | Are defined by the Bean itself. |
C. | Are analogous to instance variables. |
D. | All of the above. |
E. | None of the above. |
11. Some JavaBeans are not meant to be visible and are referred to as invisible Beans. Such invisible Beans ---E
A. | Have no GUI representation. |
B. | Are able to fire events and save persistent state. |
C. | Are invisible in builder tools. |
D. | All of the above. |
E. | A and B only. |
12. A property defined in a JavaBean typically ---D
A. | Is declared as a private type. |
B. | Has a corresponding get method and set method. |
C. | Can be saved and retrieved at a later time. |
D. | All of the above. |
E. | None of the above. |
13. When you write the code for a new JavaBean, you can test it in the BeanBox. What do you have to do to be able to test the Bean in the BeanBox? ---E
A. | Compile the Bean. |
B. | Create a manifest file for the Bean. |
C. | Create an executable JAR file for the Bean class and manifest file. |
D. | Load the JAR file into the BeanBox using the LoadJar menu option, or place the JAR file in the default directory from which the BeanBox initializes and loads its Beans. |
E. | All of the above. |
14. When you write a get method for a JavaBean property, form the method name as follows: ---C
A. | Use any name you want for the get method. |
B. | Use only the property name for the get method. |
C. | Use get followed by the property name, with the first letter of the property name capitalized. |
D. | None of the above. |
15. A manifest file for a JavaBean contains the following information: ---D
A. | The name of the JavaBean's class file. |
B. | An indicator that this is a JavaBean. |
C. | A list of the properties declared by the JavaBean. |
D. | A and B. |
E. | A, B, and C. |
16. Which kinds of properties can a Bean contain? ---B
A. | Complex properties and Event-handling properties |
B. | Constrained properties, Simple properties, Bound properties |
C. | All of the above |
17. A JavaBean that defines bound properties typically calls what methods so that other Beans can be notified of changes to the bound property? ---E
A. | The addPropertyChangeListener method so a Bean can register an interest in notification of changes to the property. |
B. | The reportChange method to send property change notification to interested Beans. |
C. | The firePropertyChange method to send property change notification to interested Beans. |
D. | The addActionListener method so a Bean can register an interest in notification of changes to the property. |
E. | A and C |
F. | D only |
G. | All of the above |
18. Bound properties appear in the BeanBox with what kind of event in the Edit -> Events menu? ---B
A. | actionPerformed event |
B. | propertyChange event |
C. | mouse pressed event |
D. | mouse moved event |
19. Constrained properties are ---B
A. | Identical to bound properties except that they are only used on certain platforms. |
B. | Identical to bound properties except that the listener Bean can veto the property change. |
C. | Identical to bound properties except that they are indexed. |
D. | None of the above. |
20. JavaBeans with constrained properties ---D
A. | Instantiate a PropertyChangeSupport object. |
B. | Use methods of the VetoableChangeSupport class. |
C. | Instantiate an ActionListener object. |
D. | A and B |
E. | None of the above |
F. | All of the above |
Answers:
1. What do you have to do to make an instance variable into a JavaBean property? | ||
D is incorrect | Answer (B): By definition, JavaBean properties are declared as private variables. To allow other components and builder tools to access these properties, a Bean must define get and set methods for each property. See Creating a Simple Bean | |
2. An application builder tool can analyze how JavaBeans work. A tool uses what mechanism to do this? | ||
C is correct! | Answer (C): Builder tools can analyze JavaBeans through the process of introspection. JavaBeans support introspection by adhering to specific rules, called design patterns, for naming Bean features. Each Bean has a related Bean information class, and this information class provides property, method, and event information about the Bean itself. A Bean information class implements a BeanInfo interface. The class explicitly lists the Bean features that are to be exposed to application builder tools. See What Distinguishes JavaBeans from Java Classes? | |
3. Properties control what aspects of a JavaBean? | ||
B is correct! | Answer (B): By definition, a JavaBean's properties control its appearance and behavior. Because builder tools can introspect on a Bean to discover its properties and to expose them for manipulation, you can change a Bean's property at design time. See Properties | |
4. JavaBean methods are all | ||
D is correct! | Answer (D): By definition, all JavaBean methods are identical to methods of other Java classes. Like other Java methods, Bean methods can be called by other Beans or via scripting languages. See Basic Bean Concepts | |
5. A source Bean is a JavaBean that fires an event, while the Bean that receives the event is called a | | |
A is correct! | Answer: (A) Beans use events to communicate with other Beans. Source beans fire events, which means the Bean sends an event to another Bean. A Bean may receive an event, in which case it is considered a listener Bean. A listener Bean registers its interest in the event with the source Bean. See Setting Up a Property Listener | |
6. JavaBeans and widgets are both considered to be reusable software components. However, JavaBeans differ from widgets because Beans | | |
A is incorrect | Answer (B): JavaBeans add standardized interfaces and object introspection mechanisms to widgets. These mechanisms allow builder tools to query JavaBean components about their properties and behavior. The tools can determine the kinds of properties defined by the components and the kinds of events that they generate or to which they respond. See What Distinguishes JavaBeans from Widgets? | |
7. The BeanBox is a JavaBean testing tool that comes with Java's BDK (Bean Developer's Kit). The BeanBox has the following windows: | | |
A is correct! | Answer (A): When you start the BeanBox, you see three windows: the ToolBox window, the BeanBox window, and the Properties window. The ToolBox window displays the names of the JavaBeans currently installed in the BeanBox. The BeanBox window is the window in which you build your application. The Properties window displays the properties of the Bean currently selected in the BeanBox window. See Starting the BeanBox | |
8. JavaBeans communicate with each other via events, such as action events. Establish the connection between Beans by: | | |
D is correct! | Answer (D): For one JavaBean to communicate to another JavaBean using an event, a communication path must first be established between the two Beans. The simplest way to establish such a communication path is to use a builder tool, such as the BeanBox. The BeanBox provides an Events selection from its Edit menu that brings up a dialog box for connecting two Beans. You select one Bean, then use its Events dialog box and the mouse to select the event action and make the connection to the second Bean. The BeanBox then generates a special adapter class to represent the communication that should occur between the two Beans when the event happens. You can also write this special adapter class yourself, rather than having the BeanBox generate it for you. See Using the BDK BeanBox | |
9. Use the Property sheet in the BeanBox tool to | | |
D is incorrect | Answer (C): The Properties window displays the current properties for the selected Bean. (Or, if no Bean is selected, it displays the BeanBox properties.) You can use the Properties window to edit a Bean's properties. The window displays the name of the property and its current value within an editable text field. Each property has an associated property editor. Clicking a property within the Property window activates the property's property editor. See A Look at Properties | |
10. The properties of a Bean | | |
D is correct! | Answer (D): JavaBean properties are analogous to Java instance variables. However, properties are declared private, and other components can access their values only through the public get and set methods. A Bean can define its own properties or it can inherit properties from its superclass, in the same manner that any Java class can define its own instance variables or inherit its variables from its superclass. See A Look at Properties | |
11. Some JavaBeans are not meant to be visible and are referred to as invisible Beans. Such invisible Beans | | |
D is incorrect | Answer (E): Not all JavaBeans have a GUI representation. If they don't have a GUI representation, then they are not visible in an application. However, they can still operate in the background of the application. In fact, invisible Beans are often used to fire events and save persistent state in an application, all of which occurs in a manner that is invisible to the application user. However, whether they are considered invisible or not, all JavaBeans are visible in builder tools. See A Look at JavaBeans | |
12. A property defined in a JavaBean typically | | |
D is correct! | Answer (D): A JavaBean property, by definition, is defined as a private instance rather than a public variable. Other components (Beans or tools) cannot directly access a property's value (because it is private). Instead, the Bean defines get and set methods for each property to make the property available to other components. JavaBeans are also serializable (they implement the java.io.Serializable interface), which means that their state-the current property settings or values-can be saved to a persistent store, such as a database, and then later retrieved. See A Look at Properties | |
13. When you write the code for a new JavaBean, you can test it in the BeanBox. What do you have to do to be able to test the Bean in the BeanBox? | | |
E is correct! | Answer (E): Every JavaBean, like any other Java class, must first be compiled before it can be run. Once the code for the Bean successfully compiles, you create a manifest file for the Bean. The manifest file includes the name of the Bean and the fact that it is a JavaBean. The manifest file becomes part of the executable JAR file that contains the compiled JavaBean. Beans are loaded into the BeanBox as executable JAR files. The JAR file can be placed in the BeanBox's initialization directory, which ensures that the BeanBox loads the JAR file and the Bean at start-up time. Or, you can manually load the JAR file using the BeanBox's LoadJar menu option. See Testing and Editing your Bean | |
14. When you write a get method for a JavaBean property, form the method name as follows: | | |
C is correct! | Answer (C): The names of the get and set methods follow a particular format so that the Bean introspection tools work. The method names begin with either get or set and are followed by the name of the property, with the initial letter of the property name capitalized. Thus, these methods have the following format: public get public void set (parameter) Get and Set Methods | |
15. A manifest file for a JavaBean contains the following information: | | |
D is correct! | Answer (D): The manifest file is an ASCII text file that can be created in any text editor. A manifest file for a JavaBean specifies the name of the JavaBean's class file and indicates that it is a JavaBean. The manifest file is a required part of the JAR file. See Test the Bean in the BeanBox | |
16. Choose the kinds of properties that a Bean may contain: | | |
C is incorrect | Answer (B): Just about all JavaBeans contain simple properties, because properties define how a Bean looks and acts. Bound and constrained properties are simple properties that have events tied to them. These properties are still instance variables, like simple properties, but the Bean also includes code to generate events and to allow other Beans to register as event listeners. If one Bean wants other Beans to be notified of changes to one of its properties, it makes that property a bound (or constrained) property and sets up an event to be generated when the property changes. Other Beans who are interested in changes to the property register their interest in such changes with the first Bean. When the property value does change, the first Bean fires an appropriate event which is received by the interested event listeners and handled appropriately. See Constrained Properties | |
17. A JavaBean that defines bound properties typically calls what methods so that other Beans can be notified of changes to the bound property? | | |
E is correct! | Answer (E): To implement a bound property, the Bean containing the property must instantiate the java.beans.PropertyChangeSupport class and then calls its two methods for managing event listeners: addPropertyChangeListener and removePropertyChangeListener. Beans interested in changes to the bound property can register their interest by adding themselves property change listeners. In addition, when the property value does change, the Bean containing the bound property must also fire an event to notify all interested property change listeners. The Bean does this by calling the PropertyChangeSupport class's firePropertyChange method from within each set method that affects a bound property. See Setting Up Bound Properties | |
18. Bound properties appear in the BeanBox with what kind of event in the Edit -> Events menu? | | |
B is correct! | Answer (B): The BeanBox recognizes when a Bean correctly defines a bound property and it includes a propertyChange interface item or event for that Bean. The propertyChange interface item appears in the BeanBox Edit -> Events menu for the selected Bean that defines a bound property. See Connecting the Beans in the BeanBox | |
19. Constrained properties are | | |
B is correct! | Answer (B): Constrained properties are identical to bound properties except for one additional feature: an outside object, either a listener Bean or the source Bean itself, can veto a proposed property change. The JavaBeans API event mechanism for handling constrained properties is similar to the one used for bound properties. See Constrained Properties | |
20. JavaBeans with constrained properties | | |
D is correct! | Answer (D): Constrained properties are identical to bound properties except for one additional feature: an outside object, either a listener Bean or the source Bean itself, can veto a proposed property change. The JavaBeans API event mechanism for handling constrained properties is similar to the one used for bound properties. See Setting Up Constrained Properties | |
*********************************************************************
Some important urls :
http://mathbits.com/MathBits/Java/arrays/Sorting.htm
http://www.tomjewett.com/dbdesign/dbdesign.php?page=multijoin.php
http://www.examcram2.com/articles/article.asp?p=30082&seqNum=1
http://www.janeg.ca/scjp/lang/arrays.html
http://struts.apache.org/1.x/userGuide/building_controller.html
http://java.sun.com/docs/books/tutorial/essential/exceptions/QandE/questions.html
1) What is the fastest database driver among typeI,II,III,IV drivers?
Ans: Type IV
2) Type 1 driver is also known as?
Ans: JDBC-ODBC Bridge Driver
3) Select avg(column) from table from the following table;
10, 20, NULL, 0
Ans:10
4) If there are 10 not null values and 5 null values in a column then the output of the following operation select count(*) from table name
Ans: 15
5) Question on the syntax of setting a property name in JSP
6) What is the best scope among the following for maintain the data efficiently
Options are : request, session, page request, application request
7) 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
8) Question on array declaration…….. given 5 declaration statements we have to choose from the five options
9) jdbc-odbc driver supports multithreading or not? Ans; no
10) Jsp supports multithreading or not . options are like this:
a) by default it will support multithreading
b) never supports
c) partially supports
d) none
Ans: JSP documents are ultimately compiled to servlets, which are multi-threaded by default and are assumed to be thread-safe. If the code in your JSP is not thread-safe, you can request the container uses a single threaded execution of the resulting servlet using the page directive <%@ page isThreadSafe="false" %>.
In this case the container may create multiple instances of the JSP servlet to handle concurrent requests or use synchronization to control access to a single instance. Both approaches are likely to reduce the performance of the page because of the overheads of instantiation and locking respectively, so this directive should be used with caution.
11) Given around 4 questions on debugging the java code……..
12) Constructors allow inheritance ? True or false
Ans: false
13) Jsp declarations syntax
14) Read carefully the following topics:
e) redirect and forward
f) IN command in SQL
g) Got one question regarding sub queries in SQL
h) Coding regarding type casting in java ( implicit type casting)
i) Javax.servlet and javax.servlet.pagecontext packages.
15) Approximate time for retreving
j) 1 value b) 100 values from data base is.
A) same
B) cannot say
C) ‘a’ requires less time than ‘b’
D) None
16) Given some coding using tag interfaces …….. Asked to debug it.
17) Given four class names and asked to pick appropriate one taking Sun java coding standards into consideration
18) nearly 5 questions from structs ……. two based on theory and three based on application.
19) Structs is based on which design pattern?
Jakarta Struts is a framework that facilitates building servlet applications based upon the Model-View-Controller (MVC) design paradigm.
20) JSP flow……….
21) a inner join gives combines both tables true or false
Ans:true
22) a inner join combines only the table in the left and not in the right true or false
Ans: false
23) truncate command deletes the table true or false
Ans:False
24) which command retrives from the database
Ans:select
25) which one is synchronized Hashmap or hashttable
Ans; hashtable
************************************************************************
26) Read servlets and structs applications……. Object scopes in jsp………. Javax. Servlet package……..
27) not in init config method
28) Output of the following:( Answer : 0 )
i=1
do{
i--;}
while(i>2)
sop(i);
Ans: Compile err. While shud be followed by “;“
29) public class name1{
public static void main(string [] args)
{
int c;
c=0;
sys("c");
}}
i c
ii 0
iii NULL
Answer : c will be displayed
30) not valid array declaration(check box)
i)string [][]a;
ii)string []i[];
iii)string 5[][];
iV)sting [0][]b;
Ans: iii & iv
31)
( Answer : Count(*) =15 and Count(row) = 10 )
if there are 10 value and 5 null values in a row select count(row) prints?
I. 10
II. 15
III. null
32) flow how a jsp works when it gets a request..
get the request, check for the servlet, if servlet present ....
33) what is given in class.forname in a jdbc file?
i)driver manager
ii)super class of driver manager
Ans: driver manager
34) which of the following are valid?( Answer: 1 . All others throw runtime exceptions .If | is used then runtime exception for 1st option also)
i=0, j=1
if ((i==0)||(j/i==1))
if ((i==0)&&(j/i==1))
if ((i!=0)|(j/i==1))
if ((i==1)&(j/i==1))
35) There will be three codes for jdbc connection which of the three is valid?
i)in the code.. finally{
con.close}
ii) con.close inside try
iii) con.close inside finally
ANS: finally
36) components of an MVC pattern? ( 1,2,3,4)
i)model
ii)view
iii)controller
iv)all the above
37) About implicit variable
i)cant be used in bean and servlet
ii)can be used in jsp
38) class parent{
}
class child extends parent{
}
which of the following can be used before child?
i)public, protected
ii) public
iii)private
iv) ...,public
Ans: public
39) some question about action mapping...
40) which is the least valid in jsp?
i) Request – second smallest
ii) page –smallest scope (like private variable)
iii) application – highest scope like global variable
iv)session –third smallest scope(each browser maintains)
Ans : scope in ascending order (smallest to largest) page,request,session,application
41) Ways to input a value...? Which of the following is true?
<set-property..>
<init-property..>
42) if(0.0==-0.0) does it returns true or false Ans : true
43) Are doget dopost service methods thread safe Ans : No
44) given an connection prog asked abt
1. password should be encrypted
2. driver name url wrong
3. incorrect sequence access,
4…………….
45) which way is correct below:
i)<% method; return method();%>
ii) <%= method; return method(); %>
iii) <%! method; return method(); %>
Ans: Method decl
<%! Return_type meth_name(args){
Method body
Return stt
}
%>
46) Can we write xml in jsp.
static pages
dynamic pages]
both static and dynamic
Ans: A JSP can now use either traditional JSP syntax or XML syntax within its source file. However, it is important to note that a JSP source file cannot intermix JSP syntax and XML syntax. No matter which type of syntax the JSP uses, it is still saved with a .jsp extension. The container will know the difference because the JSP document has a jsp:root element that cannot exist within traditional JSP syntax. The semantic model of a JSP document is no different than the semantic model of a JSP page. The JSP document generates a response stream of characters from template data and dynamic data. Text or XML fragments are common examples of template data and scripting elements, and standard or custom actions are common examples of dynamic elements. There are many reasons why you would want to use XML syntax in your JSPs. The specification describes the following reasons:
JSP documents can be passed directly to the container.
The XML view of the JSP document can be used to validate the JSP document against a description of the set of valid pages.
JSP documents can be manipulated via XML-aware tools.
An XML transformation, like XSLT, can be used to generate a JSP document from a textual representation.
Before the JSP 1.2 specification, there was no support for validating JSPs and little IDE support for manipulating JSPs. Therefore, the new abilities to validate the JSP document and manipulate it via XML-aware tools are great benefits of using XML syntax within JSPs.
JSP document
A JSP document is a JSP page written in XML syntax. It is a namespace-aware document that uses namespaces to identify the core syntax and additional syntaxes introduced to the page through tag libraries.
XML view
An XML view is the mapping between a JSP page, written in JSP syntax or XML syntax, and an XML document that describes it.
47) 28.types of drivers in jdbc.
Ans: 4 types
48) annonymous class
49) int arr[]=new int[2]
print arr[2] ArrayIndexOutOfBoundsException
50) jsp taglibs
51) Preparestatement
52) distint in sql
53) using forward in jsp
<jsp:forward>
Forwards a client request to an HTML file, JSP file, or servlet for processing.
JSP Syntax
<jsp:forward page={"relativeURL" | "<%= expression %>"} />
or
<jsp:forward page={"relativeURL" | "<%= expression %>"} >
<jsp:param name="parameterName"
value="{parameterValue | <%= expression %>}" />+
</jsp:forward>
or
<jsp:forward page={"relativeURL" | "<%= expression %>"} >
<jsp:param name="parameterName"
value="{parameterValue | <%= expression %>}" />+
</jsp:forward>
Examples
<jsp:forward page="/servlet/login" />
<jsp:forward page="/servlet/login">
<jsp:param name="username" value="jsmith" />
</jsp:forward>
<jsp:forward page="/servlet/login">
<jsp:param name="username" value="jsmith" />
</jsp:forward>
Description
The <jsp:forward> element forwards the request object containing the client request information from one JSP file to another file. The target file can be an HTML file, another JSP file, or a servlet, as long as it is in the same application context as the forwarding JSP file. The lines in the source JSP file after the <jsp:forward> element are not processed.
You can pass parameter names and values to the target file by using a <jsp:param> clause. An example of this would be passing the parameter name username (with name="username") and the value scott (with value="scott") to a servlet login file as part of the request. If you use <jsp:param>, the target file should be a dynamic file that can handle the parameters.
Be careful when using <jsp:forward> with unbuffered output. If you have used the <%@ page %> directive with buffer=none to specify that the output of your JSP file should not be buffered, and if the JSP file has any data in the out object, using <jsp:forward> will cause an IllegalStateException.
Attributes
page="{relativeURL | <%= expression %>}"
A String or an expression representing the relative URL of the file to which you are forwarding the request. The file can be another JSP file, a servlet, or any other dynamic file that can handle a request object.
The relative URL looks like a path-it cannot contain a protocol name, port number, or domain name. The URL can be absolute or relative to the current JSP file. If it is absolute (beginning with a /), the path is resolved by your Web or application server.
<jsp:param name="parameterName" value="{parameterValue | <%= expression %>}" />+
Sends one or more name/value pairs as parameters to a dynamic file. The target file should be dynamic, that is, a JSP file, servlet, or other file that can process the data that is sent to it as parameters.
You can use more than one <jsp:param> clause if you need to send more than one parameter to the target file. The name attribute specifies the parameter name and takes a case-sensitive literal string as a value. The value attribute specifies the parameter value and takes either a case-sensitive literal string or an expression that is evaluated at request time.
54) redirect and forward in servlets
A Controller servlet may perform either a forward or a redirect operation at the end of processing a request. It is important to understand the difference between these two cases, in particular with respect to browser reloads of web pages.
Forward
a forward is performed internally by the servlet
the browser is completely unaware that it has taken place, so its original URL remains intact
any browser reload of the resulting page will simple repeat the original request, with the original URL
Redirect
a redirect is a two step process, where the web application instructs the browser to fetch a second URL, which differs from the original
a browser reload of the second URL will not repeat the original request, but will rather fetch the second URL
redirect is marginally slower than a forward, since it requires two browser requests, not one
objects placed in the original request scope are not available to the second request
In general, a forward should be used if the operation can be safely repeated upon a browser reload of the resulting web page; otherwise, redirect must be used. Typically, if the operation performs an edit on the datastore, then a redirect, not a forward, is required. This is simply to avoid the possibility of inadvertently duplicating an edit to the database.
More explicitly :
for SELECT operations, use a forward
for INSERT, UPDATE, or DELETE operations, use a redirect
In HTML, a <FORM> tag can either GET or POST its data. In this context, a GET corresponds to a SELECT-then-forward, and a POST corresponds to an edit-then-redirect.
It is strongly recommended that forms for the input of search criteria should use GET, while forms for editing database records should use POST.
The important methods of the Servlet API are :
ServletRequest.getRequestDispatcher(String)
RequestDispatcher.forward(request, response)
HttpServletResponse.sendRedirect(String)
getRequestDispatcher
RequestDispatcher getRequestDispatcher(String path)
Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path. A RequestDispatcher object can be used to forward a request to the resource or to include the resource in a response. The resource can be dynamic or static.
The pathname specified may be relative, although it cannot extend outside the current servlet context. If the path begins with a "/" it is interpreted as relative to the current context root. This method returns null if the servlet container cannot return a RequestDispatcher.
The difference between this method and ServletContext.getRequestDispatcher(java.lang.String) is that this method can take a relative path.
Parameters:
path - a String specifying the pathname to the resource. If it is relative, it must be relative against the current servlet.
Returns:
a RequestDispatcher object that acts as a wrapper for the resource at the specified path, or null if the servlet container cannot return a RequestDispatcher
See Also:
RequestDispatcher, ServletContext.getRequestDispatcher(java.lang.String)
forward
void forward(ServletRequest request,
ServletResponse response)
throws ServletException,
IOException
Forwards a request from a servlet to another resource (servlet, JSP file, or HTML file) on the server. This method allows one servlet to do preliminary processing of a request and another resource to generate the response.
For a RequestDispatcher obtained via getRequestDispatcher(), the ServletRequest object has its path elements and parameters adjusted to match the path of the target resource.
forward should be called before the response has been committed to the client (before response body output has been flushed). If the response already has been committed, this method throws an IllegalStateException. Uncommitted output in the response buffer is automatically cleared before the forward.
The request and response parameters must be either the same objects as were passed to the calling servlet's service method or be subclasses of the ServletRequestWrapper or ServletResponseWrapper classes that wrap them.
Parameters:
request - a ServletRequest object that represents the request the client makes of the servlet
response - a ServletResponse object that represents the response the servlet returns to the client
Throws:
ServletException - if the target resource throws this exception
IOException - if the target resource throws this exception
IllegalStateException - if the response was already committed
55) servlet context
56) jsp in relation to servlet
57) if the package name is not known
58) difference between constructor and a method..?
a.no difference.
b.constructor cant return any value bt method can. Constructor can be called only once
bt method can be called any times.method can return values r void.
c.constructor cant return values bt mathods can.
59) use of Result set..
a. Moving the cursor
b. Itering the next row till last
c....
d...
60) For shopping cart which will you prefer?
a.application
b.session
c.page
d.request
answer: session
61) send redirect on request obj is sent to the browser...
a.true
b.false
62) Question frm localization in struts,
i) Entire specification is done.....
ii) Creates specific resource for each request
c. Either i or ii
d. Neither i nor ii
e. Only i
f. Only ii
63) which are all the valid methods in jsp??
a. jspInit()
_jspService()
jspDestroy()
b. _JSPInit()
_JSPService()
-JSPInit()
c. _JSPService()
_JspDestroy()
_JSPdodelete()
_JSPdoget()
_JSPdopost()
64) wat will happen when init() is called?
Answer :
Just like applets, servlets can define init() and destroy() methods. A servlet's init(ServletConfig) method is called by the server immediately after the server constructs the servlet's instance. Depending on the server and its configuration, this can be at any of these times:
When the server starts
When the servlet is first requested, just before the service() method is invoked
At the request of the server administrator
In any case, init() is guaranteed to be called before the servlet handles its first request.
The init() method is typically used to perform servlet initialization--creating or loading objects that are used by the servlet in the handling of its requests. Why not use a constructor instead? Well, in JDK 1.0 (for which servlets were originally written), constructors for dynamically loaded Java classes (such as servlets) couldn't accept arguments. So, in order to provide a new servlet any information about itself and its environment, a server had to call a servlet's init() method and pass along an object that implements the ServletConfig interface. Also, Java doesn't allow interfaces to declare constructors. This means that the javax.servlet.Servlet interface cannot declare a constructor that accepts a ServletConfig parameter. It has to declare another method, like init(). It's still possible, of course, for you to define constructors for your servlets, but in the constructor you don't have access to the ServletConfig object or the ability to throw a ServletException.
This ServletConfig object supplies a servlet with information about its initialization (init) parameters. These parameters are given to the servlet itself and are not associated with any single request. They can specify initial values, such as where a counter should begin counting, or default values, perhaps a template to use when not specified by the request. In the Java Web Server, init parameters for a servlet are usually set during the registration process.
P.S : about destroy()
The server calls a servlet's destroy() method when the servlet is about to be unloaded. In the destroy() method, a servlet should free any resources it has acquired that will not be garbage collected. The destroy() method also gives a servlet a chance to write out its unsaved cached information or any persistent information that should be read during the next call to init().
65) What is required for overriding...
a.overridden cls must not least public than the original class.
b...
66) difference between shallow copy and deep copy?
g. shallow copy does not share original object.Deep copy refers original obj.
h. shallow copy shares original object. Deep copy...
Java provides a mechanism for creating copies of objects called cloning. There are two ways to make a copy of an object called shallow copy and deep copy. Shallow copy is a bit-wise copy of an object. A new object is created that has an exact copy of the values in the original object. If any of the fields of the object are references to other objects, just the references are copied. Thus, if the object you are copying contains references to yet other objects, a shallow copy refers to the same subobjects. Deep copy is a complete duplicate copy of an object. If an object has references to other objects, complete new copies of those objects are also made. A deep copy generates a copy not only of the primitive values of the original object, but copies of all subobjects as well, all the way to the bottom. If you need a true, complete copy of the original object, then you will need to implement a full deep copy for the object. Java supports shallow and deep copy with the Cloneable interface to create copies of objects. To make a clone of a Java object, you declare that an object implements Cloneable, and then provide an override of the clone method of the standard Java Object base class. Implementing Cloneable tells the java compiler that your object is Cloneable. The cloning is actually done by the clone method.
67) a)config.getresourceasstream(/web.inf/asd.zip)
b)config.inputstream(“asd.zip”);
c)context.inputstream(“asd.zip”);
d) context.getresourceasstream(/web.inf/asd.zip)
68) Name of application resource file is set by the servlet init_param named.
application resources
application
resources
messages
69) Roles of Resultset
a. Used in while loop to iterate through the resultset.
b. Resultset object maintains a cursor pointing to its current row of data.
c. Initially cursor in first row, the next method moves the cursor to next row because it returns false when there are no more rows in the Resultset object
d. All the above.
Ans: a, b
70) Stuts populate a form in struts 1.1?
a. By overriding populate bean method of Action Mapping.
b. By overriding populate method of Action Form
c. By overriding process populate method of Request process
d. All the above
71) Access modifiers to Method.. public, protected, private
72) <html><body>The value of <%=” “%>…what will print
73) which is not true about Tag Library Descriptor(TLD)
74) <%@page isErrorpage=”true”%>
Seesion object is available to pages that have isErrorpage set to true
Exception object is available to pages that have isErrorpage set to true
Used to mark the current JSP page as error page
None of the above
75) When JDBC connection object would released
Ans: when close() method is called on the connection object
76) Some static data is available for entire application what to do
create a singleton object to share the data
create the application object to share the data (not sure if d is correct but b is surely correct)
use some caching mechanisms
all the above
77) Output of the code say true or false
Public class client{
Public static void main(String args[]){
String name=”java”;
System.out.println(name instance of Object)
}
}
Ans: true
78) What is the output
Public class A{
Public static void main(String args[])
For(int i=0;i<2;i++){
For(int j=2;j>=0;j--){
If(i==j) break;
System.ou.println(“i=”+i+”j=”+j);
}
}
a. i=2 j=0 b. i=0 j=0
i=2 j=1 i=0 j=1
i=2 j=2 i=0 j=2
c. i=0 j=2 d. i=1 j=0
i=0 j=1 i=1 j=1
i=1 j=2 i=1 j=2
Ans: c
79) <bean:write> what this tag will do
80) when we join two or more table in query which can be easily loaded
ascending from left to right
descending from left to right
ascending from right to left
descending from left to right
Ans: C (not sure)
81) To initialize the servlet, servlet container call on………
82) Immutable object when we create an instance of them(checkbox)
i. java.lang.stringBuffer
j. java.lang.Boolean
k. java.lang.String
l. java.lang.Integer
Ans: b,c,d
83) String a=null;
If(a!=null && a.length()>10)
{….}
When we replace && with & what will happen
Ans: NullPointerException is thrown
84) Null is a keyword in java say true or false Ans:false
“null” is keyword…..”Null” is not
85) Not a servlet Request for retriving client sent parameters
getparameterNames()
getparametervalues()
getparameter()
getvalue()------method does not exits
The signature of the methods are
public abstract java.lang.String getParameter(java.lang.String);
public abstract java.util.Enumeration getParameterNames();
public abstract java.lang.String[] getParameterValues(java.lang.String);