<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8955336342891215397</id><updated>2011-11-27T16:31:47.972-08:00</updated><title type='text'>Important Java Questions</title><subtitle type='html'>Java is a programming language expressly designed for use in the distributed environment of the Internet. Java can be used to create complete applications that may run on a single computer or be distributed among servers and clients in a network. It can also be used to build a small application module or applet for use as part of a Web page.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://javaimpquestions.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8955336342891215397/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://javaimpquestions.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Naresh Namana</name><uri>http://www.blogger.com/profile/05755392141578528676</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>12</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8955336342891215397.post-4518937705087319470</id><published>2009-06-10T02:59:00.001-07:00</published><updated>2011-03-18T22:54:48.944-07:00</updated><title type='text'>115 imp java questions</title><content type='html'>&lt;script type="text/javascript"&gt;&lt;!--&lt;br /&gt;google_ad_client = "pub-8483836134365476";&lt;br /&gt;google_ad_host = "pub-1599271086004685";&lt;br /&gt;/* 728x15, created 6/10/09 */&lt;br /&gt;google_ad_slot = "3621647723";&lt;br /&gt;google_ad_width = 728;&lt;br /&gt;google_ad_height = 15;&lt;br /&gt;//--&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript"&lt;br /&gt;src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;div style="margin: 1ex;"&gt;      &lt;div&gt;    &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;&lt;b&gt;&lt;u&gt;115 questions total.  Covers everything from basics to JDBC connectivity, AWT and JSP.&lt;/u&gt;&lt;i&gt;&lt;u&gt; &lt;/u&gt;&lt;/i&gt;  &lt;br&gt; &lt;/b&gt; &lt;br&gt; 1.What is the difference between procedural and object-oriented programs?&lt;/font&gt;&lt;/p&gt; &lt;ol type="a"&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;In procedural program,    programming logic follows certain procedures and the instructions are    executed one after another. In OOP program, unit of program is object,    which is nothing but combination of data and code.&lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;In procedural program,    data is exposed to the whole program whereas in OOPs program, it is    accessible with in the object and which in turn assures the security    of the code.&lt;/font&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt; &lt;br&gt; 2.What are Encapsulation, Inheritance and Polymorphism?&lt;/font&gt;&lt;/p&gt; &lt;ol type="a"&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;Encapsulation is    the mechanism that binds together code and data it manipulates and keeps    both safe from outside interference and misuse. &lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;Inheritance is the    process by which one object acquires the properties of another object. &lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;Polymorphism is    the feature that allows one interface to be used for general class actions. &lt;br&gt;   &lt;/font&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;3.What is the difference between  Assignment and Initialization?&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Assignment can be done as many  times as desired whereas initialization can be done only once.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt; &lt;br&gt; 4.What is OOPs?&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt; Object oriented programming  organizes a program around its data, i.e. e., objects and a set of well  defined interfaces to that data. An object-oriented program can be characterized  as data controlling access to code. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;5.What are Class, Constructor  and Primitive data types?&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Class is a template for multiple  objects with similar features and it is a blue print for objects. It  defines a type of object according to the data the object can hold and  the operations the object can perform. Constructor is a special kind  of method that determines how an object is initialized when created.  Primitive data types are 8 types and they are: byte, short, int, long,  float, double, boolean, char. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;6.What is an Object and how  do you allocate memory to it?&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Object is an instance of a  class and it is a software unit that combines a structured set of data  with a set of operations for inspecting and manipulating that data.  When an object is created using new operator, memory is allocated to  it. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;7.What is the difference between  constructor and method?&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Constructor will be automatically  invoked when an object is created whereas method has to be called explicitly. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;8.What is casting?&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Casting is used to convert  the value of one type to another. &lt;br&gt; &lt;/font&gt; &lt;br&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;9.What are methods and how  are they defined?&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Methods are functions that  operate on instances of classes in which they are defined. Objects can  communicate with each other using methods and can call methods in other  classes. Method definition has four parts. They are name of the method,  type of object or primitive type the method returns, a list of parameters  and the body of the method. A method's signature is a combination  of the first three parts mentioned above. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;10.What is the use of bin and  lib in JDK?&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Bin contains all tools such  as javac, appletviewer, awt tool, etc., whereas lib contains API and  all packages. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;11.How many ways can an argument  be passed to a subroutine and explain them?&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;An argument can be passed in  two ways.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;i) &lt;u&gt;Passing by value&lt;/u&gt;:  This method copies the value of an argument into the formal parameter  of the subroutine. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;ii) &lt;u&gt;Passing by reference&lt;/u&gt;:  In this method, a reference to an argument (not the value of the argument)  is passed to the parameter. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;12.What is the difference between  an argument and a parameter?&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;While defining method, variables  passed in the method are called parameters. While using those methods,  values passed to those variables are called arguments. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;13.What are different types  of access modifiers?&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;&lt;u&gt;Public:&lt;/u&gt; Any thing declared  as public can be accessed from anywhere.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;&lt;u&gt;Private:&lt;/u&gt; Any thing declared  as private can't be seen outside of its class.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;&lt;u&gt;Protected:&lt;/u&gt; Any thing  declared as protected can be accessed by classes in the same package  and subclasses in the other packages. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;&lt;u&gt;Default modifier&lt;/u&gt; : Can  be accessed only to classes in the same package. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;14.What is final, finalize()  and finally?&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;a)&lt;u&gt; Final:&lt;/u&gt; final keyword  can be used for class, method and variables. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;A final class cannot be subclassed  and it prevents other programmers from subclassing a secure class to  invoke insecure methods. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;A final method can't be overridden. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;A final variable can't change  from its initialized value. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;b)&lt;u&gt;Finalize() :&lt;/u&gt; finalize()  method is used just before an object is destroyed and can be called  just prior to garbage collection. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;c)&lt;u&gt;Finally :&lt;/u&gt; finally,  a key word used in exception handling, creates a block of code that  will be executed after a try/catch block has completed and before the  code following the try/catch block. The finally block will execute whether  or not an exception is thrown. For example, if a method opens a file  upon exit, then you will not want the code that closes the file to be  bypassed by the exception-handling mechanism. This finally keyword is  designed to address this contingency. &lt;br&gt; &lt;/font&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;15)What is UNICODE?&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Unicode is used for internal  representation of characters and strings and it uses 16 bits to represent  each other. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;16.What is Garbage Collection  and how to call it explicitly?- When an object is no longer referred  to by any variable, java automatically reclaims memory used by that  object. This is known as garbage collection. System. gc() method may  be used to call it explicitly. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;17. What are Transient and  Volatile Modifiers?&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;&lt;u&gt;Transient:&lt;/u&gt; The transient  modifier applies to variables only and it is not stored as part of its  object's Persistent state. Transient variables are not serialized. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;&lt;u&gt;Volatile:&lt;/u&gt; Volatile modifier  applies to variables only and it tells the compiler that the variable  modified by volatile can be changed unexpectedly by other parts of the  program. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;18.What is method overloading  and method overriding?&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;&lt;u&gt;Method overloading:&lt;/u&gt;  When a method in a class having the same method name with different  arguments is said to be method overloading. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;&lt;u&gt;Method overriding :&lt;/u&gt;  When a method in a class having the same method name with same arguments  is said to be method overriding. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;19.What is difference between  overloading and overriding?&lt;/font&gt;&lt;/p&gt; &lt;ol type="a"&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;In overloading,    there is a relationship between methods available in the same class    whereas in overriding, there is relationship between a superclass method    and subclass method. &lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;Overloading does    not block inheritance from the superclass whereas overriding blocks    inheritance from the superclass. &lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;In overloading,    separate methods share the same name whereas in overriding, subclass    method replaces the superclass. &lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;Overloading must    have different method signatures whereas overriding must have same signature. &lt;br&gt;   &lt;/font&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;20.What is meant by Inheritance  and what are its advantages?&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Inheritance is the process  of inheriting all the features from a class. The advantages of inheritance  are reusability of code and accessibility of variables and methods of  the super class by subclasses. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;21.What is the difference between  this() and super()?&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;this() can be used to invoke  a constructor of the same class whereas &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;super() can be used to invoke  a super class constructor. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;22.What is the difference between  superclass and subclass?&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;A super class is a class that  is inherited whereas sub class is a class that does the inheriting. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;23.What modifiers may be used  with top-level class? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;public, abstract and final  can be used for top-level class. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;24.What are inner class and  anonymous class?&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;&lt;u&gt;Inner class&lt;/u&gt; : classes  defined in other classes, including those defined in methods are called  inner classes. An inner class can have any accessibility including private. &lt;u&gt; Anonymous class&lt;/u&gt; : Anonymous class is a class defined inside a method  without a name and is instantiated and declared in the same place and  cannot have explicit constructors. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;25.What is a package? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;A package is a collection of  classes and interfaces that provides a high-level layer of access protection  and name space management. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;26.What is a reflection package? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;java. lang. reflect package  has the ability to analyze itself in runtime. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;27.What is interface and its  uses? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Interface is similar to a class  which may contain method's signature only but not bodies and it is  a formal set of method and constant declarations that must be defined  by the class that implements it. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Interfaces are useful for: &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;a) Declaring methods that one  or more classes are expected to implement. &lt;/font&gt;&lt;/p&gt; &lt;ol start="3" type="a"&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;Capturing similarities    between unrelated classes without forcing a class relationship. c) Determining    an object's programming interface without revealing the actual body    of the class. &lt;br&gt;   &lt;/font&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;28.What is an abstract class? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;An abstract class is a class  designed with implementation gaps for subclasses to fill in and is deliberately  incomplete. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;29.What is the difference between  Integer and int? &lt;/font&gt;&lt;/p&gt; &lt;ol type="a"&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;Integer is a class    defined in the java. lang package, whereas int is a primitive data type    defined in the Java language itself. Java does not automatically convert    from one to the other. &lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;Integer can be used    as an argument for a method that requires an object, whereas int can    be used for calculations. &lt;br&gt;   &lt;/font&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;30.What is a cloneable interface  and how many methods does it contain? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;It is not having any method  because it is a TAGGED or MARKER interface. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;31.What is the difference between  abstract class and interface?&lt;/font&gt;&lt;/p&gt; &lt;ol type="a"&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;All the methods    declared inside an interface are abstract whereas abstract class must    have at least one abstract method and others may be concrete or abstract. &lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;In abstract class,    key word abstract must be used for the methods whereas interface we    need not use that keyword for the methods. &lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;Abstract class must    have subclasses whereas interface can't have subclasses. &lt;br&gt;   &lt;/font&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;32.Can you have an inner class  inside a method and what variables can you access?&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Yes, we can have an inner class  inside a method and final variables can be accessed. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;33. What is the difference  between String and String Buffer? &lt;/font&gt;&lt;/p&gt; &lt;ol type="a"&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;String objects are    constants and immutable whereas StringBuffer objects are not. &lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;String class supports    constant strings whereas StringBuffer class supports growable and modifiable    strings.&lt;/font&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt; &lt;br&gt; 34. What is the difference between Array and vector?&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Array is a set of related data  type and static whereas vector is a growable array of objects and dynamic. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;35.What is the difference between  exception and error? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;The &lt;u&gt;exception class&lt;/u&gt;  defines mild error conditions that your program encounters. Exceptions  can occur when trying to open the file, which does not exist, the network  connection is disrupted, operands being manipulated are out of prescribed  ranges, the class file you are interested in loading is missing. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;The &lt;u&gt;error class&lt;/u&gt; defines  serious error conditions that you should not attempt to recover from.  In most cases it is advisable to let the program terminate when such  an error is encountered. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;                              &lt;font size="4" face="Times New Roman"&gt;&lt;b&gt;&lt;u&gt;Thread&lt;/u&gt;&lt;/b&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;36.What is the difference between  process and &lt;/font&gt;&lt;font size="4" face="Times New Roman"&gt;&lt;b&gt;thread&lt;/b&gt;&lt;/font&gt;&lt;font size="3" face="Times New Roman"&gt;? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Process is a program in execution  whereas thread is a separate path of execution in a program. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;37.What is multithreading and  what are the methods for inter-thread communication and what is the  class in which these methods are defined? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Multithreading is the mechanism  in which more than one thread run independent of each other within the  process. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;wait (), notify () and notifyAll()  methods can be used for inter-thread communication and these methods  are in Object class. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;wait() : When a thread executes  a call to wait() method, it surrenders the object lock and enters into  a waiting state. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;notify() or notifyAll() : To  remove a thread from the waiting state, some other thread must make  a call to notify() or notifyAll() method on the same object. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;38.What is the class and interface  in java to create thread and which is the most advantageous method? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Thread class and Runnable interface  can be used to create threads and using Runnable interface is the most  advantageous method to create threads because we need not extend thread  class here. &lt;br&gt; &lt;/font&gt; &lt;br&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;39.What are the states associated  in the thread?&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Thread contains ready, running,  waiting and dead states. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;40.What is synchronization? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Synchronization is the mechanism  that ensures that only one thread is accessed the resources at a time. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;41.When you will synchronize  a piece of your code? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;When you expect your code will  be accessed by different threads and these threads may change a particular  data causing data corruption. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;42.What is deadlock? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;When two threads are waiting  each other and can't precede the program is said to be deadlock. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;43.What is daemon thread and  which method is used to create the daemon thread? Daemon thread is a  low priority thread which runs intermittently in the back ground doing  the garbage collection operation for the java runtime system. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;SetDaemon() method is used  to create a daemon thread. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;44.Are there any global variables  in Java, which can be accessed by other part of your program? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;No, it is not the main method  in which you define variables. Global variables is not possible because  concept of encapsulation is eliminated here. &lt;br&gt; &lt;/font&gt; &lt;br&gt; &lt;br&gt; &lt;br&gt; &lt;br&gt; &lt;br&gt; &lt;br&gt;  &lt;br&gt; &lt;br&gt; &lt;br&gt; &lt;br&gt; &lt;br&gt; &lt;br&gt;  &lt;br&gt; &lt;br&gt; &lt;br&gt; &lt;br&gt; &lt;br&gt; &lt;br&gt;  &lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt; &lt;p&gt;                              &lt;font size="5" face="Times New Roman"&gt;&lt;b&gt;&lt;u&gt;Applet&lt;/u&gt;&lt;/b&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;45.What is an &lt;/font&gt;&lt;font size="4" face="Times New Roman"&gt;&lt;b&gt;applet&lt;/b&gt;&lt;/font&gt;&lt;font size="3" face="Times New Roman"&gt;? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Applet is a dynamic and interactive  program that runs inside a web page displayed by a java capable browser. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;46.What is the difference between  applications and applets? &lt;/font&gt;&lt;/p&gt; &lt;ol type="a"&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;Application must    be run on local machine whereas applet needs no explicit                               &lt;/font&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;   &lt;font size="3" face="Times New Roman"&gt;installation  on local machine. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;b)   Application  must be run explicitly within a java-compatible virtual machine whereas  applet loads and runs itself automatically in a java-enabled browser.&lt;/font&gt;&lt;/p&gt; &lt;ol start="3" type="a"&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;Application starts    execution with its main method whereas applet starts execution with    its init method.&lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;Application can    run with or without graphical user interface whereas applet must run    within a graphical user interface. &lt;br&gt;   &lt;/font&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;47.How does applet recognize  the height and width? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Using getParameters( ) method. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;48.When do you use codebase  in applet? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;When the applet class file  is not in the same directory, codebase is used. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;49.What is the lifecycle of  an applet? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;init() method - Can be called  when an applet is first loaded &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;start() method - Can be called  each time an applet is started. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;paint() method - Can be called  when the applet is minimized or maximized. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;stop() method - Can be used  when the browser moves off the applet's page. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;destroy() method - Can be called  when the browser is finished with the applet. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;50.How do you set security  in applets? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;using setSecurityManager( )  method.&lt;/font&gt; &lt;br&gt;&lt;/p&gt; &lt;p&gt;                        &lt;font size="4" face="Times New Roman"&gt;&lt;b&gt;&lt;u&gt;AWT &amp;amp; SWING&lt;/u&gt;&lt;/b&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;51.What is an event and what  are the models available for event handling? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;An event is an event object  that describes a state of change in a source. In other words, event  occurs when an action is generated, like pressing button, clicking mouse,  selecting a list, etc. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;There are two types of models  for handling events and they are: a) event-inheritance model and b)  event-delegation model &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;52.What are the advantages  of the event-delegation model over the event-inheritance model? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;The event-delegation model  has two advantages over the event-inheritance model.&lt;/font&gt;&lt;/p&gt; &lt;ol type="a"&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;It enables event    handling by objects other than the ones that generate the events. This    allows a clean separation between a component's design and its use. &lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;It performs much    better in applications where many events are generated. This performance    improvement is due to the fact that the event-delegation model does    not have to be repeatedly process unhandled events as is the case of    the event-inheritance. &lt;br&gt;   &lt;/font&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;53.What is source and listener? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;&lt;u&gt;Source&lt;/u&gt; : A source is  an object that generates an event. This occurs when the internal state  of that object changes in some way. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;&lt;u&gt;Listener&lt;/u&gt; : A listener  is an object that is notified when an event occurs. It has two major  requirements. First, it must have been registered with one or more sources  to receive notifications about specific types of events. Second, it  must implement methods to receive and process these notifications. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;54.What is adapter class? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;An adapter class provides an  empty implementation of all methods in an event listener interface.  Adapter classes are useful when you want to receive and process only  some of the events that are handled by a particular event listener interface.  You can define a new class to act listener by extending one of the adapter  classes and implementing only those events in which you are interested.  For example, the MouseMotionAdapter class has two methods, mouseDragged(  )and mouseMoved() . The signatures of these empty are exactly as defined  in the MouseMotionListener interface. If you are interested in only  mouse drag events, then you could simply extend MouseMotionAdapter and  implement mouseDragged( ) . &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;55.What is meant by controls  and what are different types of controls in AWT? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Controls are components that  allow a user to interact with your application and the AWT supports  the following types of controls: Labels, Push Buttons, Check Boxes,  Choice Lists, Lists, Scrollbars, Text Components. These controls are  subclasses of Component. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;56.What is the difference between  choice and list? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;A &lt;u&gt;Choice&lt;/u&gt; is displayed  in a compact form that requires you to pull it down to see the list  of available choices and only one item may be selected from a choice. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;A &lt;u&gt;List&lt;/u&gt; may be displayed  in such a way that several list items are visible and it supports the  selection of one or more list items. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;57.What is the difference between  scrollbar and scrollpane? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;A Scrollbar is a Component,  but not a Container whereas Scrollpane is a Container and handles its  own events and perform its own scrolling. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;58.What is a layout manager  and what are different types of layout managers available in java AWT? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;A layout manager is an object  that is used to organize components in a container. The different layouts  are available are FlowLayout, BorderLayout, CardLayout, GridLayout and  GridBagLayout. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;59.How are the elements of  different layouts organized? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;FlowLayout: The elements of  a FlowLayout are organized in a top to bottom, left to right fashion. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;BorderLayout: The elements  of a BorderLayout are organized at the borders (North, South, East and  West) and the center of a container. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;CardLayout: The elements of  a CardLayout are stacked, on top of the other, like a deck of cards. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;GridLayout: The elements of  a GridLayout are of equal size and are laid out using the square of  a grid. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;GridBagLayout: The elements  of a GridBagLayout are organized according to a grid. However, the elements  are of different size and may occupy more than one row or column of  the grid. In addition, the rows and columns may have different sizes. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;60.Which containers use a Border  layout as their default layout? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Window, Frame and Dialog classes  use a BorderLayout as their layout. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;61.Which containers use a Flow  layout as their default layout? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Panel and Applet classes use  the FlowLayout as their default layout. &lt;br&gt; &lt;/font&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt; &lt;p&gt;                        &lt;font size="4" face="Times New Roman"&gt;&lt;b&gt;&lt;u&gt;COLLECTIONS&lt;/u&gt;&lt;/b&gt;&lt;/font&gt; &lt;br&gt; &lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;62.What are wrapper classes? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Wrapper classes are classes  that allow primitive types to be accessed as objects. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;63.What are Vector, Hashtable,  LinkedList and Enumeration?  &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Vector : The Vector class provides  the capability to implement a growable array of objects. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Hashtable : The Hashtable class  implements a Hashtable data structure. A Hashtable indexes and stores  objects in a dictionary using hash codes as the object's keys. Hash  codes are integer values that identify objects. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;LinkedList: Removing or inserting  elements in the middle of an array can be done using LinkedList. A LinkedList  stores each object in a separate link whereas an array stores object  references in consecutive locations. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Enumeration: An object that  implements the Enumeration interface generates a series of elements,  one at a time. It has two methods, namely hasMoreElements( ) and nextElement(  ). HasMoreElemnts( ) tests if this enumeration has more elements and  nextElement method returns successive elements of the series. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;64.What is the difference between  set and list?&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Set stores elements in an unordered  way but does not contain duplicate elements, whereas list stores elements  in an ordered way but may contain duplicate elements. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;65.What is a stream and what  are the types of Streams and classes of the Streams? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;A Stream is an abstraction  that either produces or consumes information. There are two types of  Streams and they are: Byte Streams: Provide a convenient means for handling  input and output of bytes. Character Streams: Provide a convenient means  for handling input &amp;amp; output of characters. Byte Streams classes:  Are defined by using two abstract classes, namely InputStream and OutputStream.  Character Streams classes: Are defined by using two abstract classes,  namely Reader and Writer. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;66.What is the difference between  Reader/Writer and InputStream/ Output Stream? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;The Reader/Writer class is  character-oriented and the InputStream/ OutputStream class is byte-oriented. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;67.What is an I/O filter? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;An I/O filter is an object  that reads from one stream and writes to another, usually altering the  data in some way as it is passed from one stream to another. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;68.What is serialization and  deserialization?  &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Serialization is the process  of writing the state of an object to a byte stream. Deserialization  is the process of restoring these objects. &lt;br&gt; &lt;/font&gt; &lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt; &lt;p&gt;                              &lt;font size="5" face="Times New Roman"&gt;&lt;b&gt;&lt;u&gt;JDBC&lt;/u&gt;&lt;/b&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;69.What is JDBC? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;JDBC is a set of Java API for  executing SQL statements. This API consists of a set of classes and  interfaces to enable programs to write pure Java Database applications. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;70.What are drivers available? &lt;/font&gt;&lt;/p&gt; &lt;ol type="a"&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;JDBC-ODBC Bridge    driver b) Native API Partly-Java driver c) JDBC-Net Pure Java driver    d) Native-Protocol Pure Java driver &lt;br&gt;   &lt;/font&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;71.What is the difference between  JDBC and ODBC? &lt;/font&gt;&lt;/p&gt; &lt;ol type="a"&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;OBDC is for Microsoft    and JDBC is for Java applications. &lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;ODBC can't be    directly used with Java because it uses a C interface. &lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;ODBC makes use of    pointers which have been removed totally from Java. &lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;ODBC mixes simple    and advanced features together and has complex options for simple queries.    But JDBC is designed to keep things simple while allowing advanced capabilities    when required. &lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;ODBC requires manual    installation of the ODBC driver manager and driver on all client machines.    JDBC drivers are written in Java and JDBC code is automatically installable,    secure, and portable on all platforms. &lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;JDBC API is a natural    Java interface and is built on ODBC. JDBC retains some of the basic    features of ODBC. &lt;br&gt;   &lt;/font&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;72.What are the types of JDBC  Driver Models and explain them? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;There are two types of JDBC  Driver Models and they are: a) Two tier model and b) Three tier model &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;a) &lt;u&gt;Two tier model:&lt;/u&gt; In  this model, Java applications interact directly with the database. A &lt;/font&gt;&lt;/p&gt; &lt;ul&gt;&lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;JDBC driver is required  to communicate with the particular database management system that is  being accessed. SQL statements are sent to the database and the results  are given to user. This model is referred to as client/server configuration  where user is the client and the machine that has the database is called  as the server. &lt;/font&gt;&lt;/p&gt;&lt;/ul&gt; &lt;ol start="2" type="a"&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;&lt;u&gt;Three tier model:&lt;/u&gt;    A middle tier is introduced in this model. The functions of this model    are: a) Collection of SQL statements from the client and handing it    over to the database, b) Receiving results from database to the client    and c) Maintaining control over accessing and updating of the above. &lt;br&gt;   &lt;/font&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;73.What are the steps involved  for making a connection with a database or how do you connect to a database?&lt;/font&gt;&lt;/p&gt; &lt;ol type="a"&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;Loading the driver    : To load the driver, Class. forName() method is used. Class. forName("sun.    jdbc. odbc. JdbcOdbcDriver" ); When the driver is loaded, it registers    itself with the java. sql. DriverManager class as an available database    driver. &lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;Making a connection    with database: To open a connection to a given database, DriverManager.    getConnection( ) method is used. Connection con = DriverManager. getConnection    ("jdbc:odbc:somedb" , "user", "password"); &lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;Executing SQL statements    : To execute a SQL query, java. sql. statements class is used. createStatement(    ) method of Connection to obtain a new Statement object. Statement stmt    = con. createStatement( ); A query that returns data can be executed    using the executeQuery( ) method of Statement. This method executes    the statement and returns a java. sql. ResultSet that encapsulates the    retrieved data: ResultSet rs = &lt;br&gt;   stmt. executeQuery(" SELECT * FROM some table"); &lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;Process the results    : ResultSet returns one row at a time. Next() method of ResultSet object    can be called to move to the next row. The getString() and getObject()    methods are used for retrieving column values: while(rs. next()) { String    event = rs. getString("event" ); Object count = (Integer) rs. getObject("count"    ); &lt;br&gt;   &lt;/font&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;74.What type of driver did  you use in project? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;JDBC-ODBC Bridge driver (is  a driver that uses native(C language) libraries and makes calls to an  existing ODBC driver to access a database engine). &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;75.What are the types of statements  in JDBC? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Statement: — to be used createStatement(  ) method for executing single SQL statement PreparedStatement — To  be used preparedStatement( ) method for executing same SQL statement  over and over. &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;CallableStatement — To be  used prepareCall( ) method for multiple SQL statements over and over. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;76.What is stored procedure? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Stored procedure is a group  of SQL statements that forms a logical unit and performs a particular  task. Stored Procedures are used to encapsulate a set of operations  or queries to execute on database. Stored procedures can be compiled  and executed with different parameters and results and may have any  combination of input/output parameters. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;77.How to create and call stored  procedures? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;To create stored procedures:  Create procedure procedurename (specify in, out and in out parameters)  BEGIN Any multiple SQL statement; END; To call stored procedures: CallableStatement  csmt = con. prepareCall(" {call procedure name(?,?)}"); csmt. registerOutParamete  r(column no. , data type); csmt. setInt(column no. , column name) csmt.  execute(); &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;                              &lt;font size="4" face="Times New Roman"&gt;&lt;b&gt;&lt;u&gt;SERVELTS&lt;/u&gt;&lt;/b&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;78.What is servlet? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Servlets are modules that extend  request/response- oriented servers, such as java-enabled web servers.  For example, a servlet might be responsible for taking data in an HTML  order-entry form and applying the business logic used to update a company's  order database. &lt;br&gt; 79.What are the classes and interfaces for servlets? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;There are two packages in servlets  and they are javax.servlet and javax.http.servlet . &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;80.What is the difference between  an applet and a servlet? &lt;/font&gt;&lt;/p&gt; &lt;ol type="a"&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;Servlets are to    servers what applets are to browsers. &lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;Applets must have    graphical user interfaces whereas servlets have no graphical user interfaces. &lt;br&gt;   &lt;/font&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;81.What is the difference between  doPost and doGet methods?&lt;/font&gt;&lt;/p&gt; &lt;ol type="a"&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;doGet() method is    used to get information, while doPost() method is used for posting information. &lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;doGet() requests    can't send large amount of information and is limited to 240-255 characters.    However, doPost()requests passes all of its data, of unlimited length. &lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;A doGet() request    is appended to the request URL in a query string and this allows the    exchange is visible to the client, whereas a doPost() request passes    directly over the socket connection as part of its HTTP request body    and the exchange are invisible to the client. &lt;br&gt;   &lt;/font&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;82.What is the life cycle of  a servlet? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Each Servlet has the same life  cycle: a) A server loads and initializes the servlet by init () method.  b) The servlet handles zero or more client's requests through service()  method. c) The server removes the servlet through destroy() method. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;83.Who is loading the init()  method of servlet? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Web server.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt; &lt;br&gt; 84.What are the different servers available for developing and deploying  Servlets? &lt;/font&gt;&lt;/p&gt; &lt;ol type="a"&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;Java Web Server    b) JRun c) Apache Server d) Netscape Information Server e) Web Logic.&lt;/font&gt;&lt;/li&gt;&lt;/ol&gt;  &lt;br&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;85.How many ways can we track  client and what are they? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;The servlet API provides two  ways to track client state and they are: a) Using Session tracking and  b) Using Cookies. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;86.What is session tracking  and how do you track a user session in servlets? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Session tracking is a mechanism  that servlets use to maintain state about a series requests from the  same user across some period of time. The methods used for session tracking  are: a) User Authentication - occurs when a web server restricts access  to some of its resources to only those clients that log in using a recognized  username and password. b) Hidden form fields - fields are added to an  HTML form that are not displayed in the client's browser. When the  form containing the fields is submitted, the fields are sent back to  the server. c) URL rewriting - every URL that the user clicks on is  dynamically modified or rewritten to include extra information. The  extra information can be in the form of extra path information, added  parameters or some custom, server-specific URL change. d) Cookies -  a bit of information that is sent by a web server to a browser and which  can later be read back from that browser. e) HttpSession- places a limit  on the number of sessions that can exist in memory. This limit is set  in the session. maxresidents property. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;87.What is Server-Side Includes  (SSI)? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Server-Side Includes allows  embedding servlets within HTML pages using a special servlet tag. In  many servlets that support servlets, a page can be processed by the  server to include output from servlets at certain points inside the  HTML page. This is accomplished using a special internal SSINCLUDE,  which processes the servlet tags. SSINCLUDE servlet will be invoked  whenever a file with an. shtml extension is requested. So HTML files  that include server-side includes must be stored with an . shtml extension. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;88.What are cookies and how  will you use them? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Cookies are a mechanism that  a servlet uses to have a client hold a small amount of state-information  associated with the user. a) Create a cookie with the Cookie constructor:  public Cookie(String name, String value) b) A servlet can send a cookie  to the client by passing a Cookie object to the addCookie() method of  HttpServletResponse : public void HttpServletResponse . addCookie(Cookie  cookie) c) A servlet retrieves cookies by calling the getCookies() method  of HttpServletRequest: public Cookie[ ] HttpServletRequest. getCookie(). &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;89.Is it possible to communicate  from an applet to servlet and how many ways and how? Yes, there are  three ways to communicate from an applet to servlet and they are: a)  HTTP Communication( Text-based and object-based) b) Socket Communication  c) RMI Communication. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;90.What is connection pooling? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;With servlets, opening a database  connection is a major bottleneck because we are creating and tearing  down a new connection for every page request and the time taken to create  connection will be more. Creating a connection pool is an ideal approach  for a complicated servlet. With a connection pool, we can duplicate  only the resources we need to duplicate rather than the entire servlet.  A connection pool can also intelligently manage the size of the pool  and make sure each connection remains valid. A number of connection  pool packages are currently available. Some like DbConnectionBroker  are freely available from Java Exchange Works by creating an object  that dispenses connections and connection Ids on request. The ConnectionPool  class maintains a Hastable, using Connection objects as keys and Boolean  values as stored values. The Boolean value indicates whether a connection  is in use or not. A program calls getConnection( ) method of the ConnectionPool  for getting Connection object it can use; it calls returnConnection(  ) to give the connection back to the pool.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt; &lt;br&gt; 91.Why should we go for interservlet communication?  &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Servlets running together in  the same server communicate with each other in several ways. The three  major reasons to use interservlet communication are: a) Direct servlet  manipulation - allows to gain access to the other currently loaded servlets  and perform certain tasks (through the ServletContext object) b) Servlet  reuse - allows the servlet to reuse the public methods of another servlet.  c) Servlet collaboration - requires to communicate with each other by  sharing specific information (through method invocation) &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;92.Is it possible to call servlet  with parameters in the URL? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Yes. You can call a servlet  with parameters in the syntax as (?Param1 = xxx || m2 = yyy). &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;93.What is Servlet chaining? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Servlet chaining is a technique  in which two or more servlets can cooperate in servicing a single request.  In servlet chaining, one servlet's output is piped to the next servlet's  input. This process continues until the last servlet is reached. Its  output is then sent back to the client. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;94.How do servlets handle multiple  simultaneous requests? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;The server has multiple threads  that are available to handle requests. When a request comes in, it is  assigned to a thread, which calls a service method (for example: doGet(),  doPost() and service()) of the servlet. For this reason, a single servlet  object can have its service methods called by many threads at once. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;                              &lt;font size="4" face="Times New Roman"&gt;&lt;b&gt;&lt;u&gt;RMI&lt;/u&gt;&lt;/b&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;95.What is the difference between  TCP/IP and UDP? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;TCP/IP is a two-way communication  between the client and the server and it is a reliable and there is  a confirmation regarding reaching the message to the destination. It  is like a phone call. UDP is a one-way communication only between the  client and the server and it is not a reliable and there is no confirmation  regarding reaching the message to the destination. It is like a postal  mail. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;96.What is Inet address? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Every computer connected to  a network has an IP address. An IP address is a number that uniquely  identifies each computer on the Net. An IP address is a 32-bit number. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;97.What is Domain Naming Service(DNS)  ? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;It is very difficult to remember  a set of numbers(IP address) to connect to the Internet. The Domain  Naming Service(DNS) is used to overcome this problem. It maps one particular  IP address to a string of characters. For example, www. mascom. com  implies com is the domain name reserved for US commercial sites, moscom  is the name of the company and www is the name of the specific computer,  which is mascom's server. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;98.What is URL? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;URL stands for Uniform Resource  Locator and it points to resource files on the Internet. URL has four  components: &lt;/font&gt;&lt;a href="http://www./" target="_blank"&gt;&lt;font color="#0000ff" size="3" face="Times New Roman"&gt;&lt;u&gt;http://www.&lt;/u&gt;&lt;/font&gt;&lt;/a&gt;&lt;font size="3" face="Times New Roman"&gt; address. com:80/index. html, where  http - protocol name, address - IP address or host name, 80 - port number  and index.html - file path. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;99.What is RMI and steps involved  in developing an RMI object? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Remote Method Invocation (RMI)  allows java object that executes on one machine and to invoke the method  of a Java object to execute on another machine. The steps involved in  developing an RMI object are: a) Define the interfaces b) Implementing  these interfaces c) Compile the interfaces and their implementations  with the java compiler d) Compile the server implementation with RMI  compiler e) Run the RMI registry f) Run the application. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;100.What is RMI architecture?  &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;RMI architecture consists of  four layers and each layer performs specific functions: a) Application  layer - contains the actual object definition. b) Proxy layer - consists  of stub and skeleton. c) Remote Reference layer - gets the stream of  bytes from the transport layer and sends it to the proxy layer. d) Transportation  layer - responsible for handling the actual machine-to-machine communication. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;101.what is UnicastRemoteObject  ? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;All remote objects must extend  UnicastRemoteObject , which provides functionality that is needed to  make objects available from remote machines. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;102.Explain the methods, rebind()  and lookup() in Naming class? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;rebind() of the Naming class(found  in java. rmi) is used to update the RMI registry on the server machine.  Naming. rebind("AddSever" , AddServerImpl) ; lookup() of the Naming  class accepts one argument, the rmi URL and returns a reference to an  object of type AddServerImpl. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;103.What is a Java Bean? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;A Java Bean is a software component  that has been designed to be reusable in a variety of different environments. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;104.What is a Jar file? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Jar file allows to efficiently  deploying a set of classes and their associated resources. The elements  in a jar file are compressed, which makes downloading a Jar file much  faster than separately downloading several uncompressed files. The package  java. util. zip contains classes that read and write jar files. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;105.What is BDK? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;BDK, Bean Development Kit is  a tool that enables to create, configure and connect a set of set of  Beans and it can be used to test Beans without writing a code. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;                              &lt;font size="5" face="Times New Roman"&gt;&lt;b&gt;&lt;u&gt;JSP&lt;/u&gt;&lt;/b&gt;&lt;/font&gt; &lt;br&gt; &lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;106.What is JSP? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;JSP is a dynamic scripting  capability for web pages that allows Java as well as a few special tags  to be embedded into a web file (HTML/XML, etc). The suffix traditionally  ends with .jsp to indicate to the web server that the file is a JSP  files. JSP is a server side technology - you can't do any client side  validation with it. The advantages are: a) The JSP assists in making  the HTML more functional. Servlets on the other hand allow outputting  of HTML but it is a tedious process. b) It is easy to make a change  and then let the JSP capability of the web server you are using deal  with compiling it into a servlet and running it. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;107.What are JSP scripting  elements? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;JSP scripting elements lets  to insert Java code into the servlet that will be generated from the  current JSP page. There are three forms: a) Expressions of the form  &amp;lt;%= expression %&amp;gt; that are evaluated and inserted into the output,  b) Scriptlets of the form&amp;lt;% code %&amp;gt;that are inserted into the  servlet's service method, and c) Declarations of the form &amp;lt;%! Code  %&amp;gt;that are inserted into the body of the servlet class, outside of  any existing methods. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;108.What are JSP Directives? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;A JSP directive affects the  overall structure of the servlet class. It usually has the following  form:&amp;lt;%@ directive attribute="value" %&amp;gt; However, you can also  combine multiple attribute settings for a single directive, as follows:&amp;lt;%@  directive attribute1="value1&amp;amp; #8243; attribute 2="value2&amp;amp;#8243;  . . . attributeN ="valueN" %&amp;gt; There are two main types of directive:  page, which lets to do things like import classes, customize the servlet  superclass, and the like; and include, which lets to insert a file into  the servlet class at the time the JSP file is translated into a servlet &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;109.What are Predefined variables  or implicit objects? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;To simplify code in JSP expressions  and scriptlets, we can use eight automatically defined variables, sometimes  called implicit objects. They are request, response, out, session, application,  config, pageContext, and page. &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;110.What are JSP ACTIONS? &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;JSP actions use constructs  in XML syntax to control the behavior of the servlet engine. You can  dynamically insert a file, reuse JavaBeans components, forward the user  to another page, or generate HTML for the Java plugin. Available actions  include: jsp:include - Include a file at the time the page is requested.  jsp:useBean - Find or instantiate a JavaBean. jsp:setProperty - Set  the property of a JavaBean. jsp:getProperty - Insert the property of  a JavaBean into the output. jsp:forward - Forward the requester to a  newpage. Jsp: plugin - Generate browser-specific code that makes an  OBJECT or EMBED &lt;br&gt; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;111.How do you pass data (including  JavaBeans) to a JSP from a servlet? &lt;/font&gt;&lt;/p&gt; &lt;ol&gt;&lt;ol type="1"&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;Request Lifetime:      Using this technique to pass beans, a request dispatcher (using either      "include" or forward") can be called. This bean will disappear      after processing this request has been completed. Servlet: request.      setAttribute(" theBean", myBean); RequestDispatcher rd = getServletContext(      ). getRequestDispatche r("thepage. jsp"); rd. forward(request, response);      JSP PAGE:&amp;lt;jsp: useBean id="theBean" scope="request" class=".      . . . . " /&amp;gt;&lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;Session Lifetime:      Using this technique to pass beans that are relevant to a particular      session (such as in individual user login) over a number of requests.      This bean will disappear when the session is invalidated or it times      out, or when you remove it. Servlet: HttpSession session = request.      getSession(true) ; session. putValue("theBean" , myBean); /* You      can do a request dispatcher here, or just let the bean be visible on      the next request */ JSP Page:&amp;lt;jsp:useBean id="theBean" scope="session"      class=". . . " /&amp;gt; &lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font size="3" face="Times New Roman"&gt;Application Lifetime:      Using this technique to pass beans that are relevant to all servlets      and JSP pages in a particular app, for all users. For example, I use      this to make a JDBC connection pool object available to the various      servlets and JSP pages in my apps. This bean will disappear when the      servlet engine is shut down, or when you remove it. Servlet: GetServletContext(      ). setAttribute(" theBean", myBean); JSP PAGE:&amp;lt;jsp:useBean id="theBean"      scope="application" class=". . . " /&amp;gt; &lt;br&gt;     &lt;/font&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/ol&gt; &lt;ul&gt;&lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;112.How can I set a cookie  in JSP? &lt;/font&gt;&lt;/p&gt;&lt;/ul&gt; &lt;ul&gt;&lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;response.setHeader("Set-  Cookie", "cookie string"); To give the response-object to a bean,  write a method setResponse (HttpServletRespons e response) - to the  bean, and in jsp-file:&amp;lt;% bean. setResponse (response); %&amp;gt;  &lt;br&gt; &lt;/font&gt;&lt;/p&gt;&lt;/ul&gt; &lt;ul&gt;&lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;113.How can I delete a  cookie with JSP? &lt;/font&gt;&lt;/p&gt;&lt;/ul&gt; &lt;ul&gt;&lt;p&gt;&lt;font size="3" face="Times New Roman"&gt;Say that I have a cookie  called "foo, " that I set a while ago &amp;amp; I want it to go away.  I simply: &amp;lt;% Cookie killCookie = new Cookie("foo", null); KillCookie.  setPath("/"); killCookie. setMaxAge(0) ; response. addCookie(killCooki  e); %&amp;gt; &lt;br&gt; How are Servlets and JSP Pages related?- JSP pages are focused around  HTML (or XML) with Java codes and JSP tags inside them. When a web server  that has JSP support is asked for a JSP page, it checks to see if it  has already compiled the page into a servlet. Thus, JSP pages become  servlets and are transformed into pure Java and then compiled, loaded  into the server and executed.&lt;/font&gt;&lt;/p&gt;&lt;/ul&gt;   &lt;/div&gt;  &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8955336342891215397-4518937705087319470?l=javaimpquestions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaimpquestions.blogspot.com/feeds/4518937705087319470/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8955336342891215397&amp;postID=4518937705087319470' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8955336342891215397/posts/default/4518937705087319470'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8955336342891215397/posts/default/4518937705087319470'/><link rel='alternate' type='text/html' href='http://javaimpquestions.blogspot.com/2009/06/115-imp-java-questions.html' title='115 imp java questions'/><author><name>Naresh Namana</name><uri>http://www.blogger.com/profile/05755392141578528676</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8955336342891215397.post-5436949603765786524</id><published>2008-10-14T07:56:00.001-07:00</published><updated>2011-03-18T22:54:49.001-07:00</updated><title type='text'>Uml</title><content type='html'>&lt;script type="text/javascript"&gt;&lt;br /&gt;var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");&lt;br /&gt;document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;br /&gt;try {&lt;br /&gt;var pageTracker = _gat._getTracker("UA-9255840-1");&lt;br /&gt;pageTracker._trackPageview();&lt;br /&gt;} catch(err) {}&lt;/script&gt;&lt;br /&gt;What is UML? &lt;br /&gt;&lt;br /&gt;Graphical language for visualizing, specifying, constructing and documenting the artifacts of the system. allows to create blueprints of all the aspects of the system, before physically implementing the system.&lt;br /&gt;&lt;br /&gt;What is modeling? What are the advantages of creating a model? &lt;br /&gt;&lt;br /&gt;Well-accepted engineering technique which helps build a model. Model is the simplification of reality; blueprint of the system that needs to be built. Model helps you visualize the system. helps to specify the structural and behaviour of the sytem. helps make templates for constructing the system. helps document the sytem.&lt;br /&gt;&lt;br /&gt;What are the different views considered when building an object-oriented software system? there aer 5 veiws:&lt;br /&gt;&lt;br /&gt;1. Use case view: exposes requirements of a system.&lt;br /&gt;2. Design view: capturing the vocabulary&lt;br /&gt;3. process view: modeling the distribution of the sytems processes and threads.&lt;br /&gt;4. implementation veiw: addressing the physical implementation of the system.&lt;br /&gt;5. deployement view: focus on the modeling of components required for deploying the system.&lt;br /&gt;&lt;br /&gt;What are the major three types of modeling used? &lt;br /&gt;&lt;br /&gt;They are 9: Use case diagram, class diagram, object diagram, sequence diagram, statechart diagram, collaboration diagram, activity diagram, component diagram, deployment diagram.&lt;br /&gt;&lt;br /&gt;SDLC: Software development life cycle. SDLC of a system includes processes that are Use case driven, architecture centric and iterative and incremental. Life cycle is divided into phases. Phase is a time span between two milestones. The milestones are Inception, Elaboration, construction, and transition. Process workflows that evolve through these phase are Business Modelling, Requirement gathering, Analysis and Design, Implementation, Testing, Deployment. Supporting workflows are configuration and change management, Project management.&lt;br /&gt;&lt;br /&gt;What are relationships?&lt;br /&gt;&lt;br /&gt;1. Dependencies: relationship between two entities such that a change in specification of one thing may affect the other. used to show that one class uses another class as an argument in the signature of the operation.&lt;br /&gt;2. Generalization: relationships specified in the class subclass scenario, it is shown when one entity inherits from other.&lt;br /&gt;3. Associations: structural relationships. ‘A room has walls’, ‘Person works for a company’.&lt;br /&gt;4. Aggregation: type of association where there is-a, has-a relationship.&lt;br /&gt;&lt;br /&gt;* Static Diagrams (Structural diagrams): Class diagram, Object diagram, component diagram, deployment diagram.&lt;br /&gt;* Dynamic diagram(Behavioral diagrams): Use case diagram, sequence diagram, collaboration diagram, activity diagram, statechart diagram.&lt;br /&gt;&lt;br /&gt;Messages: Specification of a communication, when a message is passed that results in action that is in turn an executable statement.&lt;br /&gt;&lt;br /&gt;Use Case: specifies the behavior of a system or a part of a system. Involves the interaction of actors and system.&lt;br /&gt;&lt;br /&gt;Aggregation: One class owns but shares a reference to objects of another class. Child refrerence exists even if parent oject rereference is set to null. Symbol: empty diamond arrow.&lt;br /&gt;&lt;br /&gt;Composition: one class contains objects of another class. child reference does not exists independently. Symbol: filled diamond arrow.&lt;br /&gt;&lt;br /&gt;Stereotype: Extension to existing UML vocabulary. It is used to create new model elements or derive from existing ones having specific properties pertaining to problem domain. EG: you can create steriotype, &lt;&gt; derived from existing one, &lt;&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8955336342891215397-5436949603765786524?l=javaimpquestions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaimpquestions.blogspot.com/feeds/5436949603765786524/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8955336342891215397&amp;postID=5436949603765786524' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8955336342891215397/posts/default/5436949603765786524'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8955336342891215397/posts/default/5436949603765786524'/><link rel='alternate' type='text/html' href='http://javaimpquestions.blogspot.com/2008/10/uml-imp-questions.html' title='Uml'/><author><name>Naresh Namana</name><uri>http://www.blogger.com/profile/05755392141578528676</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8955336342891215397.post-4966791643439829409</id><published>2008-10-14T07:50:00.000-07:00</published><updated>2011-03-18T22:54:49.003-07:00</updated><title type='text'>42 Ejb questions</title><content type='html'>&lt;script type="text/javascript"&gt;&lt;br /&gt;var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");&lt;br /&gt;document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;br /&gt;try {&lt;br /&gt;var pageTracker = _gat._getTracker("UA-9255840-1");&lt;br /&gt;pageTracker._trackPageview();&lt;br /&gt;} catch(err) {}&lt;/script&gt;&lt;br /&gt;1. What is EJB&lt;br /&gt;&lt;br /&gt;EJB stands for Enterprise JavaBean and is a widely-adopted server side component architecture for J2EE. It enables rapid development of mission-critical application that are versatile, reusable and portable across middleware while protecting IT investment and preventing vendor lock-in.&lt;br /&gt;&lt;br /&gt;2. What is session Facade?&lt;br /&gt;&lt;br /&gt;Session Facade is a design pattern to access the Entity bean through local interface than accessing directly. It increases the performance over the network. In this case we call session bean which on turn call entity bean.&lt;br /&gt;&lt;br /&gt;3. What is EJB role in J2EE?&lt;br /&gt;&lt;br /&gt;EJB technology is the core of J2EE. It enables developers to write reusable and portable server-side business logic for the J2EE platform.&lt;br /&gt;&lt;br /&gt;4. What is the difference between EJB and Java beans?&lt;br /&gt;&lt;br /&gt;EJB is a specification for J2EE server, not a product; Java beans may be a graphical component in IDE.&lt;br /&gt;&lt;br /&gt;5. What are the key features of the EJB technology?&lt;br /&gt;&lt;br /&gt;1. EJB components are server-side components written entirely in the Java programming language&lt;br /&gt;2. EJB components contain business logic only - no system-level programming &amp; services, such as transactions, security, life-cycle, threading, persistence, etc. are automatically managed for the EJB component by the EJB server.&lt;br /&gt;3. EJB architecture is inherently transactional, distributed, portable multi-tier, scalable and secure.&lt;br /&gt;4. EJB components are fully portable across any EJB server and any OS.&lt;br /&gt;5. EJB architecture is wire-protocol neutral–any protocol can be utilized like IIOP,JRMP, HTTP, DCOM,etc.&lt;br /&gt;&lt;br /&gt;6. What are the key benefits of the EJB technology?&lt;br /&gt;&lt;br /&gt;1. Rapid application development&lt;br /&gt;2. Broad industry adoption&lt;br /&gt;3. Application portability&lt;br /&gt;4. Protection of IT investment&lt;br /&gt;&lt;br /&gt;7. How many enterprise beans?&lt;br /&gt;&lt;br /&gt;There are three kinds of enterprise beans:&lt;br /&gt;1. session beans,&lt;br /&gt;2. entity beans, and&lt;br /&gt;3. message-driven beans.&lt;br /&gt;&lt;br /&gt;8. What is message-driven bean?&lt;br /&gt;&lt;br /&gt;A message-driven bean combines features of a session bean and a Java Message Service (JMS) message listener, allowing a business component to receive JMS. A message-driven bean enables asynchronous clients to access the business logic in the EJB tier.&lt;br /&gt;&lt;br /&gt;9. What is Entity Bean and Session Bean ?&lt;br /&gt;&lt;br /&gt;Entity Bean is a Java class which implements an Enterprise Bean interface and provides the implementation of the business methods. There are two types: Container Managed Persistence(CMP) and Bean-Managed Persistence(BMP).&lt;br /&gt;Session Bean is used to represent a workflow on behalf of a client. There are two types: Stateless and Stateful. Stateless bean is the simplest bean. It doesn’t maintain any conversational state with clients between method invocations. Stateful bean maintains state between invocations.&lt;br /&gt;&lt;br /&gt;10. How EJB Invocation happens?&lt;br /&gt;&lt;br /&gt;Retrieve Home Object reference from Naming Service via JNDI. Return Home Object reference to the client. Create me a new EJB Object through Home Object interface. Create EJB Object from the Ejb Object. Return EJB Object reference to the client. Invoke business method using EJB Object reference. Delegate request to Bean (Enterprise Bean).&lt;br /&gt;&lt;br /&gt;11. Is it possible to share an HttpSession between a JSP and EJB? What happens when I change a value in the HttpSession from inside an EJB?&lt;br /&gt;&lt;br /&gt;You can pass the HttpSession as parameter to an EJB method, only if all objects in session are serializable.This has to be consider as passed-by-value, that means that it’s read-only in the EJB. If anything is altered from inside the EJB, it won’t be reflected back to the HttpSession of the Servlet Container.The pass-by-reference can be used between EJBs Remote Interfaces, as they are remote references. While it is possible to pass an HttpSession as a parameter to an EJB object, it is considered to be bad practice in terms of object-oriented design. This is because you are creating an unnecessary coupling between back-end objects (EJBs) and front-end objects (HttpSession). Create a higher-level of abstraction for your EJBs API. Rather than passing the whole, fat, HttpSession (which carries with it a bunch of http semantics), create a class that acts as a value object (or structure) that holds all the data you need to pass back and forth between front-end/back-end. Consider the case where your EJB needs to support a non HTTP-based client. This higher level of abstraction will be flexible enough to support it.&lt;br /&gt;&lt;br /&gt;12. The EJB container implements the EJBHome and EJBObject classes. For every request from a unique client, does the container create a separate instance of the generated EJBHome and EJBObject classes?&lt;br /&gt;&lt;br /&gt;The EJB container maintains an instance pool. The container uses these instances for the EJB Home reference irrespective of the client request. while refering the EJB Object classes the container creates a separate instance for each client request. The instance pool maintenance is up to the implementation of the container. If the container provides one, it is available otherwise it is not mandatory for the provider to implement it. Having said that, yes most of the container providers implement the pooling functionality to increase the performance of the application server. The way it is implemented is, again, up to the implementer.&lt;br /&gt;&lt;br /&gt;13. Can the primary key in the entity bean be a Java primitive type such as int?&lt;br /&gt;&lt;br /&gt;The primary key can’t be a primitive type. Use the primitive wrapper classes, instead. For example, you can use java.lang.Integer as the primary key class, but not int (it has to be a class, not a primitive).&lt;br /&gt;&lt;br /&gt;14. Can you control when passivation occurs?&lt;br /&gt;&lt;br /&gt;The developer, according to the specification, cannot directly control when passivation occurs. Although for Stateful Session Beans, the container cannot passivate an instance that is inside a transaction. So using transactions can be a a strategy to control passivation. The ejbPassivate() method is called during passivation, so the developer has control over what to do during this exercise and can implement the require optimized logic. Some EJB containers, such as BEA WebLogic, provide the ability to tune the container to minimize passivation calls. Taken from the WebLogic 6.0 DTD -The passivation-strategy can be either default or transaction. With the default setting the container will attempt to keep a working set of beans in the cache. With the transaction setting, the container will passivate the bean after every transaction (or method call for a non-transactional invocation).&lt;br /&gt;&lt;br /&gt;15. What is the advantage of using Entity bean for database operations, over directly using JDBC API to do database operations? When would I use one over the other?&lt;br /&gt;&lt;br /&gt;Entity Beans actually represents the data in a database. It is not that Entity Beans replaces JDBC API. There are two types of Entity Beans Container Managed and Bean Mananged. In Container Managed Entity Bean - Whenever the instance of the bean is created the container automatically retrieves the data from the DB/Persistance storage and assigns to the object variables in bean for user to manipulate or use them. For this the developer needs to map the fields in the database to the variables in deployment descriptor files (which varies for each vendor). In the Bean Managed Entity Bean - The developer has to specifically make connection, retrive values, assign them to the objects in the ejbLoad() which will be called by the container when it instatiates a bean object. Similarly in the ejbStore() the container saves the object values back the the persistance storage. ejbLoad and ejbStore are callback methods and can be only invoked by the container. Apart from this, when you use Entity beans you dont need to worry about database transaction handling, database connection pooling etc. which are taken care by the ejb container.&lt;br /&gt;&lt;br /&gt;16. What is EJB QL?&lt;br /&gt;&lt;br /&gt;EJB QL is a Query Language provided for navigation across a network of enterprise beans and dependent objects defined by means of container managed persistence. EJB QL is introduced in the EJB 2.0 specification. The EJB QL query language defines finder methods for entity beans with container managed persistenceand is portable across containers and persistence managers. EJB QL is used for queries of two types of finder methods: Finder methods that are defined in the home interface of an entity bean and which return entity objects. Select methods, which are not exposed to the client, but which are used by the Bean Provider to select persistent values that are maintained by the Persistence Manager or to select entity objects that are related to the entity bean on which the query is defined.&lt;br /&gt;&lt;br /&gt;17. Brief description about local interfaces?&lt;br /&gt;&lt;br /&gt;EEJB was originally designed around remote invocation using the Java Remote Method Invocation (RMI) mechanism, and later extended to support to standard CORBA transport for these calls using RMI/IIOP. This design allowed for maximum flexibility in developing applications without consideration for the deployment scenario, and was a strong feature in support of a goal of component reuse in J2EE. Many developers are using EJBs locally, that is, some or all of their EJB calls are between beans in a single container. With this feedback in mind, the EJB 2.0 expert group has created a local interface mechanism. The local interface may be defined for a bean during development, to allow streamlined calls to the bean if a caller is in the same container. This does not involve the overhead involved with RMI like marshalling etc. This facility will thus improve the performance of applications in which co-location is planned. Local interfaces also provide the foundation for container-managed relationships among entity beans with container-managed persistence.&lt;br /&gt;&lt;br /&gt;18. What are the special design care that must be taken when you work with local interfaces?&lt;br /&gt;&lt;br /&gt;It is important to understand that the calling semantics of local interfaces are different from those of remote interfaces. For example, remote interfaces pass parameters using call-by-value semantics, while local interfaces use call-by-reference. This means that in order to use local interfaces safely, application developers need to carefully consider potential deployment scenarios up front, then decide which interfaces can be local and which remote, and finally, develop the application code with these choices in mind. While EJB 2.0 local interfaces are extremely useful in some situations, the long-term costs of these choices, especially when changing requirements and component reuse are taken into account, need to be factored into the design decision.&lt;br /&gt;&lt;br /&gt;19. What happens if remove( ) is never invoked on a session bean?&lt;br /&gt;&lt;br /&gt;In case of a stateless session bean it may not matter if we call or not as in both cases nothing is done. The number of beans in cache is managed by the container. In case of stateful session bean, the bean may be kept in cache till either the session times out, in which case the bean is removed or when there is a requirement for memory in which case the data is cached and the bean is sent to free pool.&lt;br /&gt;&lt;br /&gt;20. What is the difference between Message Driven Beans and Stateless Session beans?&lt;br /&gt;&lt;br /&gt;In several ways, the dynamic creation and allocation of message-driven bean instances mimics the behavior of stateless session EJB instances, which exist only for the duration of a particular method call. However, message-driven beans are different from stateless session EJBs (and other types of EJBs) in several significant ways: Message-driven beans process multiple JMS messages asynchronously, rather than processing a serialized sequence of method calls. Message-driven beans have no home or remote interface, and therefore cannot be directly accessed by internal or external clients. Clients interact with message-driven beans only indirectly, by sending a message to a JMS Queue or Topic. Only the container directly interacts with a message-driven bean by creating bean instances and passing JMS messages to those instances as necessary. The Container maintains the entire lifecycle of a message-driven bean; instances cannot be created or removed as a result of client requests or other API calls.&lt;br /&gt;&lt;br /&gt;22. How can I call one EJB from inside of another EJB?&lt;br /&gt;&lt;br /&gt;EJBs can be clients of other EJBs. It just works. Use JNDI to locate the Home Interface of the other bean, then acquire an instance reference, and so forth.&lt;br /&gt;&lt;br /&gt;23. What is an EJB Context?&lt;br /&gt;&lt;br /&gt;EJBContext is an interface that is implemented by the container, and it is also a part of the bean-container contract. Entity beans use a subclass of EJBContext called EntityContext. Session beans use a subclass called SessionContext. These EJBContext objects provide the bean class with information about its container, the client using the bean and the bean itself. They also provide other functions. See the API docs and the spec for more details.&lt;br /&gt;&lt;br /&gt;24. Is is possible for an EJB client to marshal an object of class java.lang.Class to an EJB?&lt;br /&gt;&lt;br /&gt;Technically yes, spec. compliant NO! - The enterprise bean must not attempt to query a class to obtain information about the declared members that are not otherwise accessible to the enterprise bean because of the security rules of the Java language&lt;br /&gt;&lt;br /&gt;25. Is it legal to have static initializer blocks in EJB?&lt;br /&gt;&lt;br /&gt;Although technically it is legal, static initializer blocks are used to execute some piece of code before executing any constructor or method while instantiating a class. Static initializer blocks are also typically used to initialize static fields - which may be illegal in EJB if they are read/write - In EJB this can be achieved by including the code in either the ejbCreate(), setSessionContext() or setEntityContext() methods.&lt;br /&gt;&lt;br /&gt;26. Is it possible to stop the execution of a method before completion in a SessionBean?&lt;br /&gt;&lt;br /&gt;Stopping the execution of a method inside a Session Bean is not possible without writing code inside the Session Bean. This is because you are not allowed to access Threads inside an EJB.&lt;br /&gt;&lt;br /&gt;27. What is the default transaction attribute for an EJB?&lt;br /&gt;&lt;br /&gt;There is no default transaction attribute for an EJB. Section 11.5 of EJB v1.1 spec says that the deployer must specify a value for the transaction attribute for those methods having container managed transaction. In WebLogic, the default transaction attribute for EJB is SUPPORTS.&lt;br /&gt;&lt;br /&gt;28. What is the difference between session and entity beans? When should I use one or the other?&lt;br /&gt;&lt;br /&gt;An entity bean represents persistent global data from the database; a session bean represents transient user-specific data that will die when the user disconnects (ends his session). Generally, the session beans implement business methods (e.g. Bank.transferFunds) that call entity beans (e.g. Account.deposit, Account.withdraw)&lt;br /&gt;&lt;br /&gt;29. Is there any default cache management system with Entity beans ?&lt;br /&gt;&lt;br /&gt;In other words whether a cache of the data in database will be maintained in EJB ? - Caching data from a database inside the AAApplication Server are what Entity EJB’s are used for.The ejbLoad() and ejbStore() methods are used to synchronize the Entity Bean state with the persistent storage(database). Transactions also play an important role in this scenario. If data is removed from the database, via an external application - your Entity Bean can still be alive the EJB container. When the transaction commits, ejbStore() is called and the row will not be found, and the transaction rolled back.&lt;br /&gt;&lt;br /&gt;30. Why is ejbFindByPrimaryKey mandatory?&lt;br /&gt;&lt;br /&gt;An Entity Bean represents persistent data that is stored outside of the EJB Container/Server. The ejbFindByPrimaryKey is a method used to locate and load an Entity Bean into the container, similar to a SELECT statement in SQL. By making this method mandatory, the client programmer can be assured that if they have the primary key of the Entity Bean, then they can retrieve the bean without having to create a new bean each time - which would mean creating duplications of persistent data and break the integrity of EJB.&lt;br /&gt;&lt;br /&gt;31. Why do we have a remove method in both EJBHome and EJBObject?&lt;br /&gt;&lt;br /&gt;With the EJBHome version of the remove, you are able to delete an entity bean without first instantiating it (you can provide a PrimaryKey object as a parameter to the remove method). The home version only works for entity beans. On the other hand, the Remote interface version works on an entity bean that you have already instantiated. In addition, the remote version also works on session beans (stateless and stateful) to inform the container of your loss of interest in this bean.&lt;br /&gt;&lt;br /&gt;32. How can I call one EJB from inside of another EJB?&lt;br /&gt;&lt;br /&gt;EJBs can be clients of other EJBs. It just works. Use JNDI to locate the Home Interface of the other bean, then acquire an instance reference, and so forth.&lt;br /&gt;&lt;br /&gt;33. What is the difference between a Server, a Container, and a Connector?&lt;br /&gt;&lt;br /&gt;An EJB server is an application, usually a product such as BEA WebLogic, that provides (or should provide) for concurrent client connections and manages system resources such as threads, processes, memory, database connections, network connections, etc. An EJB container runs inside (or within) an EJB server, and provides deployed EJB beans with transaction and security management, etc. The EJB container insulates an EJB bean from the specifics of an underlying EJB server by providing a simple, standard API between the EJB bean and its container. A Connector provides the ability for any Enterprise Information System (EIS) to plug into any EJB server which supports the Connector architecture. See Sun’s J2EE Connectors for more in-depth information on Connectors.&lt;br /&gt;&lt;br /&gt;34. How is persistence implemented in enterprise beans?&lt;br /&gt;&lt;br /&gt;Persistence in EJB is taken care of in two ways, depending on how you implement your beans: container managed persistence (CMP) or bean managed persistence (BMP) For CMP, the EJB container which your beans run under takes care of the persistence of the fields you have declared to be persisted with the database - this declaration is in the deployment descriptor. So, anytime you modify a field in a CMP bean, as soon as the method you have executed is finished, the new data is persisted to the database by the container. For BMP, the EJB bean developer is responsible for defining the persistence routines in the proper places in the bean, for instance, the ejbCreate(), ejbStore(), ejbRemove() methods would be developed by the bean developer to make calls to the database. The container is responsible, in BMP, to call the appropriate method on the bean. So, if the bean is being looked up, when the create() method is called on the Home interface, then the container is responsible for calling the ejbCreate() method in the bean, which should have functionality inside for going to the database and looking up the data.&lt;br /&gt;&lt;br /&gt;35. What is an EJB Context?&lt;br /&gt;&lt;br /&gt;EJBContext is an interface that is implemented by the container, and it is also a part of the bean-container contract. Entity beans use a subclass of EJBContext called EntityContext. Session beans use a subclass called SessionContext. These EJBContext objects provide the bean class with information about its container, the client using the bean and the bean itself. They also provide other functions. See the API docs and the spec for more details.&lt;br /&gt;&lt;br /&gt;36. Is method overloading allowed in EJB?&lt;br /&gt;&lt;br /&gt;Yes you can overload methods Should synchronization primitives be used on bean methods? - No. The EJB specification specifically states that the enterprise bean is not allowed to use thread primitives. The container is responsible for managing concurrent access to beans at runtime.&lt;br /&gt;&lt;br /&gt;37. Are we allowed to change the transaction isolation property in middle of a transaction?&lt;br /&gt;&lt;br /&gt;No. You cannot change the transaction isolation level in the middle of transaction.&lt;br /&gt;&lt;br /&gt;38. For Entity Beans, What happens to an instance field not mapped to any persistent storage, when the bean is passivated?&lt;br /&gt;&lt;br /&gt;The specification infers that the container never serializes an instance of an Entity bean (unlike stateful session beans). Thus passivation simply involves moving the bean from the ready to the pooled bin. So what happens to the contents of an instance variable is controlled by the programmer. Remember that when an entity bean is passivated the instance gets logically disassociated from it’s remote object. Be careful here, as the functionality of passivation/activation for Stateless Session, Stateful Session and Entity beans is completely different. For entity beans the ejbPassivate method notifies the entity bean that it is being disassociated with a particular entity prior to reuse or for dereference.&lt;br /&gt;&lt;br /&gt;39. What is a Message Driven Bean, what functions does a message driven bean have and how do they work in collaboration with JMS?&lt;br /&gt;&lt;br /&gt;Message driven beans are the latest addition to the family of component bean types defined by the EJB specification. The original bean types include session beans, which contain business logic and maintain a state associated with client sessions, and entity beans, which map objects to persistent data. Message driven beans will provide asynchrony to EJB based applications by acting as JMS message consumers. A message bean is associated with a JMS topic or queue and receives JMS messages sent by EJB clients or other beans. Unlike entity beans and session beans, message beans do not have home or remote interfaces. Instead, message driven beans are instantiated by the container as required. Like stateless session beans, message beans maintain no client-specific state, allowing the container to optimally manage a pool of message-bean instances. Clients send JMS messages to message beans in exactly the same manner as they would send messages to any other JMS destination. This similarity is a fundamental design goal of the JMS capabilities of the new specification. To receive JMS messages, message driven beans implement the javax.jms.MessageListener interface, which defines a single onMessage() method. When a message arrives, the container ensures that a message bean corresponding to the message topic/queue exists (instantiating it if necessary), and calls its onMessage method passing the client’s message as the single argument. The message bean’s implementation of this method contains the business logic required to process the message. Note that session beans and entity beans are not allowed to function as message beans.&lt;br /&gt;&lt;br /&gt;40. Does RMI-IIOP support code downloading for Java objects sent by value across an IIOP connection in the same way as RMI does across a JRMP connection?&lt;br /&gt;&lt;br /&gt;Yes. The JDK 1.2 support the dynamic class loading. The EJB container implements the EJBHome and EJBObject classes. For every request from a unique client,&lt;br /&gt;&lt;br /&gt;41. Does the container create a separate instance of the generated EJBHome and EJBObject classes?&lt;br /&gt;&lt;br /&gt;The EJB container maintains an instance pool. The container uses these instances for the EJB Home reference irrespective of the client request. while refering the EJB Object classes the container creates a separate instance for each client request. The instance pool maintainence is up to the implementation of the container. If the container provides one, it is available otherwise it is not mandatory for the provider to implement it. Having said that, yes most of the container providers implement the pooling functionality to increase the performance of the application server. The way it is implemented is again up to the implementer.&lt;br /&gt;&lt;br /&gt;42. What is the advantage of putting an Entity Bean instance from the Ready State to Pooled state&lt;br /&gt;&lt;br /&gt;The idea of the Pooled State is to allow a container to maintain a pool of entity beans that has been created, but has not been yet synchronized or assigned to an EJBObject. This mean that the instances do represent entity beans, but they can be used only for serving Home methods (create or findBy), since those methods do not relay on the specific values of the bean. All these instances are, in fact, exactly the same, so, they do not have meaningful state. Jon Thorarinsson has also added: It can be looked at it this way: If no client is using an entity bean of a particular type there is no need for cachig it (the data is persisted in the database). Therefore, in such cases, the container will, after some time, move the entity bean from the Ready State to the Pooled state to save memory. Then, to save additional memory, the container may begin moving entity beans from the Pooled State to the Does Not Exist State, because even though the bean’s cache has been cleared, the bean still takes up some memory just being in the Pooled State.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8955336342891215397-4966791643439829409?l=javaimpquestions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaimpquestions.blogspot.com/feeds/4966791643439829409/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8955336342891215397&amp;postID=4966791643439829409' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8955336342891215397/posts/default/4966791643439829409'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8955336342891215397/posts/default/4966791643439829409'/><link rel='alternate' type='text/html' href='http://javaimpquestions.blogspot.com/2008/10/42-ejb-questions.html' title='42 Ejb questions'/><author><name>Naresh Namana</name><uri>http://www.blogger.com/profile/05755392141578528676</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8955336342891215397.post-8800664453081894547</id><published>2008-08-20T21:07:00.001-07:00</published><updated>2011-03-18T22:54:49.022-07:00</updated><title type='text'>200 core java questions</title><content type='html'>&lt;script type="text/javascript"&gt;&lt;br /&gt;var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");&lt;br /&gt;document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;br /&gt;try {&lt;br /&gt;var pageTracker = _gat._getTracker("UA-9255840-1");&lt;br /&gt;pageTracker._trackPageview();&lt;br /&gt;} catch(err) {}&lt;/script&gt;&lt;br /&gt;1.what  is a transient variable?&lt;br /&gt;&lt;br /&gt;A transient variable is a variable that may not be serialized.&lt;br /&gt;&lt;br /&gt;2.which containers use a border Layout as their default layout?&lt;br /&gt;&lt;br /&gt;The window, Frame and Dialog classes use a border layout as their default layout.&lt;br /&gt;&lt;br /&gt;3.Why do threads block on I/O?&lt;br /&gt;&lt;br /&gt;Threads block on i/o (that is enters the waiting state) so that other threads may execute while the i/o Operation is performed.&lt;br /&gt;&lt;br /&gt;4. How are Observer and Observable used?&lt;br /&gt;&lt;br /&gt;Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects.&lt;br /&gt;&lt;br /&gt;5. What is synchronization and why is it important?&lt;br /&gt;&lt;br /&gt;With respect to multithreading, synchronization is the capability to control the access of multiple 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.&lt;br /&gt;&lt;br /&gt;6. Can a lock be acquired on a class?&lt;br /&gt;&lt;br /&gt;Yes, a lock can be acquired on a class. This lock is acquired on the class's Class object.&lt;br /&gt;&lt;br /&gt;7. What's new with the stop(), suspend() and resume() methods in JDK 1.2?&lt;br /&gt;&lt;br /&gt;The stop(), suspend() and resume() methods have been deprecated in JDK 1.2.&lt;br /&gt;&lt;br /&gt;8. Is null a keyword?&lt;br /&gt;&lt;br /&gt;The null value is not a keyword.&lt;br /&gt;&lt;br /&gt;9. What is the preferred size of a component?&lt;br /&gt;&lt;br /&gt;The preferred size of a component is the minimum component size that will allow the component to display normally.&lt;br /&gt;&lt;br /&gt;10. What method is used to specify a container's layout?&lt;br /&gt;&lt;br /&gt;The setLayout() method is used to specify a container's layout.&lt;br /&gt;&lt;br /&gt;11. Which containers use a FlowLayout as their default layout?&lt;br /&gt;&lt;br /&gt;The Panel and Applet classes use the FlowLayout as their default layout.&lt;br /&gt;&lt;br /&gt;12. What state does a thread enter when it terminates its processing?&lt;br /&gt;&lt;br /&gt;When a thread terminates its processing, it enters the dead state.&lt;br /&gt;&lt;br /&gt;13. What is the Collections API?&lt;br /&gt;&lt;br /&gt;The Collections API is a set of classes and interfaces that support operations on collections of objects.&lt;br /&gt;&lt;br /&gt;14. Which characters may be used as the second character of an identifier, but not as the first character of an identifier?&lt;br /&gt;&lt;br /&gt;The digits 0 through 9 may not be used as the first character of an identifier but they may be used after the first character of an identifier.&lt;br /&gt;&lt;br /&gt;15. What is the List interface?&lt;br /&gt;&lt;br /&gt;The List interface provides support for ordered collections of objects.&lt;br /&gt;&lt;br /&gt;16. How does Java handle integer overflows and underflows?&lt;br /&gt;&lt;br /&gt;It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.&lt;br /&gt;&lt;br /&gt;17. What is the Vector class?&lt;br /&gt;&lt;br /&gt;The Vector class provides the capability to implement a growable array of objects&lt;br /&gt;&lt;br /&gt;18. What modifiers may be used with an inner class that is a member of an outer class?&lt;br /&gt;&lt;br /&gt;A (non-local) inner class may be declared as public, protected, private, static, final, or abstract.&lt;br /&gt;&lt;br /&gt;19. What is an Iterator interface?&lt;br /&gt;&lt;br /&gt;The Iterator interface is used to step through the elements of a Collection.&lt;br /&gt;&lt;br /&gt;20. What is the difference between the &gt;&gt; and &gt;&gt;&gt; operators?&lt;br /&gt;&lt;br /&gt;The &gt;&gt; operator carries the sign bit when shifting right. The &gt;&gt;&gt; zero-fills bits that have been shifted out.&lt;br /&gt;&lt;br /&gt;21. Which method of the Component class is used to set the position and size of a component?&lt;br /&gt;&lt;br /&gt;setBounds()&lt;br /&gt;&lt;br /&gt;22. How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters?&lt;br /&gt;&lt;br /&gt;Unicode requires 16 bits and ASCII require 7 bits. Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits. UTF-8 represents characters using 8, 16, and 18 bit patterns. UTF-16 uses 16-bit and larger bit patterns.&lt;br /&gt;&lt;br /&gt;23What is the difference between yielding and sleeping?&lt;br /&gt;&lt;br /&gt;When a task invokes its yield() method, it returns to the ready state. When a task invokes its sleep() method, it returns to the waiting state.&lt;br /&gt;&lt;br /&gt;24. Which java.util classes and interfaces support event handling?&lt;br /&gt;&lt;br /&gt;The EventObject class and the EventListener interface support event processing.&lt;br /&gt;&lt;br /&gt;25. Is sizeof a keyword?&lt;br /&gt;&lt;br /&gt;The sizeof operator is not a keyword.&lt;br /&gt;&lt;br /&gt;26. What are wrapped classes?&lt;br /&gt;&lt;br /&gt;Wrapped classes are classes that allow primitive types to be accessed as objects.&lt;br /&gt;&lt;br /&gt;27. Does garbage collection guarantee that a program will not run out of memory?&lt;br /&gt;&lt;br /&gt;Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection&lt;br /&gt;&lt;br /&gt;28. What restrictions are placed on the location of a package statement within a source code file?&lt;br /&gt;&lt;br /&gt;A package statement must appear as the first line in a source code file (excluding blank lines and comments).&lt;br /&gt;&lt;br /&gt;29. Can an object's finalize() method be invoked while it is reachable?&lt;br /&gt;&lt;br /&gt;An object's finalize() method cannot be invoked by the garbage collector while the object is still reachable. However, an object's finalize() method may be invoked by other objects.&lt;br /&gt;&lt;br /&gt;30. What is the immediate superclass of the Applet class?&lt;br /&gt;&lt;br /&gt;Panel&lt;br /&gt;&lt;br /&gt;31. What is the difference between preemptive scheduling and time slicing?&lt;br /&gt;&lt;br /&gt;Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors.&lt;br /&gt;&lt;br /&gt;32. Name three Component subclasses that support painting.&lt;br /&gt;&lt;br /&gt;The Canvas, Frame, Panel, and Applet classes support painting.&lt;br /&gt;&lt;br /&gt;33. What value does readLine() return when it has reached the end of a file?&lt;br /&gt;&lt;br /&gt;The readLine() method returns null when it has reached the end of a file.&lt;br /&gt;&lt;br /&gt;34. What is the immediate superclass of the Dialog class?&lt;br /&gt;&lt;br /&gt;Window&lt;br /&gt;&lt;br /&gt;35. What is clipping?&lt;br /&gt;&lt;br /&gt;Clipping is the process of confining paint operations to a limited area or shape.&lt;br /&gt;&lt;br /&gt;36. What is a native method?&lt;br /&gt;&lt;br /&gt;A native method is a method that is implemented in a language other than Java.&lt;br /&gt;&lt;br /&gt;37. Can a for statement loop indefinitely?&lt;br /&gt;&lt;br /&gt;Yes, a for statement can loop indefinitely. For example, consider the following: for(;;) ;&lt;br /&gt;&lt;br /&gt;38. What are order of precedence and associativity, and how are they used?&lt;br /&gt;&lt;br /&gt;Order of precedence determines the order in which operators are evaluated in expressions. Associatity determines whether an expression is evaluated left-to-right or right-to-left&lt;br /&gt;&lt;br /&gt;39. When a thread blocks on I/O, what state does it enter?&lt;br /&gt;&lt;br /&gt;A thread enters the waiting state when it blocks on I/O.&lt;br /&gt;&lt;br /&gt;40. To what value is a variable of the String type automatically initialized?&lt;br /&gt;&lt;br /&gt;The default value of an String type is null.&lt;br /&gt;&lt;br /&gt;41. What is the catch or declare rule for method declarations?&lt;br /&gt;&lt;br /&gt;If a checked exception may be thrown within the body of a method, the method must either catch the exception or declare it in its throws clause.&lt;br /&gt;&lt;br /&gt;42. What is the difference between a MenuItem and a CheckboxMenuItem?&lt;br /&gt;&lt;br /&gt;The CheckboxMenuItem class extends the MenuItem class to support a menu item that may be checked or unchecked.&lt;br /&gt;&lt;br /&gt;43. What is a task's priority and how is it used in scheduling?&lt;br /&gt;&lt;br /&gt;A task's priority is an integer value that identifies the relative order in which it should be executed with respect to other tasks. The scheduler attempts to schedule higher priority tasks before lower priority tasks.&lt;br /&gt;&lt;br /&gt;44. What class is the top of the AWT event hierarchy?&lt;br /&gt;&lt;br /&gt;The java.awt.AWTEvent class is the highest-level class in the AWT event-class hierarchy.&lt;br /&gt;&lt;br /&gt;45. When a thread is created and started, what is its initial state?&lt;br /&gt;&lt;br /&gt;A thread is in the ready state after it has been created and started.&lt;br /&gt;&lt;br /&gt;46. Can an anonymous class be declared as implementing an interface and extending a class?&lt;br /&gt;&lt;br /&gt;An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.&lt;br /&gt;&lt;br /&gt;47. What is the range of the short type?&lt;br /&gt;&lt;br /&gt;The range of the short type is -(2^15) to 2^15 - 1.&lt;br /&gt;&lt;br /&gt;48. What is the range of the char type?&lt;br /&gt;&lt;br /&gt;The range of the char type is 0 to 2^16 - 1. &lt;br /&gt;&lt;br /&gt;49. In which package are most of the AWT events that support the event-delegation model defined?&lt;br /&gt;&lt;br /&gt;Most of the AWT-related events of the event-delegation model are defined in the java.awt.event package. The AWTEvent class is defined in the java.awt package.&lt;br /&gt;&lt;br /&gt;50. What is the immediate superclass of Menu?&lt;br /&gt;&lt;br /&gt;MenuItem&lt;br /&gt;&lt;br /&gt;51. What is the purpose of finalization?&lt;br /&gt;&lt;br /&gt;The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.&lt;br /&gt;&lt;br /&gt;52. Which class is the immediate superclass of the MenuComponent class.&lt;br /&gt;&lt;br /&gt;Object&lt;br /&gt;&lt;br /&gt;53. What invokes a thread's run() method?&lt;br /&gt;&lt;br /&gt;After a thread is started, via its start() method or that of the Thread class, the JVM invokes the thread's run() method when the thread is initially executed.&lt;br /&gt;&lt;br /&gt;54. What is the difference between the Boolean &amp;amp; operator and the &amp;amp;&amp;amp; operator?&lt;br /&gt;&lt;br /&gt;If an expression involving the Boolean &amp;amp; operator is evaluated, both operands are evaluated. Then the &amp;amp; operator is applied to the operand. When an expression involving the &amp;amp;&amp;amp; operator is evaluated, the first operand is evaluated. If the first operand returns a value of true then the second operand is evaluated. The &amp;amp;&amp;amp; operator is then applied to the first and second operands. If the first operand evaluates to false, the evaluation of the second operand is skipped.&lt;br /&gt;&lt;br /&gt;55. Name three subclasses of the Component class.&lt;br /&gt;&lt;br /&gt;Box.Filler, Button, Canvas, Checkbox, Choice, Container, Label, List, Scrollbar, or TextComponent&lt;br /&gt;&lt;br /&gt;56. What is the GregorianCalendar class?&lt;br /&gt;&lt;br /&gt;The GregorianCalendar provides support for traditional Western calendars.&lt;br /&gt;&lt;br /&gt;57. Which Container method is used to cause a container to be laid out and redisplayed?&lt;br /&gt;&lt;br /&gt;validate()&lt;br /&gt;&lt;br /&gt;58. What is the purpose of the Runtime class?&lt;br /&gt;&lt;br /&gt;The purpose of the Runtime class is to provide access to the Java runtime system.&lt;br /&gt;&lt;br /&gt;59. How many times may an object's finalize() method be invoked by the garbage collector?&lt;br /&gt;&lt;br /&gt;An object's finalize() method may only be invoked once by the garbage collector.&lt;br /&gt;&lt;br /&gt;60. What is the purpose of the finally clause of a try-catch-finally statement?&lt;br /&gt;&lt;br /&gt;The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught.&lt;br /&gt;&lt;br /&gt;61. What is the argument type of a program's main() method?&lt;br /&gt;&lt;br /&gt;A program's main() method takes an argument of the String[] type.&lt;br /&gt;&lt;br /&gt;62. Which Java operator is right associative?&lt;br /&gt;&lt;br /&gt;The = operator is right associative.&lt;br /&gt;&lt;br /&gt;63. What is the Locale class?&lt;br /&gt;&lt;br /&gt;The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region. &lt;br /&gt;&lt;br /&gt;64. Can a double value be cast to a byte?&lt;br /&gt;&lt;br /&gt;Yes, a double value can be cast to a byte.&lt;br /&gt;&lt;br /&gt;65. What is the difference between a break statement and a continue statement?&lt;br /&gt;&lt;br /&gt;A break statement results in the termination of the statement to which it applies (switch, for, do, or while). A continue statement is used to end the current loop iteration and return control to the loop statement.&lt;br /&gt;&lt;br /&gt;66. What must a class do to implement an interface?&lt;br /&gt;&lt;br /&gt;It must provide all of the methods in the interface and identify the interface in its implements clause.&lt;br /&gt;&lt;br /&gt;67. What method is invoked to cause an object to begin executing as a separate thread?&lt;br /&gt;&lt;br /&gt;The start() method of the Thread class is invoked to cause an object to begin executing as a separate thread.&lt;br /&gt;&lt;br /&gt;68. Name two subclasses of the TextComponent class.&lt;br /&gt;&lt;br /&gt;TextField and TextArea&lt;br /&gt;&lt;br /&gt;69. What is the advantage of the event-delegation model over the earlier event-inheritance model?&lt;br /&gt;&lt;br /&gt;The event-delegation model has two advantages over the event-inheritance model. First, it enables event handling to be handled by objects other than the ones that generate the events (or their containers). This allows a clean separation between a component's design and its use. The other advantage of the event-delegation model is that it performs much better in applications where many events are generated. This performance improvement is due to the fact that the event-delegation model does not have to repeatedly process unhandled events, as is the case of the event-inheritance model.&lt;br /&gt;&lt;br /&gt;70. Which containers may have a MenuBar?&lt;br /&gt;&lt;br /&gt;Frame&lt;br /&gt;&lt;br /&gt;71. How are commas used in the intialization and iteration  parts of a for statement?&lt;br /&gt;&lt;br /&gt;Commas are used to separate multiple statements within the initialization and iteration parts of a for statement. &lt;br /&gt;&lt;br /&gt;72. What is the purpose of the wait(), notify(), and notifyAll() methods?&lt;br /&gt;&lt;br /&gt;The wait(),notify(), and notifyAll() methods are used to provide an efficient way for threads to wait for a shared resource. When a thread executes an object's wait() method, it enters the waiting state. It only enters the ready state after another thread invokes the object's notify() or notifyAll() methods.&lt;br /&gt;&lt;br /&gt;73. What is an abstract method?&lt;br /&gt;&lt;br /&gt;An abstract method is a method whose implementation is deferred to a subclass.&lt;br /&gt;&lt;br /&gt;74. How are Java source code files named?&lt;br /&gt;&lt;br /&gt;A Java source code file takes the name of a public class or interface that is defined within the file. A source code file may contain at most one public class or interface. If a public class or interface is defined within a source code file, then the source code file must take the name of the public class or interface. If no public class or interface is defined within a source code file, then the file must take on a name that is different than its classes and interfaces. Source code files use the .java extension.&lt;br /&gt;&lt;br /&gt;75. What is the relationship between the Canvas class and the Graphics class?&lt;br /&gt;&lt;br /&gt;A Canvas object provides access to a Graphics object via its paint() method.&lt;br /&gt;&lt;br /&gt;76. What are the high-level thread states?&lt;br /&gt;&lt;br /&gt;The high-level thread states are ready, running, waiting, and dead.&lt;br /&gt;&lt;br /&gt;77. What value does read() return when it has reached the end of a file?&lt;br /&gt;&lt;br /&gt;The read() method returns -1 when it has reached the end of a file. &lt;br /&gt;&lt;br /&gt;78. Can a Byte object be cast to a double value?&lt;br /&gt;&lt;br /&gt;No, an object cannot be cast to a primitive value.&lt;br /&gt;&lt;br /&gt;79. What is the difference between a static and a non-static inner class?&lt;br /&gt;&lt;br /&gt;A non-static inner class may have object instances that are associated with instances of the class's outer class. A static inner class does not have any object instances.&lt;br /&gt;&lt;br /&gt;80. What is the difference between the String and StringBuffer classes?&lt;br /&gt;&lt;br /&gt;String objects are constants. StringBuffer objects are not.&lt;br /&gt;&lt;br /&gt;81. If a variable is declared as private, where may the variable be accessed?&lt;br /&gt;&lt;br /&gt;A private variable may only be accessed within the class in which it is declared.&lt;br /&gt;&lt;br /&gt;82. What is an object's lock and which object's have locks?&lt;br /&gt;&lt;br /&gt;An object's lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object's lock. All objects and classes have locks. A class's lock is acquired on the class's Class object.&lt;br /&gt;&lt;br /&gt;83. What is the Dictionary class?&lt;br /&gt;&lt;br /&gt;The Dictionary class provides the capability to store key-value pairs.&lt;br /&gt;&lt;br /&gt;84. How are the elements of a BorderLayout organized?&lt;br /&gt;&lt;br /&gt;The elements of a BorderLayout are organized at the borders (North, South, East, and West) and the center of a container.&lt;br /&gt;&lt;br /&gt;85. What is the % operator?&lt;br /&gt;&lt;br /&gt;It is referred to as the modulo or remainder operator. It returns the remainder of dividing the first operand by the second operand.&lt;br /&gt;&lt;br /&gt;86. When can an object reference be cast to an interface reference?&lt;br /&gt;&lt;br /&gt;An object reference be cast to an interface reference when the object implements the referenced interface.&lt;br /&gt;&lt;br /&gt;87. What is the difference between a Window and a Frame?&lt;br /&gt;&lt;br /&gt;The Frame class extends Window to define a main application window that can have a menu bar.&lt;br /&gt;&lt;br /&gt;88. Which class is extended by all other classes?&lt;br /&gt;&lt;br /&gt;The Object class is extended by all other classes.&lt;br /&gt;&lt;br /&gt;89. Can an object be garbage collected while it is still reachable?&lt;br /&gt;&lt;br /&gt;A reachable object cannot be garbage collected. Only unreachable objects may be garbage collected..&lt;br /&gt;&lt;br /&gt;90. Is the ternary operator written x : y ? z or x ? y : z ?&lt;br /&gt;&lt;br /&gt;It is written x ? y : z.&lt;br /&gt;&lt;br /&gt;91. What is the difference between the Font and FontMetrics classes?&lt;br /&gt;&lt;br /&gt;The FontMetrics class is used to define implementation-specific properties, such as ascent and descent, of a Font object.&lt;br /&gt;&lt;br /&gt;92. How is rounding performed under integer division?&lt;br /&gt;&lt;br /&gt;The fractional part of the result is truncated. This is known as rounding toward zero.&lt;br /&gt;&lt;br /&gt;93. What happens when a thread cannot acquire a lock on an object?&lt;br /&gt;&lt;br /&gt;If a thread attempts to execute a synchronized method or synchronized statement and is unable to acquire an object's lock, it enters the waiting state until the lock becomes available. &lt;br /&gt;&lt;br /&gt;94. What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?&lt;br /&gt;&lt;br /&gt;The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented.&lt;br /&gt;&lt;br /&gt;95. What classes of exceptions may be caught by a catch clause?&lt;br /&gt;&lt;br /&gt;A catch clause can catch any exception that may be assigned to the Throwable type. This includes the Error and Exception types.&lt;br /&gt;&lt;br /&gt;96. If a class is declared without any access modifiers, where may the class be accessed?&lt;br /&gt;&lt;br /&gt;A class that is declared without any access modifiers is said to have package access. This means that the class can only be accessed by other classes and interfaces that are defined within the same package.&lt;br /&gt;&lt;br /&gt;97. What is the SimpleTimeZone class?&lt;br /&gt;&lt;br /&gt;The SimpleTimeZone class provides support for a Gregorian calendar.&lt;br /&gt;&lt;br /&gt;98. What is the Map interface?&lt;br /&gt;&lt;br /&gt;The Map interface replaces the JDK 1.1 Dictionary class and is used associate keys with values. &lt;br /&gt;&lt;br /&gt;99. Does a class inherit the constructors of its superclass?&lt;br /&gt;&lt;br /&gt;A class does not inherit constructors from any of its superclasses.&lt;br /&gt;&lt;br /&gt;100. For which statements does it make sense to use a label?&lt;br /&gt;&lt;br /&gt;The only statements for which it makes sense to use a label are those statements that can enclose a break or continue statement.&lt;br /&gt;&lt;br /&gt;101. What is the purpose of the System class?&lt;br /&gt;&lt;br /&gt;The purpose of the System class is to provide access to system resources.&lt;br /&gt;&lt;br /&gt;102. Which TextComponent method is used to set a TextComponent to the read-only state?&lt;br /&gt;&lt;br /&gt;setEditable()&lt;br /&gt;&lt;br /&gt;103. How are the elements of a CardLayout organized?&lt;br /&gt;&lt;br /&gt;The elements of a CardLayout are stacked, one on top of the other, like a deck of cards.&lt;br /&gt;&lt;br /&gt;104. Is &amp;amp;&amp;amp;= a valid Java operator?&lt;br /&gt;&lt;br /&gt;No, it is not.&lt;br /&gt;&lt;br /&gt;105. Name the eight primitive Java types.&lt;br /&gt;&lt;br /&gt;The eight primitive types are byte, char, short, int, long, float, double, and boolean.&lt;br /&gt;&lt;br /&gt;106. Which class should you use to obtain design information about an object?&lt;br /&gt;&lt;br /&gt;The Class class is used to obtain information about an object's design.&lt;br /&gt;&lt;br /&gt;107. What is the relationship between clipping and repainting?&lt;br /&gt;&lt;br /&gt;When a window is repainted by the AWT painting thread, it sets the clipping regions to the area of the window that requires repainting.&lt;br /&gt;&lt;br /&gt;108. Is "abc" a primitive value?&lt;br /&gt;&lt;br /&gt;The String literal "abc" is not a primitive value. It is a String object.&lt;br /&gt;&lt;br /&gt;109. What is the relationship between an event-listener interface and an event-adapter class?&lt;br /&gt;&lt;br /&gt;An event-listener interface defines the methods that must be implemented by an event handler for a particular kind of event. An event adapter provides a default implementation of an event-listener interface.&lt;br /&gt;&lt;br /&gt;110. What restrictions are placed on the values of each case of a switch statement?&lt;br /&gt;&lt;br /&gt;During compilation, the values of each case of a switch statement must evaluate to a value that can be promoted to an int value.&lt;br /&gt;&lt;br /&gt;111. What modifiers may be used with an interface declaration?&lt;br /&gt;&lt;br /&gt;An interface may be declared as public or abstract.&lt;br /&gt;&lt;br /&gt;112. Is a class a subclass of itself?&lt;br /&gt;&lt;br /&gt;A class is a subclass of itself.&lt;br /&gt;&lt;br /&gt;113. What is the highest-level event class of the event-delegation model?&lt;br /&gt;&lt;br /&gt;The java.util.EventObject class is the highest-level class in the event-delegation class hierarchy.&lt;br /&gt;&lt;br /&gt;114. What event results from the clicking of a button?&lt;br /&gt;&lt;br /&gt;The ActionEvent event is generated as the result of the clicking of a button.&lt;br /&gt;&lt;br /&gt;115. How can a GUI component handle its own events?&lt;br /&gt;&lt;br /&gt;A component can handle its own events by implementing the required event-listener interface and adding itself as its own event listener.&lt;br /&gt;&lt;br /&gt;116. What is the difference between a while statement and a do  statement?&lt;br /&gt;&lt;br /&gt;A while statement checks at the beginning of a loop to see whether the next loop iteration should occur. A do statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the body of a loop at least once.&lt;br /&gt;&lt;br /&gt;117. How are the elements of a GridBagLayout organized?&lt;br /&gt;&lt;br /&gt;The elements of a GridBagLayout are organized according to a grid. However, the elements are of different sizes and may occupy more than one row or column of the grid. In addition, the rows and columns may have different sizes.&lt;br /&gt;&lt;br /&gt;118. What advantage do Java's layout managers provide over traditional windowing systems?&lt;br /&gt;&lt;br /&gt;Java uses layout managers to lay out components in a consistent manner across all windowing platforms. Since Java's layout managers aren't tied to absolute sizing and positioning, they are able to accomodate platform-specific differences among windowing systems.&lt;br /&gt;&lt;br /&gt;119. What is the Collection interface?&lt;br /&gt;&lt;br /&gt;The Collection interface provides support for the implementation of a mathematical bag - an unordered collection of objects that may contain duplicates.&lt;br /&gt;&lt;br /&gt;120. What modifiers can be used with a local inner class?&lt;br /&gt;&lt;br /&gt;A local inner class may be final or abstract.&lt;br /&gt;&lt;br /&gt;121. What is the difference between static and non-static variables?&lt;br /&gt;&lt;br /&gt;A static variable is associated with the class as a whole rather than with specific instances of a class. Non-static variables take on unique values with each object instance.&lt;br /&gt;&lt;br /&gt;122. What is the difference between the paint() and repaint() methods?&lt;br /&gt;&lt;br /&gt;The paint() method supports painting via a Graphics object. The repaint() method is used to cause paint() to be invoked by the AWT painting thread.&lt;br /&gt;&lt;br /&gt;123. What is the purpose of the File class?&lt;br /&gt;&lt;br /&gt;The File class is used to create objects that provide access to the files and directories of a local file system.&lt;br /&gt;&lt;br /&gt;124. Can an exception be rethrown?&lt;br /&gt;&lt;br /&gt;Yes, an exception can be rethrown.&lt;br /&gt;&lt;br /&gt;125. Which Math method is used to calculate the absolute value of a number?&lt;br /&gt;&lt;br /&gt;The abs() method is used to calculate absolute values.&lt;br /&gt;&lt;br /&gt;126. How does multithreading take place on a computer with a single CPU?&lt;br /&gt;&lt;br /&gt;The operating system's task scheduler allocates execution time to multiple tasks. By quickly switching between executing tasks, it creates the impression that tasks execute sequentially.&lt;br /&gt;&lt;br /&gt;127. When does the compiler supply a default constructor for a class?&lt;br /&gt;&lt;br /&gt;The compiler supplies a default constructor for a class if no other constructors are provided.&lt;br /&gt;&lt;br /&gt;128. When is the finally clause of a try-catch-finally statement executed?&lt;br /&gt;&lt;br /&gt;The finally clause of the try-catch-finally statement is always executed unless the thread of execution terminates or an exception occurs within the execution of the finally clause.&lt;br /&gt;&lt;br /&gt;129. Which class is the immediate superclass of the Container class?&lt;br /&gt;&lt;br /&gt;Component&lt;br /&gt;&lt;br /&gt;130. If a method is declared as protected, where may the method be accessed?&lt;br /&gt;&lt;br /&gt;A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.&lt;br /&gt;&lt;br /&gt;131. How can the Checkbox class be used to create a radio button?&lt;br /&gt;&lt;br /&gt;By associating Checkbox objects with a CheckboxGroup.&lt;br /&gt;&lt;br /&gt;132. Which non-Unicode letter characters may be used as the first character of an identifier?&lt;br /&gt;&lt;br /&gt;The non-Unicode letter characters $ and _ may appear as the first character of an identifier&lt;br /&gt;&lt;br /&gt;133. What restrictions are placed on method overloading?&lt;br /&gt;&lt;br /&gt;Two methods may not have the same name and argument list but different return types.&lt;br /&gt;&lt;br /&gt;134. What happens when you invoke a thread's interrupt method while it is sleeping or waiting?&lt;br /&gt;&lt;br /&gt;When a task's interrupt() method is executed, the task enters the ready state. The next time the task enters the running state, an InterruptedException is thrown.&lt;br /&gt;&lt;br /&gt;135. What is casting?&lt;br /&gt;&lt;br /&gt;There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference.&lt;br /&gt;&lt;br /&gt;136. What is the return type of a program's main() method?&lt;br /&gt;&lt;br /&gt;A program's main() method has a void return type.&lt;br /&gt;&lt;br /&gt;137. Name four Container classes.&lt;br /&gt;&lt;br /&gt;Window, Frame, Dialog, FileDialog, Panel, Applet, or ScrollPane&lt;br /&gt;&lt;br /&gt;138. What is the difference between a Choice and a List?&lt;br /&gt;&lt;br /&gt;A Choice is displayed in a compact form that requires you to pull it down to see the list of available choices. Only one item may be selected from a Choice. A List may be displayed in such a way that several List items are visible. A List supports the selection of one or more List items.&lt;br /&gt;&lt;br /&gt;139. What class of exceptions are generated by the Java run-time system?&lt;br /&gt;&lt;br /&gt;The Java runtime system generates RuntimeException and Error exceptions.&lt;br /&gt;&lt;br /&gt;140. What class allows you to read objects directly from a stream?&lt;br /&gt;&lt;br /&gt;The ObjectInputStream class supports the reading of objects from input streams.&lt;br /&gt;&lt;br /&gt;141. What is the difference between a field variable and a local variable?&lt;br /&gt;&lt;br /&gt;A field variable is a variable that is declared as a member of a class. A local variable is a variable that is declared local to a method.&lt;br /&gt;&lt;br /&gt;142. Under what conditions is an object's finalize() method invoked by the garbage collector?&lt;br /&gt;&lt;br /&gt;The garbage collector invokes an object's finalize() method when it detects that the object has become unreachable.&lt;br /&gt;&lt;br /&gt;143. How are this() and super() used with constructors?&lt;br /&gt;&lt;br /&gt;this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.&lt;br /&gt;&lt;br /&gt;144. What is the relationship between a method's throws clause and the exceptions that can be thrown during the method's execution?&lt;br /&gt;&lt;br /&gt;A method's throws clause must declare any checked exceptions that are not caught within the body of the method.&lt;br /&gt;&lt;br /&gt;145. What is the difference between the JDK 1.02 event model and the event-delegation model introduced with JDK 1.1?&lt;br /&gt;&lt;br /&gt;The JDK 1.02 event model uses an event inheritance or bubbling approach. In this model, components are required to handle their own events. If they do not handle a particular event, the event is inherited by (or bubbled up to) the component's container. The container then either handles the event or it is bubbled up to its container and so on, until the highest-level container has been tried.&lt;br /&gt;&lt;br /&gt;In the event-delegation model, specific objects are designated as event handlers for GUI components. These objects implement event-listener interfaces. The event-delegation model is more efficient than the event-inheritance model because it eliminates the processing required to support the bubbling of unhandled events.&lt;br /&gt;&lt;br /&gt;146. How is it possible for two String objects with identical values not to be equal under the == operator?&lt;br /&gt;&lt;br /&gt;The == operator compares two objects to determine if they are the same object in memory. It is possible for two String objects to have the same value, but located indifferent areas of memory.&lt;br /&gt;&lt;br /&gt;147. Why are the methods of the Math class static?&lt;br /&gt;&lt;br /&gt;So they can be invoked as if they are a mathematical code library.&lt;br /&gt;&lt;br /&gt;148. What Checkbox method allows you to tell if a Checkbox is checked?&lt;br /&gt;&lt;br /&gt;getState()&lt;br /&gt;&lt;br /&gt;149. What state is a thread in when it is executing?&lt;br /&gt;&lt;br /&gt;An executing thread is in the running state.&lt;br /&gt;&lt;br /&gt;150. What are the legal operands of the instanceof operator?&lt;br /&gt;&lt;br /&gt;The left operand is an object reference or null value and the right operand is a class, interface, or array type.&lt;br /&gt;&lt;br /&gt;151. How are the elements of a GridLayout organized?&lt;br /&gt;&lt;br /&gt;The elements of a GridBad layout are of equal size and are laid out using the squares of a grid.&lt;br /&gt;&lt;br /&gt;152. What an I/O filter?&lt;br /&gt;&lt;br /&gt;An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.&lt;br /&gt;&lt;br /&gt;153. If an object is garbage collected, can it become reachable again?&lt;br /&gt;&lt;br /&gt;Once an object is garbage collected, it ceases to exist.  It can no longer become reachable again. &lt;br /&gt;&lt;br /&gt;154. What is the Set interface?&lt;br /&gt;&lt;br /&gt;The Set interface provides methods for accessing the elements of a finite mathematical set. Sets do not allow duplicate elements. &lt;br /&gt;&lt;br /&gt;155. What classes of exceptions may be thrown by a throw statement?&lt;br /&gt;&lt;br /&gt;A throw statement may throw any expression that may be assigned to the Throwable type.&lt;br /&gt;&lt;br /&gt;156. What are E and PI?&lt;br /&gt;&lt;br /&gt;E is the base of the natural logarithm and PI is mathematical value pi.&lt;br /&gt;&lt;br /&gt;157. Are true and false keywords?&lt;br /&gt;&lt;br /&gt;The values true and false are not keywords.&lt;br /&gt;&lt;br /&gt;158. What is a void return type?&lt;br /&gt;&lt;br /&gt;A void return type indicates that a method does not return a value.&lt;br /&gt;&lt;br /&gt;159. What is the purpose of the enableEvents() method?&lt;br /&gt;&lt;br /&gt;The enableEvents() method is used to enable an event for a particular object. Normally, an event is enabled when a listener is added to an object for a particular event. The enableEvents() method is used by objects that handle events by overriding their event-dispatch methods.&lt;br /&gt;&lt;br /&gt;160. What is the difference between the File and RandomAccessFile classes?&lt;br /&gt;&lt;br /&gt;The File class encapsulates the files and directories of the local file system. The RandomAccessFile class provides the methods needed to directly access data contained in any part of a file.&lt;br /&gt;&lt;br /&gt;161. What happens when you add a double value to a String?&lt;br /&gt;&lt;br /&gt;The result is a String object.&lt;br /&gt;&lt;br /&gt;162. What is your platform's default character encoding?&lt;br /&gt;&lt;br /&gt;If you are running Java on English Windows platforms, it is probably Cp1252. If you are running Java on English Solaris platforms, it is most likely 8859_1..&lt;br /&gt;&lt;br /&gt;163. Which package is always imported by default?&lt;br /&gt;&lt;br /&gt;The java.lang package is always imported by default.&lt;br /&gt;&lt;br /&gt;164. What interface must an object implement before it can be written to a stream as an object?&lt;br /&gt;&lt;br /&gt;An object must implement the Serializable or Externalizable interface before it can be written to a stream as an object.&lt;br /&gt;&lt;br /&gt;165. How are this and super used?&lt;br /&gt;&lt;br /&gt;this is used to refer to the current object instance. super is used to refer to the variables and methods of the superclass of the current object instance.&lt;br /&gt;&lt;br /&gt;166. What is the purpose of garbage collection?&lt;br /&gt;&lt;br /&gt;The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources may be reclaimed and reused.&lt;br /&gt;&lt;br /&gt;167. What is a compilation unit?&lt;br /&gt;&lt;br /&gt;A compilation unit is a Java source code file.&lt;br /&gt;&lt;br /&gt;168. What interface is extended by AWT event listeners?&lt;br /&gt;&lt;br /&gt;All AWT event listeners extend the java.util.EventListener interface. &lt;br /&gt;&lt;br /&gt;169. What restrictions are placed on method overriding?&lt;br /&gt;&lt;br /&gt;Overridden methods must have the same name, argument list, and return type. The overriding method may not limit the access of the method it overrides. The overriding method may not throw any exceptions that may not be thrown by the overridden method.&lt;br /&gt;&lt;br /&gt;170. How can a dead thread be restarted?&lt;br /&gt;&lt;br /&gt;A dead thread cannot be restarted.&lt;br /&gt;&lt;br /&gt;171. What happens if an exception is not caught?&lt;br /&gt;&lt;br /&gt;An uncaught exception results in the uncaughtException() method of the thread's ThreadGroup being invoked, which eventually results in the termination of the program in which it is thrown.&lt;br /&gt;&lt;br /&gt;172. What is a layout manager?&lt;br /&gt;&lt;br /&gt;A layout manager is an object that is used to organize components in a container.&lt;br /&gt;&lt;br /&gt;173. Which arithmetic operations can result in the throwing of an ArithmeticException?&lt;br /&gt;&lt;br /&gt;Integer / and % can result in the throwing of an ArithmeticException.&lt;br /&gt;&lt;br /&gt;174. What are three ways in which a thread can enter the waiting state?&lt;br /&gt;&lt;br /&gt;A thread can enter the waiting state by invoking its sleep() method, by blocking on I/O, by unsuccessfully attempting to acquire an object's lock, or by invoking an object's wait() method. It can also enter the waiting state by invoking its (deprecated) suspend() method.&lt;br /&gt;&lt;br /&gt;175. Can an abstract class be final?&lt;br /&gt;&lt;br /&gt;An abstract class may not be declared as final.&lt;br /&gt;&lt;br /&gt;176. What is the ResourceBundle class?&lt;br /&gt;&lt;br /&gt;The ResourceBundle class is used to store locale-specific resources that can be loaded by a program to tailor the program's appearance to the particular locale in which it is being run.&lt;br /&gt;&lt;br /&gt;177. What happens if a try-catch-finally statement does not have a catch clause to handle an exception that is thrown within the body of the try statement?&lt;br /&gt;&lt;br /&gt;The exception propagates up to the next higher level try-catch statement (if any) or results in the program's termination. &lt;br /&gt;&lt;br /&gt;178. What is numeric promotion?&lt;br /&gt;&lt;br /&gt;Numeric promotion is the conversion of a smaller numeric type to a larger numeric type, so that integer and floating-point operations may take place. In numerical promotion, byte, char, and short values are converted to int&lt;br /&gt;&lt;br /&gt;values. The int values are also converted to long values, if necessary. The long and float values are converted to double values, as required.&lt;br /&gt;&lt;br /&gt;179. What is the difference between a Scrollbar and a ScrollPane?&lt;br /&gt;&lt;br /&gt;A Scrollbar is a Component, but not a Container. A ScrollPane is a Container. A ScrollPane handles its own events and performs its own scrolling.&lt;br /&gt;&lt;br /&gt;180. What is the difference between a public and a non-public class?&lt;br /&gt;&lt;br /&gt;A public class may be accessed outside of its package. A non-public class may not be accessed outside of its package.&lt;br /&gt;&lt;br /&gt;181. To what value is a variable of the boolean type automatically initialized?&lt;br /&gt;&lt;br /&gt;The default value of the boolean type is false.&lt;br /&gt;&lt;br /&gt;182. Can try statements be nested?&lt;br /&gt;&lt;br /&gt;Try statements may be tested. &lt;br /&gt;&lt;br /&gt;183. What is the difference between the prefix and postfix forms of the ++ operator?&lt;br /&gt;&lt;br /&gt;The prefix form performs the increment operation and returns the value of  the increment operation. The postfix form returns the current value all of the expression and then performs the increment operation on that value.&lt;br /&gt;&lt;br /&gt;184. What is the purpose of a statement block?&lt;br /&gt;&lt;br /&gt;A statement block is used to organize a sequence of statements as a single statement group.&lt;br /&gt;&lt;br /&gt;185. What is a Java package and how is it used?&lt;br /&gt;&lt;br /&gt;A Java package is a naming context for classes and interfaces. A package is used to create a separate name space for groups of classes and interfaces. Packages are also used to organize related classes and interfaces into a single API unit and to control accessibility to these classes and interfaces.&lt;br /&gt;&lt;br /&gt;186. What modifiers may be used with a top-level class?&lt;br /&gt;&lt;br /&gt;A top-level class may be public, abstract, or final.&lt;br /&gt;&lt;br /&gt;187. What are the Object and Class classes used for?&lt;br /&gt;&lt;br /&gt;The Object class is the highest-level class in the Java class hierarchy. The Class class is used to represent the classes and interfaces that are loaded by a Java program.&lt;br /&gt;&lt;br /&gt;188. How does a try statement determine which catch clause should be used to handle an exception?&lt;br /&gt;&lt;br /&gt;When an exception is thrown within the body of a try statement, the catch clauses of the try statement are examined in the order in which they appear. The first catch clause that is capable of handling the exception is executed. The remaining catch clauses are ignored.&lt;br /&gt;&lt;br /&gt;189. Can an unreachable object become reachable again?&lt;br /&gt;&lt;br /&gt;An unreachable object may become reachable again. This can happen when the object's finalize() method is invoked and the object performs an operation which causes it to become accessible to reachable objects.&lt;br /&gt;&lt;br /&gt;190. When is an object subject to garbage collection?&lt;br /&gt;&lt;br /&gt;An object is subject to garbage collection when it becomes unreachable to the program in which it is used.&lt;br /&gt;&lt;br /&gt;191. What method must be implemented by all threads?&lt;br /&gt;&lt;br /&gt;All tasks must implement the run() method, whether they are a subclass of  Thread or implement the Runnable interface.&lt;br /&gt;&lt;br /&gt;192. What methods are used to get and set the text label displayed by a Button object?&lt;br /&gt;&lt;br /&gt;getLabel() and setLabel()&lt;br /&gt;&lt;br /&gt;193. Which Component subclass is used for drawing and painting?&lt;br /&gt;&lt;br /&gt;Canvas&lt;br /&gt;&lt;br /&gt;194. What are synchronized methods and synchronized statements?&lt;br /&gt;&lt;br /&gt;Synchronized methods are methods that are used to control access to an object. A thread only executes a synchronized method after it has acquired the lock for the method's object or class. Synchronized statements are similar to synchronized methods. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.&lt;br /&gt;&lt;br /&gt;195. What are the two basic ways in which classes that can be run as threads may be defined?&lt;br /&gt;&lt;br /&gt;A thread class may be declared as a subclass of Thread, or it may implement the Runnable interface.&lt;br /&gt;&lt;br /&gt;196. What are the problems faced by Java programmers who don't use layout managers?&lt;br /&gt;&lt;br /&gt;Without layout managers, Java programmers are faced with determining how their GUI will be displayed across multiple windowing systems and finding a common sizing  and positioning that will work within the constraints imposed by each windowing system.&lt;br /&gt;&lt;br /&gt;197. What is the difference between an if statement and a switch statement?&lt;br /&gt;&lt;br /&gt;The if statement is used to select among two alternatives. It uses a boolean expression to decide which alternative should be executed. The switch statement is used to select among multiple alternatives. It uses an int expression to determine which alternative should be executed.&lt;br /&gt;&lt;br /&gt;198. What happens when you add a double value to a String?&lt;br /&gt;&lt;br /&gt;The result is a String object.&lt;br /&gt;&lt;br /&gt;199. What is the List interface?&lt;br /&gt;&lt;br /&gt;The List interface provides support for ordered collections of objects.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8955336342891215397-8800664453081894547?l=javaimpquestions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaimpquestions.blogspot.com/feeds/8800664453081894547/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8955336342891215397&amp;postID=8800664453081894547' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8955336342891215397/posts/default/8800664453081894547'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8955336342891215397/posts/default/8800664453081894547'/><link rel='alternate' type='text/html' href='http://javaimpquestions.blogspot.com/2008/08/200-core-java-questions.html' title='200 core java questions'/><author><name>Naresh Namana</name><uri>http://www.blogger.com/profile/05755392141578528676</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8955336342891215397.post-1057231070592409236</id><published>2008-08-13T01:01:00.001-07:00</published><updated>2011-03-18T22:54:49.054-07:00</updated><title type='text'>Spring Imp Questions</title><content type='html'>&lt;script type="text/javascript"&gt;&lt;br /&gt;var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");&lt;br /&gt;document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;br /&gt;try {&lt;br /&gt;var pageTracker = _gat._getTracker("UA-9255840-1");&lt;br /&gt;pageTracker._trackPageview();&lt;br /&gt;} catch(err) {}&lt;/script&gt;&lt;br /&gt;How to integrate  Java Server Faces (JSF) with Spring?&lt;br /&gt;JSF and Spring do share some of the same features, most noticeably in the area of IOC services. By declaring JSF managed-beans in the faces-config.xml configuration file, you allow the FacesServlet to instantiate that bean at startup. Your JSF pages have access to these beans and all of their properties.We can integrate JSF and Spring in two ways: &lt;br /&gt;     &lt;br /&gt;DelegatingVariableResolver: Sp= ring comes with a JSF variable resolver that lets you use JSF and Spring together. &lt;br /&gt;     &lt;?xml version=3D"1.0" encoding=3D"UTF-8"?&gt;= ;&lt;br /&gt;     &lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"&lt;br /&gt;        "http://www.springframework.org/dtd/spring-beans.dtd"&gt;&lt;br /&gt;     &lt;br /&gt;     &lt;faces-config&gt;&lt;br /&gt;        &lt;application&gt;&lt;br /&gt;           &lt;variable-resolver&gt;&lt;br /&gt;              org.springframework.web.jsf.DelegatingVariableResolver&lt;br /&gt;           &lt;/variable-resolver&gt;&lt;br /&gt;        &lt;/application&gt;&lt;br /&gt;     &lt;/faces-config&gt;&lt;br /&gt;The DelegatingVariableResolver will first delegate value lookups to the default resolver of the underlying JSF implementation, and then to Spring's 'business context' WebApplicationContext. This allows one to easily inject dependencies into one's JSF-managed beans.&lt;br /&gt;&lt;br /&gt;FacesContextUtils:custom VariableResolver works well when mapping one's properties to beans in faces-config.xml, but at times one may need to grab a bean explicitly. The FacesContextUtils class makes this easy. It is similar to WebApplicationContextUtils, except that it takes a FacesContext parameter rather than a ServletContext parameter. &lt;br /&gt;     &lt;br /&gt;     ApplicationContext ctx =3D FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstan= ce());&lt;br /&gt;     &lt;br /&gt;Wh= at is Significance of JSF- Spring integration ?&lt;br /&gt;Spring - JSF integration is useful when an event handler wishes to explicitly invoke the bean factory to create beans on demand, such as a bean that encapsulates the business logic to be performed when a submit button is pressed. &lt;br /&gt;&lt;br /&gt;Ho= w to integrate your Struts application with Spring?&lt;br /&gt;To integrate your Struts application with Spring, we have two options: &lt;br /&gt;     Configure Spring to manage your Actions as beans, using the ContextLoaderPlugin, and set their dependencies in a Spring context file. &lt;br /&gt;     Subclass Spring's ActionSupport classes and grab your Spring-managed beans explicitly using a getWebApplicationContext() method. &lt;br /&gt;&lt;br /&gt;Wh= at are the different types of bean injections? &lt;br /&gt;There are two types of bean injections. &lt;br /&gt;1.    By setter &lt;br /&gt;2.    By constructor &lt;br /&gt;&lt;br /&gt;Wh= at is Auto wiring? &lt;br /&gt;You can wire the beans as you wish. But spring framework also does this work for you. It can auto wire the related beans together. All you have to do is just set the autowire attribute of bean tag to an autowire type. &lt;br /&gt;&lt;beans&gt; &lt;br /&gt;        &lt;bean id=3D"bar" class=3D"com.act.Foo" Autowire=3D"autowire type"/&gt; &lt;br /&gt;&lt;/beans&gt; &lt;br /&gt;&lt;br /&gt;Wh= at are different types of Autowire types? &lt;br /&gt;There are four different types by which autowiring can be done. &lt;br /&gt;byName &lt;br /&gt;byType &lt;br /&gt;constructor &lt;br /&gt;autodetect &lt;br /&gt;&lt;br /&gt;Wh= at are the different types of events related to Listeners? &lt;br /&gt;There are a lot of events related to ApplicationContext of spring framework. All the events are subclasses of org.springframework.context.Application-Event. They are &lt;br /&gt;ContextClosedEvent - This is fired when the context is closed. &lt;br /&gt;ContextRefreshedEvent - This is fired when the context is initialized or refreshed. &lt;br /&gt;RequestHandledEvent - This is fired when the web context handles any request. &lt;br /&gt;&lt;br /&gt;What is an Aspect? &lt;br /&gt;An aspect is the cross-cutting functionality that you are implementing. It is the aspect of your application you are modularizing. An example of an aspect is logging. Logging is something that is required throughout an application. However, because applications tend to be broken down into layers based on functionality, reusing a logging module through inheritance does not make sense. However, you can create a logging aspect and apply it throughout your application using AOP. &lt;br /&gt;&lt;br /&gt;Wh= at is a Jointpoint? &lt;br /&gt;A joinpoint is a point in the execution of the application where an aspect can be plugged in. This point could be a method being called, an exception being thrown, or even a field being modified. These are the points where your aspect's code can be inserted into the normal flow of your application to add new behavior.&lt;br /&gt;&lt;br /&gt;Wh= at is an Advice? &lt;br /&gt;Advice is the implementation of an aspect. It is something like telling your application of a new behavior. Generally, and advice is inserted into an application at joinpoints. &lt;br /&gt;&lt;br /&gt;Wh= at is a Pointcut? &lt;br /&gt;A pointcut is something that defines at what joinpoints an advice should be applied. Advices can be applied at any joinpoint that is supported by the AOP framework. These Pointcuts allow you to specify where the advice can be applied. &lt;br /&gt;&lt;br /&gt;Wh= at is an Introduction in AOP? &lt;br /&gt;An introduction allows the user to add new methods or attributes to an existing class. This can then be introduced to an existing class without having to change the structure of the class, but give them the new behavior and state. &lt;br /&gt;&lt;br /&gt;Wh= at is a Target? &lt;br /&gt;A target is the class that is being advised. The class can be a third party class or your own class to which you want to add your own custom behavior. By using the concepts of AOP, the target class is free to center on its major concern, unaware to any advice that is being applied. &lt;br /&gt;&lt;br /&gt;Wh= at is a Proxy? &lt;br /&gt;A proxy is an object that is created after applying advice to a target object. When you think of client objects the target object and the proxy object are the same. &lt;br /&gt;= &lt;br /&gt;Wh= at is meant by Weaving? &lt;br /&gt;The process of applying aspects to a target object to create a new proxy object is called as Weaving. The aspects are woven into the target object at the specified joinpoints. &lt;br /&gt;&lt;br /&gt;= Wh= at are the different points where weaving can be applied? &lt;br /&gt;Compile Time &lt;br /&gt;Classload Time &lt;br /&gt;Runtime&lt;br /&gt;&lt;br /&gt;Wh= at are the different advice types in spring? &lt;br /&gt;Around : Intercepts the calls to the target method &lt;br /&gt;Before : This is called before the target method is invoked &lt;br /&gt;After : This is called after the target method is returned &lt;br /&gt;Throws : This is called when the target method throws and exception&lt;br /&gt;Around : org.aopalliance.intercept.MethodInterceptor &lt;br /&gt;Before : org.springframework.aop.BeforeAdvice &lt;br /&gt;After : org.springframework.aop.AfterReturningAdvice &lt;br /&gt;Throws : org.springframework.aop.ThrowsAdvice &lt;br /&gt;&lt;br /&gt;Wh= at are the different types of AutoProxying? &lt;br /&gt;BeanNameAutoProxyCreator &lt;br /&gt;DefaultAdvisorAutoProxyCreator &lt;br /&gt;Metadata autoproxying &lt;br /&gt;&lt;br /&gt;Wh= at is the Exception class related to all the exceptions that are thrown in spring applications? &lt;br /&gt;DataAccessException - org.springframework.dao.DataAccessException &lt;br /&gt;&lt;br /&gt;Wh= at kind of exceptions those spring DAO classes throw? &lt;br /&gt;The spring's DAO class does not throw any technology related exceptions such as SQLException. They throw exceptions which are subclasses of DataAccessException. &lt;br /&gt;&lt;br /&gt;Wh= at is DataAccessException? &lt;br /&gt;DataAccessException is a RuntimeException. This is an Unchecked Exception. The user is not forced to handle these kinds of exceptions. &lt;br /&gt;&lt;br /&gt;Ho= w can you configure a bean to get DataSource from JNDI? &lt;br /&gt;&lt;bean id=3D"dataSource" class=3D"org.springframework.jndi.JndiObjectFactoryBean"&gt;&lt;br /&gt;     &lt;property name=3D"jndiName"&gt;       &lt;value&gt;java:comp/env/jdbc/myDatasource&lt;/value&gt;&lt;br /&gt;  &lt;/property&gt;&lt;br /&gt;&lt;/bean&gt;&lt;br /&gt;&lt;br /&gt;Ho= w can you create a DataSource connection pool? &lt;br /&gt;&lt;bean id=3D"dataSource" class=3D"org.apache.commons.dbcp.BasicDataSource"&gt;&lt;br /&gt;       &lt;property name=3D"driver"&gt;             =    &lt;value&gt;${db.driver}&lt;/value&gt;&lt;br /&gt;       &lt;/property&gt;&lt;br /&gt;       &lt;property name=3D"url"&gt;&lt;br /&gt;            =   &lt;value&gt;${db.url}&lt;/value&gt;&lt;br /&gt;       &lt;/property&gt;&lt;br /&gt;       &lt;property name=3D"username"&gt;&lt;= br&gt;             = &lt;value&gt;${db.username}&lt;/value&gt;&lt;br /&gt;       &lt;/property&gt;&lt;br /&gt;       &lt;property name=3D"password"&gt;&lt;= br&gt;             &lt;value&gt;${db.password}&lt;/value&gt;&lt;br /&gt;       &lt;/property&gt;&lt;br /&gt;&lt;/bean&gt; &lt;br /&gt;&lt;br /&gt;Ho= w JDBC can be used more efficiently in spring framework? &lt;br /&gt;JDBC can be used more efficiently with the help of a template class provided by spring framework called as JdbcTemplate. &lt;br /&gt;&lt;br /&gt;Ho= w JdbcTemplate can be used? &lt;br /&gt;With use of Spring JDBC framework the burden of resource management and error handling is reduced a lot. So it leaves developers to write the statements and queries to get the data to and from the database. &lt;br /&gt;&lt;br /&gt;JdbcTemplate template =3D new JdbcTemplate(myDataSource); &lt;br /&gt;&lt;br /&gt;A simple DAO class looks like this. &lt;br /&gt;&lt;br /&gt;public class StudentDaoJdbc implements StudentDao {&lt;br /&gt;          private JdbcTemplate jdbcTemplate;&lt;br /&gt;&lt;br /&gt;     public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {&lt;br /&gt;          this.jdbcTemplate =3D jdbcTemplate;&lt;br /&gt;     }&lt;br /&gt;     more..&lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;The configuration is shown below. &lt;br /&gt;&lt;br /&gt;&lt;bean id=3D"jdbcTemplate" class=3D"org.springframework.jdbc.core.JdbcTemplate"&gt;&lt;br /&gt;       &lt;property name=3D"dataSource"&gt;= ;&lt;br /&gt;       &lt;ref bean=3D"dataSource"/&gt;    &lt;/property&gt;&lt;br /&gt;&lt;/bean&gt;&lt;br /&gt;&lt;bean id=3D"studentDao" class=3D"StudentDaoJdbc"&gt;&lt;br /&gt;       &lt;property name=3D"jdbcTemplate"&gt;&lt;br /&gt;        &lt;ref bean=3D"jdbcTemplate"/&gt;&lt;br /&gt;   &lt;/property&gt;&lt;br /&gt;&lt;/bean&gt; &lt;br /&gt;&lt;bean id=3D"courseDao" class=3D"CourseDaoJdbc"&gt;&lt;br /&gt;        &lt;property name=3D"jdbcTemplate"&gt;&lt;br /&gt;       &lt;ref bean=3D"jdbcTemplate"/&gt;&lt;= br&gt;    &lt;/property&gt;&lt;br /&gt;&lt;/bean&gt;&lt;br /&gt;&lt;br /&gt;Ho= w do you write data to backend in spring using JdbcTemplate? &lt;br /&gt;The JdbcTemplate uses several of these callbacks when writing data to the database. The usefulness you will find in each of these interfaces will vary. There are two simple interfaces. One is PreparedStatementCreator and the other interface is BatchPreparedStatementSetter. &lt;br /&gt;&lt;br /&gt;Ex= plain about PreparedStatementCreator? &lt;br /&gt;PreparedStatementCreator is one of the most common used interfaces for writing data to database. The interface has one method createPreparedStatement(). &lt;br /&gt;&lt;br /&gt;PreparedStatement createPreparedStatement(Connection conn)&lt;br /&gt;throws SQLException; &lt;br /&gt;&lt;br /&gt;When this interface is implemented, we should create and return a PreparedStatement from the Connection argument, and the exception handling is automatically taken care off. When this interface is implemented, another interface SqlProvider is also implemented which has a method called getSql() which is used to provide sql strings to JdbcTemplate. &lt;br /&gt;&lt;br /&gt;Ex= plain about BatchPreparedStatementSetter? &lt;br /&gt;If the user what to update more than one row at a shot then he can go for BatchPreparedStatementSetter. This interface provides two methods &lt;br /&gt;&lt;br /&gt;Spring Framework Interview Questions&lt;br /&gt;What is Spring?&lt;br /&gt;Spring is a lightweight inversion of control and aspect-oriented container framework. &lt;br /&gt;&lt;br /&gt;Ex= plain Spring? &lt;br /&gt;Lightweight - spring is lightweight when it comes to size and transparency. The basic version of spring framework is around 1MB. And the processing overhead is also very negligible. &lt;br /&gt;Inversion of control (IoC) - Loose coupling is achieved in spring using the technique Inversion of Control. The objects give their dependencies instead of creating or looking for dependent objects. &lt;br /&gt;= &lt;br /&gt;Aspect oriented (AOP) - Spring supports Aspect oriented programming and enables cohesive development by separating application business logic from system services. &lt;br /&gt;Container - Spring contains and manages the life cycle and configuration of application objects. &lt;br /&gt;Framework - Spring provides most of the intra functionality leaving rest of the coding to the developer. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Wh= at is IOC (or Dependency Injection)?&lt;br /&gt;The basic concept of the Inversion of Control pattern (also known as dependency injection) is that you do not create your objects but describe how they should be created. You don't directly connect your components and services together in code but describe which services are needed by which components in a configuration file. A container (in the case of the Spring framework, the IOC container) is then responsible for hooking it all up.&lt;br /&gt;&lt;br /&gt;i.e., Applying IoC, objects are given their dependencies at creation time by some external entity that coordinates each object in the system. That is, dependencies are injected into objects. So, IoC means an inversion of responsibility with regard to how an object obtains references to collaborating objects. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Wh= at are the different types of IOC (dependency injection) ? &lt;br /&gt;There are three types of dependency injection: &lt;br /&gt;Constructor Injection (e.g. Pico container, Spring etc): Dependencies are provided as constructor parameters. &lt;br /&gt;Setter Injection (e.g. Spring): Dependencies are assigned through JavaBeans properties (ex: setter methods). &lt;br /&gt;Interface Injection (e.g. Avalon): Injection is done through an interface. &lt;br /&gt;&lt;br /&gt;Note: Spring supports only Constructor and Setter Injection&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Wh= at are the benefits of IOC (Dependency Injection)?&lt;br /&gt;Benefits of IOC (Dependency Injection) are as follows:&lt;br /&gt;&lt;br /&gt;Minimizes the amount of code in your application. With IOC containers you do not care about how services are created and how you get references to the ones you need. You can also easily add additional services by adding a new constructor or a setter method with little or no extra configuration.&lt;br /&gt;&lt;br /&gt;Make your application more testable by not requiring any singletons or JNDI lookup mechanisms in your unit test cases. IOC containers make unit testing and switching implementations very easy by manually allowing you to inject your own objects into the object under test.&lt;br /&gt;&lt;br /&gt;Loose coupling is promoted with minimal effort and least intrusive mechanism. The factory design pattern is more intrusive because components or services need to be requested explicitly whereas in IOC the dependency is injected into requesting piece of code. Also some containers promote the design to interfaces not to implementations design concept by encouraging managed objects to implement a well-defined service interface of your own.&lt;br /&gt;&lt;br /&gt;IOC containers support eager instantiation and lazy loading of services. Containers also provide support for instantiation of managed objects, cyclical dependencies, life cycles management, and dependency resolution between managed objects etc.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Wh= at are the advantages of Spring framework?&lt;br /&gt;The advantages of Spring are as follows: &lt;br /&gt;Spring has layered architecture. Use what you need and leave you don't need now. &lt;br /&gt;Spring Enables POJO Programming. There is no behind the scene magic here. POJO programming enables continuous integration and testability. &lt;br /&gt;Dependency Injection and Inversion of Control Simplifies JDBC &lt;br /&gt;Open source and no vendor lock-in. &lt;br /&gt;&lt;br /&gt;Wh= at are the different modules in Spring framework? &lt;br /&gt;The Core container module &lt;br /&gt;Application context module &lt;br /&gt;AOP module (Aspect Oriented Programming) &lt;br /&gt;JDBC abstraction and DAO module &lt;br /&gt;O/R mapping integration module (Object/Relational) &lt;br /&gt;Web module &lt;br /&gt;MVC framework module &lt;br /&gt;&lt;br /&gt;Wh= at is the structure of Spring framework? &lt;br /&gt;&lt;br /&gt;Wh= at is the Core container module? &lt;br /&gt;This module is provides the fundamental functionality of the spring framework. In this module BeanFactory is the heart of any spring-based application. The entire framework was built on the top of this module. This module makes the spring container. &lt;br /&gt;&lt;br /&gt;Wh= at is Application context module? &lt;br /&gt;The Application context module makes spring a framework. This module extends the concept of BeanFactory, providing support for internationalization (I18N) messages, application lifecycle events, and validation. This module also supplies many enterprise services such JNDI access, EJB integration, remoting, and scheduling. It also provides support to other framework. &lt;br /&gt;&lt;br /&gt;Wh= at is AOP module? &lt;br /&gt;The AOP module is used for developing aspects for our Spring-enabled application. Much of the support has been provided by the AOP Alliance in order to ensure the interoperability between Spring and other AOP frameworks. This module also introduces metadata programming to Spring. Using Spring's metadata support, we will be able to add annotations to our source code that instruct Spring on where and how to apply aspects. &lt;br /&gt;&lt;br /&gt;Wh= at is JDBC abstraction and DAO module? &lt;br /&gt;Using this module we can keep up the database code clean and simple, and prevent problems that result from a failure to close database resources. A new layer of meaningful exceptions on top of the error messages given by several database servers is bought in this module. In addition, this module uses Spring's AOP module to provide transaction management services for objects in a Spring application. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Wh= at are object/relational mapping integration module? &lt;br /&gt;Spring also supports for using of an object/relational mapping (ORM) tool over straight JDBC by providing the ORM module. Spring provide support to tie into several popular ORM frameworks, including Hibernate, JDO, and iBATIS SQL Maps. Spring's transaction management supports each of these ORM frameworks as well as JDBC. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Wh= at is web module? &lt;br /&gt;This module is built on the application context module, providing a context that is appropriate for web-based applications. This module also contains support for several web-oriented tasks such as transparently handling multipart requests for file uploads and programmatic binding of request parameters to your business objects. It also contains integration support with Jakarta Struts. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Wh= at is web module? &lt;br /&gt;Spring comes with a full-featured MVC framework for building web applications. Although Spring can easily be integrated with other MVC frameworks, such as Struts, Spring's MVC framework uses IoC to provide for a clean separation of controller logic from business objects. It also allows you to declaratively bind request parameters to your business objects. It also can take advantage of any of Spring's other services, such as I18N messaging and validation. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;= Wh= at is a BeanFactory? &lt;br /&gt;A BeanFactory is an implementation of the factory pattern that applies Inversion of Control to separate the application's configuration and dependencies from the actual application code. &lt;br /&gt;&lt;br /&gt;Wh= at is the difference between Bean Factory and Application Context ?   &lt;br /&gt;On the surface, an application context is same as a bean factory. But application context offers much more.. &lt;br /&gt;Application contexts provide a means for resolving text messages, including support for i18n of those messages. &lt;= /li&gt; &lt;br /&gt;Application contexts provide a generic way to load file resources, such as images. &lt;br /&gt;Application contexts can publish events to beans that are registered as listeners. &lt;br /&gt;Certain operations on the container or beans in the container, which have to be handled in a programmatic fashion with a bean factory, can be handled declaratively in an application context. &lt;br /&gt;ResourceLoader support: Spring's Resource interface us a flexible generic abstraction for handling low-level resources. An application context itself is a ResourceLoader, Hence provides an application with access to deployment-specific Resource instances. &lt;br /&gt;MessageSource support: The application context implements MessageSource, an interface used to obtain localized messages, with the actual implementation being pluggable &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Wh= at is AOP Alliance? &lt;br /&gt;AOP Alliance is an open-source project whose goal is to promote adoption of AOP &lt;br /&gt;and interoperability among different AOP implementations by defining a common &lt;br /&gt;set of interfaces and components. &lt;br /&gt;&lt;br /&gt;Wh= at is Spring configuration file? &lt;br /&gt;Spring configuration file is an XML file. This file contains the classes information and describes how these classes are configured and introduced to each other. &lt;br /&gt;&lt;br /&gt;Wh= at does a simple spring application contain? &lt;br /&gt;These applications are like any Java application. They are made up of several classes, each performing a specific purpose within the application. But these classes are configured and introduced to each other through an XML file. This XML file describes how to configure the classes, known as the Spring configuration file. &lt;br /&gt;&lt;br /&gt;Wh= at is XMLBeanFactory? &lt;br /&gt;BeanFactory has many implementations in Spring. But one of the most useful one is org.springframework.beans.factory.xml.XmlBeanFactory, which loads its beans based on the definitions contained in an XML file. To create an XmlBeanFactory, pass a java.io.InputStream to the constructor. The InputStream will provide the XML to the factory. For example, the following code snippet uses a java.io.FileInputStream to provide a bean definition XML file to XmlBeanFactory. &lt;br /&gt;BeanFactory factory =3D new XmlBeanFactory(new FileInputStream("beans.xml")); &lt;br /&gt;To retrieve the bean from a BeanFactory, call the getBean() method by passing the name of the bean you want to retrieve. &lt;br /&gt;MyBean myBean =3D (MyBean) factory.getBean("myBean"); &lt;br /&gt;&lt;br /&gt;Wh= at are important ApplicationContext implementations in spring framework? &lt;br /&gt;ClassPathXmlApplicationContext - This context loads a context definition from an XML file located in the class path, treating context definition files as class path resources. &lt;br /&gt;FileSystemXmlApplicationContext - This context loads a context definition from an XML file in the filesystem. &lt;br /&gt;XmlWebApplicationContext - This context loads the context definitions from an XML file contained within a web application. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Ex= plain Bean lifecycle in Spring framework? &lt;br /&gt;The spring container finds the bean's definition from the XML file and instantiates the bean. &lt;br /&gt;Using the dependency injection, spring populates all of the properties as specified in the bean definition. &lt;br /&gt;If the bean implements the BeanNameAware interface, the factory calls setBeanName() passing the bean's ID. &lt;br /&gt;If the bean implements the BeanFactoryAware interface, the factory calls setBeanFactory(), passing an instance of itself. &lt;br /&gt;If there are any BeanPostProcessors associated with the bean, their post- ProcessBeforeInitialization() methods will be called. &lt;br /&gt;If an init-method is specified for the bean, it will be called. &lt;br /&gt;Finally, if there are any BeanPostProcessors associated with the bean, their postProcessAfterInitialization() methods will be called &lt;br /&gt;&lt;br /&gt;Wh= at is bean wiring? &lt;br /&gt;Combining together beans within the Spring container is known as bean wiring or wiring. When wiring beans, you should tell the container what beans are needed and how the container should use dependency injection to tie them together. &lt;br /&gt;&lt;br /&gt;Ho= w to add a bean in spring application? &lt;br /&gt;In the bean tag the id attribute specifies the bean name and the class attribute specifies the fully qualified class name. &lt;br /&gt;&lt;br /&gt;&lt;?xml version=3D"1.0" encoding=3D"UTF-8"?&gt; &lt;br /&gt;&lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" &lt;br /&gt;"http://www.springframework.org/dtd/spring-beans.dtd"&gt; &lt;br /&gt;&lt;beans&gt; &lt;br /&gt;          &lt;bean id=3D"foo" class=3D"com.act.Foo"/&gt; &lt;br /&gt;           &lt;bean id=3D"bar" class=3D"com.act.Bar"/&gt; &lt;br /&gt;&lt;/beans&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Wh= at are singleton beans and how can you create prototype beans? &lt;br /&gt;Beans defined in spring framework are singleton beans. There is an attribute in bean tag named 'singleton' if specified true then bean becomes singleton and if set to false then the bean becomes a prototype bean. By default it is set to true. So, all the beans in spring framework are by default singleton beans. &lt;br /&gt;&lt;beans&gt; &lt;br /&gt;         &lt;bean id=3D"bar" class=3D"com.act.Foo" singleton=3D"false"/&gt; &lt;br /&gt;&lt;/beans&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Wh= at are the important beans lifecycle methods? &lt;br /&gt;There are two important bean lifecycle methods. The first one is setup which is called when the bean is loaded in to the container. The second method is the teardown method which is called when the bean is unloaded from the container. &lt;br /&gt;&lt;br /&gt;Ho= w can you override beans default lifecycle methods? &lt;br /&gt;The bean tag has two more important attributes with which you can define your own custom initialization and destroy methods. Here I have shown a small demonstration. Two new methods fooSetup and fooTeardown are to be added to your Foo class. &lt;br /&gt;&lt;beans&gt; &lt;br /&gt;      &lt;bean id=3D"bar" class=3D"com.act.Foo"= init-method=3D"fooSetup" destroy=3D"fooTeardown"/&gt; &lt;br /&gt;&lt;/beans&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Wh= at are Inner Beans? &lt;br /&gt;When wiring beans, if a bean element is embedded to a property tag directly, then that bean is said to the Inner Bean. The drawback of this bean is that it cannot be reused anywhere else. &lt;br /&gt;&lt;br /&gt;Wh= at is DelegatingVariableResolver?&lt;br /&gt;Spring provides a custom JavaServer Faces VariableResolver implementation that extends the standard Java Server Faces managed beans mechanism which lets you use JSF and Spring together. This variable resolver is called as DelegatingVariableResolver&lt;br /&gt;setValues(PreparedStatement ps, int i) throws SQLException;&lt;br /&gt;&lt;br /&gt;int getBatchSize();&lt;br /&gt;&lt;br /&gt;The getBatchSize() tells the JdbcTemplate class how many statements to create. And this also determines how many times setValues() will be called. &lt;br /&gt;&lt;br /&gt;Ex= plain about RowCallbackHandler and why it is used? &lt;br /&gt;In order to navigate through the records we generally go for ResultSet. But spring provides an interface that handles this entire burden and leaves the user to decide what to do with each row. The interface provided by spring is RowCallbackHandler. There is a method processRow() which needs to be implemented so that it is applicable for each and everyrow. &lt;br /&gt;&lt;br /&gt;void processRow(java.sql.ResultSet rs);&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8955336342891215397-1057231070592409236?l=javaimpquestions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaimpquestions.blogspot.com/feeds/1057231070592409236/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8955336342891215397&amp;postID=1057231070592409236' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8955336342891215397/posts/default/1057231070592409236'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8955336342891215397/posts/default/1057231070592409236'/><link rel='alternate' type='text/html' href='http://javaimpquestions.blogspot.com/2008/08/spring-imp-questions.html' title='Spring Imp Questions'/><author><name>Naresh Namana</name><uri>http://www.blogger.com/profile/05755392141578528676</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8955336342891215397.post-5313915054379282889</id><published>2008-08-13T01:01:00.000-07:00</published><updated>2011-03-18T22:54:55.577-07:00</updated><title type='text'>Spring Imp Questions</title><content type='html'>Spring Framework Interview Questions&lt;br /&gt;What is Spring?&lt;br /&gt;Spring is a lightweight inversion of control and aspect-oriented container framework. &lt;br /&gt;&lt;br /&gt;Ex= plain Spring? &lt;br /&gt;Lightweight - spring is lightweight when it comes to size and transparency. The basic version of spring framework is around 1MB. And the processing overhead is also very negligible. &lt;br /&gt;Inversion of control (IoC) - Loose coupling is achieved in spring using the technique Inversion of Control. The objects give their dependencies instead of creating or looking for dependent objects. &lt;br /&gt;= &lt;br /&gt;Aspect oriented (AOP) - Spring supports Aspect oriented programming and enables cohesive development by separating application business logic from system services. &lt;br /&gt;Container - Spring contains and manages the life cycle and configuration of application objects. &lt;br /&gt;Framework - Spring provides most of the intra functionality leaving rest of the coding to the developer. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Wh= at is IOC (or Dependency Injection)?&lt;br /&gt;The basic concept of the Inversion of Control pattern (also known as dependency injection) is that you do not create your objects but describe how they should be created. You don't directly connect your components and services together in code but describe which services are needed by which components in a configuration file. A container (in the case of the Spring framework, the IOC container) is then responsible for hooking it all up.&lt;br /&gt;&lt;br /&gt;i.e., Applying IoC, objects are given their dependencies at creation time by some external entity that coordinates each object in the system. That is, dependencies are injected into objects. So, IoC means an inversion of responsibility with regard to how an object obtains references to collaborating objects. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Wh= at are the different types of IOC (dependency injection) ? &lt;br /&gt;There are three types of dependency injection: &lt;br /&gt;Constructor Injection (e.g. Pico container, Spring etc): Dependencies are provided as constructor parameters. &lt;br /&gt;Setter Injection (e.g. Spring): Dependencies are assigned through JavaBeans properties (ex: setter methods). &lt;br /&gt;Interface Injection (e.g. Avalon): Injection is done through an interface. &lt;br /&gt;&lt;br /&gt;Note: Spring supports only Constructor and Setter Injection&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Wh= at are the benefits of IOC (Dependency Injection)?&lt;br /&gt;Benefits of IOC (Dependency Injection) are as follows:&lt;br /&gt;&lt;br /&gt;Minimizes the amount of code in your application. With IOC containers you do not care about how services are created and how you get references to the ones you need. You can also easily add additional services by adding a new constructor or a setter method with little or no extra configuration.&lt;br /&gt;&lt;br /&gt;Make your application more testable by not requiring any singletons or JNDI lookup mechanisms in your unit test cases. IOC containers make unit testing and switching implementations very easy by manually allowing you to inject your own objects into the object under test.&lt;br /&gt;&lt;br /&gt;Loose coupling is promoted with minimal effort and least intrusive mechanism. The factory design pattern is more intrusive because components or services need to be requested explicitly whereas in IOC the dependency is injected into requesting piece of code. Also some containers promote the design to interfaces not to implementations design concept by encouraging managed objects to implement a well-defined service interface of your own.&lt;br /&gt;&lt;br /&gt;IOC containers support eager instantiation and lazy loading of services. Containers also provide support for instantiation of managed objects, cyclical dependencies, life cycles management, and dependency resolution between managed objects etc.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Wh= at are the advantages of Spring framework?&lt;br /&gt;The advantages of Spring are as follows: &lt;br /&gt;Spring has layered architecture. Use what you need and leave you don't need now. &lt;br /&gt;Spring Enables POJO Programming. There is no behind the scene magic here. POJO programming enables continuous integration and testability. &lt;br /&gt;Dependency Injection and Inversion of Control Simplifies JDBC &lt;br /&gt;Open source and no vendor lock-in. &lt;br /&gt;&lt;br /&gt;Wh= at are the different modules in Spring framework? &lt;br /&gt;The Core container module &lt;br /&gt;Application context module &lt;br /&gt;AOP module (Aspect Oriented Programming) &lt;br /&gt;JDBC abstraction and DAO module &lt;br /&gt;O/R mapping integration module (Object/Relational) &lt;br /&gt;Web module &lt;br /&gt;MVC framework module &lt;br /&gt;&lt;br /&gt;Wh= at is the structure of Spring framework? &lt;br /&gt;&lt;br /&gt;Wh= at is the Core container module? &lt;br /&gt;This module is provides the fundamental functionality of the spring framework. In this module BeanFactory is the heart of any spring-based application. The entire framework was built on the top of this module. This module makes the spring container. &lt;br /&gt;&lt;br /&gt;Wh= at is Application context module? &lt;br /&gt;The Application context module makes spring a framework. This module extends the concept of BeanFactory, providing support for internationalization (I18N) messages, application lifecycle events, and validation. This module also supplies many enterprise services such JNDI access, EJB integration, remoting, and scheduling. It also provides support to other framework. &lt;br /&gt;&lt;br /&gt;Wh= at is AOP module? &lt;br /&gt;The AOP module is used for developing aspects for our Spring-enabled application. Much of the support has been provided by the AOP Alliance in order to ensure the interoperability between Spring and other AOP frameworks. This module also introduces metadata programming to Spring. Using Spring's metadata support, we will be able to add annotations to our source code that instruct Spring on where and how to apply aspects. &lt;br /&gt;&lt;br /&gt;Wh= at is JDBC abstraction and DAO module? &lt;br /&gt;Using this module we can keep up the database code clean and simple, and prevent problems that result from a failure to close database resources. A new layer of meaningful exceptions on top of the error messages given by several database servers is bought in this module. In addition, this module uses Spring's AOP module to provide transaction management services for objects in a Spring application. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Wh= at are object/relational mapping integration module? &lt;br /&gt;Spring also supports for using of an object/relational mapping (ORM) tool over straight JDBC by providing the ORM module. Spring provide support to tie into several popular ORM frameworks, including Hibernate, JDO, and iBATIS SQL Maps. Spring's transaction management supports each of these ORM frameworks as well as JDBC. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Wh= at is web module? &lt;br /&gt;This module is built on the application context module, providing a context that is appropriate for web-based applications. This module also contains support for several web-oriented tasks such as transparently handling multipart requests for file uploads and programmatic binding of request parameters to your business objects. It also contains integration support with Jakarta Struts. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Wh= at is web module? &lt;br /&gt;Spring comes with a full-featured MVC framework for building web applications. Although Spring can easily be integrated with other MVC frameworks, such as Struts, Spring's MVC framework uses IoC to provide for a clean separation of controller logic from business objects. It also allows you to declaratively bind request parameters to your business objects. It also can take advantage of any of Spring's other services, such as I18N messaging and validation. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;= Wh= at is a BeanFactory? &lt;br /&gt;A BeanFactory is an implementation of the factory pattern that applies Inversion of Control to separate the application's configuration and dependencies from the actual application code. &lt;br /&gt;&lt;br /&gt;Wh= at is the difference between Bean Factory and Application Context ?   &lt;br /&gt;On the surface, an application context is same as a bean factory. But application context offers much more.. &lt;br /&gt;Application contexts provide a means for resolving text messages, including support for i18n of those messages. &lt;= /li&gt; &lt;br /&gt;Application contexts provide a generic way to load file resources, such as images. &lt;br /&gt;Application contexts can publish events to beans that are registered as listeners. &lt;br /&gt;Certain operations on the container or beans in the container, which have to be handled in a programmatic fashion with a bean factory, can be handled declaratively in an application context. &lt;br /&gt;ResourceLoader support: Spring's Resource interface us a flexible generic abstraction for handling low-level resources. An application context itself is a ResourceLoader, Hence provides an application with access to deployment-specific Resource instances. &lt;br /&gt;MessageSource support: The application context implements MessageSource, an interface used to obtain localized messages, with the actual implementation being pluggable &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Wh= at is AOP Alliance? &lt;br /&gt;AOP Alliance is an open-source project whose goal is to promote adoption of AOP &lt;br /&gt;and interoperability among different AOP implementations by defining a common &lt;br /&gt;set of interfaces and components. &lt;br /&gt;&lt;br /&gt;Wh= at is Spring configuration file? &lt;br /&gt;Spring configuration file is an XML file. This file contains the classes information and describes how these classes are configured and introduced to each other. &lt;br /&gt;&lt;br /&gt;Wh= at does a simple spring application contain? &lt;br /&gt;These applications are like any Java application. They are made up of several classes, each performing a specific purpose within the application. But these classes are configured and introduced to each other through an XML file. This XML file describes how to configure the classes, known as the Spring configuration file. &lt;br /&gt;&lt;br /&gt;Wh= at is XMLBeanFactory? &lt;br /&gt;BeanFactory has many implementations in Spring. But one of the most useful one is org.springframework.beans.factory.xml.XmlBeanFactory, which loads its beans based on the definitions contained in an XML file. To create an XmlBeanFactory, pass a java.io.InputStream to the constructor. The InputStream will provide the XML to the factory. For example, the following code snippet uses a java.io.FileInputStream to provide a bean definition XML file to XmlBeanFactory. &lt;br /&gt;BeanFactory factory =3D new XmlBeanFactory(new FileInputStream("beans.xml")); &lt;br /&gt;To retrieve the bean from a BeanFactory, call the getBean() method by passing the name of the bean you want to retrieve. &lt;br /&gt;MyBean myBean =3D (MyBean) factory.getBean("myBean"); &lt;br /&gt;&lt;br /&gt;Wh= at are important ApplicationContext implementations in spring framework? &lt;br /&gt;ClassPathXmlApplicationContext - This context loads a context definition from an XML file located in the class path, treating context definition files as class path resources. &lt;br /&gt;FileSystemXmlApplicationContext - This context loads a context definition from an XML file in the filesystem. &lt;br /&gt;XmlWebApplicationContext - This context loads the context definitions from an XML file contained within a web application. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Ex= plain Bean lifecycle in Spring framework? &lt;br /&gt;The spring container finds the bean's definition from the XML file and instantiates the bean. &lt;br /&gt;Using the dependency injection, spring populates all of the properties as specified in the bean definition. &lt;br /&gt;If the bean implements the BeanNameAware interface, the factory calls setBeanName() passing the bean's ID. &lt;br /&gt;If the bean implements the BeanFactoryAware interface, the factory calls setBeanFactory(), passing an instance of itself. &lt;br /&gt;If there are any BeanPostProcessors associated with the bean, their post- ProcessBeforeInitialization() methods will be called. &lt;br /&gt;If an init-method is specified for the bean, it will be called. &lt;br /&gt;Finally, if there are any BeanPostProcessors associated with the bean, their postProcessAfterInitialization() methods will be called &lt;br /&gt;&lt;br /&gt;Wh= at is bean wiring? &lt;br /&gt;Combining together beans within the Spring container is known as bean wiring or wiring. When wiring beans, you should tell the container what beans are needed and how the container should use dependency injection to tie them together. &lt;br /&gt;&lt;br /&gt;Ho= w to add a bean in spring application? &lt;br /&gt;In the bean tag the id attribute specifies the bean name and the class attribute specifies the fully qualified class name. &lt;br /&gt;&lt;br /&gt;&lt;?xml version=3D"1.0" encoding=3D"UTF-8"?&gt; &lt;br /&gt;&lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" &lt;br /&gt;"http://www.springframework.org/dtd/spring-beans.dtd"&gt; &lt;br /&gt;&lt;beans&gt; &lt;br /&gt;          &lt;bean id=3D"foo" class=3D"com.act.Foo"/&gt; &lt;br /&gt;           &lt;bean id=3D"bar" class=3D"com.act.Bar"/&gt; &lt;br /&gt;&lt;/beans&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Wh= at are singleton beans and how can you create prototype beans? &lt;br /&gt;Beans defined in spring framework are singleton beans. There is an attribute in bean tag named 'singleton' if specified true then bean becomes singleton and if set to false then the bean becomes a prototype bean. By default it is set to true. So, all the beans in spring framework are by default singleton beans. &lt;br /&gt;&lt;beans&gt; &lt;br /&gt;         &lt;bean id=3D"bar" class=3D"com.act.Foo" singleton=3D"false"/&gt; &lt;br /&gt;&lt;/beans&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Wh= at are the important beans lifecycle methods? &lt;br /&gt;There are two important bean lifecycle methods. The first one is setup which is called when the bean is loaded in to the container. The second method is the teardown method which is called when the bean is unloaded from the container. &lt;br /&gt;&lt;br /&gt;Ho= w can you override beans default lifecycle methods? &lt;br /&gt;The bean tag has two more important attributes with which you can define your own custom initialization and destroy methods. Here I have shown a small demonstration. Two new methods fooSetup and fooTeardown are to be added to your Foo class. &lt;br /&gt;&lt;beans&gt; &lt;br /&gt;      &lt;bean id=3D"bar" class=3D"com.act.Foo"= init-method=3D"fooSetup" destroy=3D"fooTeardown"/&gt; &lt;br /&gt;&lt;/beans&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Wh= at are Inner Beans? &lt;br /&gt;When wiring beans, if a bean element is embedded to a property tag directly, then that bean is said to the Inner Bean. The drawback of this bean is that it cannot be reused anywhere else. &lt;br /&gt;&lt;br /&gt;Wh= at is DelegatingVariableResolver?&lt;br /&gt;Spring provides a custom JavaServer Faces VariableResolver implementation that extends the standard Java Server Faces managed beans mechanism which lets you use JSF and Spring together. This variable resolver is called as DelegatingVariableResolver&lt;br /&gt;&lt;br /&gt;How to integrate  Java Server Faces (JSF) with Spring?&lt;br /&gt;JSF and Spring do share some of the same features, most noticeably in the area of IOC services. By declaring JSF managed-beans in the faces-config.xml configuration file, you allow the FacesServlet to instantiate that bean at startup. Your JSF pages have access to these beans and all of their properties.We can integrate JSF and Spring in two ways: &lt;br /&gt;     &lt;br /&gt;DelegatingVariableResolver: Sp= ring comes with a JSF variable resolver that lets you use JSF and Spring together. &lt;br /&gt;     &lt;?xml version=3D"1.0" encoding=3D"UTF-8"?&gt;= ;&lt;br /&gt;     &lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"&lt;br /&gt;        "http://www.springframework.org/dtd/spring-beans.dtd"&gt;&lt;br /&gt;     &lt;br /&gt;     &lt;faces-config&gt;&lt;br /&gt;        &lt;application&gt;&lt;br /&gt;           &lt;variable-resolver&gt;&lt;br /&gt;              org.springframework.web.jsf.DelegatingVariableResolver&lt;br /&gt;           &lt;/variable-resolver&gt;&lt;br /&gt;        &lt;/application&gt;&lt;br /&gt;     &lt;/faces-config&gt;&lt;br /&gt;The DelegatingVariableResolver will first delegate value lookups to the default resolver of the underlying JSF implementation, and then to Spring's 'business context' WebApplicationContext. This allows one to easily inject dependencies into one's JSF-managed beans.&lt;br /&gt;&lt;br /&gt;FacesContextUtils:custom VariableResolver works well when mapping one's properties to beans in faces-config.xml, but at times one may need to grab a bean explicitly. The FacesContextUtils class makes this easy. It is similar to WebApplicationContextUtils, except that it takes a FacesContext parameter rather than a ServletContext parameter. &lt;br /&gt;     &lt;br /&gt;     ApplicationContext ctx =3D FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstan= ce());&lt;br /&gt;     &lt;br /&gt;Wh= at is Significance of JSF- Spring integration ?&lt;br /&gt;Spring - JSF integration is useful when an event handler wishes to explicitly invoke the bean factory to create beans on demand, such as a bean that encapsulates the business logic to be performed when a submit button is pressed. &lt;br /&gt;&lt;br /&gt;Ho= w to integrate your Struts application with Spring?&lt;br /&gt;To integrate your Struts application with Spring, we have two options: &lt;br /&gt;     Configure Spring to manage your Actions as beans, using the ContextLoaderPlugin, and set their dependencies in a Spring context file. &lt;br /&gt;     Subclass Spring's ActionSupport classes and grab your Spring-managed beans explicitly using a getWebApplicationContext() method. &lt;br /&gt;&lt;br /&gt;Wh= at are the different types of bean injections? &lt;br /&gt;There are two types of bean injections. &lt;br /&gt;1.    By setter &lt;br /&gt;2.    By constructor &lt;br /&gt;&lt;br /&gt;Wh= at is Auto wiring? &lt;br /&gt;You can wire the beans as you wish. But spring framework also does this work for you. It can auto wire the related beans together. All you have to do is just set the autowire attribute of bean tag to an autowire type. &lt;br /&gt;&lt;beans&gt; &lt;br /&gt;        &lt;bean id=3D"bar" class=3D"com.act.Foo" Autowire=3D"autowire type"/&gt; &lt;br /&gt;&lt;/beans&gt; &lt;br /&gt;&lt;br /&gt;Wh= at are different types of Autowire types? &lt;br /&gt;There are four different types by which autowiring can be done. &lt;br /&gt;byName &lt;br /&gt;byType &lt;br /&gt;constructor &lt;br /&gt;autodetect &lt;br /&gt;&lt;br /&gt;Wh= at are the different types of events related to Listeners? &lt;br /&gt;There are a lot of events related to ApplicationContext of spring framework. All the events are subclasses of org.springframework.context.Application-Event. They are &lt;br /&gt;ContextClosedEvent - This is fired when the context is closed. &lt;br /&gt;ContextRefreshedEvent - This is fired when the context is initialized or refreshed. &lt;br /&gt;RequestHandledEvent - This is fired when the web context handles any request. &lt;br /&gt;&lt;br /&gt;What is an Aspect? &lt;br /&gt;An aspect is the cross-cutting functionality that you are implementing. It is the aspect of your application you are modularizing. An example of an aspect is logging. Logging is something that is required throughout an application. However, because applications tend to be broken down into layers based on functionality, reusing a logging module through inheritance does not make sense. However, you can create a logging aspect and apply it throughout your application using AOP. &lt;br /&gt;&lt;br /&gt;What is a Jointpoint? &lt;br /&gt;A joinpoint is a point in the execution of the application where an aspect can be plugged in. This point could be a method being called, an exception being thrown, or even a field being modified. These are the points where your aspect's code can be inserted into the normal flow of your application to add new behavior.&lt;br /&gt;&lt;br /&gt;What is an Advice? &lt;br /&gt;Advice is the implementation of an aspect. It is something like telling your application of a new behavior. Generally, and advice is inserted into an application at joinpoints. &lt;br /&gt;&lt;br /&gt;What is a Pointcut? &lt;br /&gt;A pointcut is something that defines at what joinpoints an advice should be applied. Advices can be applied at any joinpoint that is supported by the AOP framework. These Pointcuts allow you to specify where the advice can be applied. &lt;br /&gt;&lt;br /&gt;What is an Introduction in AOP? &lt;br /&gt;An introduction allows the user to add new methods or attributes to an existing class. This can then be introduced to an existing class without having to change the structure of the class, but give them the new behavior and state. &lt;br /&gt;&lt;br /&gt;What is a Target? &lt;br /&gt;A target is the class that is being advised. The class can be a third party class or your own class to which you want to add your own custom behavior. By using the concepts of AOP, the target class is free to center on its major concern, unaware to any advice that is being applied. &lt;br /&gt;&lt;br /&gt;What is a Proxy? &lt;br /&gt;A proxy is an object that is created after applying advice to a target object. When you think of client objects the target object and the proxy object are the same. &lt;br /&gt; &lt;br /&gt;What is meant by Weaving? &lt;br /&gt;The process of applying aspects to a target object to create a new proxy object is called as Weaving. The aspects are woven into the target object at the specified joinpoints. &lt;br /&gt;&lt;br /&gt;What are the different points where weaving can be applied? &lt;br /&gt;Compile Time &lt;br /&gt;Classload Time &lt;br /&gt;Runtime&lt;br /&gt;&lt;br /&gt;What are the different advice types in spring? &lt;br /&gt;Around : Intercepts the calls to the target method &lt;br /&gt;Before : This is called before the target method is invoked &lt;br /&gt;After : This is called after the target method is returned &lt;br /&gt;Throws : This is called when the target method throws and exception&lt;br /&gt;Around : org.aopalliance.intercept.MethodInterceptor &lt;br /&gt;Before : org.springframework.aop.BeforeAdvice &lt;br /&gt;After : org.springframework.aop.AfterReturningAdvice &lt;br /&gt;Throws : org.springframework.aop.ThrowsAdvice &lt;br /&gt;&lt;br /&gt;What are the different types of AutoProxying? &lt;br /&gt;BeanNameAutoProxyCreator &lt;br /&gt;DefaultAdvisorAutoProxyCreator &lt;br /&gt;Metadata autoproxying &lt;br /&gt;&lt;br /&gt;What is the Exception class related to all the exceptions that are thrown in spring applications? &lt;br /&gt;DataAccessException - org.springframework.dao.DataAccessException &lt;br /&gt;&lt;br /&gt;What kind of exceptions those spring DAO classes throw? &lt;br /&gt;The spring's DAO class does not throw any technology related exceptions such as SQLException. They throw exceptions which are subclasses of DataAccessException. &lt;br /&gt;&lt;br /&gt;What is DataAccessException? &lt;br /&gt;DataAccessException is a RuntimeException. This is an Unchecked Exception. The user is not forced to handle these kinds of exceptions. &lt;br /&gt;&lt;br /&gt;How can you configure a bean to get DataSource from JNDI? &lt;br /&gt;&lt;bean id=3D"dataSource" class=3D"org.springframework.jndi.JndiObjectFactoryBean"&gt;&lt;br /&gt;     &lt;property name=3D"jndiName"&gt;       &lt;value&gt;java:comp/env/jdbc/myDatasource&lt;/value&gt;&lt;br /&gt;  &lt;/property&gt;&lt;br /&gt;&lt;/bean&gt;&lt;br /&gt;&lt;br /&gt;How can you create a DataSource connection pool? &lt;br /&gt;&lt;bean id=3D"dataSource" class=3D"org.apache.commons.dbcp.BasicDataSource"&gt;&lt;br /&gt;       &lt;property name=3D"driver"&gt;             =    &lt;value&gt;${db.driver}&lt;/value&gt;&lt;br /&gt;       &lt;/property&gt;&lt;br /&gt;       &lt;property name=3D"url"&gt;&lt;br /&gt;            =   &lt;value&gt;${db.url}&lt;/value&gt;&lt;br /&gt;       &lt;/property&gt;&lt;br /&gt;       &lt;property name=3D"username"&gt;&lt;= br&gt;             = &lt;value&gt;${db.username}&lt;/value&gt;&lt;br /&gt;       &lt;/property&gt;&lt;br /&gt;       &lt;property name=3D"password"&gt;&lt;= br&gt;             &lt;value&gt;${db.password}&lt;/value&gt;&lt;br /&gt;       &lt;/property&gt;&lt;br /&gt;&lt;/bean&gt; &lt;br /&gt;&lt;br /&gt;How JDBC can be used more efficiently in spring framework? &lt;br /&gt;JDBC can be used more efficiently with the help of a template class provided by spring framework called as JdbcTemplate. &lt;br /&gt;&lt;br /&gt;How JdbcTemplate can be used? &lt;br /&gt;With use of Spring JDBC framework the burden of resource management and error handling is reduced a lot. So it leaves developers to write the statements and queries to get the data to and from the database. &lt;br /&gt;&lt;br /&gt;JdbcTemplate template =3D new JdbcTemplate(myDataSource); &lt;br /&gt;&lt;br /&gt;A simple DAO class looks like this. &lt;br /&gt;&lt;br /&gt;public class StudentDaoJdbc implements StudentDao {&lt;br /&gt;          private JdbcTemplate jdbcTemplate;&lt;br /&gt;&lt;br /&gt;     public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {&lt;br /&gt;          this.jdbcTemplate =3D jdbcTemplate;&lt;br /&gt;     }&lt;br /&gt;     more..&lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;The configuration is shown below. &lt;br /&gt;&lt;br /&gt;&lt;bean id=3D"jdbcTemplate" class=3D"org.springframework.jdbc.core.JdbcTemplate"&gt;&lt;br /&gt;       &lt;property name=3D"dataSource"&gt;= ;&lt;br /&gt;       &lt;ref bean=3D"dataSource"/&gt;    &lt;/property&gt;&lt;br /&gt;&lt;/bean&gt;&lt;br /&gt;&lt;bean id=3D"studentDao" class=3D"StudentDaoJdbc"&gt;&lt;br /&gt;       &lt;property name=3D"jdbcTemplate"&gt;&lt;br /&gt;        &lt;ref bean=3D"jdbcTemplate"/&gt;&lt;br /&gt;   &lt;/property&gt;&lt;br /&gt;&lt;/bean&gt; &lt;br /&gt;&lt;bean id=3D"courseDao" class=3D"CourseDaoJdbc"&gt;&lt;br /&gt;        &lt;property name=3D"jdbcTemplate"&gt;&lt;br /&gt;       &lt;ref bean=3D"jdbcTemplate"/&gt;&lt;= br&gt;    &lt;/property&gt;&lt;br /&gt;&lt;/bean&gt;&lt;br /&gt;&lt;br /&gt;How do you write data to backend in spring using JdbcTemplate? &lt;br /&gt;The JdbcTemplate uses several of these callbacks when writing data to the database. The usefulness you will find in each of these interfaces will vary. There are two simple interfaces. One is PreparedStatementCreator and the other interface is BatchPreparedStatementSetter. &lt;br /&gt;&lt;br /&gt;Explain about PreparedStatementCreator? &lt;br /&gt;PreparedStatementCreator is one of the most common used interfaces for writing data to database. The interface has one method createPreparedStatement(). &lt;br /&gt;&lt;br /&gt;PreparedStatement createPreparedStatement(Connection conn)&lt;br /&gt;throws SQLException; &lt;br /&gt;&lt;br /&gt;When this interface is implemented, we should create and return a PreparedStatement from the Connection argument, and the exception handling is automatically taken care off. When this interface is implemented, another interface SqlProvider is also implemented which has a method called getSql() which is used to provide sql strings to JdbcTemplate. &lt;br /&gt;&lt;br /&gt;Ex= plain about BatchPreparedStatementSetter? &lt;br /&gt;If the user what to update more than one row at a shot then he can go for BatchPreparedStatementSetter. This interface provides two methods &lt;br /&gt;&lt;br /&gt;setValues(PreparedStatement ps, int i) throws SQLException;&lt;br /&gt;&lt;br /&gt;int getBatchSize();&lt;br /&gt;&lt;br /&gt;The getBatchSize() tells the JdbcTemplate class how many statements to create. And this also determines how many times setValues() will be called. &lt;br /&gt;&lt;br /&gt;Explain about RowCallbackHandler and why it is used? &lt;br /&gt;In order to navigate through the records we generally go for ResultSet. But spring provides an interface that handles this entire burden and leaves the user to decide what to do with each row. The interface provided by spring is RowCallbackHandler. There is a method processRow() which needs to be implemented so that it is applicable for each and everyrow. &lt;br /&gt;&lt;br /&gt;void processRow(java.sql.ResultSet rs);&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8955336342891215397-5313915054379282889?l=javaimpquestions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaimpquestions.blogspot.com/feeds/5313915054379282889/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8955336342891215397&amp;postID=5313915054379282889' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8955336342891215397/posts/default/5313915054379282889'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8955336342891215397/posts/default/5313915054379282889'/><link rel='alternate' type='text/html' href='http://javaimpquestions.blogspot.com/2008/08/spring-imp-questions_13.html' title='Spring Imp Questions'/><author><name>Naresh Namana</name><uri>http://www.blogger.com/profile/05755392141578528676</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8955336342891215397.post-4800476772882245902</id><published>2008-08-13T00:44:00.000-07:00</published><updated>2011-03-18T22:54:49.075-07:00</updated><title type='text'>Ejb Imp Questions</title><content type='html'>&lt;script type="text/javascript"&gt;&lt;br /&gt;var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");&lt;br /&gt;document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;br /&gt;try {&lt;br /&gt;var pageTracker = _gat._getTracker("UA-9255840-1");&lt;br /&gt;pageTracker._trackPageview();&lt;br /&gt;} catch(err) {}&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Is is possible for an EJB client to marshal an object of class java.lang.Class to an EJB? - Technically yes, spec. compliant NO! - The enterprise bean must not attempt to query a class to obtain information about the declared members that are not otherwise accessible to the enterprise bean because of the security rules of the Java language.&lt;br /&gt;Is it legal to have static initializer blocks in EJB? - Although technically it is legal, static initializer blocks are used to execute some piece of code before executing any constructor or method while instantiating a class. Static initializer blocks are also typically used to initialize static fields - which may be illegal in EJB if they are read/write - In EJB this can be achieved by including the code in either the ejbCreate(), setSessionContext() or setEntityContext() methods.&lt;br /&gt;&lt;br /&gt;Is it possible to stop the execution of a method before completion in a SessionBean? - Stopping the execution of a method inside a Session Bean is not possible without writing code inside the Session Bean. This is because you are not allowed to access Threads inside an EJB.&lt;br /&gt;What is the default transaction attribute for an EJB? - There is no default transaction attribute for an EJB. Section 11.5 of EJB v1.1 spec says that the deployer must specify a value for the transaction attribute for those methods having container managed transaction. In WebLogic, the default transaction attribute for EJB is SUPPORTS.&lt;br /&gt;What is the difference between session and entity beans? When should I use one or the other? - An entity bean represents persistent global data from the database; a session bean represents transient user-specific data that will die when the user disconnects (ends his session). Generally, the session beans implement business methods (e.g. Bank.transferFunds) that call entity beans (e.g. Account.deposit, Account.withdraw)&lt;br /&gt;Is there any default cache management system with Entity beans ? In other words whether a cache of the data in database will be maintained in EJB ? - Caching data from a database inside the Application Server are what Entity EJB’s are used for.The ejbLoad() and ejbStore() methods are used to synchronize the Entity Bean state with the persistent storage(database). Transactions also play an important role in this scenario. If data is removed from the database, via an external application - your Entity Bean can still be “alive” the EJB container. When the transaction commits, ejbStore() is called and the row will not be found, and the transaction rolled back.&lt;br /&gt;Why is ejbFindByPrimaryKey mandatory? - An Entity Bean represents persistent data that is stored outside of the EJB Container/Server. The ejbFindByPrimaryKey is a method used to locate and load an Entity Bean into the container, similar to a SELECT statement in SQL. By making this method mandatory, the client programmer can be assured that if they have the primary key of the Entity Bean, then they can retrieve the bean without having to create a new bean each time - which would mean creating duplications of persistent data and break the integrity of EJB.&lt;br /&gt;Why do we have a remove method in both EJBHome and EJBObject? - With the EJBHome version of the remove, you are able to delete an entity bean without first instantiating it (you can provide a PrimaryKey object as a parameter to the remove method). The home version only works for entity beans. On the other hand, the Remote interface version works on an entity bean that you have already instantiated. In addition, the remote version also works on session beans (stateless and stateful) to inform the container of your loss of interest in this bean.&lt;br /&gt;How can I call one EJB from inside of another EJB? - EJBs can be clients of other EJBs. It just works. Use JNDI to locate the Home Interface of the other bean, then acquire an instance reference, and so forth.&lt;br /&gt;What is the difference between a Server, a Container, and a Connector? - An EJB server is an application, usually a product such as BEA WebLogic, that provides (or should provide) for concurrent client connections and manages system resources such as threads, processes, memory, database connections, network connections, etc. An EJB container runs inside (or within) an EJB server, and provides deployed EJB beans with transaction and security management, etc. The EJB container insulates an EJB bean from the specifics of an underlying EJB server by providing a simple, standard API between the EJB bean and its container. A Connector provides the ability for any Enterprise Information System (EIS) to plug into any EJB server which supports the Connector architecture. See Sun’s J2EE Connectors for more in-depth information on Connectors.&lt;br /&gt;How is persistence implemented in enterprise beans? - Persistence in EJB is taken care of in two ways, depending on how you implement your beans: container managed persistence (CMP) or bean managed persistence (BMP) For CMP, the EJB container which your beans run under takes care of the persistence of the fields you have declared to be persisted with the database - this declaration is in the deployment descriptor. So, anytime you modify a field in a CMP bean, as soon as the method you have executed is finished, the new data is persisted to the database by the container. For BMP, the EJB bean developer is responsible for defining the persistence routines in the proper places in the bean, for instance, the ejbCreate(), ejbStore(), ejbRemove() methods would be developed by the bean developer to make calls to the database. The container is responsible, in BMP, to call the appropriate method on the bean. So, if the bean is being looked up, when the create() method is called on the Home interface, then the container is responsible for calling the ejbCreate() method in the bean, which should have functionality inside for going to the database and looking up the data.&lt;br /&gt;What is an EJB Context? - EJBContext is an interface that is implemented by the container, and it is also a part of the bean-container contract. Entity beans use a subclass of EJBContext called EntityContext. Session beans use a subclass called SessionContext. These EJBContext objects provide the bean class with information about its container, the client using the bean and the bean itself. They also provide other functions. See the API docs and the spec for more details.&lt;br /&gt;Is method overloading allowed in EJB? - Yes you can overload methods&lt;br /&gt;Should synchronization primitives be used on bean methods? - No. The EJB specification specifically states that the enterprise bean is not allowed to use thread primitives. The container is responsible for managing concurrent access to beans at runtime.&lt;br /&gt;Are we allowed to change the transaction isolation property in middle of a transaction? - No. You cannot change the transaction isolation level in the middle of transaction.&lt;br /&gt;For Entity Beans, What happens to an instance field not mapped to any persistent storage, when the bean is passivated? - The specification infers that the container never serializes an instance of an Entity bean (unlike stateful session beans). Thus passivation simply involves moving the bean from the “ready” to the “pooled” bin. So what happens to the contents of an instance variable is controlled by the programmer. Remember that when an entity bean is passivated the instance gets logically disassociated from it’s remote object. Be careful here, as the functionality of passivation/activation for Stateless Session, Stateful Session and Entity beans is completely different. For entity beans the ejbPassivate method notifies the entity bean that it is being disassociated with a particular entity prior to reuse or for dereference.&lt;br /&gt;What is a Message Driven Bean, what functions does a message driven bean have and how do they work in collaboration with JMS? - Message driven beans are the latest addition to the family of component bean types defined by the EJB specification. The original bean types include session beans, which contain business logic and maintain a state associated with client sessions, and entity beans, which map objects to persistent data. Message driven beans will provide asynchrony to EJB based applications by acting as JMS message consumers. A message bean is associated with a JMS topic or queue and receives JMS messages sent by EJB clients or other beans. Unlike entity beans and session beans, message beans do not have home or remote interfaces. Instead, message driven beans are instantiated by the container as required. Like stateless session beans, message beans maintain no client-specific state, allowing the container to optimally manage a pool of message-bean instances. Clients send JMS messages to message beans in exactly the same manner as they would send messages to any other JMS destination. This similarity is a fundamental design goal of the JMS capabilities of the new specification. To receive JMS messages, message driven beans implement the javax.jms.MessageListener interface, which defines a single “onMessage()” method. When a message arrives, the container ensures that a message bean corresponding to the message topic/queue exists (instantiating it if necessary), and calls its onMessage method passing the client’s message as the single argument. The message bean’s implementation of this method contains the business logic required to process the message. Note that session beans and entity beans are not allowed to function as message beans.&lt;br /&gt;Does RMI-IIOP support code downloading for Java objects sent by value across an IIOP connection in the same way as RMI does across a JRMP connection? - Yes. The JDK 1.2 support the dynamic class loading.&lt;br /&gt;The EJB container implements the EJBHome and EJBObject classes. For every request from a unique client, does the container create a separate instance of the generated EJBHome and EJBObject classes? - The EJB container maintains an instance pool. The container uses these instances for the EJB Home reference irrespective of the client request. while refering the EJB Object classes the container creates a separate instance for each client request. The instance pool maintainence is up to the implementation of the container. If the container provides one, it is available otherwise it is not mandatory for the provider to implement it. Having said that, yes most of the container providers implement the pooling functionality to increase the performance of the application server. The way it is implemented is again up to the implementer.&lt;br /&gt;What is the advantage of putting an Entity Bean instance from the “Ready State” to “Pooled state”? - The idea of the “Pooled State” is to allow a container to maintain a pool of entity beans that has been created, but has not been yet “synchronized” or assigned to an EJBObject. This mean that the instances do represent entity beans, but they can be used only for serving Home methods (create or findBy), since those methods do not relay on the specific values of the bean. All these instances are, in fact, exactly the same, so, they do not have meaningful state. Jon Thorarinsson has also added: It can be looked at it this way: If no client is using an entity bean of a particular type there is no need for cachig it (the data is persisted in the database). Therefore, in such cases, the container will, after some time, move the entity bean from the “Ready State” to the “Pooled state” to save memory. Then, to save additional memory, the container may begin moving entity beans from the “Pooled State” to the “Does Not Exist State”, because even though the bean’s cache has been cleared, the bean still takes up some memory just being in the “Pooled State”.&lt;br /&gt;Can a Session Bean be defined without ejbCreate() method? - The ejbCreate() methods is part of the bean’s lifecycle, so, the compiler will not return an error because there is no ejbCreate() method. However, the J2EE spec is explicit: the home interface of a Stateless Session Bean must have a single create() method with no arguments, while the session bean class must contain exactly one ejbCreate() method, also without arguments. Stateful Session Beans can have arguments (more than one create method) stateful beans can contain multiple ejbCreate() as long as they match with the home interface definition. You need a reference to your EJBObject to startwith. For that Sun insists on putting a method for creating that reference (create method in the home interface). The EJBObject does matter here. Not the actual bean.&lt;br /&gt;Is it possible to share an HttpSession between a JSP and EJB? What happens when I change a value in the HttpSession from inside an EJB? - You can pass the HttpSession as parameter to an EJB method, only if all objects in session are serializable.This has to be consider as “passed-by-value”, that means that it’s read-only in the EJB. If anything is altered from inside the EJB, it won’t be reflected back to the HttpSession of the Servlet Container.The “pass-by-reference” can be used between EJBs Remote Interfaces, as they are remote references. While it IS possible to pass an HttpSession as a parameter to an EJB object, it is considered to be “bad practice (1)” in terms of object oriented design. This is because you are creating an unnecessary coupling between back-end objects (ejbs) and front-end objects (HttpSession). Create a higher-level of abstraction for your ejb’s api. Rather than passing the whole, fat, HttpSession (which carries with it a bunch of http semantics), create a class that acts as a value object (or structure) that holds all the data you need to pass back and forth between front-end/back-end. Consider the case where your ejb needs to support a non-http-based client. This higher level of abstraction will be flexible enough to support it. (1) Core J2EE design patterns (2001)&lt;br /&gt;Is there any way to read values from an entity bean without locking it for the rest of the transaction (e.g. read-only transactions)? We have a key-value map bean which deadlocks during some concurrent reads. Isolation levels seem to affect the database only, and we need to work within a transaction. - The only thing that comes to (my) mind is that you could write a ‘group accessor’ - a method that returns a single object containing all of your entity bean’s attributes (or all interesting attributes). This method could then be placed in a ‘Requires New’ transaction. This way, the current transaction would be suspended for the duration of the call to the entity bean and the entity bean’s fetch/operate/commit cycle will be in a separate transaction and any locks should be released immediately. Depending on the granularity of what you need to pull out of the map, the group accessor might be overkill.&lt;br /&gt;What is the difference between a “Coarse Grained” Entity Bean and a “Fine Grained” Entity Bean? - A ‘fine grained’ entity bean is pretty much directly mapped to one relational table, in third normal form. A ‘coarse grained’ entity bean is larger and more complex, either because its attributes include values or lists from other tables, or because it ‘owns’ one or more sets of dependent objects. Note that the coarse grained bean might be mapped to a single table or flat file, but that single table is going to be pretty ugly, with data copied from other tables, repeated field groups, columns that are dependent on non-key fields, etc. Fine grained entities are generally considered a liability in large systems because they will tend to increase the load on several of the EJB server’s subsystems (there will be more objects exported through the distribution layer, more objects participating in transactions, more skeletons in memory, more EJB Objects in memory, etc.) &lt;br /&gt;What is EJBDoclet? - EJBDoclet is an open source JavaDoc doclet that generates a lot of the EJB related source files from custom JavaDoc comments tags embedded in the EJB source file.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8955336342891215397-4800476772882245902?l=javaimpquestions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaimpquestions.blogspot.com/feeds/4800476772882245902/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8955336342891215397&amp;postID=4800476772882245902' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8955336342891215397/posts/default/4800476772882245902'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8955336342891215397/posts/default/4800476772882245902'/><link rel='alternate' type='text/html' href='http://javaimpquestions.blogspot.com/2008/08/ejb-imp-questions.html' title='Ejb Imp Questions'/><author><name>Naresh Namana</name><uri>http://www.blogger.com/profile/05755392141578528676</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8955336342891215397.post-3890336703152939450</id><published>2008-08-13T00:03:00.000-07:00</published><updated>2011-03-18T22:54:49.085-07:00</updated><title type='text'>Rmi Important Questions</title><content type='html'>&lt;script type="text/javascript"&gt;&lt;br /&gt;var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");&lt;br /&gt;document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;br /&gt;try {&lt;br /&gt;var pageTracker = _gat._getTracker("UA-9255840-1");&lt;br /&gt;pageTracker._trackPageview();&lt;br /&gt;} catch(err) {}&lt;/script&gt;&lt;br /&gt;Explain RMI Architecture?&lt;br /&gt;RMI uses a layered architecture, each of the layers could be enhanced or replaced without affecting the rest of the system. The details of layers can be summarised as follows:&lt;= br&gt; Application Layer: The client and server program &lt;br /&gt;Stub &amp; Skeleton Layer: Intercepts method calls made by the client/redirects these calls to a remote RMI service. &lt;br /&gt;Remote Reference Layer: Understands how to interpret and manage references made from clients to the remote service objects. &lt;br /&gt;Transport layer: Based on TCP/IP connections between machines in a network. It provides basic connectivity, as well as some firewall penetration strategies. &lt;br /&gt;&lt;br /&gt;Explain about RMI and it's usage &lt;br /&gt;RMI is one of the distributed computing technology alternative powered by Java . RMI stands for Remote Method Invocation ,to keep it simple it means accessing a service from different node ( i.e., accessing a service provided by an object on server machine , here an object in client JVM talks with object in the server JVM ). Java provides an API and base some classes (  in package java.rmi  ) to perform these kind of operations . &lt;br /&gt;We basically use this methodology when we need to publish an object at server side which exposes set of services ( as methods in Object oriented programming terminology ) and where in one or more clients access these services from remote machines. By this we are distibuting a common code in two different JVM's and we are able to access the code on different JVM.&lt;br /&gt;&lt;br /&gt;How do RMI clients contact remote RMI servers? &lt;br /&gt;For an RMI client to contact a remote RMI server, the client must first hold a reference to the server. The Naming.lookup method call is the most common mechanism by which clients initially obtain references to remote servers. Remote references may be obtained by other means, for example: all remote method calls can return remote references. This is what Naming.lookup does; it uses a well-known stub to make a remote method call to the rmiregistry, which sends back the remote reference to the object requested by the lookup method. &lt;br /&gt;Every remote reference contains a server hostname and port number that allow clients to locate the VM that is serving a particular remote object. Once an RMI client has a remote reference, the client will use the hostname and port provided in the reference to open a socket connection to the remote server. &lt;br /&gt;Please note that with RMI the terms client and server can refer to the same program. A Java program that acts as an RMI server contains an exported remote object. An RMI client is a program that invokes one or more methods on a remote object in another virtual machine. If a VM performs both of these functions, it may be referred to as an RMI client and an RMI server. &lt;br /&gt;&lt;br /&gt;Why do I get the exception "java.net.SocketException: Address already in use" when I try to run the registry? &lt;br /&gt;This exception means that the port that the RegistryImpl uses (by default 1099) is already in use. You may have another registry running on your machine and will need to stop it. &lt;br /&gt;&lt;br /&gt;How can I make outgoing RMI calls through a local firewall? &lt;br /&gt;There are three main methods: HTTP tunnelling, SOCKS, and downloaded socket factories. &lt;br /&gt;HTTP tunnelling&lt;br /&gt;This well-worn method is popular since it requires almost no setup, and works quite well in firewalled environments which permit you to handle HTTP through a proxy, but disallow regular outbound TCP connections. If RMI fails to make a normal (or SOCKS) connection to the intended server, and it notices that a HTTP proxy server is configured, it will attempt to tunnel RMI requests through that proxy server, one at a time. &lt;br /&gt;There are two forms of HTTP tunnelling, tried in order. The first is http-to-port; the second is http-to-cgi. &lt;br /&gt;In http-to-port tunneling, RMI attempts a HTTP POST request to a http: URL directed at the exact hostname and port number of the target server. The HTTP request contains a single RMI request. If the HTTP proxy accepts this URL, it will forward the POST request to the listening RMI server, which will recognize the request and unwrap it. The result of the call is wrapped in a HTTP reply, which is returned through the same proxy. &lt;br /&gt;Often, HTTP proxies will refuse to proxy requests to unusual port numbers. In this case, RMI will fall back to http-to-cgi tunneling. The RMI request is encapsulated in a HTTP POST request as before, but the request URL is of the form http://hostname:80/cgi-bin/java-rmi.cgi?port=3Dn (where hostname and n are the hostname and port number of the intended server). There must be a HTTP server listening on port 80 on the server host, which will run the java-rmi.cgi script (supplied with the JDK), which will in turn forward the request to an RMI server listening on port n. RMI can unwrap a HTTP-tunneled request without help from a http server, CGI script, or any other external entity. So, if the client's HTTP proxy can connect directly to the server's port, then you don't need a java-rmi.cgi script at all. &lt;br /&gt;To trigger the use of HTTP tunneling, the standard system property http.proxyHost must be set to the hostname of the local HTTP proxy. (There are reports that some Navigator versions do not set this property.) &lt;br /&gt;The major disadvantage of HTTP tunneling is that it does not permit inward calls or multiplexed connections. A secondary disadvantage is that the http-to-cgi method opens a dramatic security hole on the server side, since without modification it will redirect any incoming request to any port. &lt;br /&gt;&lt;br /&gt;SOCKS&lt;br /&gt;The default implementation of sockets in the JDK will use a SOCKS server if available and configured. The system property socksProxyHost must have been set to the hostname of the SOCKS server; if the port number of the SOCKS server is not 1080, it must be specified in the socksProxyPort property. &lt;br /&gt;This approach would appear to be the most generally useful solution. As yet, ServerSockets do not use SOCKS, so incoming calls must use another mechanism. &lt;br /&gt;&lt;br /&gt;Downloaded socket factories This is an innovation in the Java 2 SDK, allowing the server to specify the socket factory that the clients must use. The clients must be running Java 2 SDK, Standard Edition, v1.2 or later. See the tutorial Using a Custom RMI Socket Factory for details. &lt;br /&gt;The disadvantage of this approach is that the traversal of the firewall must be done by code provided by the RMI server side, which does not necessarily know how that traversal must be done, nor does it automatically have sufficient privilege to traverse the firewall. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;How can I receive incoming RMI calls through a local firewall? &lt;br /&gt;There are three main methods: known ports, transport-level bridges, and application-level proxies. &lt;br /&gt;Known Ports&lt;br /&gt;If the exported objects are all exported on a known port on a known host, then that host and port can be explicitly permitted at the firewall. Normally, RMI asks for port 0 (which is code for "any port"). In the Java 2 SDK, there is an extra argument to the exportObject method to specify the exact port number. In JDK v1.1, the server must subclass the RMISocketFactory and intercept requests to createServerSocket(0), replacing it with a request to bind to a specific port number. &lt;br /&gt;This approach has the disadvantage that it requires the assistance of the network administrator responsible for the local firewall. If the exported object is being run in a different location (because code was downloaded to that site), then the local firewall may be run by network administrators who don't know who you are. &lt;br /&gt;&lt;br /&gt;Transport-level bridges&lt;br /&gt;A transport-level bridge is a program that reads bytes from one TCP connection and writes them to another (and vice versa) without knowing or caring what the bytes represent. &lt;br /&gt;The idea here is to export objects in such a way that anyone outside the firewall who wants to call remote methods on that object instead contacts a different port (perhaps on a different machine). That different port has a running program which makes a second connection to the real server and then pumps bytes each way. &lt;br /&gt;The tricky part is convincing the client to connect to the bridge. A downloadable socket factory (Java 2 SDK, v1.2 or later) can do this efficiently; otherwise, it is possible to set the java.rmi.server.hostname property to name the bridge host and arrange for port numbers to be the same. &lt;br /&gt;&lt;br /&gt;Application-level proxies&lt;br /&gt;This approach is quite a bit of work, but leads to a very secure arrangement. A proxy program runs on a firewall host (one which can be accessed from outside as well as inside). When an internal server intends to make an exported object available to the world, it contacts the proxy server and gives it a remote reference. The proxy server creates a proxy object (a new remote object residing in the proxy server) which implements the same remote interfaces as the original. The proxy server returns a remote reference for the new proxy object to the internal server, which communicates it to the outside world (somehow). &lt;br /&gt;When an outsider makes a call on the proxy, the proxy immediately forwards the call to its original object on the internal server. The use of the proxy is transparent to the outsider (but not to the internal server, who has to decide whether to pass the original reference or the proxy reference when talking to anyone). &lt;br /&gt;Needless to say, this requires considerable setup and the cooperation of the local network administrators. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Does RMI handle "out" and "inout" parameters (like CORBA)? &lt;br /&gt;RMI does not support "out" or "inout" parameters, just like the rest of the core Java programming language. All remote calls are methods of a remote object. Local objects are passed by copy and remote objects are passed by reference to a stub.&lt;br /&gt;&lt;br /&gt;Normally in the Java programming language, it is possible to cast an interface instance to an instance of the class from which it was created and use the result. Why doesn't this work in RMI? &lt;br /&gt;In RMI the client sees only a stub for the original object. The stub implements only the remote interfaces and their remote methods and cannot be cast back to the original implementation class because it's just a stub. &lt;br /&gt;So, you cannot pass a remote object reference from a server to a client, and then send it back to the server and be able to cast it back to the original implementation class. You can, though, use the remote object reference on the server to make a remote call to the object. &lt;br /&gt;If you need to find the implementation class again, you'll need to keep a table that maps the remote reference to the implementation class. &lt;br /&gt;&lt;br /&gt;What is the difference between RMI &amp; Corba ?&lt;br /&gt;The most significant difference between RMI and CORBA is that CORBA was made specifically for interoperability across programming languages. That is CORBA fosters the notion that programs can be built to interact in multiple languages. The server could be written in C++, the business logic in Python, and the front-end written in COBOL in theory. RMI, on the other hand is a total Java solution, the interfaces, the implementations and the clients--all are written in Java. &lt;br /&gt;RMI allows dynamic loading of classes at runtime. In a multi-language CORBA environment, dynamic class loading is not possible. The important advantage to dynamic class loading is that it allows arguments to be passed in remote invocations that are subtypes of the declared types. In CORBA, all types have to be known in advance. RMI (as well as RMI/IIOP) provides support for polymorphic parameter passing, whereas strict CORBA does not. CORBA does have support for multiple languages which is good for some applications, but RMI has the advantage of being dynamic, which is good for other applications. &lt;br /&gt;&lt;br /&gt;What are the services in RMI ? &lt;br /&gt;An RMI "service" could well be any Java method that can be invoked remotely. The other service is the JRMP RMI naming service which is a lookup service. &lt;br /&gt;&lt;br /&gt;Does RMI-IIOP support code downloading for Java objects sent by value across an IIOP connection in the same way as RMI does across a JRMP connection?= &lt;br /&gt;Yes. The JDK 1.2 and above support the dynamic class loading.&lt;br /&gt;&lt;br /&gt;How many types of protocol implementations does RMI have? &lt;br /&gt;RMI has at least three protocol implementations: Java Remote Method Protocol(JRMP), Internet Inter ORB Protocol(IIOP), and Jini Extensible Remote Invocation(JERI). These are alternatives, not part of the same thing, All three are indeed layer 6 protocols for those who are still speaking OSI reference model. &lt;br /&gt;&lt;br /&gt;Does RMI-IIOP support dynamic downloading of classes?  &lt;br /&gt;No, RMI-IIOP doesn't support dynamic downloading of the classes as it is done with CORBA in DII (Dynamic Interface Invocation).Actually RMI-IIOP combines the usability of Java Remote Method Invocation (RMI) with the interoperability of the Internet Inter-ORB Protocol (IIOP).So in order to attain this interoperability between RMI and CORBA,some of the features that are supported by RMI but not CORBA and vice versa are eliminated from the RMI-IIOP specification. &lt;br /&gt;&lt;br /&gt;Can RMI and Corba based applications interact ? &lt;br /&gt;Yes they can. RMI is available with IIOP as the transport protocol instead of JRMP&lt;br /&gt;&lt;br /&gt;Explain lazy activation &lt;br /&gt;Lazy activation of remote objects is implemented using a faulting remote reference (sometimes referred to as a fault block). A faulting remote reference to a remote object "faults in" the active object's reference upon the first method invocation to the object. Each faulting reference maintains both a persistent handle (an activation identifier) and a transient remote reference to the target remote object. The remote object's activation identifier contains enough information to engage a third party in activating the object. The transient reference is the actual "live" reference to the active remote object that can be used to contact the executing object.&lt;br /&gt;In a faulting reference, if the live reference to a remote object is null, the target object is not known to be active. Upon method invocation, the faulting reference (for that object) engages in the activation protocol to obtain a "live" reference, which is a remote reference (such as a unicast remote reference) for the newly-activated object. Once the faulting reference obtains the live reference, the faulting reference forwards method invocations to the underlying remote reference which, in turn, forwards the method invocation to the remote object.&lt;br /&gt;In more concrete terms, a remote object's stub contains a "faulting" remote reference type that contains both:&lt;br /&gt;an activation identifier for a remote object, and &lt;br /&gt;a "live" reference (possibly null) containing the "active" remote reference type of the remote object (for example, a remote reference type with unicast semantics). &lt;br /&gt;&lt;br /&gt;Why does the RMI implementation create so many sockets when my application uses custom socket factories; or why are stubs (using a custom socket factory) that refer to the same remote object not equal; or why does the RMI implementation not reuse server-side ports when I use a custom server socket factory? &lt;br /&gt;The RMI implementation attempts to reuse open sockets where possible for remote invocations. When a remote method is invoked on a stub that uses a custom socket factory, the RMI implementation will reuse an open connection (if any) as long as that socket was created by an equivalent socket factory. Since client socket factories are serialized to clients, a single client may have several distinct copies of the same logical socket factory. To ensure that the RMI implementation will reuse sockets created by custom socket factories, make sure your custom client socket factory classes implement the hashCode and equals methods appropriately. If the client socket factory does not implement these methods correctly, another ramification is that stubs (using the client socket factory) that refer to the same remote object will not be equal. &lt;br /&gt;The RMI implementation attempts to reuse server-side ports as well. It will only do so if there is an existing server socket for the port created by an equivalent socket factory. Make sure the server socket factory class implements the hashCode and equals methods too. &lt;br /&gt;&lt;br /&gt;If your socket factory has no instance state, a trivial implementation of the hashCode and equals methods are the following: &lt;br /&gt;&lt;br /&gt;    public int hashCode() { return 57; }    &lt;br /&gt;    public boolean equals(Object o) { return this.getClass() =3D=3D o.getClass() }&lt;br /&gt;    &lt;br /&gt;What is difference RMI registry and OSAgent ? &lt;br /&gt;RMI Registry&lt;br /&gt;The rmiregistry command creates and starts a remote object registry on the specified port on the current host. If port is omitted, the registry is started on port 1099. The rmiregistry command produces no output and is typically run in the background. For example: &lt;br /&gt;start rmiregistry &lt;br /&gt;A remote object registry is a bootstrap naming service that is used by RMI servers on the same host to bind remote objects to names. Clients on local and remote hosts can then look up remote objects and make remote method invocations. &lt;br /&gt;The registry is typically used to locate the first remote object on which an application needs to invoke methods. That object in turn will provide application-specific support for finding other objects. &lt;br /&gt;The methods of the java.rmi.registry.LocateRegistry class are used to get a registry operating on the local host or local host and port. &lt;br /&gt;The URL-based methods of the java.rmi.Naming class operate on a registry and can be used to look up a remote object on any host, and on the local host: bind a simple (string) name to a remote object, rebind a new name to a remote object (overriding the old binding), unbind a remote object, and list the URLs bound in the registry. &lt;br /&gt;&lt;br /&gt;OSAgent&lt;br /&gt;The osagent is a process that allows CORBA servers to register their objects and assists client applications in the location of objects. To avoid a single point of failure, the osagent is designed to be operated on more than one node. Osagent processes (and the clients and servers that access them) follow a set of rules to discover each other and cooperate in the location of registered objects. &lt;br /&gt;&lt;br /&gt;Difference in between Unicast and Multicast object ? &lt;br /&gt;A unicast packet is the complete opposite: one machine is talking to only one other machine. All TCP connections are unicast, since they can only have one destination host for each source host. UDP packets are almost always unicast too, though they can be sent to the broadcast address so that they reach every single machine in some cases. &lt;br /&gt;&lt;br /&gt;A multicast packet is from one machine to one or more. The difference between a multicast packet and a broadcast packet is that hosts receiving multicast packets can be on different lans, and that each multicast data-stream is only transmitted between networks once, not once per machine on the remote network. Rather than each machine connecting to a video server, the multicast data is streamed per-network, and multiple machines just listen-in on the multicast data once it's on the network.&lt;br /&gt;&lt;br /&gt;What is the main functionality of the Remote Reference Layer ? &lt;br /&gt;RRL exists in both the RMI client and server. It is used by the stub or skeleton protocol layer and uses the transport layer. RRL is reponsible for transport-independent functioning of RMI, such as connection management or unicast/multicast object invocation.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8955336342891215397-3890336703152939450?l=javaimpquestions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaimpquestions.blogspot.com/feeds/3890336703152939450/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8955336342891215397&amp;postID=3890336703152939450' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8955336342891215397/posts/default/3890336703152939450'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8955336342891215397/posts/default/3890336703152939450'/><link rel='alternate' type='text/html' href='http://javaimpquestions.blogspot.com/2008/08/rmi-important-questions.html' title='Rmi Important Questions'/><author><name>Naresh Namana</name><uri>http://www.blogger.com/profile/05755392141578528676</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8955336342891215397.post-133511879608522642</id><published>2008-08-12T23:54:00.000-07:00</published><updated>2011-03-18T22:54:49.093-07:00</updated><title type='text'>Jsp Imp Questions</title><content type='html'>&lt;script type="text/javascript"&gt;&lt;br /&gt;var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");&lt;br /&gt;document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));&lt;br /&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript"&gt;&lt;br /&gt;try {&lt;br /&gt;var pageTracker = _gat._getTracker("UA-9255840-1");&lt;br /&gt;pageTracker._trackPageview();&lt;br /&gt;} catch(err) {}&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;What is a translation unit? &lt;br /&gt;JSP page can include the contents of other HTML pages or other JSP files. This is done by using the include directive. When the JSP engine is presented with such a JSP page it is converted to one servlet class and this is called a translation unit, Things to remember in a translation unit is that page directives affect the whole unit, one variable declaration cannot occur in the same unit more than once, the standard action jsp:useBean cannot declare the same bean twice in one unit. &lt;br /&gt;&lt;br /&gt;How is JSP used in the MVC model&lt;br /&gt;JSP is usually used for presentation in the MVC pattern (Model View Controller ) i.e. it plays the role of the view. The controller deals with calling the model and the business classes which in turn get the data, this data is then presented to the JSP for rendering on to the client. &lt;br /&gt;&lt;br /&gt;What are context initialization parameters&lt;br /&gt;Context initialization parameters are specified by the in the web.xml file, these are initialization parameter for the whole application and not specific to any servlet or JSP. &lt;br /&gt;&lt;br /&gt;What is a output comment&lt;br /&gt;A comment that is sent to the client in the viewable page source. The JSP engine handles an output comment as un-interpreted HTML text, returning the comment in the HTML output sent to the client. You can see the comment by viewing the page source from your Web browser. &lt;br /&gt;&lt;br /&gt;What is a Hidden Comment&lt;br /&gt;A comment that documents the JSP page but is not sent to the client. The JSP engine ignores a hidden comment, and does not process any code within hidden comment tags. A hidden comment is not sent to the client, either in the displayed JSP page or the HTML page source. The hidden comment is useful when you want to hide or =E2=80=9Ccomment out=E2=80=9D part of your JSP page. &lt;br /&gt;Wh= at is a Expression&lt;br /&gt;Expressions are act as place holders for language expression, expression is evaluated each time the page is accessed. &lt;br /&gt;&lt;br /&gt;What is a Declaration&lt;br /&gt;It declares one or more variables or methods for use later in the JSP source file. A declaration must contain at least one complete declarative statement. You can declare any number of variables or methods within one declaration tag, as long as semicolons separate them. The declaration must be valid in the scripting language used in the JSP file. &lt;br /&gt;&lt;br /&gt;What is a Scriptlet&lt;br /&gt;A scriptlet can contain any number of language statements, variable or method declarations, or expressions that are valid in the page scripting language. Within scriptlet tags, you can declare variables or methods to use later in the file, write expressions valid in the page scripting language, use any of the JSP implicit objects or any object declared with a . &lt;br /&gt;&lt;br /&gt;What are the implicit objects&lt;br /&gt;List them. Certain objects that are available for the use in JSP documents without being declared first. These objects are parsed by the JSP engine and inserted into the generated servlet. The implicit objects are: &lt;br /&gt;request &lt;br /&gt;response &lt;br /&gt;pageContext &lt;br /&gt;session &lt;br /&gt;application &lt;br /&gt;out &lt;br /&gt;config &lt;br /&gt;page &lt;br /&gt;exception &lt;br /&gt;&lt;br /&gt;What is the difference between forward and sendRedirect&lt;br /&gt;When you invoke a forward request, the request is sent to another resource on the server, without the client being informed that a different resource is going to process the request. This process occurs completely with in the web container And then returns to the calling method. When a sendRedirect 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. &lt;br /&gt;&lt;br /&gt;Wh= at are the different scope values for the &lt;br /&gt;The different scope values for are:&lt;br /&gt;page &lt;br /&gt;request &lt;br /&gt;session &lt;br /&gt;application &lt;br /&gt;&lt;br /&gt;Why are JSP pages the preferred API for creating a web-based client program&lt;= /span&gt;&lt;br /&gt;Because no plug-ins or security policy files are needed on the client systems(applet does). Also, JSP pages enable cleaner and more module application design because they provide a way to separate applications programming from web page design. This means personnel involved in web page design do not need to understand Java programming language syntax to do their jobs. &lt;br /&gt;&lt;br /&gt;Is JSP technology extensible&lt;br /&gt;Yes, it is. JSP technology is extensible through the development of custom actions, or tags, which are encapsulated in tag libraries. &lt;br /&gt;&lt;br /&gt; What is difference between custom JSP tags and beans&lt;br /&gt;Custom JSP tag is a tag you defined. You define how a tag, its attributes and its body are interpreted, and then group your tags into collections called tag libraries that can be used in any number of JSP files. Custom tags and beans accomplish the same goals =E2=80=94 encapsulating complex behavior into simple and accessible forms. There are several differences: &lt;br /&gt;Custom tags can manipulate JSP content; beans cannot. &lt;br /&gt;Complex operations can be reduced to a significantly simpler form with custom tags than with beans. &lt;br /&gt;Custom tags require quite a bit more work to set up than do beans. &lt;br /&gt;Custom tags usually define relatively self-contained behavior, whereas beans are often defined in one servlet and used in a different servlet or JSP page. &lt;br /&gt;Custom tags are available only in JSP 1.1 and later, but beans can be used in all JSP 1.x versions. &lt;br /&gt;&lt;br /&gt;How can I implement a thread-safe JSP page? What are the advantages and Disadvantages of using it?&lt;br /&gt;You can make your JSPs thread-safe by having them implement the SingleThreadModel interface. This is done by adding the directive &lt;%@ page isThreadSafe=3D"false" %&gt; within your JSP page. With this, instead of a single instance of the servlet generated for your JSP page loaded in memory, you will have N instances of the servlet loaded and initialized, with the service method of each instance effectively synchronized. You can typically control the number of instances (N) that are instantiated for all servlets implementing SingleThreadModel through the admin screen for your JSP engine. More importantly, avoid using the tag for variables. If you do use this tag, then you should set isThreadSafe to true, as mentioned above. Otherwise, all requests to that page will access those variables, causing a nasty race condition. SingleThreadModel is not recommended for normal use. There are many pitfalls, including the example above of not being able to use &lt;%! %&gt;. You should try really hard to make them thread-safe the old fashioned way: by making them thread-safe &lt;br /&gt;&lt;br /&gt;How does JSP handle run-time exceptions&lt;br /&gt;You can use the errorPage attribute of the page directive to have uncaught run-time exceptions automatically forwarded to an error processing page. For example: &lt;%@ page errorPage=3D"error.jsp" %&gt;&lt;br /&gt;redirects the browser to the JSP page error.jsp if an uncaught exception is encountered during request processing. Within error.jsp, if you indicate that it is an error-processing page, via the directive: &lt;%@ page isErrorPage=3D"true" %&gt; Throwable object describing the exception may be accessed within the error page via the exception implicit object. Note: You must always use a relative URL as the value for the errorPage attribute.&lt;br /&gt;&lt;br /&gt;How do I prevent the output of my JSP or Servlet pages from being cached by the browser&lt;br /&gt;You will need to set the appropriate HTTP header attributes to prevent the dynamic content output by the JSP page from being cached by the browser. Just execute the following scriptlet at the beginning of your JSP pages to prevent them from being cached at the browser. You need both the statements to take care of some of the older browser versions. &lt;br /&gt;&lt;%&lt;br /&gt;response.setHeader("Cache-Control","no-store"); //HTTP 1.1&lt;br /&gt;response.setHeader("Pragma","no-cache"); //HTTP 1.0&lt;br /&gt;response.setDateHeader ("Expires", 0); //prevents caching at the proxy server&lt;br /&gt;%&gt; &lt;br /&gt;&lt;br /&gt;Ho= w do I use comments within a JSP page&lt;br /&gt;You can use JSP-style comments to selectively block out code while debugging or simply to comment your scriptlets. JSP comments are not visible at the client. For example:     &lt;%-- the scriptlet is now commented out&lt;br /&gt;    &lt;%&lt;br /&gt;    out.println("Hello World");&lt;br /&gt;    %&gt;&lt;br /&gt;    --%&gt;&lt;br /&gt;&lt;br /&gt;You can also use HTML-style comments anywhere within your JSP page. These comments are visible at the client. For example:&lt;br /&gt;&lt;=&lt;br /&gt;;!-- (c) 2004 --&gt;&lt;br /&gt;Of course, you can also use c= omments supported by your JSP scripting language within your scriptlets. For example, assuming Java is the scripting language, you can have:&lt;br /&gt;&lt;br /&gt;    &lt;%&lt;br /&gt;    //some comment&lt;br /&gt;    /**&lt;br /&gt;    yet another comment&lt;br /&gt;    **/&lt;br /&gt;    %&gt;&lt;br /&gt;&lt;br /&gt;Re= sponse has already been commited error. What does it mean&lt;br /&gt;This error show only when you try to redirect a page after you already have written something in your page. This happens because HTTP specification force the header to be set up before the lay out of the page can be shown (to make sure of how it should be displayed, content-type=3D"=9Dtext/html" or "text/xml" or "plain-text"=9D or "image/jpg", etc.) When you try to send a redirect status (Number is line_status_402), your HTTP server cannot send it right now if it hasn't finished to set up the header. If not starter to set up the header, there are no problems, but if it's already begin to set up the header, then your HTTP server expects these headers to be finished setting up and it cannot be the case if the stream of the page is not over.. In this last case it's like you have a file started with some output (like testing your variables.) Before you indicate that the file is over (and before the size of the page can be setted up in the header), you try to send a redirect status. It s simply impossible due to the specification of HTTP 1.0 and 1.1&lt;br /&gt;&lt;br /&gt;How do I use a scriptlet to initialize a newly instantiated bean&lt;br /&gt;A jsp:useBean action may optionally have a body. If the body is specified, its contents will be automatically invoked when the specified bean is instantiated. Typically, the body will contain scriptlets or jsp:setProperty tags to initialize the newly instantiated bean, although you are not restricted to using those alone.&lt;br /&gt;The following example shows the "today"=9D property of the Foo bean initialized to the current date when it is instantiated. Note that here, we make use of a JSP expression within the jsp:setProperty action.= &lt;br /&gt;&lt;br /&gt;value=3D"&lt;%=3Djava.text.DateFormat.getDateInstance().format(new java.util.Date()) %&gt;"/ &gt;&lt;br /&gt;&lt;%-- scriptlets calling bean setter methods go here --%&gt;"&lt;br /&gt;&lt;br /&gt;How can I enable session tracking for JSP pages if the browser has disabled cookies&lt;br /&gt;We know that session tracking uses cookies by default to associate a session identifier with a unique user. If the browser does not support cookies, or if cookies are disabled, you can still enable session tracking using URL rewriting. URL rewriting essentially includes the session ID within the link itself as a name/value pair. However, for this to be effective, you need to append the session ID for each and every link that is part of your servlet response. Adding the session ID to a link is greatly simplified by means of of a couple of methods: response.encodeURL() associates a session ID with a given URL, and if you are using redirection, response.encodeRedirectURL() can be used by giving the redirected URL as input. Both encodeURL() and encodeRedirectedURL() first determine whether cookies are supported by the browser; if so, the input URL is returned unchanged since the session ID will be persisted as a cookie. Consider the following example, in which two JSP files, say hello1.jsp and hello2.jsp, interact with each other. Basically, we create a new session within hello1.jsp and place an object within this session. The user can then traverse to hello2.jsp by clicking on the link present within the page.Within hello2.jsp, we simply extract the object that was earlier placed in the session and display its contents. Notice that we invoke the encodeURL() within hello1.jsp on the link used to invoke hello2.jsp; if cookies are disabled, the session ID is automatically appended to the URL, allowing hello2.jsp to still retrieve the session object. Try this example first with cookies enabled. Then disable cookie support, restart the brower, and try again. Each time you should see the maintenance of the session across pages. Do note that to get this example to work with cookies disabled at the browser, your JSP engine has to support URL rewriting. &lt;= br&gt;     hello1.jsp&lt;br /&gt;    &lt;%@ page session=3D"true" %&gt;&lt;br /&gt;    &lt;%&lt;br /&gt;    Integer num =3D new Integer(100);&lt;br /&gt;    session.putValue("num",num);&lt;br /&gt;    String url =3Dresponse.encodeURL("hello2.jsp");&lt;br /&gt;    %&gt;&lt;br /&gt;    hello2.jsp&lt;br /&gt;    &lt;%@ page session=3D"true" %&gt;&lt;br /&gt;    &lt;%&lt;br /&gt;    Integer i=3D (Integer )session.getValue("num");&lt;br /&gt;    out.println("Num value in session is "+i.intValue());= &lt;br /&gt;&lt;br /&gt;How can I declare methods within my JSP page&lt;br /&gt;You can declare methods for use within your JSP page as declarations. The methods can then be invoked within any other methods you declare, or within JSP scriptlets and expressions. Do note that you do not have direct access to any of the JSP implicit objects like request, response, session and so forth from within JSP methods. However, you should be able to pass any of the implicit JSP variables as parameters to the methods you declare. For example: &lt;br /&gt;    &lt;%!&lt;br /&gt;    public String whereFrom(HttpServletRequest req) {&lt;br /&gt;=     HttpSession ses =3D req.getSession();&lt;br /&gt;    ...&lt;br /&gt;    return req.getRemoteHost();&lt;br /&gt;    }&lt;br /&gt;    %&gt;&lt;br /&gt;    &lt;%&lt;br /&gt;    out.print("Hi there, I see that you are coming in from ");&lt;br /&gt;    %&gt;&lt;br /&gt;    &lt;%=3D whereFrom(request) %&gt;&lt;br /&gt;    Another Example&lt;br /&gt;    file1.jsp:&lt;br /&gt;    &lt;%@page contentType=3D"text/html"%&gt;&lt;br /&gt;    &lt;%!&lt;br /&gt;    public void test(JspWriter writer) throws IOException{&lt;br /&gt;    writer.println("Hello!");&lt;br /&gt;    }&lt;br /&gt;    %&gt;&lt;br /&gt;    file2.jsp&lt;br /&gt;    &lt;%@include file=3D"file1.jsp"%&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;    &lt;%test(out);% &gt;&lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;Is there a way I can set the inactivity lease period on a per-session basis= &lt;br /&gt;Typically, a default inactivity lease period for all sessions is set within your JSP engine admin screen or associated properties file. However, if your JSP engine supports the Servlet 2.1 API, you can manage the inactivity lease period on a per-session basis. This is done by invoking the HttpSession.setMaxInactiveInterval() method, right after the session has been created. For example: &lt;br /&gt;    &lt;%&lt;br /&gt;    session.setMaxInactiveInterval(300);&lt;br /&gt;    %&gt;&lt;br /&gt;would reset the inactivity period for this session to 5 minutes. The inactivity interval is set in seconds.&lt;br /&gt;&lt;br /&gt; How can I set a cookie and delete a cookie from within a JSP page&lt;br /&gt;= A cookie, mycookie, can be deleted using the following scriptlet: &lt;br /&gt;    &lt;%&lt;br /&gt;    //creating a cookie&lt;br /&gt;    Cookie mycookie =3D new Cookie("aName","aValue");&lt;br /&gt;=     response.addCookie(mycookie);&lt;br /&gt;    //delete a cookie&lt;br /&gt;    Cookie killMyCookie =3D new Cookie("mycookie", null);= &lt;br /&gt;    killMyCookie.setMaxAge(0);&lt;br /&gt;    killMyCookie.setPath("/");&lt;br /&gt;    response.addCookie(killMyCookie);&lt;br /&gt;    %&gt;&lt;br /&gt;&lt;br /&gt;Ho= w does a servlet communicate with a JSP page&lt;br /&gt;The following code snippet shows how a servlet instantiates a bean and initializes it with FORM data posted by a browser. The bean is then placed into the request, and the call is then forwarded to the JSP page, Bean1.jsp, by means of a request dispatcher for downstream processing. &lt;br /&gt;    public void doPost (HttpServletRequest request, HttpServletResponse response) {&lt;br /&gt;    try {&lt;br /&gt;        govi.FormBean f =3D new govi.FormBean();&lt;br /&gt;        String id =3D request.getParameter("id");&lt;br /&gt;        f.setName(request.getParameter("name"));&lt;br /&gt;        f.setAddr(request.getParameter("addr"));&lt;br /&gt;        f.setAge(request.getParameter("age"));&lt;br /&gt;        //use the id to compute&lt;br /&gt;        //additional bean properties like info&lt;br /&gt;        //maybe perform a db query, etc.         // . . .&lt;br /&gt;        f.setPersonalizationInfo(info);         request.setAttribute("fBean",f);         getServletConfig().getServletContext().getRequestDispatcher&lt;br /&gt;            =           ("/jsp/Bean1.jsp").forward(request, response);&lt;br /&gt;        } catch (Exception ex) {&lt;br /&gt;    . . .&lt;br /&gt;       }&lt;br /&gt;    }&lt;br /&gt;The JSP page Bean1.jsp can then process fBean, after first extracting it from the default request scope via the useBean action.&lt;br /&gt;&lt;br /&gt;jsp:useBean id=3D"fBean" class=3D"govi.FormBean" scope=3D"request"&lt;br /&gt;/ jsp:getProperty name=3D"fBean" property=3D"name"&lt;br /&gt;/ jsp:getProperty name=3D"fBean" property=3D"addr"&lt;br /&gt;/ jsp:getProperty name=3D"fBean" property=3D"age"&lt;br /&gt;/ jsp:getProperty name=3D"fBean" property=3D"personalizationInfo" /&lt;br /&gt;&lt;br /&gt;Ho= w do I have the JSP-generated servlet subclass my own custom servlet class, instead of the default&lt;br /&gt;One should be very careful when having JSP pages extend custom servlet classes as opposed to the default one generated by the JSP engine. In doing so, you may lose out on any advanced optimization that may be provided by the JSP engine. In any case, your new superclass has to fulfill the contract with the JSP engine by:&lt;br /&gt;Implementing the HttpJspPage interface, if the protocol used is HTTP, or implementing JspPage otherwise Ensuring that all the methods in the Servlet interface are declared final Additionally, your servlet superclass also needs to do the following:&lt;br /&gt;&lt;br /&gt;The service() method has to invoke the _jspService() method&lt;br /&gt;&lt;br /&gt;The init() method has to invoke the jspInit() method &lt;br /&gt;The destroy() method has to invoke jspDestroy()&lt;br /&gt;If any of the above conditions are not satisfied, the JSP engine may throw a translation error.&lt;br /&gt;Once the superclass has been developed, you can have your JSP extend it as follows:&lt;br /&gt;&lt;br /&gt;    &lt;%@ page extends=3D"packageName.ServletName" %&gt;= &lt;br /&gt;&lt;br /&gt;Ho= w can I prevent the word "null" from appearing in my HTML input text fields when I populate them with a resultset that has null values= &lt;br /&gt;You could make a simple wrapper function, like &lt;br /&gt;    &lt;%!&lt;br /&gt;    String blanknull(String s) {&lt;br /&gt;    return (s =3D=3D null) ? "" : s;&lt;br /&gt;    }&lt;br /&gt;    %&gt;&lt;br /&gt;    then use it inside your JSP form, like&lt;br /&gt;    &lt;input type=3D"text" name=3D"shoesize" value=3D"&lt;%=3Dblanknull(shoesize)% &gt;" &gt; &lt;br /&gt;&lt;br /&gt;How can I get to print the stacktrace for an exception occuring within my JSP page&lt;br /&gt;By printing out the exception=E2=80=99s stack trace, you can usually diagonse a problem better when debugging JSP pages. By looking at a stack trace, a programmer should be able to discern which method threw the exception and which method called that method. However, you cannot print the stacktrace using the JSP out implicit variable, which is of type JspWriter. You will have to use a PrintWriter object instead. The following snippet demonstrates how you can print a stacktrace from within a JSP error page: &lt;br /&gt;    &lt;%@ page isErrorPage=3D"true" %&gt;&lt;br /&gt;    &lt;%&lt;br /&gt;    out.println("    ");&lt;br /&gt;     PrintWriter pw =3D response.getWriter();&lt;br /&gt;     exception.printStackTrace(pw);&lt;br /&gt;    out.println(" ");&lt;br /&gt;    %&gt;&lt;br /&gt;&lt;br /&gt;How do you pass an InitParameter to a JSP&lt;br /&gt;The JspPage interface defines the jspInit() and jspDestroy() method which the page writer can use in their pages and are invoked in much the same manner as the init() and destory() methods of a servlet. The example page below enumerates through all the parameters and prints them to the console. &lt;br /&gt;    &lt;%@ page import=3D"java.util.*" %&gt;&lt;br /&gt;    &lt;%!&lt;br /&gt;    ServletConfig cfg =3Dnull;&lt;br /&gt;    public void jspInit(){&lt;br /&gt;    ServletConfig cfg=3DgetServletConfig();&lt;br /&gt;    for (Enumeration e=3Dcfg.getInitParameterNames(); e.hasMoreElements();) {&lt;br /&gt;    String name=3D(String)e.nextElement();&lt;br /&gt;    String value =3D cfg.getInitParameter(name);&lt;br /&gt;    System.out.println(name+"=3D"+value);&lt;br /&gt;    }&lt;br /&gt;    }&lt;br /&gt;    %&gt;&lt;br /&gt;&lt;br /&gt;How can my JSP page communicate with an EJB Session Bean&lt;br /&gt;The following is a code snippet that demonstrates how a JSP page can interact with an EJB session bean: &lt;br /&gt;    &lt;%@ page import=3D"javax.naming.*, javax.rmi.PortableRemoteObject, foo.AccountHome, foo.Account" %&gt;&lt;br /&gt;    &lt;%!&lt;br /&gt;    //declare a "global" reference to an instance of the home interface of the session bean&lt;br /&gt;    AccountHome accHome=3Dnull;&lt;br /&gt;    public void jspInit() {&lt;br /&gt;    //obtain an instance of the home interface&lt;br /&gt;    InitialContext cntxt =3D new InitialContext( );&lt;br /&gt;    Object ref=3D cntxt.lookup("java:comp/env/ejb/AccountEJB");&lt;br /&gt;    accHome =3D (AccountHome)PortableRemoteObject.narrow(ref,AccountHome.class);&lt;br /&gt;    }&lt;br /&gt;    %&gt;&lt;br /&gt;    &lt;%&lt;br /&gt;    //instantiate the session bean&lt;br /&gt;    Account acct =3D accHome.create();&lt;br /&gt;    //invoke the remote methods&lt;br /&gt;    acct.doWhatever(...);&lt;br /&gt;    // etc etc...&lt;br /&gt;    %&gt;&lt;br /&gt;&lt;br /&gt;Can we implement an interface in a JSP&lt;br /&gt;No &lt;br /&gt;&lt;br /&gt;What is the difference between ServletContext and PageContext&lt;br /&gt;ServletContext: Gives the information about the container. PageContext: Gives the information about the Request &lt;br /&gt;&lt;br /&gt;What is the difference in using request.getRequestDispatcher() and context.getRequestDispatcher()&lt;br /&gt;request.getRequestDispatcher(path): In order to create it we need to give the relative path of the resource, &lt;br /&gt;context.getRequestDispatcher(path): In order to create it we need to give the absolute path of the resource. &lt;br /&gt;&lt;br /&gt;How to pass information from JSP to included JSP&lt;br /&gt;Using &lt;%jsp:param&gt; tag. &lt;br /&gt;&lt;br /&gt;What is the difference between directive include and jsp include&lt;br /&gt;&lt;%@ include&gt;: Used to include static resources during translation time. JSP include: Used to include dynamic content or static content during runtime. &lt;br /&gt;&lt;br /&gt;What is the difference between RequestDispatcher and sendRedirect&lt;br /&gt;RequestDispatcher: server-side redirect with request and response objects. sendRedirect : Client-side redirect with new request and response objects. &lt;br /&gt;&lt;br /&gt;How do I mix JSP and SSI #include&lt;br /&gt;If you're just including raw HTML, use the #include directive as usual inside your .jsp file. &lt;br /&gt;&lt;br /&gt;But it's a little trickier if you want the server to evaluate any JSP code that's inside the included file. If your data.inc file contains jsp code you will have to use&lt;br /&gt;    &lt;%@ vinclude=3D"data.inc" %&gt;&lt;br /&gt;The is used for including non-JSP files.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8955336342891215397-133511879608522642?l=javaimpquestions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaimpquestions.blogspot.com/feeds/133511879608522642/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8955336342891215397&amp;postID=133511879608522642' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8955336342891215397/posts/default/133511879608522642'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8955336342891215397/posts/default/133511879608522642'/><link rel='alternate' type='text/html' href='http://javaimpquestions.blogspot.com/2008/08/jsp-imp-questions.html' title='Jsp Imp Questions'/><author><name>Naresh Namana</name><uri>http://www.blogger.com/profile/05755392141578528676</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8955336342891215397.post-5606267515185194875</id><published>2008-08-12T23:39:00.000-07:00</published><updated>2008-08-12T23:46:12.540-07:00</updated><title type='text'>Jdbc Imp Questions</title><content type='html'>What is JDBC?&lt;br /&gt;Short for Java Database Connectivity, a Java API that enables Java programs to execute SQL statements. This allows Java programs to interact with any SQL-compliant database. Since nearly all relational database management systems (DBMSs) support SQL, and because Java itself runs on most platforms, JDBC makes it possible to write a single database application that can run on different platforms and interact with different DBMSs. &lt;br /&gt;JDBC is similar to ODBC, but is designed specifically for Java programs, whereas ODBC is language-independent. &lt;br /&gt;&lt;br /&gt;What are the components of JDBC&lt;br /&gt;JDBC Components=97Connection Pools, Data Sources, and MultiPools &lt;br /&gt;&lt;br /&gt;How to you load the drivers&lt;br /&gt;Class.forName() method is used in JDBC to load the JDBC drivers dynamically&lt;br /&gt;&lt;br /&gt;What does Class.forname() do&lt;br /&gt;Class.forName() method is used in JDBC to load the JDBC drivers dynamically&lt;br /&gt;&lt;br /&gt;What are the different types of JDBC drivers&lt;br /&gt;A JDBC-ODBC bridge provides JDBC API access via one or more ODBC drivers. Note that some ODBC native code and in many cases native database client code must be loaded on each client machine that uses this type of driver. Hence, this kind of driver is generally most appropriate when automatic installation and downloading of a Java technology application is not important.  &lt;br /&gt;A native-API partly Java technology-enabled driver converts JDBC calls into calls on the client API for Oracle, Sybase, Informix, DB2, or other DBMS. Note that, like the bridge driver, this style of driver requires that some binary code be loaded on each client machine. &lt;br /&gt;A net-protocol fully Java technology-enabled driver translates JDBC API calls into a DBMS-independent net protocol which is then translated to a DBMS protocol by a server. This net server middleware is able to connect all of its Java technology-based clients to many different databases. The specific protocol used depends on the vendor. In general, this is the most flexible JDBC API alternative. It is likely that all vendors of this solution will provide products suitable for Intranet use. In order for these products to also support Internet access they must handle the additional requirements for security, access through firewalls, etc., that the Web imposes. Several vendors are adding JDBC technology-based drivers to their existing database middleware products. &lt;br /&gt;A native-protocol fully Java technology-enabled driver converts JDBC technology calls into the network protocol used by DBMSs directly. This allows a direct call from the client machine to the DBMS server and is a practical solution for Intranet access. Since many of these protocols are proprietary the database vendors themselves will be the primary source for this style of driver. Several database vendors have these in progress. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;What are the pros and cons of all the 4 drivers&lt;br /&gt;Type 1: JDBC-ODBC Bridge&lt;br /&gt;The type 1 driver, JDBC-ODBC Bridge, translates all JDBC calls into ODBC (Open DataBase Connectivity) calls and sends them to the ODBC driver. As such, the ODBC driver, as well as, in many cases, the client database code, must be present on the client machine. Pros&lt;br /&gt;The JDBC-ODBC Bridge allows access to almost any database, since the database's ODBC drivers are already available. Type 1 drivers may be useful for those companies that have an ODBC driver already installed on client machines.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Cons&lt;br /&gt;The performance is degraded since the JDBC call goes through the bridge to the ODBC driver, then to the native database connectivity interface. The result comes back through the reverse process. Considering the performance issue, type 1 drivers may not be suitable for large-scale applications. &lt;br /&gt;The ODBC driver and native connectivity interface must already be installed on the client machine. Thus any advantage of using Java applets in an intranet environment is lost, since the deployment problems of traditional applications remain. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Type 2: Native-API/partly Java driver&lt;br /&gt;JDBC driver type 2 -- the native-API/partly Java driver -- converts JDBC calls into database-specific calls for databases such as SQL Server, Informix, Oracle, or Sybase. The type 2 driver communicates directly with the database server; therefore it requires that some binary code be present on the client machine. &lt;br /&gt;Pros&lt;br /&gt;Type 2 drivers typically offer significantly better performance than the JDBC-ODBC Bridge.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Cons&lt;br /&gt;The vendor database library needs to be loaded on each client machine. Consequently, type 2 drivers cannot be used for the Internet. Type 2 drivers show lower performance than type 3 and type 4 drivers.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Type 3: Net-protocol/all-Java driver&lt;br /&gt;JDBC driver type 3 -- the net-protocol/all-Java driver -- follows a three-tiered approach whereby the JDBC database requests are passed through the network to the middle-tier server. The middle-tier server then translates the request (directly or indirectly) to the database-specific native-connectivity interface to further the request to the database server. If the middle-tier server is written in Java, it can use a type 1 or type 2 JDBC driver to do this. &lt;br /&gt;&lt; Pros&lt;br /&gt;The net-protocol/all-Java driver is server-based, so there is no need for any vendor database library to be present on client machines. Further, there are many opportunities to optimize portability, performance, and scalability. Moreover, the net protocol can be designed to make the client JDBC driver very small and fast to load. Additionally, a type 3 driver typically provides support for features such as caching (connections, query results, and so on), load balancing, and advanced system administration such as logging and auditing.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Cons&lt;br /&gt;Type 3 drivers require database-specific coding to be done in the middle tier. Additionally, traversing the recordset may take longer, since the data comes through the backend server.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Type 4: Native-protocol/all-Java driver&lt;br /&gt;The native-protocol/all-Java driver (JDBC driver type 4) converts JDBC calls into the vendor-specific database management system (DBMS) protocol so that client applications can communicate directly with the database server. Level 4 drivers are completely implemented in Java to achieve platform independence and eliminate deployment administration issues. &lt;br /&gt;Pros&lt;br /&gt;Since type 4 JDBC drivers don't have to translate database requests to ODBC or a native connectivity interface or to pass the request on to another server, performance is typically quite good. Moreover, the native-protocol/all-Java driver boasts better performance than types 1 and 2. Also, there's no need to install special software on the client or server. Further, these drivers can be downloaded dynamically.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Cons&lt;br /&gt;With type 4 drivers, the user needs a different driver for each database. &lt;br /&gt;&lt;br /&gt;How to you establish a connection&lt;br /&gt;Loading Drivers&lt;br /&gt;Class.forName("Drive= r");&lt;br /&gt;Getting connection&lt;br /&gt;Connection con =3D DriverManager.getConnection(url,&lt;br /&gt;            =          "myLogin", "myPassword");&lt;br /&gt;What are different types of statements in JDBC&lt;br /&gt;java.sql.Statement - Top most interface which provides basic methods useful for executing SELECT, INSERT, UPDATE and DELETE SQL statements. &lt;br /&gt;&lt;br /&gt;java.sql.PreparedStatement - An enhanced verion of java.sql.Statement which allows precompiled queries with parameters. It is more efficient to use java.sql.PreparedStatement if you have to specify parameters to your SQL queries. &lt;br /&gt;&lt;br /&gt;java.sql.CallableStatement - Allows you to execute stored procedures within a RDBMS which supports stored procedures (MySQL doesn't support stored procedures at the moment). &lt;br /&gt;&lt;br /&gt;When do we used prepared statements&lt;br /&gt;If you want to execute a Statement object many times, it will normally reduce execution time to use a PreparedStatement object instead. &lt;br /&gt;&lt;br /&gt;The main feature of a PreparedStatement object is that, unlike a Statement object, it is given an SQL statement when it is created. The advantage to this is that in most cases, this SQL statement will be sent to the DBMS right away, where it will be compiled. As a result, the PreparedStatement object contains not just an SQL statement, but an SQL statement that has been precompiled. This means that when the PreparedStatement is executed, the DBMS can just run the PreparedStatement 's SQL statement without having to compile it first. &lt;= br&gt; &lt;br /&gt;Although PreparedStatement objects can be used for SQL statements with no parameters, you will probably use them most often for SQL statements that take parameters. The advantage of using SQL statements that take parameters is that you can use the same statement and supply it with different values each time you execute it. You will see an example of this in the following sections.&lt;br /&gt;&lt;br /&gt;Ho= w do you create JDBC statements&lt;= /span&gt;&lt;br /&gt;Connection con =3D null;&lt;br /&gt;Statement st =3D null;&lt;br /&gt;&lt;br /&gt;// Obtain connection here&lt;br /&gt;st =3D con.createStatement();&lt;br /&gt;ResultSet rs =3D null;&lt;br /&gt;&lt;br /&gt;rs =3D st.executeQuery("SELECT * FROM users");&lt;br /&gt;int recordsUpdated;&lt;br /&gt;&lt;br /&gt;recordsUpdated =3D st.executeUpdate("DELETE FROM users WHERE user_id =3D= 1");&lt;br /&gt;&lt;br /&gt;&lt;= /span&gt;H= ow do you retrieve data from a result set &lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;br /&gt;Statement stmt =3D conn.createStatement(); &lt;br /&gt;ResultSet rs =3D stmt.executeQuery(SELECT COF_NAME, PRICE FROM COFFEES=94); &lt;br /&gt;while (rs .next() ) &lt;br /&gt;{ &lt;br /&gt;//Iam assuming there are 3 columns in the table. &lt;br /&gt;System.out.println ( rs.getString(1)); &lt;br /&gt;System.out.println(rs.getString(2)); &lt;br /&gt;System.out.println(rs.getString(3)); &lt;br /&gt;} &lt;br /&gt;//don=92t forget to close the resultset, statement &amp; connection  rs.close(); //First  &lt;br /&gt;stmt.close(); //Second &lt;br /&gt;con.close(); //Last  &lt;br /&gt;System.out.println(=94You are done=94); &lt;br /&gt;&lt;br /&gt;What is a stored procedure&lt;br /&gt;A stored procedure is a group of SQL statements that form a logical unit and perform a particular task. Stored procedures are used to encapsulate a set of operations or queries to execute on a database server. For example, operations on an employee database (hire, fire, promote, lookup) could be coded as stored procedures executed by application code. Stored procedures can be compiled and executed with different parameters and results, and they may have any combination of input, output, and input/output parameters. &lt;br /&gt;&lt;br /&gt;What are the tasks of JDBC&lt;br /&gt;Following are the tasks of JDBC&lt;br /&gt;Load the JDBC drivers&lt;br /&gt;Register the drivers&lt;br /&gt;Specify a database &lt;br /&gt;Open a connection to database&lt;br /&gt;Submit a query to database&lt;br /&gt;Gets the results&lt;br /&gt;&lt;br /&gt;What do you mean by batch updates&lt;br /&gt;if you want to execute a set of statements, i.e. SQL statements at a time then we use batch update statement.&lt;br /&gt;&lt;br /&gt;resultset=3Dpst.batchUpdate();&lt;br /&gt;&lt;br /&gt;Why do we need batch updates&lt;br /&gt;Let's say there are 100 records need to be insert. If we execute normal statemets the no of transactions will be 100 (in terms of connection making to DB). using batch updates we can add 100 rec to batch and the no of transactions will be only one in this case. This will reduce the burdon on db, which is very costly in terms of resources.&lt;br /&gt;&lt;br /&gt;How do you call a stored procedure from java&lt;br /&gt;You can call a stored procedure using Callable statements&lt;br /&gt;CallableStatement cs =3D con.prepareCall("{call StoredProc}");&lt;br /&gt;ResultSet rs =3D cs.executeQuery(); &lt;br /&gt;&lt;br /&gt;What packages are being used by JDBC&lt;br /&gt;Following packages are used in JDBC&lt;br /&gt;java.sql &lt;br /&gt;javax.sql&lt;br /&gt;&lt;br /&gt;Explain how to get the resultset of Stored procedure&lt;br /&gt;CallableStatement cstmt;&lt;br /&gt;ResultSet rs;&lt;br /&gt;int i;&lt;br /&gt;String s;&lt;br /&gt;...&lt;br /&gt;cstmt.execute();// Call the stored procedure &amp;nbs= p;1 &lt;br /&gt;rs =3D cstmt.getResultSet();// Get the first result set =  2 &lt;br /&gt;&lt;br /&gt;while (rs.next()) {            = ;   // Position the cursor  3 &lt;br /&gt;        i =3D rs.getInt(1);          // Retrieve current result set value&lt;br /&gt;       System.out.println("Value from first result set =3D " + i);   // Print the value&lt;br /&gt;}&lt;br /&gt;cstmt.getMoreResults();  // Point to the second result set  4a &lt;br /&gt;            =             =             =        // and close the first result set&lt;br /&gt;rs =3D cstmt.getResultSet(); // Get the second result set  4b &lt;br /&gt;&lt;br /&gt;while (rs.next()) {            = ;   // Position the cursor  4c &lt;br /&gt;        s =3D rs.getString(1);   // Retrieve current result set value&lt;br /&gt;        System.out.println("Value from second result set =3D " + s); &lt;br /&gt;            =             =             =        // Print the value&lt;br /&gt;}&lt;br /&gt;rs.close();          &amp;= nbsp;           &amp;= nbsp;   // Close the result set&lt;br /&gt;cstmt.close();         &amp;nbs= p;          // Close the statement &lt;br /&gt;&lt;br /&gt;Wh= at do we use setAutoCommit() for&lt;br /&gt;The DML operations by default are committed. If we wish to &lt;br /&gt;avoid the commit by default, setAutoCommit(false) has to be called on the Connection object.&lt;br /&gt;Once the statements are executed, commit() has to be called on the Connection object explicitly.&lt;br /&gt;&lt;br /&gt; Di= fference between Resultset and Rowset&lt;br /&gt;Ro= wSet&lt;br /&gt; &lt;br /&gt;The interface that adds support to the JDBC API for the JavaBeansTM component model. A rowset, which can be used as a JavaBeans component in a visual Bean development environment, can be created and configured at design time and executed at run time. &lt;br /&gt;&lt;br /&gt;The RowSet interface provides a set of JavaBeans properties that allow a RowSet instance to be configured to connect to a JDBC data source and read some data from the data source. A group of setter methods (setInt, setBytes, setString, and so on) provide a way to pass input parameters to a rowset's command property. This command is the SQL query the rowset uses when it gets its data from a relational database, which is generally the case. &lt;br /&gt;&lt;br /&gt;The RowSet interface supports JavaBeans events, allowing other components in an application to be notified when an event occurs on a rowset, such as a change in its value. &lt;br /&gt;&lt;br /&gt;The RowSet interface is unique in that it is intended to be implemented using the rest of the JDBC API. In other words, a RowSet implementation is a layer of software that executes "on top" of a JDBC driver. Implementations of the RowSet interface can be provided by anyone, including JDBC driver vendors who want to provide a RowSet implementation as part of their JDBC products. &lt;br /&gt;&lt;br /&gt;A RowSet object may make a connection with a data source and maintain that connection throughout its life cycle, in which case it is called a connected rowset. A rowset may also make a connection with a data source, get data from it, and then close the connection. Such a rowset is called a disconnected rowset. A disconnected rowset may make changes to its data while it is disconnected and then send the changes back to the original source of the data, but it must reestablish a connection to do so. &lt;br /&gt;&lt;br /&gt;ResultSet&lt;br /&gt;&lt;br /&gt;A table of data representing a database result set, which is usually generated by executing a statement that queries the database. &lt;br /&gt;&lt;br /&gt;A ResultSet object maintains a cursor pointing to its current row of data. Initially the cursor is positioned before the first row. The next method moves the cursor to the next row, and because it returns false when there are no more rows in the ResultSet object, it can be used in a while loop to iterate through the result set. &lt;br /&gt;&lt;br /&gt;A default ResultSet object is not updatable and has a cursor that moves forward only. Thus, you can iterate through it only once and only from the first row to the last row. It is possible to produce ResultSet objects that are scrollable and/or updatable. The following code fragment, in which con is a valid Connection object, illustrates how to make a result set that is scrollable and insensitive to updates by others, and that is updatable. See ResultSet fields for other options. &lt;= br&gt; &lt;br /&gt;&lt;br /&gt;How do we retrieve warning&lt;br /&gt;SQLWarning objects are a subclass of SQLException that deal with database access warnings. Warnings do not stop the execution of an application, as exceptions do.&lt;= br&gt; &lt;br /&gt;They simply alert the user that something did not happen as planned. A warning can be reported on a Connection object, a Statement object (including PreparedStatement and CallableStatement objects), or a ResultSet object. Each of these classes has a getWarnings method, which you must invoke in order to see the first warning reported on the calling object.&lt;br /&gt;&lt;br /&gt;E.g.&lt;br /&gt;&lt;br /&gt;SQLWarning warning =3D stmt.getWarnings();&lt;br /&gt;&lt;br /&gt;if (warning !=3D null) {&lt;br /&gt;&lt;br /&gt;while (warning !=3D null) {&lt;br /&gt;&lt;br /&gt;System.out.println("Message: " + warning.getMessage());&lt;br /&gt;System.out.println("SQLState: " + warning.getSQLState());&lt;br /&gt;System.out.print("Vendor error code: ");&lt;br /&gt;System.out.println(warning.getErrorCode());&lt;br /&gt;warning =3D warning.getNextWarning();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Ho= w many statements can we create with one connection&lt;br /&gt;There is no such limit on number of statements to be created&lt;br /&gt;&lt;br /&gt;Ho= w to Make Updates to Updatable Result Sets&lt;br /&gt;Usinf JDBC 2.0 API we have the ability to update rows in a result set. &lt;br /&gt;For this we need to create a ResultSet object that is updatable. &lt;br /&gt;For this, we pass the ResultSet constant CONCUR_UPDATABLE to the createStatement method. &lt;br /&gt;Connection con =3D&lt;br /&gt;    DriverManager.getConnection(url, "myLogin", "myPassword"); &lt;br /&gt;Statement stmt =3D&lt;br /&gt;    con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);&lt;br /&gt;ResultSet uprs =3D&lt;br /&gt;    stmt.executeQuery("SELECT NAME, SALARY FROM EMPLOYEES");&lt;br /&gt;&lt;br /&gt;How can you move the cursor in scrollable result sets&lt;br /&gt;In JDBC 2.0 API we have the ability to move a result set=92s cursor backward as well as forward. We can also move the cursor to a particular row and check the position of the cursor. &lt;br /&gt;Statement stmt =3D con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);&lt;br /&gt;ResultSet srs =3D stmt.executeQuery(=94SELECT NAME, SALARY FROM EMPLOYEES=94); &lt;br /&gt;&lt;br /&gt;The first argument is one of three constants added to the ResultSet API to indicate the type of a ResultSet object: TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE , and TYPE_SCROLL_SENSITIVE. The second argument is one of two ResultSet constants for specifying whether a result set is read-only or updatable: CONCUR_READ_ONLY and CONCUR_UPDATABLE. &lt;br /&gt;&lt;br /&gt;Make sure that when you specify a type, you must also specify whether it is read-only or updatable. Specifying the constant TYPE_FORWARD_ONLY creates a nonscrollable result set, that is, one in which the cursor moves only forward. If you do not specify any constants for the type and updatability of a ResultSet object, you will automatically get one that is TYPE_FORWARD_ONLY and CONCUR_READ_ONLY. &lt;br /&gt;&lt;br /&gt;What=92s the difference between TYPE_SCROLL_INSENSITIVE , and TYPE_SCROLL_SENSITIVE&lt;br /&gt;You will get a scrollable ResultSet object if you specify one of these ResultSet constants.The difference between the two has to do with whether a result set reflects changes that are made to it while it is open and whether certain methods can be called to detect these changes. Generally speaking, a result set that is TYPE_SCROLL_INSENSITIVE does not reflect changes made while it is still open and one that is TYPE_SCROLL_SENSITIVE does. All three types of result sets will make changes visible if they are closed and then reopened: &lt;br /&gt;Statement stmt =3D&lt;br /&gt;    con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);&lt;br /&gt;ResultSet srs =3D&lt;br /&gt;    stmt.executeQuery("SELECT NAME, SALARY FROM PERSON");= &lt;br /&gt;srs.afterLast();&lt;br /&gt;while (srs.previous())&lt;br /&gt;{&lt;br /&gt;    String name =3D srs.getString("NAME");&lt;br /&gt;    float salary =3D srs.getFloat("SALARY");&lt;br /&gt;    System.out.println(name + " " + salary);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;How do you insert images in Database using JDBC&lt;br /&gt;We can store images in the databse using the BLOB datatype where in the image is stored as a byte stream&lt;br /&gt;&lt;br /&gt;What is Metadata&lt;br /&gt;It is information about one of two things: Database information (java.sql.DatabaseMetaData), or Information about a specific ResultSet (java.sql.ResultSetMetaData). Use DatabaseMetaData to find information about your database, such as its capabilities and structure. Use ResultSetMetaData to find information about the results of an SQL query, such as size and types of columns &lt;br /&gt;&lt;br /&gt;What is a data source&lt;br /&gt;A DataSource class brings another level of abstraction than directly using a connection object. Data source can be referenced by JNDI. Data Source may point to RDBMS, file System , any DBMS etc.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8955336342891215397-5606267515185194875?l=javaimpquestions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaimpquestions.blogspot.com/feeds/5606267515185194875/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8955336342891215397&amp;postID=5606267515185194875' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8955336342891215397/posts/default/5606267515185194875'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8955336342891215397/posts/default/5606267515185194875'/><link rel='alternate' type='text/html' href='http://javaimpquestions.blogspot.com/2008/08/jdbc-imp-questions.html' title='Jdbc Imp Questions'/><author><name>Naresh Namana</name><uri>http://www.blogger.com/profile/05755392141578528676</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8955336342891215397.post-8983651869870931388</id><published>2008-08-12T23:23:00.000-07:00</published><updated>2008-08-12T23:28:28.552-07:00</updated><title type='text'>Servlet Questions</title><content type='html'>Servlet is a script, which resides and executes on server side, to create dynamic HTML. In servlet programming we will use java language. A servlet can handle multiple requests concurrently&lt;br /&gt;&lt;br /&gt;What is the architechture of servlet package? Servlet Interface is the central abstraction. All servlets implements this Servlet &lt;br /&gt;Interface either direclty or indirectly &lt;br /&gt;( may implement or extend Servlet Interfaces sub classes or sub interfaces)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Servlet&lt;br /&gt;|&lt;br /&gt;Generic Servlet&lt;br /&gt;|&lt;br /&gt;HttpServlet ( Class ) -- we will extend this class to handle GET / PUT HTTP requests&lt;br /&gt;|&lt;br /&gt;MyServlet&lt;br /&gt;&lt;br /&gt;Wh= at is the difference between HttpServlet and GenericServlet? A GenericServlet has a service() method to handle requests.&lt;br /&gt;HttpServlet extends GenericServlet added new methods &lt;br /&gt;doGet() &lt;br /&gt;doPost() &lt;br /&gt;doHead() &lt;br /&gt;doPut() &lt;br /&gt;doOptions() &lt;br /&gt;doDelete() &lt;br /&gt;doTrace() methods &lt;br /&gt;Both these classes are abstract.&lt;br /&gt;&lt;br /&gt;What's the difference between servlets and applets? Servlets executes on Servers. Applets executes on browser. Unlike applets, however, servlets have no graphical user interface. &lt;br /&gt;&lt;br /&gt;What are the uses of Servlets? A servlet can handle multiple requests concurrently, and can synchronize requests. Servlets can forward requests to other servers and servlets. Thus servlets can be used to balance load among several servers.&lt;br /&gt;&lt;br /&gt;When doGET() method will going to execute? When we specified method=3D'GET' in HTML&lt;br /&gt;Example : &lt; form name=3D'SSS' method=3D'GET'&gt;&lt;br /&gt;&lt;br /&gt;Wh= en doPOST() method will going to execute? When we specified method=3D'POST' in HTML&lt;br /&gt;&lt; form name=3D'SSS' method=3D'POST' &gt;&lt;br /&gt;&lt;br /&gt;What is the difference between Difference between doGet() and doPost()? GET Method : Using get method we can able to pass 2K data from HTML &lt;br /&gt;All data we are passing to Server will be displayed in URL (request string).&lt;br /&gt;&lt;br /&gt;POST Method : In this method we does not have any size limitation.&lt;br /&gt;All data passed to server will be hidden, User cannot able to see this info&lt;br /&gt;on the browser.&lt;br /&gt;&lt;br /&gt;What is the servlet life cycle?&lt;br /&gt;When first request came in for the servlet , Server will invoke init() method of the servlet. There after if any user request the servlet program, Server will directly executes the service() method. When Server want to remove the servlet from pool, then it will execute the destroy() method&lt;br /&gt;&lt;br /&gt; Which code line must be set before any of the lines that use the PrintWriter?&lt;br /&gt;setContentType() method must be set.&lt;br /&gt;&lt;br /&gt;Which protocol will be used by browser and servlet to communicate ?&lt;br /&gt;HTTP&lt;br /&gt;&lt;br /&gt;In= how many ways we can track the sessions?&lt;br /&gt;Method 1) By URL rewriting &lt;br /&gt;&lt;br /&gt;Method 2) Using Session object&lt;br /&gt;&lt;br /&gt;Getting Session form HttpServletRequest object &lt;br /&gt;HttpSession session =3D request.getSession(true);&lt;br /&gt;&lt;br /&gt;Get a Value from the session &lt;br /&gt;session.getValue(session.getId()); &lt;br /&gt;&lt;br /&gt;Adding values to session&lt;br /&gt;cart =3D new Cart();&lt;br /&gt;session.putValue(session.getId(), cart); &lt;br /&gt;&lt;br /&gt;At the end of the session, we can inactivate the session by using the following command&lt;br /&gt;session.invalidate();&lt;br /&gt;&lt;br /&gt;Method 3) Using cookies&lt;br /&gt;&lt;br /&gt;Method 4) Using hidden fields&lt;br /&gt;&lt;br /&gt;How Can You invoke other web resources (or other servlet / jsp ) ?&lt;br /&gt;Servelt can invoke other Web resources in two ways: indirect and direct. &lt;br /&gt;&lt;br /&gt;Indirect Way : Servlet will return the resultant HTML to the browser which will point to another Servlet (Web resource)&lt;br /&gt;&lt;br /&gt;Direct Way : We can call another Web resource (Servelt / Jsp) from Servelt program itself, by using RequestDispatcher object.&lt;br /&gt;&lt;br /&gt;You can get this object using getRequestDispatcher("URL") method. You can get this object from either a request or a Context.&lt;br /&gt;&lt;br /&gt;Example : &lt;br /&gt;RequestDispatcher dispatcher =3D request.getRequestDispatcher("/jspsample.jsp");&lt;br /&gt;if (dispatcher !=3D null)&lt;br /&gt;dispatcher.forward(request, response);&lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;How Can you include other Resources in the Response?&lt;br /&gt;Using include method of a RequestDispatcher object.&lt;br /&gt;&lt;br /&gt;Included WebComponent (Servlet / Jsp) cannot set headers or call any method (for example, setCookie) that affects the headers of the response.&lt;br /&gt;&lt;br /&gt;Example : RequestDispatcher dispatcher =3D getServletContext().getRequestDispatcher("/banner");&lt;br /&gt;            if (dispatcher !=3D null)&lt;br /&gt;            dispa= tcher.include(request, response);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt; What is the difference between the getRequestDispatcher(String path) ServletRequest interface and ServletContext interface?&lt;br /&gt;The getRequestDispatcher(String path) method of ServletRequest interface accepts parameter the path to the resource to be included or forwarded to, which can be relative to the request of the calling servlet. If the path begins with a "/" it is interpreted as relative to the current context root.&lt;br /&gt;&lt;br /&gt;The getRequestDispatcher(String path) method of ServletContext interface cannot accepts relative paths. All path must sart with a "/" and are interpreted as relative to curent context root. If the resource is not available, or if the server has not implemented a RequestDispatcher object for that type of resource, getRequestDispatcher will return null. Your servlet should be prepared to deal with this condition.&lt;br /&gt;&lt;br /&gt;What is the use of ServletContext ?&lt;br /&gt;Using ServletContext, We can access data from its environment. Servlet context is common to all Servlets so all Servlets share the information through ServeltContext.&lt;br /&gt;&lt;br /&gt;Is there any way to generate PDF'S dynamically in servlets?&lt;br /&gt;We need to use iText. A open source library for java. Please refer sourceforge site for sample servlet examples.&lt;br /&gt;&lt;br /&gt;What is the difference between using getSession(true) and getSession(false) methods?&lt;br /&gt;getSession(true) - This method will check whether already a session is existing for the user. If a session is existing, it will return that session object, Otherwise it will create new session object and return taht object.&lt;br /&gt;&lt;br /&gt;getSession(false) - This method will check existence of session. If session exists, then it returns the reference of that session object, if not, this methods will return null&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8955336342891215397-8983651869870931388?l=javaimpquestions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaimpquestions.blogspot.com/feeds/8983651869870931388/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8955336342891215397&amp;postID=8983651869870931388' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8955336342891215397/posts/default/8983651869870931388'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8955336342891215397/posts/default/8983651869870931388'/><link rel='alternate' type='text/html' href='http://javaimpquestions.blogspot.com/2008/08/servlet-questions.html' title='Servlet Questions'/><author><name>Naresh Namana</name><uri>http://www.blogger.com/profile/05755392141578528676</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8955336342891215397.post-6945452037001334377</id><published>2008-08-12T23:07:00.000-07:00</published><updated>2008-08-12T23:17:26.721-07:00</updated><title type='text'>Struts imp</title><content type='html'>Struts is based on the MVC design pattern. Struts components can be categories into Model, View and Controller.&lt;br /&gt;Model: Components like business logic / business processes and data are the part of Model.&lt;br /&gt;View: JSP, HTML etc. are part of View&lt;br /&gt;Controller: Action Servlet of Struts is part of Controller components which works as front controller to handle all the requests.&lt;br /&gt;&lt;br /&gt;De= scribe is ActionServlet&lt;br /&gt;ActionServlet provides the "controller" in the Model-View-Controller (MVC) design pattern for web applications that is commonly known as "Model 2". This nomenclature originated with a description in the JavaServerPages Specification, version 0.92, and has persisted ever since (in the absence of a better name).Controller is responsible for handling all the requests.&lt;br /&gt;   &lt;br /&gt;Wh= at is an Action Class used for?&lt;br /&gt;An Action is an adapter between the contents of an incoming HTTP request and the corresponding business logic that should be executed to process this request. The controller (ActionServlet) will select an appropriate Action for each request, create an instance (if necessary), and call the perform method. &lt;br /&gt;Actions must be programmed in a thread-safe manner, because the controller will share the same instance for multiple simultaneous requests. In this means you should design with the following items in mind: &lt;br /&gt;=95    Instance and static variables MUST NOT be used to store information related to the state of a particular request. They MAY be used to share global resources across requests for the same action. &lt;br /&gt;=95    Access to other resources (JavaBeans, session variables, etc.) MUST be synchronized if those resources require protection. (Generally, however, resource classes should be designed to provide their own protection where necessary. &lt;br /&gt;When an Action instance is first created, the controller servlet will call setServlet() with a non-null argument to identify the controller servlet instance to which this Action is attached. When the controller servlet is to be shut down (or restarted), the setServlet() method will be called with a null argument, which can be used to clean up any allocated resources in use by this Action. &lt;br /&gt;&lt;br /&gt;Wh= at is ActionForm?&lt;br /&gt;An ActionForm is a JavaBean optionally associated with one or more ActionMappings. Such a bean will have had its properties initialized from the corresponding request parameters before the corresonding action's perform() method is called.&lt;= br&gt; When the properties of this bean have been populated, but before the perform() method of the action is called, this bean's validate() method will be called, which gives the bean a chance to verify that the properties submitted by the user are correct and valid. If this method finds problems, it returns an error messages object that encapsulates those problems, and the controller servlet will return control to the corresponding input form. Otherwise, the validate() method returns null(), indicating that everything is acceptable and the corresponding Action's perform() method should be called.&lt;br /&gt;This class must be subclassed in order to be instantiated. Subclasses should provide property getter and setter methods for all of the bean properties they wish to expose, plus override any of the public or protected methods for which they wish to provide modified functionality. &lt;br /&gt;&lt;br /&gt;Wh= at is Struts Validator Framework?&lt;br /&gt;Struts Framework provides the functionality to validate the form data. It can be use to validate the data on the users browser as well as on the server side. Struts Framework emits the java scripts and it can be used validate the form data on the client browser. Server side validation of form can be accomplished by sub classing your From Bean with DynaValidatorForm class.  &lt;br /&gt;&lt;br /&gt;Wh= at are the core classes of the Struts Framework?&lt;br /&gt;Core classes of Struts Framework are ActionForm, Action, ActionMapping, ActionForward, ActionServlet etc.= &lt;br /&gt;&lt;br /&gt;Wh= at are Tag Libraries provided with Struts?&lt;br /&gt;Struts provides a number of tag libraries that helps to create view components easily. These tag libraries are:&lt;br /&gt;a) Bean Tags: Bean Tags are used to access the beans and their properties.&lt;br /&gt;b) HTML Tags: HTML Tags provides tags for creating the view components like forms, buttons, etc..&lt;br /&gt;c) Logic Tags: Logic Tags provides presentation logics that eliminate the need for scriptlets.&lt;br /&gt;d) Nested Tags: Nested Tags helps to work with the nested context.&lt;br /&gt;&lt;br /&gt;Wh= at are difference between ActionErrors and ActionMessage?&lt;br /&gt;ActionMessage: A class that encapsulates messages. Messages can be either global or they are specific to a particular bean property.&lt;br /&gt;Each individual message is described by an ActionMessage object, which contains a message key (to be looked up in an appropriate message resources database), and up to four placeholder arguments used for parametric substitution in the resulting message.&lt;br /&gt;ActionErrors: A class that encapsulates the error messages being reported by the validate() method of an ActionForm. Validation errors are either global to the entire ActionForm bean they are associated with, or they are specific to a particular bean property (and, therefore, a particular input field on the corresponding form).&lt;br /&gt;&lt;br /&gt;Ho= w you will handle exceptions in Struts?&lt;br /&gt;In Struts you can handle the exceptions in two ways:&lt;br /&gt;a) Declarative Exception Handling: You can either define global exception handling tags in your struts-config.xml or define the exception handling tags within .. tag. &lt;br /&gt;Example:&lt;br /&gt;&lt;br /&gt;      key=3D"database.error.duplicate" &lt;br /&gt;      path=3D"/UserExists.jsp" &lt;br /&gt;      type=3D"mybank.account.DuplicateUserException"/&gt;&lt;br /&gt;b) Programmatic Exception Handling: Here you can use try{}catch{} block to handle the exception. &lt;br /&gt;&lt;br /&gt;Gi= ve the Details of XML files used in Validator Framework?&lt;br /&gt;The Validator Framework uses two XML configuration files validator-rules.xml and validation.xml&lt;br /&gt;The validation-rules.xml is provided with the Validator Framework and it declares and assigns the logical names to the validation routines. It also contains the client-side javascript code for each validation routine. The validation routines are java methods plugged into the system to perform specific validations.&lt;br /&gt;&lt;br /&gt;Following table contains the details of the elements in this file:&lt;br /&gt;Element=  &lt;br /&gt;Attributes and Description&lt;br /&gt;&lt;br /&gt;form-validation &lt;br /&gt;This is the root node. It contains nested elements for all of the other configuration settings.&lt;br /&gt;&lt;br /&gt;global &lt;br /&gt;The validator details specified within this, are global and are accessed by all forms.&lt;= span style=3D"color: navy;"&gt;&lt;br /&gt;&lt;br /&gt;validator &lt;br /&gt;The validator element defines what validators objects can be used with the fields referenced by the formset elements.&lt;= /span&gt;&lt;br /&gt;&lt;br /&gt;The attributes are: &lt;br /&gt;&lt;br /&gt;name: Contains a logical name for the validation routine&lt;br /&gt;&lt;br /&gt;classname: Name of the Form Bean class that extends the subclass of ActionForm class&lt;br /&gt;&lt;br /&gt;method&lt;= /b&gt;: Name of the method of the Form Bean class&lt;br /&gt;&lt;br /&gt;methodParams: parameters passed to the method&lt;br /&gt;&lt;br /&gt;msg= :Validator uses Struts' Resource Bundle mechanism for externalizing error messages. Instead of having hard-coded error messages in the framework, Validator allows you to specify a key to a message in the ApplicationResources.properties file that should be returned if a validation fails. Each validation routine in the validator-rules.xml file specifies an error message key as value for this attribute.&lt;= span style=3D"color: navy;"&gt;&lt;br /&gt;&lt;br /&gt;depends= : If validation is required, the value here is specified as 'required' for this attribute.&lt;br /&gt;&lt;br /&gt;jsFunctionName= : Name of the javascript function is specified here. &lt;br /&gt;&lt;br /&gt;javascript &lt;br /&gt;Contains the code of the javascript function used for client-side validation. Starting in Struts 1.2.0 the default javascript definitions have been consolidated to commons-validator.  The default can be overridden by supplying a element with a CDATA section, just as in struts 1.1.&lt;= /span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The Validator plug-in (validator-rules.xml) is supplied with a predefined set of commonly used validation rules such as Required, Minimum Length, Maximum length, Date Validation, Email Address validation and more. This basic set of rules can also be extended with custom validators if required.&lt;br /&gt;&lt;br /&gt;Structure of validation.xml This validation.xml configuration file defines which validation routines that is used to validate Form Beans. You can define validation logic for any number of  Form Beans in this configuration file. Inside that definition, you specify the validations you want to apply to the Form Bean's fields. The definitions in this file use the logical names of Form Beans from the struts-config.xml file along with the logical names of validation routines from the validator-rules.xml file to tie the two together.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Example of form in the validation.xml file:&lt;br /&gt;&lt;!-- An example form --&gt;&lt;br /&gt;&lt;form name="3D"&gt;&lt;br /&gt;&lt;field property="'3D" depends="'3D"&gt;&lt;br /&gt;       &lt;arg key="3D"&gt;&lt;br /&gt;     &lt;br /&gt;     &lt;field property="'3D" depends="'3D"&gt;&lt;br /&gt;         &lt;arg key="3D"&gt;&lt;br /&gt;         &lt;var&gt;&lt;br /&gt;            &lt;var-name&gt;mask&lt;/var-name&gt;&lt;br /&gt;            &lt;var-value&gt;^[0-9a-zA-Z]*$&lt;/var-value&gt;&lt;br /&gt;        &lt;/var&gt;&lt;br /&gt;   &lt;br /&gt;  &lt;/form&gt; &lt;br /&gt;Element=  &lt;br /&gt;Attributes and Description&lt;br /&gt;&lt;br /&gt;form-validation &lt;br /&gt;This is the root node. It contains nested elements for all of the other configuration settings&lt;br /&gt;&lt;br /&gt;global &lt;br /&gt;The constant details are specified in element within this element.&lt;br /&gt;&lt;br /&gt;constant &lt;br /&gt;Constant properties are specified within this element for pattern matching.&lt;br /&gt;&lt;br /&gt;constant-name &lt;br /&gt;Name of the constant property is specified here&lt;br /&gt;&lt;br /&gt;constant-value &lt;br /&gt;Value of the constant property is specified here.&lt;br /&gt;&lt;br /&gt;formset &lt;br /&gt;This element contains multiple &lt;form&gt;elements &lt;br /&gt;&lt;br /&gt;form &lt;br /&gt;This element contains the form details.&lt;br /&gt;The attributes are:&lt;br /&gt;name:Contains the form name. Validator uses this logical name to map the validations to a Form Bean defined in the struts-config.xml file= &lt;br /&gt;&lt;br /&gt;field &lt;br /&gt;This element is inside the form element, and it defines the validations to apply to specified Form Bean fields.&lt;br /&gt;&lt;br /&gt;The attributes are:&lt;br /&gt;&lt;br /&gt;property: Contains the name of a field in the specified Form Bean&lt;br /&gt;&lt;br /&gt;depends= : Specifies the logical names of validation routines from the validator-rules.xml file that should be applied to the field.&lt;br /&gt;&lt;br /&gt;arg &lt;br /&gt;A key for the error message to be thrown incase the validation fails, is specified here&lt;br /&gt;&lt;br /&gt;var &lt;br /&gt;Contains the variable names and their values as nested elements within this element.&lt;br /&gt;&lt;br /&gt;var-name &lt;br /&gt;The name of the criteria against which a field is validated is specified here as a variable&lt;br /&gt;&lt;br /&gt;var-value &lt;br /&gt;The value of the field is specified here&lt;br /&gt;= &lt;br /&gt;&lt;br /&gt;= Ho= w you will display validation fail errors on jsp page?&lt;br /&gt;Following tag displays all the errors:&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Ho= w you will enable front-end validation based on the xml in validation.xml?&lt;br /&gt;The tag to allow front-end validation based on the xml in validation.xml. For  example the code: generates the client side java script for the form "logonForm" as defined in the validation.xml file. The when added in the jsp file generates the client site validation script.&lt;br /&gt;&lt;br /&gt;Ca= n I setup Apache Struts to use multiple configuration files?&lt;br /&gt;Yes Struts can use multiple configuration files. Here is the configuration example:&lt;br /&gt;&lt;servlet&gt;         &lt;br /&gt;            &lt;servlet-name&gt;banking&lt;/servlet-name&gt;&lt;br /&gt;            &lt;servlet-class&gt;org.apache.struts.action.ActionServlet&lt;/servlet-class&gt;&lt;br /&gt;            &lt;init-param&gt;&lt;br /&gt;            =        &lt;param-name&gt;config&lt;/param-name&gt;&lt;br /&gt;            =        &lt;param-value&gt;/WEB-INF/struts-config.xml,&lt;br /&gt;            =             =             =         /WEB-INF/struts-authentication.xml,&lt;br /&gt;            =             =             =        /WEB-INF/struts-help.xml&lt;/param-value&gt;&lt;br /&gt;            &lt;/init-param&gt;&lt;br /&gt;            &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;&lt;br /&gt;&lt;/servlet&gt;&lt;br /&gt;&lt;br /&gt;Ho= w you will make available any Message Resources Definitions file to the Struts Framework Environment?&lt;= /span&gt;&lt;br /&gt;Message Resources Definitions file are simple .properties files and these files contains the messages that can be used in the struts project. Message Resources Definitions files can be added to the struts-config.xml file through tag.&lt;br /&gt;Example:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Wh= at is Struts Flow?&lt;br /&gt;Struts Flow is a port of Cocoon's Control Flow to Struts to allow complex workflow, like multi-form wizards, to be easily implemented using continuations-capable JavaScript. It provides the ability to describe the order of Web pages that have to be sent to the client, at any given point in time in an application. The code is based on a proof-of-concept Dave Johnson put together to show how the Control Flow could be extracted from Cocoon. (Ref: http://struts.sourceforge.net/struts-flow/index.html )&lt;br /&gt;&lt;br /&gt;Wh= at are the difference between and ?= &lt;br /&gt;: This tag is used to output locale-specific text (from the properties files) from a MessageResources bundle.&lt;br /&gt;: This tag is used to output property values from a bean. is a commonly used tag which enables the programmers to easily present the data.&lt;br /&gt;&lt;br /&gt;Wh= at is LookupDispatchAction?&lt;br /&gt;An abstract Action that dispatches to the subclass mapped execute method. This is useful in cases where an HTML form has multiple submit buttons with the same name. The button name is specified by the parameter property of the corresponding ActionMapping. &lt;br /&gt;&lt;br /&gt;Wh= at do you understand by DispatchAction?&lt;br /&gt;DispatchAction is an action that comes with Struts 1.1 or later, that lets you combine Struts actions into one class, each with their own method. The org.apache.struts.action.DispatchAction class allows multiple operation to mapped to the different functions in the same Action class. &lt;br /&gt;For example: &lt;br /&gt;A package might include separate RegCreate, RegSave, and RegDelete Actions, which just perform different operations on the same RegBean object. Since all of these operations are usually handled by the same JSP page, it would be handy to also have them handled by the same Struts Action. &lt;br /&gt;A very simple way to do this is to have the submit button modify a field in the form which indicates which operation to perform.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SAVE&lt;br /&gt;SAVE AS NEW &lt;br /&gt;DELETE&lt;br /&gt;Then, in the Action you can setup different methods to handle the different operations, and branch to one or the other depending on which value is passed in the dispatch field.&lt;br /&gt;String dispatch =3D myForm.getDispatch();&lt;br /&gt;if ("create".equals(dispatch)) { ...&lt;br /&gt;if ("save".equals(dispatch)) { ...&lt;br /&gt;The Struts Dispatch Action [org.apache.struts.actions] is designed to do exactly the same thing, but without messy branching logic. The base perform method will check a dispatch field for you, and invoke the indicated method. The only catch is that the dispatch methods must use the same signature as perform. This is a very modest requirement, since in practice you usually end up doing that anyway.&lt;br /&gt;To convert an Action that was switching on a dispatch field to a DispatchAction, you simply need to create methods like this&lt;br /&gt;public ActionForward create(&lt;br /&gt;    ActionMapping mapping, &lt;br /&gt;    ActionForm form, &lt;br /&gt;    HttpServletRequest request, &lt;br /&gt;    HttpServletResponse response) &lt;br /&gt;  throws IOException, ServletException { ...&lt;br /&gt;public ActionForward save(&lt;br /&gt;    ActionMapping mapping, &lt;br /&gt;    ActionForm form, &lt;br /&gt;    HttpServletRequest request, &lt;br /&gt;    HttpServletResponse response) &lt;br /&gt;  throws IOException, ServletException { ...&lt;br /&gt;Cool. But do you have to use a property named dispatch? No, you don't. The only other step is to specify the name of of the dispatch property as the "parameter" property of the action-mapping. So a mapping for our example might look like this:&lt;br /&gt;&lt;br /&gt;  path=3D"/reg/dispatch" &lt;br /&gt;  type=3D"app.reg.RegDispatch" &lt;br /&gt;  name=3D"regForm" &lt;br /&gt;  scope=3D"request" &lt;br /&gt;  validate=3D"true" &lt;br /&gt;  parameter=3D"dispatch"/&gt;&lt;br /&gt;If you wanted to use the property "o" instead, as in o=3Dcreate, you would change the mapping to&lt;br /&gt;&lt;br /&gt;  path=3D"/reg/dispatch" &lt;br /&gt;  type=3D"app.reg.RegDispatch" &lt;br /&gt;  name=3D"regForm" &lt;br /&gt;  scope=3D"request" &lt;br /&gt;  validate=3D"true" &lt;br /&gt;  parameter=3D"o"/&gt;&lt;br /&gt;Again, very cool. But why use a JavaScript button in the first place? Why not use several buttons named "dispatch" and use a different value for each?&lt;br /&gt;You can, but the value of the button is also its label. This means if the page designers want to label the button something different, they have to coordinate the Action programmer. Localization becomes virtually impossible. &lt;br /&gt;&lt;br /&gt;Is= struts threadsafe?Give an example?&lt;br /&gt;Struts is not only thread-safe but thread-dependant. The response to a request is handled by a light-weight Action object, rather than an individual servlet. Struts instantiates each Action class once, and allows other requests to be threaded through the original object. This core strategy conserves resources and provides the best possible throughput. A properly-designed application will exploit this further by routing related operations through a single Action&lt;br /&gt;&lt;br /&gt;Wh= at are the uses of tiles-def.xml file, resourcebundle.properties file, validation.xml file?= &lt;br /&gt;tiles-def.xml is is an xml file used to configure tiles with the struts application. You can define the layout / header / footer / body content for your View.&lt;br /&gt;&lt;br /&gt;Wh= at is the difference between perform() and execute() methods?&lt;br /&gt;Perform method is the method which was deprecated in the Struts Version 1.1.  In Struts 1.x, Action.perform() is the method called by the ActionServlet. This is typically where your business logic resides, or at least the flow control to your JavaBeans and EJBs that handle your business logic. As we already mentioned, to support declarative exception handling, the method signature changed in perform. Now execute just throws Exception. Action.perform() is now deprecated; however, the Struts v1.1 ActionServlet is smart enough to know whether or not it should call perform or execute in the Action, depending on which one is available.     &lt;br /&gt;Ho= w Struts relates to J2EE?&lt;br /&gt;Struts framework  is built on J2EE technologies (JSP, Servlet, Taglibs), but it is itself not part of the J2EE standard.&lt;br /&gt;&lt;br /&gt;Wh= at is Struts actions and action mappings?&lt;br /&gt;A Struts action is an instance of a subclass of an Action class, which implements a portion of a Web application and whose perform or execute method returns a forward.&lt;br /&gt;&lt;br /&gt;An action can perform tasks such as validating a user name and password.= &lt;br /&gt;&lt;br /&gt;An action mapping is a configuration file entry that, in general, associates an action name with an action. An action mapping can contain a reference to a form bean that the action can use, and can additionally define a list of local forwards that is visible only to this action.&lt;br /&gt;&lt;br /&gt;An action servlet is a servlet that is started by the servlet container of a Web server to process a request that invokes an action. The servlet receives a forward from the action and asks the servlet container to pass the request to the forward's URL. An action servlet must be an instance of an org.apache.struts.action.ActionServlet class or of a subclass of that class. An action servlet is the primary component of the controller.&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8955336342891215397-6945452037001334377?l=javaimpquestions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javaimpquestions.blogspot.com/feeds/6945452037001334377/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8955336342891215397&amp;postID=6945452037001334377' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8955336342891215397/posts/default/6945452037001334377'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8955336342891215397/posts/default/6945452037001334377'/><link rel='alternate' type='text/html' href='http://javaimpquestions.blogspot.com/2008/08/struts-imp.html' title='Struts imp'/><author><name>Naresh Namana</name><uri>http://www.blogger.com/profile/05755392141578528676</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
