You are on page 1of 10

1. What is the difference between procedural and object-oriented programs?

- a) 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. b) 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.
. What are Encapsulation, Inheritance and Polymorphism?- !ncapsulation is the
mechanism that binds together code and data it manipulates and "eeps both safe from
outside interference and misuse. Inheritance is the process by which one object ac#uires the
properties of another object. Polymorphism is the feature that allows one interface to be used
for general class actions.
$. What is the difference between Assignment and Initialization?- %ssignment can be done
as many times as desired whereas initiali&ation can be done only once.
'. What is Ps?- Object oriented programming organi&es a program around its data, i. e. ,
objects and a set of well defined interfaces to that data. %n object-oriented program can be
characteri&ed as data controlling access to code.
(. What are !lass, !onstructor and Primiti"e data types?- )lass 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.
)onstructor is a special "ind of method that determines how an object is initiali&ed when
created. Primiti*e data types are + types and they are, byte, short, int, long, float, double,
boolean, char.
-. What is an bject and how do you allocate memory to it?- 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. .hen an object is created using new operator,
memory is allocated to it.
/. What is the difference between constructor and method?- )onstructor will be
automatically in*o"ed when an object is created whereas method has to be called explicitly.
+. What are methods and how are they defined?- 0ethods 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. 0ethod definition has four parts. 1hey
are name of the method, type of object or primiti*e type the method returns, a list of
parameters and the body of the method. % method2s signature is a combination of the first
three parts mentioned abo*e.
3. What is the use of bin and lib in #$%?- 4in contains all tools such as ja*ac, applet*iewer,
awt tool, etc., whereas lib contains %PI and all pac"ages.
15.What is casting?- )asting is used to con*ert the *alue of one type to another.
11.&ow many ways can an argument be passed to a subroutine and e'plain them?- %n
argument can be passed in two ways. 1hey are passing by *alue and passing by reference.
Passing by *alue, 1his method copies the *alue of an argument into the formal parameter of
the subroutine. Passing by reference, In this method, a reference to an argument 6not the
*alue of the argument) is passed to the parameter.
1.What is the difference between an argument and a parameter?- .hile defining method,
*ariables passed in the method are called parameters. .hile using those methods, *alues
passed to those *ariables are called arguments.
1$.What are different types of access modifiers?- public, %ny thing declared as public can be
accessed from anywhere. pri*ate, %ny thing declared as pri*ate can2t be seen outside of its
class. protected, %ny thing declared as protected can be accessed by classes in the same
pac"age and subclasses in the other pac"ages. default modifier , )an be accessed only to
classes in the same pac"age.
1'.What is final, finalize() and finally?- final , final "eyword can be used for class, method
and *ariables. % final class cannot be subclassed and it pre*ents other programmers from
subclassing a secure class to in*o"e insecure methods. % final method can2t be o*erridden. %
final *ariable can2t change from its initiali&ed *alue. finali&e6) , finali&e6) method is used
just before an object is destroyed and can be called just prior to garbage collection. finally ,
finally, a "ey word used in exception handling, creates a bloc" of code that will be executed
after a try7catch bloc" has completed and before the code following the try7catch bloc". 1he
finally bloc" will execute whether or not an exception is thrown. 8or 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. 1his finally "eyword is designed to address this
contingency.
1(.What is *+I!$E?- 9nicode is used for internal representation of characters and strings
and it uses 1- bits to represent each other.
1-.What is ,arbage !ollection and how to call it e'plicitly?- .hen an object is no longer
referred to by any *ariable, ja*a automatically reclaims memory used by that object. 1his is
"nown as garbage collection. :ystem. gc6) method may be used to call it explicitly.
1/.What is finalize() method?- finali&e 6) method is used just before an object is destroyed
and can be called just prior to garbage collection.
1+.What are -ransient and .olatile /odifiers?- 1ransient, 1he transient modifier applies to
*ariables only and it is not stored as part of its object2s Persistent state. 1ransient *ariables
are not seriali&ed. ;olatile, ;olatile modifier applies to *ariables only and it tells the
compiler that the *ariable modified by *olatile can be changed unexpectedly by other parts
of the program.
13.What is method o"erloading and method o"erriding?- 0ethod o*erloading, .hen a
method in a class ha*ing the same method name with different arguments is said to be
method o*erloading. 0ethod o*erriding , .hen a method in a class ha*ing the same method
name with same arguments is said to be method o*erriding.
5.What is difference between o"erloading and o"erriding?- a) In o*erloading, there is a
relationship between methods a*ailable in the same class whereas in o*erriding, there is
relationship between a superclass method and subclass method. b) O*erloading does not
bloc" inheritance from the superclass whereas o*erriding bloc"s inheritance from the
superclass. c) In o*erloading, separate methods share the same name whereas in o*erriding,
subclass method replaces the superclass. d) O*erloading must ha*e different method
signatures whereas o*erriding must ha*e same signature.
1.What is meant by Inheritance and what are its ad"antages?- Inheritance is the process
of inheriting all the features from a class. 1he ad*antages of inheritance are reusability of
code and accessibility of *ariables and methods of the super class by subclasses.
.What is the difference between this() and super()?- this6) can be used to in*o"e a
constructor of the same class whereas super6) can be used to in*o"e a super class
constructor.
$.What is the difference between superclass and subclass?- % super class is a class that is
inherited whereas sub class is a class that does the inheriting.
'.What modifiers may be used with top-le"el class?- public, abstract and final can be used
for top-le*el class.
(.What are inner class and anonymous class?- Inner class , classes defined in other classes,
including those defined in methods are called inner classes. %n inner class can ha*e any
accessibility including pri*ate. %nonymous class , %nonymous class is a class defined inside
a method without a name and is instantiated and declared in the same place and cannot ha*e
explicit constructors.
-.What is a pac0age?- % pac"age is a collection of classes and interfaces that pro*ides a
high-le*el layer of access protection and name space management.
/.What is a reflection pac0age?- ja*a. lang. reflect pac"age has the ability to analy&e itself in
runtime.
+.What is interface and its use?- Interface is similar to a class which may contain method2s
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. Interfaces are useful for, a)<eclaring
methods that one or more classes are expected to implement b))apturing similarities
between unrelated classes without forcing a class relationship. c)<etermining an object2s
programming interface without re*ealing the actual body of the class.
3.What is an abstract class?- %n abstract class is a class designed with implementation gaps
for subclasses to fill in and is deliberately incomplete.
$5.What is the difference between Integer and int?- a) Integer is a class defined in the ja*a.
lang pac"age, whereas int is a primiti*e data type defined in the =a*a language itself. =a*a
does not automatically con*ert from one to the other. b) Integer can be used as an argument
for a method that re#uires an object, whereas int can be used for calculations.
$1.What is a cloneable interface and how many methods does it contain?- It is not ha*ing
any method because it is a 1%>>!< or 0%?@!? interface.
$.What is the difference between abstract class and interface?- a) %ll the methods declared
inside an interface are abstract whereas abstract class must ha*e at least one abstract method
and others may be concrete or abstract. b) In abstract class, "ey word abstract must be used
for the methods whereas interface we need not use that "eyword for the methods. c) %bstract
class must ha*e subclasses whereas interface can2t ha*e subclasses.
$$.!an you ha"e an inner class inside a method and what "ariables can you access?- Aes,
we can ha*e an inner class inside a method and final *ariables can be accessed.
$'.What is the difference between 1tring and 1tring 2uffer?- a) :tring objects are constants
and immutable whereas :tring4uffer objects are not. b) :tring class supports constant
strings whereas :tring4uffer class supports growable and modifiable strings.
$(.What is the difference between Array and "ector?- %rray is a set of related data type and
static whereas *ector is a growable array of objects and dynamic.
$-.What is the difference between e'ception and error?- 1he exception class defines mild
error conditions that your program encounters. !xceptions can occur when trying to open the
file, which does not exist, the networ" connection is disrupted, operands being manipulated
are out of prescribed ranges, the class file you are interested in loading is missing. 1he error
class defines serious error conditions that you should not attempt to reco*er from. In most
cases it is ad*isable to let the program terminate when such an error is encountered.
$/.What is the difference between process and thread?- Process is a program in execution
whereas thread is a separate path of execution in a program.
$+.What is multithreading and what are the methods for inter-thread communication and
what is the class in which these methods are defined?- 0ultithreading is the mechanism
in which more than one thread run independent of each other within the process. wait 6),
notify 6) and notify%ll6) methods can be used for inter-thread communication and these
methods are in Object class. wait6) , .hen a thread executes a call to wait6) method, it
surrenders the object loc" and enters into a waiting state. notify6) or notify%ll6) , 1o remo*e
a thread from the waiting state, some other thread must ma"e a call to notify6) or notify%ll6)
method on the same object.
$3.What is the class and interface in ja"a to create thread and which is the most
ad"antageous method?- 1hread class and ?unnable interface can be used to create threads
and using ?unnable interface is the most ad*antageous method to create threads because we
need not extend thread class here.
'5.What are the states associated in the thread?- 1hread contains ready, running, waiting
and dead states.
'1.What is synchronization?- :ynchroni&ation is the mechanism that ensures that only one
thread is accessed the resources at a time.
'.When you will synchronize a piece of your code?- .hen you expect your code will be
accessed by different threads and these threads may change a particular data causing data
corruption.
'$.What is deadloc0?- .hen two threads are waiting each other and can2t precede the
program is said to be deadloc".
''.What is daemon thread and which method is used to create the daemon thread?-
<aemon thread is a low priority thread which runs intermittently in the bac" ground doing
the garbage collection operation for the ja*a runtime system. set<aemon method is used to
create a daemon thread.
'(.Are there any global "ariables in #a"a, which can be accessed by other part of your
program?- Bo, it is not the main method in which you define *ariables. >lobal *ariables is
not possible because concept of encapsulation is eliminated here.
'-.What is an applet?- %pplet is a dynamic and interacti*e program that runs inside a web
page displayed by a ja*a capable browser.
'/.What is the difference between applications and applets?- a)%pplication must be run on
local machine whereas applet needs no explicit installation on local machine. b)%pplication
must be run explicitly within a ja*a-compatible *irtual machine whereas applet loads and
runs itself automatically in a ja*a-enabled browser. d)%pplication starts execution with its
main method whereas applet starts execution with its init method. e)%pplication can run
with or without graphical user interface whereas applet must run within a graphical user
interface.
'+.&ow does applet recognize the height and width?- 9sing getParameters6) method.
'3.When do you use codebase in applet?- .hen the applet class file is not in the same
directory, codebase is used.
(5.What is the lifecycle of an applet?- init6) method - )an be called when an applet is first
loaded start6) method - )an be called each time an applet is started. paint6) method - )an be
called when the applet is minimi&ed or maximi&ed. stop6) method - )an be used when the
browser mo*es off the applet2s page. destroy6) method - )an be called when the browser is
finished with the applet.
(1.&ow do you set security in applets?- using set:ecurity0anager6) method
(.What is an e"ent and what are the models a"ailable for e"ent handling?- %n e*ent is an
e*ent object that describes a state of change in a source. In other words, e*ent occurs when
an action is generated, li"e pressing button, clic"ing mouse, selecting a list, etc. 1here are
two types of models for handling e*ents and they are, a) e*ent-inheritance model and b)
e*ent-delegation model
($.What are the ad"antages of the model o"er the e"ent-inheritance model?- 1he e*ent-
delegation model has two ad*antages o*er the e*ent-inheritance model. 1hey are, a)It
enables e*ent handling by objects other than the ones that generate the e*ents. 1his allows a
clean separation between a component2s design and its use. b)It performs much better in
applications where many e*ents are generated. 1his performance impro*ement is due to the
fact that the e*ent-delegation model does not ha*e to be repeatedly process unhandled
e*ents as is the case of the e*ent-inheritance.
('.What is source and listener?- source , % source is an object that generates an e*ent. 1his
occurs when the internal state of that object changes in some way. listener , % listener is an
object that is notified when an e*ent occurs. It has two major re#uirements. 8irst, it must
ha*e been registered with one or more sources to recei*e notifications about specific types
of e*ents. :econd, it must implement methods to recei*e and process these notifications.
((.What is adapter class?- %n adapter class pro*ides an empty implementation of all methods
in an e*ent listener interface. %dapter classes are useful when you want to recei*e and
process only some of the e*ents that are handled by a particular e*ent listener interface. Aou
can define a new class to act listener by extending one of the adapter classes and
implementing only those e*ents in which you are interested. 8or example, the
0ouse0otion%dapter class has two methods, mouse<ragged6)and mouse0o*ed6). 1he
signatures of these empty are exactly as defined in the 0ouse0otionCistener interface. If
you are interested in only mouse drag e*ents, then you could simply extend
0ouse0otion%dapter and implement mouse<ragged6) .
(-.What is meant by controls and what are different types of controls in AW-?- )ontrols
are components that allow a user to interact with your application and the %.1 supports the
following types of controls, Cabels, Push 4uttons, )hec" 4oxes, )hoice Cists, Cists,
:crollbars, 1ext )omponents. 1hese controls are subclasses of )omponent.
(/.What is the difference between choice and list?- % )hoice is displayed in a compact form
that re#uires you to pull it down to see the list of a*ailable choices and only one item may be
selected from a choice. % Cist may be displayed in such a way that se*eral list items are
*isible and it supports the selection of one or more list items.
(+.What is the difference between scrollbar and scrollpane?- % :crollbar is a )omponent,
but not a )ontainer whereas :crollpane is a )onatiner and handles its own e*ents and
perform its own scrolling.
(3.What is a layout manager and what are different types of layout managers a"ailable in
ja"a AW-?- % layout manager is an object that is used to organi&e components in a
container. 1he different layouts are a*ailable are 8lowCayout, 4orderCayout, )ardCayout,
>ridCayout and >rid4agCayout.
-5.&ow are the elements of different layouts organized?- 8lowCayout, 1he elements of a
8lowCayout are organi&ed in a top to bottom, left to right fashion. 4orderCayout, 1he
elements of a 4orderCayout are organi&ed at the borders 6Borth, :outh, !ast and .est) and
the center of a container. )ardCayout, 1he elements of a )ardCayout are stac"ed, on top of
the other, li"e a dec" of cards. >ridCayout, 1he elements of a >ridCayout are of e#ual si&e
and are laid out using the s#uare of a grid. >rid4agCayout, 1he elements of a
>rid4agCayout are organi&ed according to a grid. Dowe*er, the elements are of different
si&e and may occupy more than one row or column of the grid. In addition, the rows and
columns may ha*e different si&es.
-1.Which containers use a 2order layout as their default layout?- .indow, 8rame and
<ialog classes use a 4orderCayout as their layout.
-.Which containers use a 3low layout as their default layout?- Panel and %pplet classes
use the 8lowCayout as their default layout.
-$.What are wrapper classes?- .rapper classes are classes that allow primiti*e types to be
accessed as objects.
-'.What are .ector, &ashtable, 4in0ed4ist and Enumeration?- ;ector , 1he ;ector class
pro*ides the capability to implement a growable array of objects. Dashtable , 1he Dashtable
class implements a Dashtable data structure. % Dashtable indexes and stores objects in a
dictionary using hash codes as the object2s "eys. Dash codes are integer *alues that identify
objects. Cin"edCist, ?emo*ing or inserting elements in the middle of an array can be done
using Cin"edCist. % Cin"edCist stores each object in a separate lin" whereas an array stores
object references in consecuti*e locations. !numeration, %n object that implements the
!numeration interface generates a series of elements, one at a time. It has two methods,
namely has0ore!lements6) and next!lement6). Das0ore!lemnts6) tests if this enumeration
has more elements and next!lement method returns successi*e elements of the series.
-(.What is the difference between set and list?- :et 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.
--.What is a stream and what are the types of 1treams and classes of the 1treams?- %
:tream is an abstraction that either produces or consumes information. 1here are two types
of :treams and they are, 4yte :treams, Pro*ide a con*enient means for handling input and
output of bytes. )haracter :treams, Pro*ide a con*enient means for handling input E output
of characters. 4yte :treams classes, %re defined by using two abstract classes, namely
Input:tream and Output:tream. )haracter :treams classes, %re defined by using two
abstract classes, namely ?eader and .riter.
-/.What is the difference between 5eader6Writer and Input1tream6utput 1tream?- 1he
?eader7.riter class is character-oriented and the Input:tream7Output:tream class is byte-
oriented.
-+.What is an I6 filter?- %n I7O 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.
-3.What is serialization and deserialization?- :eriali&ation is the process of writing the state
of an object to a byte stream. <eseriali&ation is the process of restoring these objects.
/5.What is #$2!?- =<4) is a set of =a*a %PI for executing :FC statements. 1his %PI
consists of a set of classes and interfaces to enable programs to write pure =a*a <atabase
applications.
/1.What are dri"ers a"ailable?- a) =<4)-O<4) 4ridge dri*er b) Bati*e %PI Partly-=a*a
dri*er c) =<4)-Bet Pure =a*a dri*er d) Bati*e-Protocol Pure =a*a dri*er
/.What is the difference between #$2! and $2!?- a) O4<) is for 0icrosoft and =<4)
is for =a*a applications. b) O<4) can2t be directly used with =a*a because it uses a )
interface. c) O<4) ma"es use of pointers which ha*e been remo*ed totally from =a*a. d)
O<4) mixes simple and ad*anced features together and has complex options for simple
#ueries. 4ut =<4) is designed to "eep things simple while allowing ad*anced capabilities
when re#uired. e) O<4) re#uires manual installation of the O<4) dri*er manager and
dri*er on all client machines. =<4) dri*ers are written in =a*a and =<4) code is
automatically installable, secure, and portable on all platforms. f) =<4) %PI is a natural
=a*a interface and is built on O<4). =<4) retains some of the basic features of O<4).
/$.What are the types of #$2! $ri"er /odels and e'plain them?- 1here are two types of
=<4) <ri*er 0odels and they are, a) 1wo tier model and b) 1hree tier model 1wo tier
model, In this model, =a*a applications interact directly with the database. % =<4) dri*er is
re#uired to communicate with the particular database management system that is being
accessed. :FC statements are sent to the database and the results are gi*en to user. 1his
model is referred to as client7ser*er configuration where user is the client and the machine
that has the database is called as the ser*er. 1hree tier model, % middle tier is introduced in
this model. 1he functions of this model are, a) )ollection of :FC statements from the client
and handing it o*er to the database, b) ?ecei*ing results from database to the client and c)
0aintaining control o*er accessing and updating of the abo*e.
/'.What are the steps in"ol"ed for ma0ing a connection with a database or how do you
connect to a database?a) Coading the dri*er , 1o load the dri*er, )lass. forBame6) method
is used. )lass. forBame6Gsun. jdbc. odbc. =dbcOdbc<ri*erG)H .hen the dri*er is loaded, it
registers itself with the ja*a. s#l. <ri*er0anager class as an a*ailable database dri*er. b)
0a"ing a connection with database, 1o open a connection to a gi*en database,
<ri*er0anager. get)onnection6) method is used. )onnection con I <ri*er0anager.
get)onnection 6Gjdbc,odbc,somedbG, JuserG, JpasswordG)H c) !xecuting :FC statements , 1o
execute a :FC #uery, ja*a. s#l. statements class is used. create:tatement6) method of
)onnection to obtain a new :tatement object. :tatement stmt I con. create:tatement6)H %
#uery that returns data can be executed using the executeFuery6) method of :tatement. 1his
method executes the statement and returns a ja*a. s#l. ?esult:et that encapsulates the
retrie*ed data, ?esult:et rs I stmt. executeFuery6G:!C!)1 K 8?O0 some tableG)H d)
Process the results , ?esult:et returns one row at a time. Bext6) method of ?esult:et object
can be called to mo*e to the next row. 1he get:tring6) and getObject6) methods are used for
retrie*ing column *alues, while6rs. next6)) L :tring e*ent I rs. get:tring6Ge*entG)H Object
count I 6Integer) rs. getObject6GcountG)H
/(.What type of dri"er did you use in project?- =<4)-O<4) 4ridge dri*er 6is a dri*er that
uses nati*e6) language) libraries and ma"es calls to an existing O<4) dri*er to access a
database engine).
/-.What are the types of statements in #$2!?- :tatement, to be used create:tatement6)
method for executing single :FC statement Prepared:tatement M 1o be used
prepared:tatement6) method for executing same :FC statement o*er and o*er.
)allable:tatement M 1o be used prepare)all6) method for multiple :FC statements o*er
and o*er.
//.What is stored procedure?- :tored procedure is a group of :FC statements that forms a
logical unit and performs a particular tas". :tored Procedures are used to encapsulate a set of
operations or #ueries to execute on database. :tored procedures can be compiled and
executed with different parameters and results and may ha*e any combination of
input7output parameters.
/+.&ow to create and call stored procedures?- 1o create stored procedures, )reate procedure
procedurename 6specify in, out and in out parameters) 4!>IB %ny multiple :FC statementH
!B<H 1o call stored procedures, )allable:tatement csmt I con. prepare)all6GLcall
procedure name6N,N)OG)H csmt. registerOutParameter6column no. , data type)H csmt.
setInt6column no. , column name) csmt. execute6)H
/3.What is ser"let?- :er*lets are modules that extend re#uest7response-oriented ser*ers, such
as ja*a-enabled web ser*ers. 8or example, a ser*let might be responsible for ta"ing data in
an D10C order-entry form and applying the business logic used to update a company2s
order database.
+5.What are the classes and interfaces for ser"lets?- 1here are two pac"ages in ser*lets and
they are ja*ax. ser*let and
+1.What is the difference between an applet and a ser"let?- a) :er*lets are to ser*ers what
applets are to browsers. b) %pplets must ha*e graphical user interfaces whereas ser*lets ha*e
no graphical user interfaces.
+.What is the difference between doPost and do,et methods?- a) do>et6) method is used
to get information, while doPost6) method is used for posting information. b) do>et6)
re#uests can2t send large amount of information and is limited to '5-(( characters.
Dowe*er, doPost6)re#uests passes all of its data, of unlimited length. c) % do>et6) re#uest is
appended to the re#uest 9?C in a #uery string and this allows the exchange is *isible to the
client, whereas a doPost6) re#uest passes directly o*er the soc"et connection as part of its
D11P re#uest body and the exchange are in*isible to the client.
+$.What is the life cycle of a ser"let?- !ach :er*let has the same life cycle, a) % ser*er loads
and initiali&es the ser*let by init 6) method. b) 1he ser*let handles &ero or more client2s
re#uests through ser*ice6) method. c) 1he ser*er remo*es the ser*let through destroy6)
method.
+'.Who is loading the init() method of ser"let?- .eb ser*er
+(.What are the different ser"ers a"ailable for de"eloping and deploying 1er"lets?- a) =a*a
.eb :er*er b) =?un g) %pache :er*er h) Betscape Information :er*er i) .eb Cogic
+-.&ow many ways can we trac0 client and what are they?- 1he ser*let %PI pro*ides two
ways to trac" client state and they are, a) 9sing :ession trac"ing and b) 9sing )oo"ies.
+/.What is session trac0ing and how do you trac0 a user session in ser"lets?- :ession
trac"ing is a mechanism that ser*lets use to maintain state about a series re#uests from the
same user across some period of time. 1he methods used for session trac"ing are, a) 9ser
%uthentication - occurs when a web ser*er restricts access to some of its resources to only
those clients that log in using a recogni&ed username and password. b) Didden form fields -
fields are added to an D10C form that are not displayed in the client2s browser. .hen the
form containing the fields is submitted, the fields are sent bac" to the ser*er. c) 9?C
rewriting - e*ery 9?C that the user clic"s on is dynamically modified or rewritten to include
extra information. 1he extra information can be in the form of extra path information, added
parameters or some custom, ser*er-specific 9?C change. d) )oo"ies - a bit of information
that is sent by a web ser*er to a browser and which can later be read bac" from that browser.
e) Dttp:ession- places a limit on the number of sessions that can exist in memory. 1his limit
is set in the session. maxresidents property.
++.What is 1er"er-1ide Includes (11I)?- :er*er-:ide Includes allows embedding ser*lets
within D10C pages using a special ser*let tag. In many ser*lets that support ser*lets, a page
can be processed by the ser*er to include output from ser*lets at certain points inside the
D10C page. 1his is accomplished using a special internal ::IB)C9<!, which processes
the ser*let tags. ::IB)C9<! ser*let will be in*o"ed whene*er a file with an. shtml
extension is re#uested. :o D10C files that include ser*er-side includes must be stored with
an . shtml extension.
+3.What are coo0ies and how will you use them?- )oo"ies are a mechanism that a ser*let
uses to ha*e a client hold a small amount of state-information associated with the user. a)
)reate a coo"ie with the )oo"ie constructor, public )oo"ie6:tring name, :tring *alue) b) %
ser*let can send a coo"ie to the client by passing a )oo"ie object to the add)oo"ie6) method
of Dttp:er*let?esponse, public *oid Dttp:er*let?esponse. add)oo"ie6)oo"ie coo"ie) c) %
ser*let retrie*es coo"ies by calling the get)oo"ies6) method of Dttp:er*let?e#uest, public
)oo"ieP Q Dttp:er*let?e#uest. get)oo"ie6).
35.Is it possible to communicate from an applet to ser"let and how many ways and how?-
Aes, there are three ways to communicate from an applet to ser*let and they are, a) D11P
)ommunication61ext-based and object-based) b) :oc"et )ommunication c) ?0I
)ommunication
31.What is connection pooling?- .ith ser*lets, opening a database connection is a major
bottlenec" because we are creating and tearing down a new connection for e*ery page
re#uest and the time ta"en to create connection will be more. )reating a connection pool is
an ideal approach for a complicated ser*let. .ith a connection pool, we can duplicate only
the resources we need to duplicate rather than the entire ser*let. % connection pool can also
intelligently manage the si&e of the pool and ma"e sure each connection remains *alid. %
number of connection pool pac"ages are currently a*ailable. :ome li"e
<b)onnection4ro"er are freely a*ailable from =a*a !xchange .or"s by creating an object
that dispenses connections and connection Ids on re#uest. 1he )onnectionPool class
maintains a Dastable, using )onnection objects as "eys and 4oolean *alues as stored *alues.
1he 4oolean *alue indicates whether a connection is in use or not. % program calls
get)onnection6) method of the )onnectionPool for getting )onnection object it can useH it
calls return)onnection6) to gi*e the connection bac" to the pool.
3.Why should we go for interser"let communication?- :er*lets running together in the
same ser*er communicate with each other in se*eral ways. 1he three major reasons to use
interser*let communication are, a) <irect ser*let manipulation - allows to gain access to the
other currently loaded ser*lets and perform certain tas"s 6through the :er*let)ontext object)
b) :er*let reuse - allows the ser*let to reuse the public methods of another ser*let. c) :er*let
collaboration - re#uires to communicate with each other by sharing specific information
6through method in*ocation)
3$.Is it possible to call ser"let with parameters in the *54?- Aes. Aou can call a ser*let with
parameters in the syntax as 6NParam1 I xxx RR m I yyy).
3'.What is 1er"let chaining?- :er*let chaining is a techni#ue in which two or more ser*lets
can cooperate in ser*icing a single re#uest. In ser*let chaining, one ser*let2s output is piped
to the next ser*let2s input. 1his process continues until the last ser*let is reached. Its output
is then sent bac" to the client.
3(.&ow do ser"lets handle multiple simultaneous re7uests?- 1he ser*er has multiple threads
that are a*ailable to handle re#uests. .hen a re#uest comes in, it is assigned to a thread,
which calls a ser*ice method 6for example, do>et6), doPost6) and ser*ice6)) of the ser*let.
8or this reason, a single ser*let object can ha*e its ser*ice methods called by many threads
at once.
3-.What is the difference between -!P6IP and *$P?- 1)P7IP is a two-way communication
between the client and the ser*er and it is a reliable and there is a confirmation regarding
reaching the message to the destination. It is li"e a phone call. 9<P is a one-way
communication only between the client and the ser*er and it is not a reliable and there is no
confirmation regarding reaching the message to the destination. It is li"e a postal mail.
3/.What is Inet address?- !*ery computer connected to a networ" has an IP address. %n IP
address is a number that uni#uely identifies each computer on the Bet. %n IP address is a $-
bit number.
3+.What is $omain +aming 1er"ice($+1)?- It is *ery difficult to remember a set of
numbers6IP address) to connect to the Internet. 1he <omain Baming :er*ice6<B:) is used
to o*ercome this problem. It maps one particular IP address to a string of characters. 8or
example, www. mascom. com implies com is the domain name reser*ed for 9: commercial
sites, moscom is the name of the company and www is the name of the specific computer,
which is mascom2s ser*er.
33.What is *54?- 9?C stands for 9niform ?esource Cocator and it points to resource files on
the Internet. 9?C has four components, http,77www. address. com,+57index.html, where http
- protocol name, address - IP address or host name, +5 - port number and index.html - file
path.
155.What is 5/I and steps in"ol"ed in de"eloping an 5/I object?- ?emote 0ethod
In*ocation 6?0I) allows ja*a object that executes on one machine and to in*o"e the method
of a =a*a object to execute on another machine. 1he steps in*ol*ed in de*eloping an ?0I
object are, a) <efine the interfaces b) Implementing these interfaces c) )ompile the
interfaces and their implementations with the ja*a compiler d) )ompile the ser*er
implementation with ?0I compiler e) ?un the ?0I registry f) ?un the application
151.What is 5/I architecture?- ?0I architecture consists of four layers and each layer
performs specific functions, a) %pplication layer - contains the actual object definition. b)
Proxy layer - consists of stub and s"eleton. c) ?emote ?eference layer - gets the stream of
bytes from the transport layer and sends it to the proxy layer. d) 1ransportation layer -
responsible for handling the actual machine-to-machine communication.
15.what is *nicast5emotebject?- %ll remote objects must extend 9nicast?emoteObject,
which pro*ides functionality that is needed to ma"e objects a*ailable from remote machines.
15$.E'plain the methods, rebind() and loo0up() in +aming class?- rebind6) of the Baming
class6found in ja*a. rmi) is used to update the ?0I registry on the ser*er machine. Baming.
rebind6G%dd:e*erG, %dd:er*erImpl)H loo"up6) of the Baming class accepts one argument,
the rmi 9?C and returns a reference to an object of type %dd:er*erImpl.
15'.What is a #a"a 2ean?- % =a*a 4ean is a software component that has been designed to be
reusable in a *ariety of different en*ironments.
15(.What is a #ar file?- =ar file allows to efficiently deploying a set of classes and their
associated resources. 1he elements in a jar file are compressed, which ma"es downloading a
=ar file much faster than separately downloading se*eral uncompressed files. 1he pac"age
ja*a. util. &ip contains classes that read and write jar files.
15-.What is 2$%?- 4<@, 4ean <e*elopment @it is a tool that enables to create, configure
and connect a set of set of 4eans and it can be used to test 4eans without writing a code.
15/.What is #1P?- =:P is a dynamic scripting capability for web pages that allows =a*a as well
as a few special tags to be embedded into a web file 6D10C7S0C, etc). 1he suffix
traditionally ends with .jsp to indicate to the web ser*er that the file is a =:P files. =:P is a
ser*er side technology - you can2t do any client side *alidation with it. 1he ad*antages are,
a) 1he =:P assists in ma"ing the D10C more functional. :er*lets on the other hand allow
outputting of D10C but it is a tedious process. b) It is easy to ma"e a change and then let
the =:P capability of the web ser*er you are using deal with compiling it into a ser*let and
running it.
15+.What are #1P scripting elements?- =:P scripting elements lets to insert =a*a code into the
ser*let that will be generated from the current =:P page. 1here are three forms, a)
!xpressions of the form TUI expression UV that are e*aluated and inserted into the output,
b) :criptlets of the formTU code UVthat are inserted into the ser*let2s ser*ice method, and
c) <eclarations of the form TUW )ode UVthat are inserted into the body of the ser*let class,
outside of any existing methods.
153.What are #1P $irecti"es?- % =:P directi*e affects the o*erall structure of the ser*let class.
It usually has the following form,TUX directi*e attributeIG*alueG UV Dowe*er, you can
also combine multiple attribute settings for a single directi*e, as follows,TUX directi*e
attribute1IG*alue1Y attribute IG*alueY . . . attributeB IG*alueBG UV 1here are two main
types of directi*e, page, which lets to do things li"e import classes, customi&e the ser*let
superclass, and the li"eH and include, which lets to insert a file into the ser*let class at the
time the =:P file is translated into a ser*let
115.What are Predefined "ariables or implicit objects?- 1o simplify code in =:P expressions
and scriptlets, we can use eight automatically defined *ariables, sometimes called implicit
objects. 1hey are re#uest, response, out, session, application, config, page)ontext, and page.
111.What are #1P A!-I+1?- =:P actions use constructs in S0C syntax to control the
beha*ior of the ser*let engine. Aou can dynamically insert a file, reuse =a*a4eans
components, forward the user to another page, or generate D10C for the =a*a plugin.
%*ailable actions include, jsp,include - Include a file at the time the page is re#uested.
jsp,use4ean - 8ind or instantiate a =a*a4ean. jsp,setProperty - :et the property of a
=a*a4ean. jsp,getProperty - Insert the property of a =a*a4ean into the output. jsp,forward -
8orward the re#uester to a newpage. =sp, plugin - >enerate browser-specific code that ma"es
an O4=!)1 or !04!<
11.&ow do you pass data (including #a"a2eans) to a #1P from a ser"let?- 61) ?e#uest
Cifetime, 9sing this techni#ue to pass beans, a re#uest dispatcher 6using either JincludeG or
forwardG) can be called. 1his bean will disappear after processing this re#uest has been
completed. :er*let, re#uest. set%ttribute6Gthe4eanG, my4ean)H ?e#uest<ispatcher rd I
get:er*let)ontext6). get?e#uest<ispatcher6Gthepage. jspG)H rd. forward6re#uest, response)H
=:P P%>!,Tjsp, use4ean idIGthe4eanG scopeIGre#uestG classIG. . . . . G 7V6) :ession
Cifetime, 9sing this techni#ue to pass beans that are rele*ant to a particular session 6such as
in indi*idual user login) o*er a number of re#uests. 1his bean will disappear when the
session is in*alidated or it times out, or when you remo*e it. :er*let, Dttp:ession session I
re#uest. get:ession6true)H session. put;alue6Gthe4eanG, my4ean)H 7K Aou can do a re#uest
dispatcher here, or just let the bean be *isible on the next re#uest K7 =:P Page,Tjsp,use4ean
idIGthe4eanG scopeIGsessionG classIG. . . G 7V $) %pplication Cifetime, 9sing this techni#ue
to pass beans that are rele*ant to all ser*lets and =:P pages in a particular app, for all users.
8or example, I use this to ma"e a =<4) connection pool object a*ailable to the *arious
ser*lets and =:P pages in my apps. 1his bean will disappear when the ser*let engine is shut
down, or when you remo*e it. :er*let, >et:er*let)ontext6). set%ttribute6Gthe4eanG,
my4ean)H =:P P%>!,Tjsp,use4ean idIGthe4eanG scopeIGapplicationG classIG. . . G 7V
11$.&ow can I set a coo0ie in #1P?- response. setDeader6G:et-)oo"ieG, Jcoo"ie stringG)H 1o
gi*e the response-object to a bean, write a method set?esponse 6Dttp:er*let?esponse
response) - to the bean, and in jsp-file,TU bean. set?esponse 6response)H UV
11'.&ow can I delete a coo0ie with #1P?- :ay that I ha*e a coo"ie called Jfoo, G that I set a
while ago E I want it to go away. I simply, TU )oo"ie "ill)oo"ie I new )oo"ie6GfooG,
null)H @ill)oo"ie. setPath6G7G)H "ill)oo"ie. set0ax%ge65)H response. add)oo"ie6"ill)oo"ie)H
UV
11(.&ow are 1er"lets and #1P Pages related?- =:P pages are focused around D10C 6or
S0C) with =a*a codes and =:P tags inside them. .hen a web ser*er that has =:P support is
as"ed for a =:P page, it chec"s to see if it has already compiled the page into a ser*let. 1hus,
=:P pages become ser*lets and are transformed into pure =a*a and then compiled, loaded
into the ser*er and executed.