java quetions
-
Upload
gurdeep1234 -
Category
Documents
-
view
217 -
download
0
Transcript of java quetions
-
8/7/2019 java quetions
1/32
1)What is a singleton class?How do you writer it? Tell examples?
A class which must create only one object (ie. One instance) irrespective of any
number of object creations based on that class.
Steps to develop single ton class:-
1.Create a Private construcor, so that outside class can not access this constructor. And
declare a private static reference of same class2.Write a public Factory method which creates an object. Assign this object to private
static Reference and return the object
Sample Code:-
class SingleTon
{
private static SingleTon st=null;
private SingleTon()
{
System.out.println(\nIn constructor);
}
public static SingleTon stfactory()
{
if(st==null)
st=new SingleTon();\
return st;
}
}
2) What is the difference between using HttpSeassion & a Stateful Session bean? Why
can't HttpSessionn be used instead of of Session bean?
HttpSession is used to maintain the state of a client in webservers which are based on
Http protocol. Where as Stateful Session bean is a type of bean which can also maintain
the state of the client in Application servers based on RMI-IIOP
3)Question on Seggregation in UML?
http://system.out.println/http://system.out.println/ -
8/7/2019 java quetions
2/32
4)What is Temporary Servlet?
When we sent a request to access a JSP, servlet container internally creates a 'servlet'& executes it. This servlet is called as 'Temporary servlet'. In general this servlet will
be deleted immediately to create & execute a servlet base on a JSP we can used
following command.
Java weblogic.jspckeepgenerated *.jsp
5) Generally Servlets are used for complete HTML generation. If you want to generate
partial HTML's that include some static text (this should not be hard coded in servlets)
as well as some dynamic text, what method do you use?
Using 'RequestDispather.include(xx.html) in the servlet code we can mix the partial
static HTDirectoryML page.
Ex:- RequestDispatcher rd=ServletContext.getRequestDispatcher(xx.html);
rd.include(request,response);
6)Difference between and tags?
action tag redirect the servlet Request and Servlet Response to another
resource specified in the tag. The path of the resource is 'relative path'. The output
generated by current JSP will be discarded.
action tag process the resource as part of the current jsp. It include theo/p generated by resource, which is specified in the Tag to the current JSP
*) In both the cases single Request proceses multiple resources.
7) Purpose of tag:
It is used to generate client broser specified HTML tags which results in download
of the java plugin sofware. And the execution of the applet or java Bean component
that is specified in the tag.
8) The time between Command Execution and Response is called?
9)Which method is called first each time a Servlet is invoked?
When the servlet obj is not created init() method will be called. It servlet obje is already
exists 'service() method will be called.
10)Tell about EJB tranctions and how to manage them?
-
8/7/2019 java quetions
3/32
11)Why DB connections are not written directly in JSP's?
The main purpose of JSP is to seperate the business logic & presentation logic. DB
connections deal with pure java code. If write this kind of code in JSP, servlet container
converts the JSP to servlet using JSP compiler which is the time consuming process so
this is better to write code wich deals with DB connections, Authentication and
Authorization etc. in the java bean and use the tag to perform the action
12)What is key diffrence between using a and
HttpServletResponse.sendRedirect()?
Ans: The action allows the request to be forwarded to another resource
(servlet/jsp/HTMl> which are available in the same web-application (context).
Where as in the case of Response.sendRedirect() the request to be forwarded/redirected
to another resource in the same web-application or some other web-application in the
same server, or to a resource on solme other web-server. The key difference is by using
single request from a browser can process multiple resources. Where as by
using SendRedirect() multiple requests take place in order to process multiple resources.
13)Why beans are used in J2EE architecture instead of writing all the code in jsp's?
In order to seperate the business logic and presentation logic beans are used. We write thebusiness logic in the Beans. Where there is a change in business process we have to
modify only the bean code not jsp code and viceversa.
14)How can a servlet can call a JSP error page?
By simply includeing an tag in web.xml file
< error-page>
< exception-type>javax.servlet.ServletException
/errorjsp.jsp
By using Response.sendRedirect(error.jsp); or by using
RequestDispatches.forward(error.jsp); we can call jsp error page in servlet.
15)What exception is thrown when Servlet initalization fails?
http://javax.servlet.servletexception/http://javax.servlet.servletexception/ -
8/7/2019 java quetions
4/32
ServletException . since init() throws ServeletException .
16) Explain MVC (Model-View-Controller) architecture?
MVC:- In model view controller design pattern, the software has split into 3 pieces.
MODEL-> Responsible for Managing Data-> Ex. Java BeansVIEW-> Responsible for generating the views->Ex. Jsp's
CONTROLLER-> Responsible for user interactions & co-ordinate with MODEL
&VIEW
17)What are the design patterns? Explain FACADE Design Pattern?
18) How do you perform testing? Do you use any automated testing tools? If so, what are
they?
19)Difference between Application Server & Web server?
Web servers are used for running web applications, the features are very less to
compare application server the application server is specific to application. And it can
run all the application including web application.
Ex:- weblogic,websphere, Jbose.All are providing the more features than websever like tomcat.
Application servers used for enterprise solutions, webservers are used middle tier
webapplications. We can
20)JSP implicit Objects:-
1)out: used to send the content to the browser
ex: out.println(xx)2)Response: Represent HttpServlet Reques
3) Response: Represent HttpServletResponse
4) Page Context: used to access the objects like session, servlet context, Request,
Response etc...
5) Session: Points to HttpSession objects
6) Application: Points to servlet context objects
-
8/7/2019 java quetions
5/32
7)Page: Points to current servlet objects
8) Exception: Points to Exception
21)JSP Action Tags, Directive Tags & Scripting Tags?
Action Tag: These tags effect the runtime behaviour of the jsp page and the response
set back to client tags are :
instantiate a new jsp bean class
< jsp: setProperty>: setting the properties at runtime
:used to sending parameters
include a resource at runtime
forward the control to specific resource
:to plugin a web resource url applet
Directives:
These tags effect the overall structure of the servlet that result from translation. 3
types of directives are defiend.
Page directive: used to define and manipulate the no of page dependent attributes
that effect the whole jsp.
include directive: This instructs the container to include the content of the resource
in the current jsp
.
this file is parsed once, when translation.
Taglib directive: To use tag extendtions to define custom tags.
Scriptlets: There are used to include javacode in jsp page these are of 3 types
scriptlet: used to write pure java code
declarations: used to declare java variables and methods
Expressions:
This send the value of a java expression back to client. These results is
converted to string and displayed at client.
-
8/7/2019 java quetions
6/32
22) tag and it's properties?
To saparate the code from the presentation it would be good idea to encapsulate the code
in java object instantiate it and use it in our jsp. This instance is varaible is called 'id'.
We can also specific life time of this object by using 'scope' attribute
Properties:
id: a case sensitive name is used.
Scope: The scope with in which the reference is available. page, request,session,
application are possible values
page is default
class: the fully qulified classes name
beanname: The name of the java beanclass
type: This type must be super class of the beans classes
23)How do you implement Singe Thread Model in JSP?
By simply include a page directives
24)How do you declare a page as Erro Page. What tag you include in a JSP page so that it
goes to specified error page in case of an exception?
By includeing a page directive
then this page is including a page directive in our jsp pages
calling this page is including a page directive in our jsp page
25)Difference between Include Directive & Incude Tag?
26)Servlet is a java class. So, can there be a constructor in Servlet class or not? Why?
-
8/7/2019 java quetions
7/32
Include Directive Include Jas
-
8/7/2019 java quetions
8/32
context object
sc.getRequestDispatcher();
30)Tag Libraries, their syntax, & usage?
31) Difference between JSP & Servlets?
Both are webapplications used to produce web content that mean dynamic web pages.
Bot are used to take the requests and service the clients. The main difference between
them is, In servlets both the presentation and business logic are place it together. Where
as in jsp both are saparated by defining by java beans .
In jsp's the overall code is modulated so the developer who deesn't know about java can
write jsp pages by simply knowing the additional tages and class names.
One more important to be considered is servlet take less time to compile. Jsp is a tool to
simplify the process and make the process automate.
32)Difference between Hashtable & HashMap?
Hash table is a Collection .To successfully store and retrieve objects from a
hashtable, the objects used as keys must implement the hashCode method and the equalsmethod. Hashtable is Sychronized and permit not null values only.
Hashtable maps keys to values. Any non-null object can be used as a key or as a
value.
The HashMap class is roughly equivalent to Hashtable, except that it is
unsynchronized and permits nulls.
33) Question on Collections framework?
The Collection API is set of classes and interfaces that support operations on
Collections of Objects.
-
8/7/2019 java quetions
9/32
34) By default, Hastable is unordered. Then, how can you retrieve Hastable elements in
the same order as they are put inside?
we can retrieve hashtable elements in the same order by using the method elements
which returns enumeration.
35) About Map data structures in Collections framework?
A map cannot contain duplicate keys; each key can map to at most one value. The
Map interface provides three collection views, which allow a map's contents to be
viewed as a set of keys, collection of values, or set of key-value mappings. The order
of a map is defined as the order in which the iterators on the map's collection views
return their elements.The TreeMap class, make specific guarantees as to their order;
others, like the HashMap class, do not.
36)Life Cycles of beans?
37)Isolation levels & Transaction levels?
The isolation level measures concurrent transaction's capacity to view data that have been
updated, but not yet committed, by another transaction if other transactions were allowed
to read data that are as yet uncommitted, those transactions could end up with
inconsistent data were the transaction to roll back, or end up waiting unnecessarily were
the transaction to commit successfully.
A higher isolation level means less concurrence and a greater likelihood of performance
bottleneck, but alos adecreased chance of reading inconsistent data. A good rule of thumb
is to use the highest isolation level that yields an acceptable performace level. The
following are commin issilation levels, arranged from lowest to highest.
1) ReadUncommitted: Data that have been updated but not yet committed by atransaction my be read by other transactions
2) Readcommitted: Only data that have been committed by a transaction can be read
by other transactions.
3) Repeatable Read: Only data that have been commited by a trasaction can be read by
other transactions, and multiple reads will yield the same result as log as the data have
been committed.
-
8/7/2019 java quetions
10/32
4) Serializable: This highest possible iosolation level, ensures a transaction's
execlusive read-write access to data, it includes the conditions of ReadCommitted and
Repeatable Read and stiplulates that all transactions run serially to achieve maximum
data integrity. This yields the slowest performance and least concurrency. The term
serializable in this context is absolutely unrelated to the database.
38)ejbActivate() Vs ejbPassivate(), ejbCreate() Vs ejbPostCreate(), ejbLoad() Vss
ejbStore(). Which type of EJB can use bean pooling? How can you call an EJB from a
JSP/servlet?
EjbCreate() is called before the state of the bean is written to the presistence storage.
After this method is completed, a new record is created and written to the presistence
storage. If you are developing an EJB following 2.0 specs, you can have overloading
methods in the form of ejbcreatexxx(). This will improve the development so you can
have different behaviour for creating a bean, if the parameters differs. The only
requirement is that for each ejbCreatexxx() you need to have corrisponding createxxx()
methods in the home or local interface. EjbPostCreate() is called after the bean has been
written to the database and the bean data has been assigned to an EJB object. So when the
bean is available. In CMP, this method is normally used to manage the beans container-
managed relationship file
39)How to configure Data Source in WebSphere server?
40)How you manage configuration control?
41) What is a singleton class?
-
8/7/2019 java quetions
11/32
42)How do you send data from an applet to Servlet? What are the steps involved in it?
When ever we send a request to the JSP file it checks the servlet representing the JSP
file. Then the web container runs the jsp compiler that generates the servlet code
Directory
43)I have a file of very very large file size at client side, and i want to send the file to a
servlet(this servlet will store it somewhere), what is the best method to do it?
44)What is the difference between normal beans and EJBs?
JavaBeans may be visible or nonvisibleat
runtime. For example, the visual GUI
component may be a button, list box,
graphic, or a chart
An EJB is a nonvisual, remote object
Java Beans are intended to be local to a
single process and are primarily intended to
run on the client side. Although one candeevelop server-side JavaBeans, it is far
easier to develop them usin the EJB
specification instead.
EJBs are remotely executable components
or business objects that can be deployed
only on the server
JavaBeans is a component technology to
create generic java component that can be
composed together into applets and
applications
Even though EJB is a component
technology, it neither builds upon nor
extends the original javaBeans specification.
Java Bean have an external interface called
the properties interface, which allows a
builder tool to interpret the functionality of
the bean
EJBs have a deployment descriptor that
describes its functionality to an exteternal
builder tool or IDE
-
8/7/2019 java quetions
12/32
45)How system level services in EJBs are managed? And tell about Deployment
Descriptor?
50) In webLogic clusters, what is the load balancing algorithm
Load Balancing for servlets & jsps
Load Balancing for EJB &RMI objects
Load Balancing for JMS
Load Balancing for JDBC connection
Round Robin Load Balancing
Weight based load Balancing
Random Load Balancing
Round Robin, weight based & Random affinity.
46)What are various types of EJBs?
We have 3 types of EJB's
1) Seasion Beans:
Stateless Seasion bean
Stateful Seasion bean
Session beans are mainly used to implement business process applications
2) Enatity Beans:
Entity beans used to manage business entites
Bean Managed Persistance beans(BMP):--we need to write jdbc code to manage
business data
Container Managed Persistance bean(CMP):--Tools supllied as part of the containergenerates the jdbc code for managing the data
3) Message Driven Beans: Used to implement business processing and Business Data
47)What is the purpose of ejbLoad()?
With CMP , the bean developer doesnot need to write any database access logic into
the bean, but bean is notified by the container when its state is synchronized with the
database. The container notifies the bean using the ejbLoad() and ejbStore() methods.
The ejbLoad() method alerts the bean that its container-managed fields have just been
populated with data from the database. This gives the bean an opportunity to do any post
-
8/7/2019 java quetions
13/32
processing before the data can be used by the business methods.
The ejbStore() method alerts the bean that its data is about to be written to the
database. This give the bean an opportunity to do any pre-processing to the fields before
they are written to the database.
The BMP bean manges its own persistance , but relies on the container to coordinateits reads and writes so that persistance is accomplished in a transactional safe manner.
Coordination with the container is accomplished through two mechanisms:
the persistance callback methods [ejbLoad() and ejbStore()] and the Environment
Naming Context (EJB).
The ejbLoad() and ejbStore() methods notify a bean that its time to read and write
data to the database respectively. In a BMP entity bean the code for reading and writing
data to the database is done with in these methods . The ejbLoad() is called at the
beginning of transaction, just before any business methods are executed , and the
ejbStore() is called at the end of a transaction just before its commited. This keeps the
bean state in perfect synchronization with transactions being executed , without the bean
developer having to explicitly manage the transactional operation.
48)What is the purpose of ejbStore()?
49)What is the purpose of XML?When ever we send a request to the JSP file it checks
the servlet representing the JSP file. Then the web container runs the jsp compiler that
generates the servlet code
50) In webLogic clusters, what is the load balancing algorithm
Load Balancing for servlets & jsps
Load Balancing for EJB &RMI objects
Load Balancing for JMS
Load Balancing for JDBC connection
Round Robin Load Balancing
Weight based load Balancing
Random Load Balancing
Round Robin, weight based & Random affinity.
51)How many Queues does a MDB listen to?
-
8/7/2019 java quetions
14/32
52)Where is the Deployment Descriptor placed?
Deployment Descriptors gives the information about our resources used in ourapplication to the server. To avoid the hand coding we used these deployment
descriptors. Which are placed under WEB-INF directory as an .xml file
53)Can a JSP be converted to SERVLET and the vice versa always?
We can convert a JSP to servlet but it is not possible in case of servlet to a jsp.
Usually server takes the responsibility of converting a JSP to a servlet based on .tld
files and taghandlers. But there is no server which takes servlet as input and gives jsp
file as output.
54)About EJB types,CMP,BMP,session, Entity beans?
Used for implementing business processing session beans are divided into two types
1) Stateful Session Bean
2) Stateless Session Bean
In stateful Bean, state of the session is maintained. It takes more memory to maintain
the state for each object. If there are 100 clients/requests. The server maintains 100
stateful beans each bean for a client. In stateless session Bean, no need to maintain
the state of a bean.
ii) Entity Beans: used to manage business data
BMP: we need to write jdbc code for managing dataCMP: code to manage the data will be generated by the tools.
iii) Message Driven Bean: Used for implementing business process ( some as session
beans use). This will be driven by message.
55)Can a client Context call ebjRemove() method?
In ejbRemove() method will be called before removing the object, it is similar to
destroy() method in servlets. In case of stateless session bean we cant call
ejbRevove() method from client context. It depends upon the server when to remove
on delete the object from the server
In case of stateful session bean. The client can call ejbRemove() method by callingremove method to remove the object from the server. In case of entity beans,
ejbRemove() method means deleting the data from two database. It can be called
from the client context.
56)Which is faster in execution-JSP or SERVLET ? Why?
-
8/7/2019 java quetions
15/32
Servlet is faster in execution as every jsp is changed on converted to servlet before
starting the execution. Thus the server need to spend some time to convent a JSP file
to servlet at its first time execution. But developing a jsp is very easy when
compared to servlet.
Every time before executing a jsp & server searches for related servlet file. If it
existsWhen ever we send a request to the JSP file it checks the servlet representingthe JSP file. Then the web container runs the jsp compiler that generates the servlet
code
then start the execution of that servlet otherwise server creates servlet files for those
jsps first and then execution takes place
57) What is the difference between Callable Statement and Prepared Statement?
Callable statement are used to call the stored procedures in a database where as
prepared statements are used to provide dynamic input for the statement.
58)Can we declare final method in abstract class?
If a method is defined as final then we cant provide the reimplementation for that
final method in its derived classes i.e overriding is not possible for that method.
An abstract class constains one or mole abstract method. If all the methods ar of type
abstract then use we can declare that class as abstract or interface. But in interface allthe methods must be of type abstract.
We can declare final method in abstract class suspose of it is abstract too, then there
is no used to declare like that.
Final abstract int test(String str);
Here we cant provide the implementation for the test method as it is declared as
final. But at the same time you declare it as abstract. [Abstract means it is
responsibility of derived class to provide implementation for this] Here we cant
provide the implementation for the test method. Even we descried to provide
implementation totally our meaning for declaring it as abstract is spoiled.
59) Can we declare abstract method in final class?
It indicates an error to declare abstract method in final class. Because of final class
never allows any class to inherit it.
-
8/7/2019 java quetions
16/32
60)How can you pass an object of data from one JSP to anoter JSP?
61) Can the same object os Stateless Session bean be shared by multiple clients? Can
the same object os Stateful Session bean be shared by multiple clients?
It is possible to share the same object of stateless session bean by multiple
clients.
A Server maintains a pool of objects in case of stateless session bean. And every
When ever we send a request to the JSP file it checks the servlet representing the
JSP file. Then the web container runs the jsp compiler that generates the servlet
code
time for a request it uses one of the pool of objects which is free at that time. The
server gets back that object in to the pool only after the client work on that object
is Directoryover [ client says that by invoking ejbremove() method]
After the client release that object, the server may used the same object to handle
another client request, thus the same object to handle another client request. Thus
the same object of stateless session can be shared by multiple clients But sharing
the same object for multiple clients is not possible in case of state full session
bean. Here server should maintain an object for every clients to handle / maintain
the state of that object.
62)In java, which has more wider scope? Default or Private?
Default has more scope than private
Private: accessible only to the members of that class where it is defined.
Default: We can access this from any class in the program/file
63)Design Pattern?
Design pattern is a solution for recurring (reoccurring ) problems. Any one can
provide best solution for a problem which is occurring repeatedly or often and we
can give any name for that solution is known as design pattern.
64)Which Design Pattern hides the complexities of all sub-systems?
-
8/7/2019 java quetions
17/32
-
8/7/2019 java quetions
18/32
the xml document get larger.
70)Have u ever used how to include an xslt in another xslt?
The extensively Stylesheet Language (XSL) is a W3C standard for describing apresentation rules that applied to xml documents. XSL includes both transformation
language an d formatting language. XSLT is an xml based language and W3C specific
that describes how to transform an xml document into another xml document.
71)Which loads driver classloader or JVM?
72)Types of Drivers in JDBC?
Types of drivers in JDBC
Type 1 : JDBC ODBC Bridge Driver
Type 2 : Native API Partly Java Driver
Type 3 : JDBC Net pure Java Driver
Type 4 : Native Protocol Pure Java Driver
73)How to implement connection pooling by ourself?
74) Will service all doget,dopost or the reverse?
75) How can u implement connection pooling by ourself?
-
8/7/2019 java quetions
19/32
When ever we send a request to the JSP file it checks the servlet representing the JSP
file. Then the web container runs the jsp compiler that generates the servlet code
76)How can u implement hasmap if u r not having it in java?
77)How will u declare a synchronized block? What does this represent in the
Declaration of sunchronized block?
When two or more threads need to access to a shared resource they need some way
to ensure that the resource will be used by only one thread at a time. The process by
which this achieved is called synchronization.
The general form of synchronize statement :
Synchronized (object) {
// statement to be synchronized
}
here the object is a reference to the object being synchronized. A
synchronized block ensures that a call to a method that is member of object occurs
only after the current thread has successfully entered the objects moniter.
78) What is servlet chaining?
One servlet output will give as a intput of another servlet in servlet chaining.
79)What is dynamic bindig? Can u explain with an example?
When ever we send a request to the JSP file it checks the servlet representing the JSPfile. Then the web container runs the jsp compiler that generates the servlet code
80)Can u read all elements from any array?
-
8/7/2019 java quetions
20/32
81)What is event delegtion model? Describe it with an example?
The event Delegation model defines standard and consistant mechanisms to
generate and process events. A source generates and event and sends it to one or
more listeners. The listeners simply waits until it receives an event. The advantage
of this design is that the application logic that processes events is cleanly separated
from the uses interface logic that generates those events.
82)What is a tier? What is the difference between tier and system or computer?
83)What do u mean by portability?
In c and c++ sizeof() operator tell us the number of bytes allocated for data items.
Different data types might be different sizes on different machines, so the
programmer must find out how big those types are when performaing operations that
are sensitive to the size. For example one computer might store integer in 32 bites,
where as another might store integers as 16bits. So the java does not need a sizeof()
operator for this purpose because all the data types are the same size on allmachines. We need not think about protability.
84)What is translation unit in jsp?
When we create a source code file for java its commonly called a compilation unit
or translation unit.
85) What is context in webapplication?
86)What are multiple and single processor servers? How session is handled when
the server is multi processor server?
When ever we send a request to the JSP file it checks the servlet representing the JSP
file. Then the web container runs the jsp compiler that generates the servlet code
-
8/7/2019 java quetions
21/32
87)If server crashes the threads will continue running or will they stop? What
happens to the servlet?
88)Explain MVC pattern by taking any one component ex JtextField or Jbutton?
89) What is pooling of servlet?
Whenever a request is called it picks up the instance of that servlet from a
Container which contains the number of instances from it & this is maintained by the
controls that is web.xml
90)Why cocoon? Why not struts? What is cocon?
91)How are u implementing session in ur applicatin?
The web containers can create the session objects on behalf of client request. For
accessing this session objects we need to use request.getSession(Boolean value);For every session object it is creating a sessionID to generate
92) What is serialization? What are the method in implementing serialization?
When ever we send a request to the JSP file it checks the servlet representing the JSP
file. ThDirectoryen the web container runs the jsp compiler that generates the servlet
code
93) Why jsp is used if we have servlets?
Java server pages are designed to simplify the process of developing a web
application on the top of servlet technology
94)Is servlet threadsafe?
Yes Servlet is a thread safe by implementing the single thread model we can fulfill
this.
95) What happens when jsp is called?
-
8/7/2019 java quetions
22/32
When ever we send a request to the JSP file it checks the servlet representing the JSP
file. Then the web container runs the jsp compiler that generates the servlet code
96)When Jsp code changes, how the servlet is reloaded?
When ever we send a request to the JSP file it checks the servlet representing the JSPfile. Then the web container runs the jsp compiler that generates the servlet code
97)What is difference between StateFul and Satateless Session Bean?
98)What is difference between Bean ManagedPersistance and Container
ManagedPersistance?
IN the case of Bean Managed Persistant we need to write the manual coding but
in the case of container managed persistant bean the tool itself will generate the
code to satisfy our requirements
99) Difference between forware(request,response) and SendRedirect(url)inservlet?
In the case of forward (req, res) the outputs generated by the first servlet will be
discarded but only the output generated by the second servlet will be send to the client .
But in the case of send redirect() will be setting the status code & pointing to the new url.
100)Draw & explain MVC Architectur?
101) What is synchronize?
With respect to multithreading , synchronization is the capability to control the access of
multipul threads to shared resources . Without synchronization, it is possible for one
thread to modify a shared
object while another thread is in the process of using or updating that object's value.
This often leads to significant errors.
102)How to prevent Dead Lock?
We can prevent this Dead Lock by implementing synchronization proceder & improve
the efficiency of the Application.
103)How Servlet Maintain Session and EJB Maintaine Session?
-
8/7/2019 java quetions
23/32
-
8/7/2019 java quetions
24/32
inside the file & this is used to identify the Home object
112) XML deployment descriptor?
It is nothing but web.xml where we can store all the resource information of all the
objects inside this file
113) Entity Bean session Bean where to use which Bean? Container Types:
114) What is the Max amount of information that can be saved in a Session Object?
As such there is no limit on the amount of information that can be saved in a Session
Object. Only the RAM available on the server machine is the limitation. The only limitis the Session ID length(Identifier) , which should not exceed more than 4K. If the
data to be store is very huge, then it's preferred to save it to a temporary file ontohard disk, rather than saving it in session. Internally if the amount of data being
saved in Session exceeds the predefined limit, most of the servers write it to atemporary cache on Hard disk.
115) How to confirm that user's browser accepted the Cookie?
There's no direct API to directly verify that user's browser accepted the cookie. Butthe quick alternative would be, after sending the required data tothe users browser,
redirect the response to a different Servlet which would try to read back the cookie.If this Servlet is able to read back the cookie, then it was successfully saved, else
user had disabled the option to accept cookies.
116) How do i get the name of the currently executing script?
Use req.getRequestURI() or req.getServletPath(). The former returns the path to
the script including any extra path information following the name of the servlet; thelatter strips the extra path info. For example:
URLhttp://www.javasoft.com/servlets/HelloServlet/jdata/userinfo?pagetype=s3&pagenum=4
getRequestURI servlets/HelloServlet/jdata/userinfogetServletPath servlets/HelloServlet/getPathInfo /jdata/userinfo
getQueryString pagetype=s3&pagenum=4
117) What are Good Ways of Debugging a Servlet? Are IDE's which support Servlet
Debugging?
There are couple of Methods. Firstly servers like JRun and others provide separate
logs where all your Print requests will print their data into. For example requests to
System.out. and System.err go to different log files. If this features is not available
-
8/7/2019 java quetions
25/32
or you want to maintain logs separately for each module then you can create astatic class called "LogWriter" and call the method inside the try catch loop. The print
method in Log Writer will be writing to a custom defined Log File.
try
{ ....}
catch(Exception exp){
LogWriter.print("Debug : The following error occurred at function .... ')}
Also Inprise JBuilder supports Servlet Debugging. Please refer to JBuilderdocumentation for details.
Just as a Cautionary note, from your Servlets, never call System.exit(0). Theresults might be unpredictable. Might close down the entire Server. The Best way is
to catch the Exception and either send resultant Error Page to the Browser or Writeto a Log file and inform user about the Error.
118) How do I know when user Session has expired or removed?
119) How can i stress test my Servlets?
You can use one of the following products to stress test your Servlets.ServletKiller From Allaire Software (Free Product)
E-Load from RSW Software
Web Application Stress Tool From Microsoft
JMeter from Apache
120) What is Server Side Push and how is it implemented and when is it useful?
Server Side push is useful when data needs to change regularly on the clients
application or browser , without intervention from client. Standard examples mightinclude apps like Stock's Tracker, Current News etc. As such server cannot connect
to client's application automatically. The mechanism used is, when client firstconnects to Server, (Either through login etc..), then Server keeps the TCP/IP
connection open.
It's not always possible or feasible to keep the connection to Server open. So
another method used is, to use the standard HTTP protocols ways of refreshing thepage, which is normally supported by all browsers.
http://www.allaire.com/products/jrun/ServletAddOn.cfmhttp://www.rswsoftware.com/products/eload.htmlhttp://homer.rte.microsoft.com/http://java.apache.org/jmeter/index.htmlhttp://www.allaire.com/products/jrun/ServletAddOn.cfmhttp://www.rswsoftware.com/products/eload.htmlhttp://homer.rte.microsoft.com/http://java.apache.org/jmeter/index.html -
8/7/2019 java quetions
26/32
This will refresh the page in the browser automatically and loads the new data every5 seconds.
121) What is the difference between Multiple Instances of Browser and Multiple
Windows? How does this affect Sessions?
From the current Browser window, if we open a new Window, then it referred to asMultiple Windows. Sessions properties are maintained across all these windows, even
though they are operating in multiple windows.
Instead, if we open a new Browser, by either double clicking on the Browser Shortcuticon or shortcut link, then we are creating a new Instance of the Browser. This is
referred to as Multiple Instances of Browser. Here each Browser window isconsidered as different client. So Sessions are not maintained across these windows.
123)Difference b/w jsp:forward and request.sendRedirect.
124)Using which obj we can call trasnsaction control statements.
125) Question on native with synchronized is it possible?
126) Can more than one will have his state in stateful session bean?
127) How u can database operations used in stateful session bean?
128) What do we use as path in xml?
129) What is struts?
130) Explain MVC Architecture?
View : - The UI view involves the presentation layout(the actual HTML output),
for the result of the interaction . For HTML clients, this can be done using JSP.
Controller : - presentation logic (the logical connection between the user and EJB
services), necessary to process the HTTP request , control the bussiness logic, and select
an appropriate response . This can be provided by Java Servlets or Session Beans.
Business logic (Model) :- The business logic ( the core business transactions and
processing ), necessary to accomplish the goal of the interaction ( calculations, queries ,
and / or updates to a database ,etc). Business logic should be separated from
UI logic. This makes it possible to have different clients( for ex browser and GUI) using
the same beans . Separating the 2 also makes the business components easier to re-use ,
maintain, and update or change.
-
8/7/2019 java quetions
27/32
131) How you can create servlet objects at the time of web application starts?
1
a) if we use configure a servelet using Load-on-startup the webContainer creates our
servlet object when we deploy the webapplication.
b) when we undeploy the webapplication the webcontainer destroys ( removing theobject from JVM destroys the servelet object ).
132) Suppose i created 5 servlet objects dynamically and i make a request to the
container, the which object will give to me?
133)What is the difference between servlet config and servlet context?
There will be only one ServletContext object for a webapplication.
There can be multiple ServletConfig objects in a single webapplication.
Servlet Config can used get Parameters
134) How you can create a connnection object in weblogic? And how you can access that
object?
135) What is difference between jsp:forward and Reqdisp.forward()?
136) What is difference between Req.sendRedirect and reqdisp.forward()?
137) How you can insert values into a table without writing the code()?
138) How you can call a jsp from a servlet and vice versa?
139) What is the difference between jsp writer, printwriter?
140) What are the implicite variables in jsp?
141) How may ways you can use threadclass and in which situation you can be use
runnableinterface?
142) What is the difference between string and String Buffer?
143) What is the difference between SAX and DOM?
144) If we can implement a constructor in a servlet? What will be happen?
145) What is difference between stateless and stateful session beans?
-
8/7/2019 java quetions
28/32
Stateless:
1) Stateless session bean maintains across method and transction
2) The EJB server transparently reuses instances of the Bean to service different
clients at the per-method level (access to the session bean is serialized and is 1 client
per session bean per method.
3) Used mainly to provide a pool of beans to handle frequent but brief reuests. TheEJB server transparently reuses instances of the bean to service different clients.
4) Do not retain client information from one method invocation to the next. So many
requir the client tomaintain on the client side which can mean more complex client
code.
5) Client passes needed information as parameters to the business methods.6)
Performance can be improved due to fewer connections across the network.
Stateful:
1) A stateful session bean holds the client session's state.
2) A stateful session bean is an extesion of the client that creates it.
3) Its fields contain a conversational state on behalf of the session object's client. This
state describes the conversation represented by a specific client/session object pair.
4) Its lifetime is controlled by the client.
5) Cannot be shared between clients.
146) What are the disadvantatges of CMP?
147) Structs concept you are implementing on model1 or model2?
148)What in an interface?
149)What are the difference between interface and abstract class?
The key difference between an interface and the corresponding abstract class is that a
class or interface can have unlimited number of immediate super interface but it can only
hace one super class.There are two primary axes of inheritance an object-oriented language like java.
Implementation inheritance is where the sub-class inherits the actual code
implementation from the parent. Interface inhyeritance is where the sub-class adheres to
the public interface of the parent.
Also java actally mixes the two notions together a bi.... java interfaces are nice and
clean. When you implement an interface, you are stipulating that your class adheres to the
contract of the interface that you spefified. Java class inheritance isn't so clean when
you sub-class in java you are getting both the code inheritance but you are also
stipulating that you sub-class adheres to the contract of the interface of the parent class.
Abstrct class in java are just like regular java classes but with the added constraint thatyou cannot instance then directly. In terms of that added constraint, they are basically
classes which don't actually implement all lof the code specified by their contract.
-
8/7/2019 java quetions
29/32
150) How you can access the implementation from the database to JSP/Servlet?
151) How you can get connection object from weblogic?
A checked exception is an exception that must be dealt with in the code, either by
catching it or by specifying a throws clause. Checked exceptions are all exceptions that
are subclassed from Exception except RuntimeException. An unchecked exception is an
exception that need not be dealt with programmatically. It includes RuntimeExceptions
(and its subclasses) and Error and its subclasses.
===============================================================
===== Checked vs. unchecked exceptions There are two kinds of exceptions in Java,
checked and unchecked, and only checked exceptions need appear in throws clauses. The
general rule is: Any checked exceptions that may be thrown in a method must either be
caught or declared in the method's throws clause. Checked exceptions are so called
because both the Java compiler and the Java virtual machine check to make sure this rule
is obeyed. Whether or not an exception is "checked" is determined by its position in the
hierarchy of throwable classes. Figure 4 shows that some parts of the Throwable family
tree contain checked exceptions while other parts contain unchecked exceptions. To
create a new checked exception, you simply extend another checked exception. All
throwables that are subclasses of Exception, but not subclasses of RuntimeException are
checked exceptions.
152) How you can send parameters to a servlet?
153) How you can create global parameters that is the parameters which are used by all
the servlets?
154) How many types of transactions are supported by EJB? What are they tx-support,tx-
no.supported what is the difference between tx-required,tx-not supported?
REQUIRED : Method calls require a transaction context. If one exists , it will be used ;if none exists, one will be created.
Can use Existing Transaction.
If not already in transaction will start new one , commit when method completes.This
transaction attribute should be used when ever the bean is accessing any transactional
resouce manager. ForEx: a bean accessing a database through JDBC should use the
transaction attribute Required. You should use this if you want the operation to always
-
8/7/2019 java quetions
30/32
run in a transaction.
TX- NOT-SUPPORTED :
The bean runs out side the context of a transaction. Existing
transactions are
suspended for the duration of method calls.
Does not execute in a Transaction.
Existing transaction is suspended.
This transaction attribute can be used when the resource manager
responsible for transaction
is not integrated with the application server. ForEx, if the bean method is invoking an
operation on a SAP System which is not integrated with the application server, the server
has no control over the transactions happening at the SAP system. In such a case , it is
best to set transaction attribute of the bean to be Not-Supported.
155) Explain about checked and unchecked exceptions?
A checked exception is an exception that must be dealt with in the code, either by
catching it or by specifying a throws clause. Checked exceptions are all exceptions that
are subclassed from Exception except RuntimeException. An unchecked exception is an
exception that need not be dealt with programmatically. It includes RuntimeExceptions
(and its subclasses) and Error and its subclasses.
===============================================================
===== Checked vs. unchecked exceptions There are two kinds of exceptions in Java,
checked and unchecked, and only checked exceptions need appear in throws clauses. The
general rule is: Any checked exceptions that may be thrown in a method must either becaught or declared in the method's throws clause. Checked exceptions are so called
because both the Java compiler and the Java virtual machine check to make sure this rule
is obeyed. Whether or not an exception is "checked" is determined by its position in the
hierarchy of throwable classes. Figure 4 shows that some parts of the Throwable family
tree contain checked exceptions while other parts contain unchecked exceptions. To
create a new checked exception, you simply extend another checked exception. All
throwables that are subclasses of Exception, but not subclasses of RuntimeException are
checked exceptions.
156) How you can create dynamically servlet objects at the time of webapplicationdeploying?
157) What is the difference between function and procedure in oracle?
-
8/7/2019 java quetions
31/32
158) What is the difference between drop and truncate?
159) What is the difference between truncate and delete?
160) Suppose you are doing any actions on database but you system will not doing any
actions on database? How you can know about this thing?( By starting logging
information in a file)
161) Servlet are by defaulty single threaded or multiple threaded?
162) What is the syntax of jsp:usebean?
jspusebean syntax:
163) What is the difference between reqdis.forward(),jsp:forward?
jsp:forward is a Action tag in jsp which is used to forward the request from one page
to other page . This is similar to requestDespatcher.forward.
In requestdespatcher forward ,only one request will be sent by the browser and it
is processed by two servlets/jsps.
164)What is a view?
View in a Mvc pattern is containing the presentation logic.
We are using jsps as view in MVC architecture.
165) What is the difference between callable statements, prepare statements ,createstatements?
callable statements: callable statements are used to retrieve the stored procedures from
the database. ie., these statements are used when two or more sql statements are retrived
over and over.
prepare statement: theser are precompiled statements which are stored in database.
-
8/7/2019 java quetions
32/32
We are using these prepare statemnts if the same query is to be executed over and over.
statement: statement is used to execute single sql statement.