Вы находитесь на странице: 1из 100

Java Language Questions

1. What is a platform? A platform is the hardware or software environment in which a program runs. Most platforms can be described as a combination of the operating system and hardware, like Windows 2 !"#, $inu%, &olaris, and Mac'&.

2. What is the main difference between (ava platform and other platforms? )he (ava platform differs from most other platforms in that it*s a software+only platform that runs on top of other hardware+based platforms. )he (ava platform has two components, 1. )he (ava -irtual Machine .(ava -M/ 2. )he (ava Application #rogramming 0nterface .(ava A#0/

1. What is the (ava -irtual Machine? )he (ava -irtual Machine is a software that can be ported onto various hardware+based platforms.

2. What is the (ava A#0? )he (ava A#0 is a large collection of ready+made software components that provide many useful capabilities, such as graphical user interface .340/ widgets.

5. What is the package? )he package is a (ava namespace or part of (ava libraries. )he (ava A#0 is grouped into libraries of related classes and interfaces6 these libraries are known as packages.

7. What is native code? )he native code is code that after you compile it, the compiled code runs on a specific hardware platform.

8. 0s (ava code slower than native code? 9ot really. As a platform+independent environment, the (ava platform can be a bit slower than native code. :owever, smart compilers, well+tuned interpreters, and ;ust+in+time bytecode compilers can bring performance close to that of native code without threatening portability.

<. What is the seriali=ation? )he seriali=ation is a kind of mechanism that makes a class or a bean persistence by having its properties or fields and state information saved and restored to and from storage.

>. :ow to make a class or a bean seriali=able? ?y implementing either the ;ava.io.&eriali=able interface, or the ;ava.io.@%ternali=able interface. As long as one class in a class*s inheritance hierarchy implements &eriali=able or @%ternali=able, that class is seriali=able.

1 . :ow many methods in the &eriali=able interface? )here is no method in the &eriali=able interface. )he &eriali=able interface acts as a marker, telling the ob;ect seriali=ation tools that your class is seriali=able.

11. :ow many methods in the @%ternali=able interface? )here are two methods in the @%ternali=able interface. Aou have to implement these two methods in order to make your class e%ternali=able. )hese two methods are read@%ternal./ and write@%ternal./.

12. What is the difference between &eriali=alble and @%ternali=able interface? When you use &eriali=able interface, your class is seriali=ed automatically by default. ?ut you can override write'b;ect./ and read'b;ect./ two methods to control more comple% ob;ect seraili=ation process. When you use @%ternali=able interface, you have a complete control over your class*s seriali=ation process.

11. What is a transient variable? A transient variable is a variable that may not be seriali=ed. 0f you don*t want some field not to be seriali=ed, you can mark that field transient or static.

12. Which containers use a border layout as their default layout? )he window, Brame and Cialog classes use a border layout as their default layout.

15. :ow are 'bserver and 'bservable used? 'b;ects that subclass the 'bservable class maintain a list of observers. When an 'bservable ob;ect is updated it invokes the update./ method of each of its observers to notify the observers that it has changed state. )he 'bserver interface is implemented by ob;ects that observe 'bservable ob;ects.

17. What is synchroni=ation and why is it important? With respect to multithreading, synchroni=ation is the capability to control the access of multiple threads to shared resources. Without synchroni=ation, it is possible for one thread to modify a shared ob;ect while another thread is in the process of using or updating that ob;ect*s value. )his often causes dirty data and leads to significant errors.

18. What are synchroni=ed methods and synchroni=ed statements? &ynchroni=ed methods are methods that are used to control access to an ob;ect. A thread only e%ecutes a synchroni=ed method after it has acDuired the lock for the method*s ob;ect or class. &ynchroni=ed statements are similar to synchroni=ed methods. A synchroni=ed statement can only be e%ecuted after a thread has acDuired the lock for the ob;ect or class referenced in the synchroni=ed statement.

1<. What are three ways in which a thread can enter the waiting state? A thread can enter the waiting state by invoking its sleep./ method, by blocking on 0!', by unsuccessfully attempting to acDuire an ob;ect*s lock, or by invoking an ob;ect*s wait./ method. 0t can also enter the waiting state by invoking its .deprecated/ suspend./ method.

1>. Ean a lock be acDuired on a class? Aes, a lock can be acDuired on a class. )his lock is acDuired on the class*s Elass ob;ect.

2 . What*s new with the stop./, suspend./ and resume./ methods in (CF 1.2?

)he stop./, suspend./ and resume./ methods have been deprecated in (CF 1.2.

21. What is the preferred si=e of a component? )he preferred si=e of a component is the minimum component si=e that will allow the component to display normally.

22. What method is used to specify a container*s layout? )he set$ayout./ method is used to specify a container*s layout.

21. Which containers use a Blow$ayout as their default layout? )he #anel and Applet classes use the Blow$ayout as their default layout.

22. What state does a thread enter when it terminates its processing? When a thread terminates its processing, it enters the dead state.

25. What is the Eollections A#0? )he Eollections A#0 is a set of classes and interfaces that support operations on collections of ob;ects.

27. What is the $ist interface? )he $ist interface provides support for ordered collections of ob;ects.

28. :ow does (ava handle integer overflows and underflows? 0t uses those low order bytes of the result that can fit into the si=e of the type allowed by the operation.

2<. What is the -ector class? )he -ector class provides the capability to implement a growable array of ob;ects

2>. What modifiers may be used with an inner class that is a member of an outer class? A .non+local/ inner class may be declared as public, protected, private, static, final, or abstract.

1 . 0f a method is declared as protected, where may the method be accessed? 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.

11. What is an 0terator interface? )he 0terator interface is used to step through the elements of a Eollection.

12. :ow many bits are used to represent 4nicode, A&E00, 4)B+17, and 4)B+< characters? 4nicode reDuires 17 bits and A&E00 reDuire 8 bits. Although the A&E00 character set uses only 8 bits, it is usually represented as < bits. 4)B+< represents characters using <, 17, and 1< bit patterns. 4)B+17 uses 17+bit and larger bit patterns.

11. What is the difference between yielding and sleeping? 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.

12. 0s si=eof a keyword? )he si=eof operator is not a keyword.

15. What are wrapped classes? Wrapped classes are classes that allow primitive types to be accessed as ob;ects.

17. Coes garbage collection guarantee that a program will not run out of memory? 9o, it doesn*t. 0t is possible for programs to use up memory resources faster than they are garbage collected. 0t is also possible for programs to create ob;ects that are not sub;ect to garbage collection

18. What is the difference between preemptive scheduling and time slicing? 4nder preemptive scheduling, the highest priority task e%ecutes until it enters the waiting or dead states or a higher priority task comes into e%istence. 4nder time slicing, a task e%ecutes for a predefined slice of time and then reenters the pool of ready tasks. )he scheduler then determines which task should e%ecute ne%t, based on priority and other factors.

1<. 9ame Eomponent subclasses that support painting. )he Eanvas, Brame, #anel, and Applet classes support painting.

1>. What is a native method? A native method is a method that is implemented in a language other than (ava.

2 . :ow can you write a loop indefinitely? for.66/++for loop6 while.true/++always true, etc.

21. Ean an anonymous class be declared as implementing an interface and e%tending a class? An anonymous class may implement an interface or e%tend a superclass, but may not be declared to do both.

22. What is the purpose of finali=ation? )he purpose of finali=ation is to give an unreachable ob;ect the opportunity to perform any cleanup processing before the ob;ect is garbage collected.

21. Which class is the superclass for every class. 'b;ect

22. What invokes a thread*s run./ method?

After a thread is started, via its start./ method or that of the )hread class, the (-M invokes the thread*s run./ method when the thread is initially e%ecuted.

25. What is the difference between the ?oolean G operator and the GG operator? 0f an e%pression involving the ?oolean G operator is evaluated, both operands are evaluated. )hen the G operator is applied to the operand. When an e%pression involving the GG operator is evaluated, the first operand is evaluated. 0f the first operand returns a value of true then the second operand is evaluated. )he GG operator is then applied to the first and second operands. 0f the first operand evaluates to false, the evaluation of the second operand is skipped. 'perator G has no chance to skip both sides evaluation and GG operator does. 0f asked why, give details as above.

27. What is the 3regorianEalendar class? )he 3regorianEalendar provides support for traditional Western calendars.

28. What is the &imple)imeHone class? )he &imple)imeHone class provides support for a 3regorian calendar.

2<. Which Eontainer method is used to cause a container to be laid out and redisplayed? validate./

2>. What is the #roperties class? )he properties class is a subclass of :ashtable that can be read from or written to a stream. 0t also provides the capability to specify a set of default values to be used.

5 . What is the purpose of the Iuntime class? )he purpose of the Iuntime class is to provide access to the (ava runtime system.

51. What is the purpose of the &ystem class? )he purpose of the &ystem class is to provide access to system resources.

52. What is the purpose of the finally clause of a try+catch+finally statement? )he finally clause is used to provide the capability to e%ecute code no matter whether or not an e%ception is thrown or caught.

51. What is the $ocale class? )he $ocale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region.

52. What must a class do to implement an interface? 0t must provide all of the methods in the interface and identify the interface in its implements clause.

55. What is the purpose of the wait./, notify./, and notifyAll./ methods? )he wait./,notify./, and notifyAll./ methods are used to provide an efficient way for threads to communicate each other.

57. What is an abstract method? An abstract method is a method whose implementation is deferred to a subclass. 'r, a method that has no implementation .an interface of a method/.

58. What is a static method? A static method is a method that belongs to the class rather than any ob;ect of the class and doesn*t apply to an ob;ect or even reDuire that any ob;ects of the class have been instantiated.

5<. What is a protected method? A protected method is a method that can be accessed by any method in its package and inherited by any subclass of its class. 5>. What are the high+level thread states?

)he high+level thread states are ready, running, waiting, and dead.

7 . What is the difference between a static and a non+static inner class? A non+static inner class may have ob;ect instances that are associated with instances of the class*s outer class. A static inner class does not have any ob;ect instances.

71. What is an ob;ect*s lock and which ob;ect*s have locks? An ob;ect*s lock is a mechanism that is used by multiple threads to obtain synchroni=ed access to the ob;ect. A thread may e%ecute a synchroni=ed method of an ob;ect only after it has acDuired the ob;ect*s lock. All ob;ects and classes have locks. A class*s lock is acDuired on the class*s Elass ob;ect.

72. When can an ob;ect reference be cast to an interface reference? An ob;ect reference be cast to an interface reference when the ob;ect implements the referenced interface.

71. What is the difference between a Window and a Brame? )he Brame class e%tends Window to define a main application window that can have a menu bar.

72. What do heavy weight components mean? :eavy weight components like Abstract Window )oolkit .AW)/, depend on the local windowing toolkit. Bor e%ample, ;ava.awt.?utton is a heavy weight component, when it is running on the (ava platform for 4ni% platform, it maps to a real Motif button. 0n this relationship, the Motif button is called the peer to the ;ava.awt.?utton. 0f you create two ?uttons, two peers and hence two Motif ?uttons are also created. )he (ava platform communicates with the Motif ?uttons using the (ava 9ative 0nterface. Bor each and every component added to the application, there is an additional overhead tied to the local windowing system, which is why these components are called heavy weight.

75. Which package has light weight components? ;ava%.&wing package. All components in &wing, e%cept (Applet, (Cialog, (Brame and (Window are lightweight components.

77. What are peerless components? )he peerless components are called light weight components.

78. What is the difference between the Bont and BontMetrics classes? )he BontMetrics class is used to define implementation+specific properties, such as ascent and descent, of a Bont ob;ect.

7<. What happens when a thread cannot acDuire a lock on an ob;ect? 0f a thread attempts to e%ecute a synchroni=ed method or synchroni=ed statement and is unable to acDuire an ob;ect*s lock, it enters the waiting state until the lock becomes available.

7>. What is the difference between the Ieader!Writer class hierarchy and the 0nput&tream!'utput&tream class hierarchy? )he Ieader!Writer class hierarchy is character+oriented, and the 0nput&tream!'utput&tream class hierarchy is byte+oriented.

8 . What classes of e%ceptions may be caught by a catch clause? A catch clause can catch any e%ception that may be assigned to the )hrowable type. )his includes the @rror and @%ception types.

81. What is the difference between throw and throws keywords? )he throw keyword denotes a statement that causes an e%ception to be initiated. 0t takes the @%ception ob;ect to be thrown as argument. )he e%ception will be caught by an immediately encompassing try+catch construction or propagated further up the calling hierarchy. )he throws keyword is a modifier of a method that designates that e%ceptions may come out of the mehtod, either by virtue of the method throwing the e%ception itself or because it fails to catch such e%ceptions that a method it calls may throw.

82. 0f a class is declared without any access modifiers, where may the class be accessed?

A class that is declared without any access modifiers is said to have package or friendly access. )his means that the class can only be accessed by other classes and interfaces that are defined within the same package.

81. What is the Map interface? )he Map interface replaces the (CF 1.1 Cictionary class and is used associate keys with values.

82. Coes a class inherit the constructors of its superclass? A class does not inherit constructors from any of its superclasses.

85. 9ame primitive (ava types. )he primitive types are byte, char, short, int, long, float, double, and boolean.

87. Which class should you use to obtain design information about an ob;ect? )he Elass class is used to obtain information about an ob;ect*s design.

88. :ow can a 340 component handle its own events? A component can handle its own events by implementing the reDuired event+listener interface and adding itself as its own event listener.

8<. :ow are the elements of a 3rid?ag$ayout organi=ed? )he elements of a 3rid?ag$ayout are organi=ed according to a grid. :owever, the elements are of different si=es and may occupy more than one row or column of the grid. 0n addition, the rows and columns may have different si=es.

8>. What advantage do (ava*s layout managers provide over traditional windowing systems? (ava uses layout managers to lay out components in a consistent manner across all windowing platforms. &ince (ava*s layout managers aren*t tied to absolute si=ing and positioning, they are able to accommodate platform+specific differences among windowing systems.

< . What are the problems faced by (ava programmers who don*t use layout managers? Without layout managers, (ava programmers are faced with determining how their 340 will be displayed across multiple windowing systems and finding a common si=ing and positioning that will work within the constraints imposed by each windowing system.

<1. What is the difference between static and non+static variables? A static variable is associated with the class as a whole rather than with specific instances of a class. 9on+static variables take on uniDue values with each ob;ect instance.

<2. What is the difference between the paint./ and repaint./ methods? )he paint./ method supports painting via a 3raphics ob;ect. )he repaint./ method is used to cause paint./ to be invoked by the AW) painting thread.

<1. What is the purpose of the Bile class? )he Bile class is used to create ob;ects that provide access to the files and directories of a local file system.

<2. :ow does multithreading take place on a computer with a single E#4? )he operating system*s task scheduler allocates e%ecution time to multiple tasks. ?y Duickly switching between e%ecuting tasks, it creates the impression that tasks e%ecute seDuentially.

<5. What restrictions are placed on method overloading? )wo methods may not have the same name and argument list but different return types.

<7. What restrictions are placed on method overriding? 'verridden methods must have the same name, argument list, and return type. )he overriding method may not limit the access of the method it overrides. )he overriding method may not throw any e%ceptions that may not be thrown by the overridden method.

<8. What is casting?

)here are two types of casting, casting between primitive numeric types and casting between ob;ect references. Easting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Easting between ob;ect references is used to refer to an ob;ect by a compatible class, interface, or array type reference.

<<. 9ame Eontainer classes. Window, Brame, Cialog, BileCialog, #anel, Applet, or &croll#ane

<>. What class allows you to read ob;ects directly from a stream? )he 'b;ect0nput&tream class supports the reading of ob;ects from input streams.

> . :ow are this./ and super./ used with constructors? this./ is used to invoke a constructor of the same class. super./ is used to invoke a superclass constructor.

>1. :ow is it possible for two &tring ob;ects with identical values not to be eDual under the JJ operator? )he JJ operator compares two ob;ects to determine if they are the same ob;ect in memory. 0t is possible for two &tring ob;ects to have the same value, but located indifferent areas of memory.

>2. What an 0!' filter? An 0!' filter is an ob;ect 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.

>1. What is the &et interface? )he &et interface provides methods for accessing the elements of a finite mathematical set. &ets do not allow duplicate elements.

>2. What is the $ist interface?

)he $ist interface provides support for ordered collections of ob;ects.

>5. What is the purpose of the enable@vents./ method? )he enable@vents./ method is used to enable an event for a particular ob;ect. 9ormally, an event is enabled when a listener is added to an ob;ect for a particular event. )he enable@vents./ method is used by ob;ects that handle events by overriding their event+ dispatch methods.

>7. What is the difference between the Bile and IandomAccessBile classes? )he Bile class encapsulates the files and directories of the local file system. )he IandomAccessBile class provides the methods needed to directly access data contained in any part of a file.

>8. What interface must an ob;ect implement before it can be written to a stream as an ob;ect? An ob;ect must implement the &eriali=able or @%ternali=able interface before it can be written to a stream as an ob;ect.

><. What is the Iesource?undle class? )he Iesource?undle 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.

>>. What is the difference between a &crollbar and a &croll#ane? A &crollbar is a Eomponent, but not a Eontainer. A &croll#ane is a Eontainer. A &croll#ane handles its own events and performs its own scrolling.

What is a (ava package and how is it used? A (ava package is a naming conte%t for classes and interfaces. A package is used to create a separate name space for groups of classes and interfaces. #ackages are also used to organi=e related classes and interfaces into a single A#0 unit and to control accessibility to these classes and interfaces.

1 1.

What are the 'b;ect and Elass classes used for?

)he 'b;ect class is the highest+level class in the (ava class hierarchy. )he Elass class is used to represent the classes and interfaces that are loaded by a (ava program.

1 2.

What is &eriali=ation and deseriali=ation? &eriali=ation is the process of writing the state of an ob;ect to a byte stream. Ceseriali=ation is the process of restoring these ob;ects.

1 1.

what is tunnelling? )unnelling is a route to somewhere. Bor e%ample, IM0 tunnelling is a way to make IM0 application get through firewall. 0n E& world, tunnelling means a way to transfer data.

1 2. Coes the code in finally block get e%ecuted if there is an e%ception and a return statement in a catch block? 0f an e%ception occurs and there is a return statement in catch block, the finally block is still e%ecuted. )he finally block will not be e%ecuted when the &ystem.e%it.1/ statement is e%ecuted earlier or the system shut down earlier or the memory is used up earlier before the thread goes to finally block.

1 5.

:ow you restrict a user to cut and paste from the html page? 4sing ;ava&cript to lock keyboard keys. 0t is one of solutions.

1 7.

0s (ava a super set of (ava&cript? 9o. )hey are completely different. &ome synta% may be similar.

1 8.

What is a Eontainer in a 340? A Eontainer contains and arranges other components .including other containers/ through the use of layout managers, which use specific layout policies to determine where components should go as a function of the si=e of the container.

1 <. :ow the ob;ect oriented approach helps us keep comple%ity of software development under control?

We can discuss such issue from the following aspects, o o o 'b;ects allow procedures to be encapsulated with their data to reduce potential interference. 0nheritance allows well+tested procedures to be reused and enables changes to make once and have effect in all relevant places. )he well+defined separations of interface and implementation allows constraints to be imposed on inheriting classes while still allowing the fle%ibility of overriding and overloading.

2.

What is polymorphism? #olymorphism allows methods to be written that needn*t be concerned about the specifics of the ob;ects they will be applied to. )hat is, the method can be specified at a higher level of abstraction and can be counted on to work even on ob;ects of yet unconceived classes.

3.

What is design by contract? )he design by contract specifies the obligations of a method to any other methods that may use its services and also theirs to it. Bor e%ample, the preconditions specify what the method reDuired to be true when the method is called. :ence making sure that preconditions are. &imilarly, postconditions specify what must be true when the method is finished, thus the called method has the responsibility of satisfying the post conditions. 0n (ava, the e%ception handling facilities support the use of design by contract, especially in the case of checked e%ceptions. )he assert keyword can be used to make such contracts.

4.

What are use cases? A use case describes a situation that a program might encounter and what behavior the program should e%hibit in that circumstance. 0t is part of the analysis of a program. )he collection of use cases should, ideally, anticipate all the standard circumstances and many of the e%traordinary circumstances possible so that the program will be robust.

5.

What is the difference between interface and abstract class? o interface contains methods that must be abstract6 abstract class may contain concrete methods. o interface contains variables that must be static and final6 abstract class may contain non+final and final variables. o members in an interface are public by default, abstract class may contain non+public members. o interface is used to KimplementsK6 whereas abstract class is used to Ke%tendsK.

o o o o o

interface can be used to achieve multiple inheritance6 abstract class can be used as a single inheritance. interface can Ke%tendsK another interface, abstract class can Ke%tendsK another class and KimplementsK multiple interfaces. interface is absolutely abstract6 abstract class can be invoked if a main./ e%ists. interface is more fle%ible than abstract class because one class can only Ke%tendsK one super class, but KimplementsK multiple interfaces. 0f given a choice, use interface instead of abstract class.

1. Where and how can you use a private constuctor. #rivate constructor can be used if you do not want any other class to instanstiate the ob;ect , the instantiation is done from a static public method, this method is used when dealing with the factory method pattern when the designer wants only one controller .fatory method / to create the ob;ect . 2. 0n &ystem.out.println./,what is &ystem,out and println,pls e%plain? System is a predefined final class,out is a #rint&tream ob;ect and println is a built+in overloaded method in the out ob;ect. 1. What is meant by KAbstract 0nterfaceK? Birst, an interface is abstract. )hat means you cannot have any implementation in an interface. All the methods declared in an interface are abstract methods or signatures of the methods. 2. Ean you make an instance of an abstract class? Bor e%ample + ;ava.util.Ealender is an abstract class with a method get0nstance./ which returns an instance of the Ealender class. 9oL Aou cannot make an instance of an abstract class. An abstract class has to be sub+ classed. 0f you have an abstract class and you want to use a method which has been implemented, you may need to subclass that abstract class, instantiate your subclass and then call that method. 5. What is the output of %My? a,b J pND when %J1,yJ2,pJ1,DJ2? When this kind of Duestion has been asked, find the problems you think is necessary to ask before you give an answer. Ask if variables a and b have been declared or initiali=ed. 0f the answer is yes. Aou can say that the synta% is wrong. 0f the statement is rewritten as, %My? a, .bJpND/6 the return value would be variable a because the % is 1 and less than y J 26 the % M y statement return true and variable a is returned. 7. What is the difference between &wing and AW) components?

AW) components are heavy+weight, whereas &wing components are lightweight. :eavy weight components depend on the local windowing toolkit. Bor e%ample, ;ava.awt.?utton is a heavy weight component, when it is running on the (ava platform for 4ni% platform, it maps to a real Motif button. 8. Why (ava does not support pointers? ?ecause pointers are unsafe. (ava uses reference types to hide pointers and programmers feel easier to deal with reference types without pointers. )his is why (ava and EO shine. <. #arsers? C'M vs &A" parser parsers are fundamental %ml components, a bridge between "M$ documents and applications that process that "M$. )he parser is responsible for handling %ml synta%, checking the contents of the document against constraints established in a C)C or &chema.
DOM SAX

---------------------------------------------------------------1. Tree of nodes 2.Memory: Occup es more memory! preffered for sm#$$ XM% documents 3.S$o'er #t runt me 4.stored #s o)*ects 5.+ro&r#mm#t c#$$y e#sy! s nce o)*ects o)*ects #re to reffered -..#se of n#v &#t on poss )$e #s -.)#c/'#rd n#v &#t on s not 1.Sequence of events 2.does"nt use #ny memory preferred for $#r&e documents 3. (#ster #t runt me 4. o)*ects #re to )e cre#ted 5.,eed to 'r te code for cre#t n&

Networking Questions
1. What is the difference between 4I$ instance and 4I$Eonnection instance? A 4I$ instance represents the location of a resource, and a 4I$Eonnection instance represents a link for accessing or communicating with the resource at the location.

2. :ow do 0 make a connection to 4I$? Aou obtain a 4I$ instance and then invoke openEonnection on it. 4I$Eonnection is an abstract class, which means you can*t directly create instances of it using a constructor. We have to invoke openEonnection method on a 4I$ instance, to get the right kind of connection for your 4I$. @g. 4I$ url6
01%2onnect on connect on3 try4 ur$ 5 ne' 01%67...783 connect on 5 ur$.open2onnect on683 9c#tc: 6M#$(ormed01%.;cept on e8 4 9

1. What 0s a &ocket? A socket is one end+point of a two+way communication link between two programs running on the network. A socket is bound to a port number so that the )E# layer can identify the application that data is destined to be sent. &ocket classes are used to represent the connection between a client program and a server program. )he ;ava.net package provides two classes++&ocket and &erver&ocket++which implement the client side of the connection and the server side of the connection, respectively.

2. What information is needed to create a )E# &ocket? )he $ocal &ystem?s 0# Address and #ort 9umber. And the Iemote &ystem*s 0#Address and #ort 9umber.

5. What are the two important )E# &ocket classes? &ocket and &erver&ocket. &erver&ocket is used for normal two+way socket communication. &ocket class allows us to read and write through the sockets. get0nput&tream./ and get'utput&tream./ are the two methods available in &ocket class.

7. When Malformed4I$@%ception and 4nknown:ost@%ception throws?

When the specified 4I$ is not connected then the 4I$ throw Malformed4I$@%ception and 0f 0netAddress? methods get?y9ame and get$ocal:ost are unable to resolve the host name they throw an 4nknown:ost@%ception.

8. What does IM0 stand for? 0t stands for Iemote Method 0nvocation.

<. What is IM0? IM0 is a set of A#0s that allows to build distributed applications. IM0 uses interfaces to define remote ob;ects to turn local method invocations into remote method invocations.

1. What two protocols are used in (ava IM0 technology? (ava 'b;ect &eriali=ation and :))#. )he 'b;ect &eriali=ation protocol is used to marshal call and return data. )he :))# protocol is used to K#'&)K a remote method invocation and obtain return data when circumstances warrant. 2. What is difference between &wing and (&B? )he key difference is that (&B runs on the server in a standard (ava servlet container like )omcat or Web$ogic and display :)M$ or some other markup to the client. 1. What is (&B? (&B stands for (ava&erver Baces, or simply Baces. 0t is a framework for building Web+based user interfaces in (ava. $ike &wing, it provides a set of standard widgets such as buttons, hyperlinks, checkbo%es, ans so on.

JDBC Questions
1. What is (C?E? (C?E is a layer of abstraction that allows users to choose between databases. 0t allows you to change to a different database engine and to write to a single A#0. (C?E allows you to write database applications in (ava without having to concern yourself with the underlying details of a particular database.

2. What are the two ma;or components of (C?E?

'ne implementation interface for database manufacturers, the other implementation interface for application and applet writers.

1. What is (C?E Criver interface? )he (C?E Criver interface provides vendor+specific implementations of the abstract classes provided by the (C?E A#0. @ach vendors driver must provide implementations of the ;ava.sDl.Eonnection,&tatement,#repared&tatement, Eallable&tatement, Iesult&et and Criver.

2. What are the common tasks of (C?E? o Ereate an instance of a (C?E driver or load (C?E drivers through ;dbc.drivers o Iegister a driver o &pecify a database o 'pen a database connection o &ubmit a Duery o Ieceive results

5. What packages are used by (C?E? )here are < packages, ;ava.sDl.Criver, Eonnection,&tatement, #repared&tatement, Eallable&tatement, Iesult&et, Iesult&etMetaCata, CatabaseMetaCata.

7. What are the flow statements of (C?E? A 4I$ string ++PgetEonnection++PCriverManager++PCriver++PEonnection++P&tatement++ Pe%ecuteQuery++PIesult&et.

8. What are the steps involved in establishing a connection? )his involves two steps, .1/ loading the driver and .2/ making the connection.

<. :ow can you load the drivers? $oading the driver or drivers you want to use is very simple and involves ;ust one line of code. 0f, for e%ample, you want to use the (C?E+'C?E ?ridge driver, the following code will load it,
.&. 2$#ss.for,#me67sun.*d)c.od)c.<d)cOd)cDr ver783

Aour driver documentation will give you the class name to use. Bor instance, if the class name is ;dbc.Criver"AH , you would load the driver with the following line of code,
..&. 2$#ss.for,#me67*d)c.Dr verX=>783

>. What Elass.for9ame will do while loading drivers? 0t is used to create an instance of a driver and register it with the CriverManager. When you have loaded a driver, it is available for making a connection with a C?M&.

1 . :ow can you make the connection? 0n establishing a connection is to have the appropriate driver connect to the C?M&. )he following line of code illustrates the general idea,
..&. Str n& ur$ 5 7*d)c:od)c:(red73 2onnect on con 5 Dr verM#n#&er.&et2onnect on6ur$! 7(ern#nd#7! 7<?783

11. :ow can you create (C?E statements? A &tatement ob;ect is what sends your &Q$ statement to the C?M&. Aou simply create a &tatement ob;ect and then e%ecute it, supplying the appropriate e%ecute method with the &Q$ statement you want to send. Bor a &@$@E) statement, the method to use is e%ecuteQuery. Bor statements that create or modify tables, the method to use is e%ecute4pdate. @.g. 0t takes an instance of an active connection to create a &tatement ob;ect. 0n the following e%ample, we use our Eonnection ob;ect con to create the &tatement ob;ect stmt ,
St#tement stmt 5 con.cre#teSt#tement683

12. :ow can you retrieve data from the Iesult&et? Birst (C?E returns results in a Iesult&et ob;ect, so we need to declare an instance of the class Iesult&et to hold our results. )he following code demonstrates declaring the Iesult&et ob;ect rs.
..&. 1esu$tSet rs 5 stmt.e;ecute@uery67S.%.2T 2O(A,AM.! +1B2. (1OM 2O((..S783 Second: Str n& s 5 rs.&etStr n&672O(A,AM.783

)he method get&tring is invoked on the Iesult&et ob;ect rs , so get&tring will retrieve .get/ the value stored in the column E'BR9AM@ in the current row of rs

11. What are the different types of &tatements? 1.&tatement .use create&tatement method/ 2. #repared &tatement .4se prepare&tatement method/ and 1. Eallable &tatement .4se prepareEall/

12. :ow can you use #repared&tatement? )his special type of statement is derived from the more general class, &tatement. 0f you want to e%ecute a &tatement ob;ect many times, it will normally reduce e%ecution time to use a #repared&tatement ob;ect instead. )he advantage to this is that in most cases, this &Q$ statement will be sent to the C?M& right away, where it will be compiled. As a result, the #repared&tatement ob;ect contains not ;ust an &Q$ statement, but an &Q$ statement that has been precompiled. )his means that when the #repared&tatement is e%ecuted, the C?M& can ;ust run the #repared&tatement *s &Q$ statement without having to compile it first.
..&. +rep#redSt#tement upd#teS#$es 5 con.prep#reSt#tement670+DAT. 2O((..S S.T SA%.S 5 C DE.1. 2O(A,AM. %BF. C783

15. :ow to call a &tored #rocedure from (C?E? )he first step is to create a Eallable&tatement ob;ect. As with &tatement an and #repared&tatement ob;ects, this is done with an open Eonnection ob;ect. A Eallable&tatement ob;ect contains a call to a stored procedure6
..&. 2#$$#)$eSt#tement cs 5 con.prep#re2#$$674c#$$ SEODAS0++%B.1S9783 1esu$tSet rs 5 cs.e;ecute@uery683

17. :ow to Ietrieve Warnings? &Q$Warning ob;ects are a subclass of &Q$@%ception that deal with database access warnings. Warnings do not stop the e%ecution of an application, as e%ceptions do6 they simply alert the user that something did not happen as planned. A warning can be reported on a Eonnection ob;ect, a &tatement ob;ect .including #repared&tatement and Eallable&tatement ob;ects/, or a Iesult&et ob;ect. @ach of these classes has a getWarnings method, which you must invoke in order to see the first warning reported on the calling ob;ect
..&.

S@%D#rn n& '#rn n& 5 stmt.&etD#rn n&s683 f 6'#rn n& G5 nu$$8 4 ': $e 6'#rn n& G5 nu$$8 4 System.out.pr nt$n67Mess#&e: 7 H '#rn n&.&etMess#&e6883 System.out.pr nt$n67S@%St#te: 7 H '#rn n&.&etS@%St#te6883 System.out.pr nt67Iendor error code: 783 System.out.pr nt$n6'#rn n&.&et.rror2ode6883 '#rn n& 5 '#rn n&.&et,e;tD#rn n&683 9 9

18. :ow to Make 4pdates to 4pdatable Iesult &ets? Another new feature in the (C?E 2. A#0 is the ability to update rows in a result set using methods in the (ava programming language rather than having to send an &Q$ command. ?ut before you can take advantage of this capability, you need to create a Iesult&et ob;ect that is updatable. 0n order to do this, you supply the Iesult&et constant E'9E4IR4#CA)A?$@ to the create&tatement method.
..&. 2onnect on con 5 Dr verM#n#&er.&et2onnect on67*d)c:mySu)protoco$:mySu),#me783 St#tement stmt 5 con.cre#teSt#tement61esu$tSet.T=+.AS21O%%AS.,SBTBI.! 1esu$tSet.2O,201A0+DATAJ%.83 1esu$tSet uprs 5 67S.%.2T 2O(A,AM.! +1B2. (1OM 2O((..S783

JSP Questions
1. What is (&# technology? (ava &erver #age is a standard (ava e%tension that is defined on top of the servlet @%tensions. )he goal of (&# is the simplified creation and management of dynamic Web pages. (&#s are secure, platform+independent, and best of all, make use of (ava as a server+ side scripting language.

2. What is (&# page? A (&# page is a te%t+based document that contains two types of te%t, static template data, which can be e%pressed in any te%t+based format such as :)M$, &-3, WM$, and "M$, and (&# elements, which construct dynamic content.

1. What are the implicit ob;ects?

0mplicit ob;ects are ob;ects that are created by the web container and contain information related to a particular reDuest, page, or application. )hey are,
o o o o o o o o o

reDuest response pageEonte%t session application out config page e%ception

2. :ow many (&# scripting elements and what are they? )here are three scripting language elements,
1. 2. 3.

declarations scriptlets e%pressions

2. Why are (&# pages the preferred A#0 for creating a web+based client program? ?ecause no plug+ins or security policy files are needed on the client systems.applet does/. Also, (&# pages enable cleaner and more module application design because they provide a way to separate applications programming from web page design. )his means personnel involved in web page design do not need to understand (ava programming language synta% to do their ;obs.

1. 0s (&# technology e%tensible? A@&. (&# technology is e%tensible through the development of custom actions, or tags, which are encapsulated in tag libraries.

2. What are the two kinds of comments in (&# and what*s the difference between them? MS++ (&# Eomment ++SP ML++ :)M$ Eomment ++P

5. 0n the &ervlet 2.2 specification &ingle)hreadModel has been deprecates, why?

?ecause it is not practical to have such model. Whether you set is)hread&afe to true or false, you should take care of concurrent client reDuests to the (&# page by synchroni=ing access to any shared ob;ects defined at the page level.

7. What is difference between custom (&# tags and beans? Eustom (&# tag is a tag you defined. Aou 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 (&# files. )o use custom (&# tags, you need to define three separate components, the tag handler class that defines the tag*s behavior the tag library descriptor file that maps the "M$ element names to the tag implementations 3. the (&# file that uses the tag library
1. 2.

When the first two components are done, you can use the tag by using taglib directive,
KLM t#&$ ) ur 57;;;.t$d7 pref ;57...7 LN

)hen you are ready to use the tags you defined. $et*s say the tag prefi% is test,
Ktest:t#&1NMy<S+T#&KOtest:t#&1N or Ktest:t#&1 ON

(ava?eans are (ava utility classes you defined. ?eans have a standard format for (ava classes. Aou use tags
K*sp:useJe#n d57 dent f er7 c$#ss57p#c/#&e,#me.c$#ss,#me7ON

to declare a bean and use


K*sp:set+roperty n#me57 dent f er7 property57c$#ss( e$d7 v#$ue57someI#$ue7 ON

to set value of the bean class and use


K*sp:&et+roperty n#me57 dent f er7 property57c$#ss( e$d7 ON K L5 dent f er.&etc$#ss( e$d68 LN

to get value of the bean class. Eustom tags and beans accomplish the same goals ++ encapsulating comple% behavior into simple and accessible forms. )here are several differences,
o

Eustom tags can manipulate (&# content6 beans cannot.

o o o o

Eomple% operations can be reduced to a significantly simpler form with custom tags than with beans. Eustom tags reDuire Duite a bit more work to set up than do beans. Eustom tags usually define relatively self+contained behavior, whereas beans are often defined in one servlet and used in a different servlet or (&# page. Eustom tags are available only in (&# 1.1 and later, but beans can be used in all (&# 1.% versions.

1. What is a (&# and what is it used for? (ava &erver #ages .(&#/ is a platform independent presentation layer technology that comes with &49Ts (2@@ platform. (&#s are normal :)M$ pages with (ava code pieces embedded in them. (&# pages are saved to N.;sp files. A (&# compiler is used in the background to generate a &ervlet from the (&# page. 2. What is difference between custom (&# tags and beans? Eustom (&# tag is a tag you defined. Aou 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 (&# files. )o use custom (&# tags, you need to define three separate components, 1. the tag handler class that defines the tag*s behavior 2. the tag library descriptor file that maps the "M$ element names to the tag implementations 1. the (&# file that uses the tag library When the first two components are done, you can use the tag by using taglib directive,
KLM t#&$ ) ur 57;;;.t$d7 pref ;57...7 LN

)hen you are ready to use the tags you defined. $et*s say the tag prefi% is test,
Ktest:t#&1NMy<S+T#&KOtest:t#&1N or Ktest:t#&1 ON

(ava?eans are (ava utility classes you defined. ?eans have a standard format for (ava classes. Aou use tags
K*sp:useJe#n d57 dent f er7 c$#ss57p#c/#&e,#me.c$#ss,#me7ON

to declare a bean and use


K*sp:set+roperty n#me57 dent f er7 property57c$#ss( e$d7 v#$ue57someI#$ue7 ON

to set value of the bean class and use

K*sp:&et+roperty n#me57 dent f er7 property57c$#ss( e$d7 ON K L5 dent f er.&etc$#ss( e$d68 LN

to get value of the bean class. Eustom tags and beans accomplish the same goals ++ encapsulating comple% behavior into simple and accessible forms. )here are several differences, o o o o o Eustom tags can manipulate (&# content6 beans cannot. Eomple% operations can be reduced to a significantly simpler form with custom tags than with beans. Eustom tags reDuire Duite a bit more work to set up than do beans. Eustom tags usually define relatively self+contained behavior, whereas beans are often defined in one servlet and used in a different servlet or (&# page. Eustom tags are available only in (&# 1.1 and later, but beans can be used in all (&# 1.% versions.

o 2. what are the two kinds of comments in (&# and whats the difference between them MS++ (&# Eomment ++SP ML++ :)M$ Eomment ++P

Servlet Questions
1. What is the servlet? &ervlets are modules that e%tend reDuest!response+oriented servers, such as (ava+enabled web servers. Bor e%ample, a servlet may be responsible for taking data in an :)M$ order+ entry form and applying the business logic used to update a company*s order database. 2. What*s the difference between servlets and applets? &ervlets are to servers6 applets are to browsers. 4nlike applets, however, servlets have no graphical user interface. 1. What*s the advantages using servlets than using E30? &ervlets provide a way to generate dynamic documents that is both easier to write and faster to run. 0t is efficient, convenient, powerful, portable, secure and ine%pensive. &ervlets also address the problem of doing server+side programming with platform+specific A#0s, they are developed with (ava &ervlet A#0, a standard (ava e%tension. 2. What are the uses of &ervlets?

A servlet can handle multiple reDuests concurrently, and can synchroni=e reDuests. )his allows servlets to support systems such as on+line conferencing. &ervlets can forward reDuests to other servers and servlets. )hus servlets can be used to balance load among several servers that mirror the same content, and to partition a single logical service over several servers, according to task type or organi=ational boundaries. 5. What*s the &ervlet 0nterface? )he central abstraction in the &ervlet A#0 is the &ervlet interface. All servlets implement this interface, either directly or, more commonly, by e%tending a class that implements it such as :ttp&ervlet.
Serv$ets--NPener c Serv$et--NEttpServ$et--NMyServ$et.

)he &ervlet interface declares, but does not implement, methods that manage the servlet and its communications with clients. &ervlet writers provide some or all of these methods when developing a servlet. 7. When a servlet accepts a call from a client, it receives two ob;ects. What are they? &erveltIeDuest, which encapsulates the communication from the client to the server. &ervletIesponse, which encapsulates the communication from the servlet back to the client. &ervletIeDuest and &ervletIesponse are interfaces defined by the ;ava%.servlet package. 8. What information that the &ervletIeDuest interface allows the servlet access to? 0nformation such as the names of the parameters passed in by the client, the protocol .scheme/ being used by the client, and the names of the remote host that made the reDuest and the server that received it. )he input stream, &ervlet0nput&tream.&ervlets use the input stream to get data from clients that use application protocols such as the :))# #'&) and #4) methods. <. What information that the &ervletIesponse interface gives the servlet methods for replying to the client? 0t Allows the servlet to set the content length and M0M@ type of the reply. #rovides an output stream, &ervlet'utput&tream and a Writer through which the servlet can send the reply data. >. 0f you want a servlet to take the same action for both 3@) and #'&) reDuest, what should you do? &imply have do3et call do#ost, or vice versa.

1 . What is the servlet life cycle? @ach servlet has the same life cycle, A server loads and initiali=es the servlet .init.// )he servlet handles =ero or more client reDuests .service.// )he server removes the servlet .destroy.// .some servers do this step only when they shut down/ 11. Which code line must be set before any of the lines that use the #rintWriter? setEontent)ype./ method must be set before transmitting the actual document. 12. :ow :))# &ervlet handles client reDuests? An :))# &ervlet handles client reDuests through its service method. )he service method supports standard :))# client reDuests by dispatching each reDuest to a method designed to handle that reDuest. 11. When using servlets to build the :)M$, you build a C'E)A#@ line, why do you do that? 0 know all ma;or browsers ignore it even though the :)M$ 1.2 and 2. specifications reDuire it. ?ut building a C'E)A#@ line tells :)M$ validators which version of :)M$ you are using so they know which specification to check your document against. )hese validators are valuable debugging services, helping you catch :)M$ synta% errors.
:ttp:OOv#$ d#tor.'3.or& #nd :ttp:OO'''.:tm$:e$p.comOtoo$sOv#$ d#torO

are two ma;or online validators. 1. What mechanisms are used by a &ervlet Eontainer to maintain session information? Eookies, 4I$ rewriting, and :))#& protocol information are used to maintain session information 2. Cifference between 3@) and #'&) 0n 3@) your entire form submission can be encapsulated in one 4I$, like a hyperlink. Duery length is limited to 27 characters, not secure, faster, Duick and easy. 0n #'&) Aour name!value pairs inside the body of the :))# reDuest, which makes for a cleaner 4I$ and imposes no si=e limitations on the form*s output. 0t is used to send a chunk of data to the server to be processed, more versatile, most secure. 1. What is session? )he session is an ob;ect used by a servlet to track a user*s interaction with a Web application across multiple :))# reDuests.

2. What is servlet mapping? )he servlet mapping defines an association between a 4I$ pattern and a servlet. )he mapping is used to map reDuests to servlets. 5. What is servlet conte%t ? )he servlet conte%t is an ob;ect that contains a servlet*s view of the Web application within which the servlet is running. 4sing the conte%t, a servlet can log events, obtain 4I$ references to resources, and set and store attributes that other servlets in the conte%t can use. .answer supplied by &un*s tutorial/. 7. Which interface must be implemented by all servlets? &ervlet interface.

EJB Questions
1. What is @(?? @(? stands for @nterprise (ava?ean and is the widely+adopted server side component architecture for (2@@. it enables rapid development of mission+critical application that are versatile, reusable and portable across middleware while protecting 0) investment and preventing vendor lock+in. 2. What is @(? role in (2@@? @(? technology is the core of (2@@. 0t enables developers to write reusable and portable server+side business logic for the (2@@ platform. 1. What is the difference between @(? and (ava beans? @(? is a specification for (2@@ server, not a product6 (ava beans may be a graphical component in 0C@. 2. What are the key features of the @(? technology? 1. @(? components are server+side components written entirely in the (ava programming language 2. @(? components contain business logic only + no system+level programming G services, such as transactions, security, life+cycle, threading, persistence, etc. are automatically managed for the @(? component by the @(? server. 1. @(? architecture is inherently transactional, distributed, portable multi+tier, scalable and secure. 2. @(? components are fully portable across any @(? server and any '&.

5. @(? architecture is wire+protocol neutral++any protocol can be utili=ed like 00'#,(IM#, :))#, CE'M,etc. 5. What are the key benefits of the @(? technology? o Iapid application development o ?road industry adoption o Application portability o #rotection of 0) investment 2. :ow many enterprice beans? )here are three kinds of enterprise beans, o session beans, o entity beans, and o message+driven beans. 3. What is message+driven bean? A message+driven bean combines features of a session bean and a (ava Message &ervice .(M&/ message listener, allowing a business component to receive (M&. A message+driven bean enables asynchronous clients to access the business logic in the @(? tier.
4.

What is @ntity ?ean and &ession ?ean ? @ntity ?ean is a (ava class which implements an @nterprise ?ean interface and provides the implementation of the business methods. )here are two types, Eontainer Managed #ersistence.EM#/ and ?ean+Managed #ersistence.?M#/. &ession ?ean is used to represent a workflow on behalf of a client. )here are two types, &tateless and &tateful. &tateless bean is the simplest bean. 0t doesn*t maintain any conversational state with clients between method invocations. &tateful bean maintains state between invocations.

1. What is session Bacade &ession Bacade is a design pattern to access the @ntity bean through local interface than acessing directly. 0t increases the performance over the network. 0n this case we call session bean which on turn call entity bean 2. what is the difference between session and entity bean? &ession beans are business data and have not any persistance. @ntity beans are Cata 'b;ects and have more persistance.

J2EE General Questions

1. What is (2@@? (2@@ is an environment for developing and deploying enterprise applications. )he (2@@ platform consists of a set of services, application programming interfaces .A#0s/, and protocols that provide the functionality for developing multitiered, web+based applications. 2. What are the components of (2@@ application? A (2@@ component is a self+contained functional software unit that is assembled into a (2@@ application with its related classes and files and communicates with other components. )he (2@@ specification defines the following (2@@ components, Application clients and applets are client components. (ava &ervlet and (ava&erver #ages)M .(&#)M/ technology components are web components. o @nterprise (ava?eans)M .@(?)M/ components .enterprise beans/ are business components. o Iesource adapter components provided by @0& and tool vendors. 1. What is difference between (2@@ 1.1 and (2@@ 1.2?
o o

(2@@ 1.2 is an enhancement version of (2@@ 1.1. 0t is the most complete Web services platform ever. (2@@ 1.2 includes,
o o o o o o o o o o o o o

(ava A#0 for "M$+?ased I#E .(A"+I#E 1.1/ &'A# with Attachments A#0 for (ava .&AA(/, Web &ervices for (2@@.(&I >21/ (2@@ Management Model.1. / (2@@ Ceployment A#0.1.1/ (ava Management @%tensions .(M"/, (ava Authori=ation Eontract for Eontainers.(avaAEE/ (ava A#0 for "M$ Iegistries .(A"I/ &ervlet 2.2 (&# 2. @(? 2.1 (M& 1.1 (2@@ Eonnector 1.5

)he (2@@ 1.2 features complete Web services support through the new (A"+I#E 1.1 A#0, which supports service endpoints based on servlets and enterprise beans. (A"+I#E 1.1 provides interoperability with Web services based on the W&C$ and &'A# protocols. )he (2@@ 1.2 platform also supports the Web &ervices for (2@@ specification .(&I >21/, which defines deployment reDuirements for Web services and utili=es the (A"+I#E programming model.

0n addition to numerous Web services A#0s, (2@@ 1.2 platform also features support for the W&+0 ?asic #rofile 1. . )his means that in addition to platform independence and complete Web services support, (2@@ 1.2 offers platform Web services interoperability. )he (2@@ 1.2 platform also introduces the (2@@ Management 1. A#0, which defines the information model for (2@@ management, including the standard Management @(? .M@(?/. )he (2@@ Management 1. A#0 uses the (ava Management @%tensions A#0 .(M"/. )he (2@@ 1.2 platform also introduces the (2@@ Ceployment 1.1 A#0, which provides a standard A#0 for deployment of (2@@ applications. )he (2@@ 1.2 platform includes security enhancements via the introduction of the (ava Authori=ation Eontract for Eontainers .(avaAEE/. )he (avaAEE A#0 improves security by standardi=ing how authentication mechanisms are integrated into (2@@ containers. )he (2@@ platform now makes it easier to develop web front ends with enhancements to (ava &ervlet and (ava&erver #ages .(&#/ technologies. &ervlets now support reDuest listeners and enhanced filters. (&# technology has simplified the page and e%tension development models with the introduction of a simple e%pression language, tag files, and a simpler tag e%tension A#0, among other features. )his makes it easier than ever for developers to build (&#+enabled pages, especially those who are familiar with scripting languages. 'ther enhancements to the (2@@ platform include the (2@@ Eonnector Architecture, which provides incoming resource adapter and (ava Message &ervice .(M&/ pluggability. 9ew features in @nterprise (ava?eans .@(?/ technology include Web service endpoints, a timer service, and enhancements to @(? Q$ and message+driven beans. )he (2@@ 1.2 platform also includes enhancements to deployment descriptors. )hey are now defined using "M$ &chema which can also be used by developers to validate their "M$ structures. 9ote, )he above information comes from &49 released notes. 2. 0s (2@@ application only a web+based? 9'. A (2@@ application can be web+based or non+web+based. if an application client e%ecutes on the client machine, it is a non+web+based (2@@ application. )he (2@@ application can provide a way for users to handle tasks such as (2@@ system or application administration. 0t typically has a graphical user interface created from &wing or AW) A#0s, or a command+line interface. When user reDuest, it can open an :))# connection to establish communication with a servlet running in the web tier. 5. Are (ava?eans (2@@ components?

9'. (ava?eans components are not considered (2@@ components by the (2@@ specification. (ava?eans components written for the (2@@ platform have instance variables and get and set methods for accessing the data in the instance variables. (ava?eans components used in this way are typically simple in design and implementation, but should conform to the naming and design conventions outlined in the (ava?eans component architecture. 7. 0s :)M$ page a web component? 9'. &tatic :)M$ pages and applets are bundled with web components during application assembly, but are not considered web components by the (2@@ specification. @ven the server+side utility classes are not considered web components,either. 8. What is the container? A container is a runtime support of a system+level entity. Eontainers provide components with services such as lifecycle management, security, deployment, and threading. <. What is the web container? &ervlet and (&# containers are collectively referred to as Web containers. >. What is the thin client? A thin client is a lightweight interface to the application that does not have such operations like Duery databases, e%ecute comple% business rules, or connect to legacy applications. 1 . What are types of (2@@ clients? o Applets o Application clients o (ava Web &tart+enabled rich clients, powered by (ava Web &tart technology. o Wireless clients, based on Mobile 0nformation Cevice #rofile .M0C#/ technology. 11. What is deployment descriptor? A deployment descriptor is an @%tensible Markup $anguage ."M$/ te%t+based file with an .%ml e%tension that describes a component*s deployment settings. A (2@@ application and each of its modules has its own deployment descriptor. 12. What is the @AI file? An @AI file is a standard (AI file with an .ear e%tension, named from @nterprice AIchive file. A (2@@ application with all of its modules is delivered in @AI file. 11. What is ()A and ()&?

()A is the abbreviation for the (ava )ransaction A#0. ()& is the abbreviation for the (ave )ransaction &ervice. ()A provides a standard interface and allows you to demarcate transactions in a manner that is independent of the transaction manager implementation. )he (2@@ &CF implements the transaction manager with ()&. ?ut your code doesn*t call the ()& methods directly. 0nstead, it invokes the ()A methods, which then call the lower+ level ()& routines. )herefore, ()A is a high level transaction interface that your application uses to control transaction. and ()& is a low level transaction interface and e;b uses behind the scenes .client code doesn*t directly interact with ()&. 0t is based on ob;ect transaction service.')&/ which is part of E'I?A. 12. What is (A"#? (A"# stands for (ava A#0 for "M$. "M$ is a language for representing and describing te%t+based data which can be read and handled by any program or tool that uses "M$ A#0s. 15. What is (2@@ Eonnector? )he (2@@ Eonnector A#0 is used by (2@@ tools vendors and system integrators to create resource adapters that support access to enterprise information systems that can be plugged into any (2@@ product. @ach type of database or @0& has a different resource adapter. 17. What is (AA#? )he (ava Authentication and Authori=ation &ervice .(AA&/ provides a way for a (2@@ application to authenticate and authori=e a specific user or group of users to run it. 0t is a standard #luggable Authentication Module .#AM/ framework that e%tends the (ava 2 platform security architecture to support user+based authori=ation. 18. What is Model 1? 4sing (&# technology alone to develop Web page. &uch term is used in the earlier (&# specification. Model 1 architecture is suitable for applications that have very simple page flow, have little need for centrali=ed security control or logging, and change little over time. Model 1 applications can often be refactored to Model 2 when application reDuirements change. 1<. What is Model 2? 4sing (&# and &ervelet together to develop Web page. Model 2 applications are easier to maintain and e%tend, because views do not refer to each other directly. 1>. What is &truts?

A Web page development framework. &truts combines (ava &ervlets, (ava &erver #ages, custom tags, and message resources into a unified framework. 0t is a cooperative, synergistic platform, suitable for development teams, independent developers, and everyone between. 2 . :ow is the M-E design pattern used in &truts framework? 0n the M-E design pattern, application flow is mediated by a central Eontroller. )he Eontroller delegates reDuests to an appropriate handler. )he handlers are tied to a Model, and each handler acts as an adapter between the reDuest and the Model. )he Model represents, or encapsulates, an application*s business logic or state. Eontrol is usually then forwarded back through the Eontroller to the appropriate -iew. )he forwarding can be determined by consulting a set of mappings, usually loaded from a database or configuration file. )his provides a loose coupling between the -iew and Model, which can make an application significantly easier to create and maintain. Eontroller++&ervlet controller which supplied by &truts itself6 -iew +++ what you can see on the screen, a (&# page and presentation components6 Model +++ &ystem state and a business logic (ava?eans. 1. What is difference between (2@@ 1.1 and (2@@ 1.2? (2@@ 1.2 is an enhancement version of (2@@ 1.1. 0t is the most complete Web services platform ever. (2@@ 1.2 includes,
o o o o o o o o o o o o o

(ava A#0 for "M$+?ased I#E .(A"+I#E 1.1/ &'A# with Attachments A#0 for (ava .&AA(/, Web &ervices for (2@@.(&I >21/ (2@@ Management Model.1. / (2@@ Ceployment A#0.1.1/ (ava Management @%tensions .(M"/, (ava Authori=ation Eontract for Eontainers.(avaAEE/ (ava A#0 for "M$ Iegistries .(A"I/ &ervlet 2.2 (&# 2. @(? 2.1 (M& 1.1 (2@@ Eonnector 1.5

)he (2@@ 1.2 features complete Web services support through the new (A"+I#E 1.1 A#0, which supports service endpoints based on servlets and enterprise beans. (A"+I#E 1.1 provides interoperability with Web services based on the W&C$ and &'A# protocols.

)he (2@@ 1.2 platform also supports the Web &ervices for (2@@ specification .(&I >21/, which defines deployment reDuirements for Web services and utili=es the (A"+I#E programming model. 0n addition to numerous Web services A#0s, (2@@ 1.2 platform also features support for the W&+0 ?asic #rofile 1. . )his means that in addition to platform independence and complete Web services support, (2@@ 1.2 offers platform Web services interoperability. )he (2@@ 1.2 platform also introduces the (2@@ Management 1. A#0, which defines the information model for (2@@ management, including the standard Management @(? .M@(?/. )he (2@@ Management 1. A#0 uses the (ava Management @%tensions A#0 .(M"/. )he (2@@ 1.2 platform also introduces the (2@@ Ceployment 1.1 A#0, which provides a standard A#0 for deployment of (2@@ applications. )he (2@@ 1.2 platform includes security enhancements via the introduction of the (ava Authori=ation Eontract for Eontainers .(avaAEE/. )he (avaAEE A#0 improves security by standardi=ing how authentication mechanisms are integrated into (2@@ containers. )he (2@@ platform now makes it easier to develop web front ends with enhancements to (ava &ervlet and (ava&erver #ages .(&#/ technologies. &ervlets now support reDuest listeners and enhanced filters. (&# technology has simplified the page and e%tension development models with the introduction of a simple e%pression language, tag files, and a simpler tag e%tension A#0, among other features. )his makes it easier than ever for developers to build (&#+enabled pages, especially those who are familiar with scripting languages. 'ther enhancements to the (2@@ platform include the (2@@ Eonnector Architecture, which provides incoming resource adapter and (ava Message &ervice .(M&/ pluggability. 9ew features in @nterprise (ava?eans .@(?/ technology include Web service endpoints, a timer service, and enhancements to @(? Q$ and message+driven beans. )he (2@@ 1.2 platform also includes enhancements to deployment descriptors. )hey are now defined using "M$ &chema which can also be used by developers to validate their "M$ structures. 9ote, )he above information comes from &49 released notes. 2. Co you have to use design pattern in (2@@ pro;ect? Aes. 0f 0 do it, 0 will use it. $earning design pattern will boost my coding skill. 1. 0s (2@@ a super set of (2&@? Aes

JMS
1. What is (M&? (ava Message &ervice is the new standard for interclient communication. 0t allows (2@@ application components to create, send, receive, and read messages. 0t enables distributed communication that is loosely coupled, reliable, and asynchronous. 2. what type messaging is provided by (M& ?oth synchronous and asynschronous 1. :ow may messaging models do (M& provide for and what are they? (M& provide for two messaging models, publish+and+subscribe and point+to+point Dueuing

Threading

Question Answer

What method must be implemented by all threads?

(Threads)

All tasks must implement the run() method, whether they are a subclass of Thread or implement the Runnable interface. What are the two basic ways in which classes that can be run as threads may be defined? (Threads) A thread class may be declared as a subclass of Thread, or it may implement the Runnable interface.
(Threads)

Question Answer

Question E plain about !eadlock state of a thread Answer

"ynchroni#in$ run() is a $ood e ample of a simple deadlock scenario, where a thread is blocked fore%er, waitin$ for somethin$ to happen that can&t. 'et&s look at a few e amples that are more realistic than this. The most common deadlock scenario occurs when two threads are both waitin$ for each other to do somethin$. The followin$ (admittedly contri%ed) code snippet makes what&s $oin$ on painfully ob%ious( see code at( http())www.*a%a$ala y.com(+,+,)Threads)-iew.*sp?slno./0tbl., 1ow, ima$ine a scenario whereby one thread (call it Wilma) calls fred(), passes

throu$h the synchroni#ation of lock23, and is then preempted, allowin$ another thread (call it 4etty) to e ecute. 4etty calls barney(), ac5uires lock26, and tries to ac5uire lock23, but can&t because Wilma has it. 4etty is now blocked, waitin$ for lock23 to become a%ailable, so Wilma wakes up and tries to ac5uire lock26 but can&t because 4etty has it. Wilma and 4etty are now deadlocked. 1either one can e%er e ecute. (1ote that lock23 and lock26 ha%e to be one7element arrays rather than simple ints, because only ob*ects ha%e monitors in 8a%a9 the ar$ument to synchroni#ed must be an ob*ect. An array is a first7class ob*ect in 8a%a9 a primiti%e7type such as int is not. :onse5uently, you can synchroni#e on it. ;oreo%er, a one7element array is efficient to brin$ into e istence compared to a more elaborate ob*ect (like an <nte$er) since it&s both small and does not re5uire a constructor call. Also, note that < can keep the reference to the lock as a simple =b*ect reference, since <&ll ne%er access the array elements. Question What is a daemon thread?
(Threads)

Answer

!aemon threads are ser%ice pro%iders for other threads runnin$ in the same process as the daemon thread. When the only remainin$ threads in a process are daemon threads, the interpreter e its. This is because when only daemon threads remain, there is no other thread for which a daemon thread can pro%ide a ser%ice. An e ample would be AWT7E%ent threads. Another e ample would be a mail daemon. When a mail messa$e is recie%ed by a mail ser%er it $enerally needs to be forwarded on to another machine. =ne way to do this is to ha%e a daemon check for mail e%ery so often and cause the mail to be forwarded.
(Threads)

Question :an you e plain the difference between $reen threads and nati%e threads?

Answer

>reen threads is thread mechanism implemented in 8-; itself. <t is blind and can run on any =", so actually all threads are run in one nati%e thread and schedulin$ is up to 8-;. This is disad%anta$eously for ";? systems, since only one processor can ser%e 8a%a application. 1ati%e threads is a mechanism based on =" threadin$ mechanism. This allows to use features of hardware and =". @or e ample,there is <4;&s 8!A for A<B that supports nati%e threads. The perfomance of applications can be hi$hly implo%ed by this.

< ha%e created a pro$ram with a main method that instantiates and starts three Question threads, the first two of which are daemons. Why daemons does die when normal thread die? (Threads) Answer 4ecause of nature of daemon threads. They are ali%e if e ists at least one Cnormal user&sC thread. =therwise they die immediately
(Threads)

Question When will a Thread =b*ect be $arba$e collected? Answer

"ince Thread is also an =b*ect, it will only $arba$e collected when the reference count is #ero. Dou may think it is 5uite non7sense. the thread is useless when it enter CdeadC state. why not $arba$e collect it? That&s because the thread ob*ect itself may contain some other useful information e%en the thread dead , e.$. the result of the e ecution of the thread. Thus, it is not sensible to do $arba$e collect when the

reference count is not #ero. Question What happens when you call yield() on a thread? Answer
(Threads)

:auses the currently e ecutin$ thread ob*ect to temporarily pause and allow other threads to e ecute

ra!le "nterview Questions and #nswers $ SQL


%& To see !urrent user na'e &DlP show user6 2& Change SQL (ro'(t na'e &Q$P set sDlprompt UManimara P U Manimara P Manimara P )& Swit!h to D S (ro'(t &Q$P host *& +ow do " eli'inate the du(li!ate rows , &Q$P delete from tableRname where rowid not in .select ma%.rowid/ from table group by duplicateRvaluesRfieldRname/6 or &Q$P delete duplicateRvaluesRfieldRname dv from tableRname ta where rowid M.select min.rowid/ from tableRname tb where ta.dvJtb.dv/6 @%ample. )able @mp @mpno @name 1 1 &cott 1 2 (iyo 1 1 Millor 1 2 (iyo 1 5 &mith delete ename from emp a where rowid M . select min.rowid/ from emp b where a.ename J b.ename/6 )he output like, @mpno @name 1 1 &cott 1 2 Millor

1 1 1 2

(iyo &mith

-& +ow do " dis(la. row nu'/er with re!ords, )o achive this use rownum pseudocolumn with Duery, like &Q$P &Q$P select rownum, ename from emp6 'utput, 1 &cott 2 Millor 1 (iyo 2 &mith 0& Dis(la. the re!ords /etween two range select rownum, empno, ename from emp where rowid in .select rowid from emp where rownum MJGupto minus select rowid from emp where rownumMG&tart/6 @nter value for upto, 1 @nter value for &tart, 8 I'W94M @M#9' @9AM@ +++++++++ +++++++++ ++++++++++ 1 88<2 E$AIF 2 88<< &E')) 1 8<1> F093 2 8<22 )4I9@I 1& " know the nvl 2un!tion onl. allows the sa'e data t.(e3ie& nu'/er or !har or date Nvl3!o''4 5664 i2 !o''ission is null then the te7t 8Not #((li!a/le9 want to dis(la.4 instead o2 /lank s(a!e& +ow do " write the :uer., &Q$P select nvl.toRchar.comm./,*9A*/ from emp6 'utput , 9-$.)'RE:AI.E'MM/,*9A*/ +++++++++++++++++++++++ 9A 1 5 9A 12 9A 9A

;& ra!le !ursor $ "'(li!it < E7(li!it !ursors 'racle uses work areas called private &Q$ areas to create &Q$ statements. #$!&Q$ construct to identify each and every work are used, is called as Eursor. Bor &Q$ Dueries returning a single row, #$!&Q$ declares all implicit cursors. Bor Dueries that returning more than one row, the cursor needs to be e%plicitly declared. =& E7(li!it Cursor attri/utes )here are four cursor attributes used in 'racle cursorRnameSBound, cursorRnameS9')B'49C, cursorRnameSI'WE'49), cursorRname S0&'#@9 %5& "'(li!it Cursor attri/utes &ame as e%plicit cursor but prefi%ed by the word &Q$ &Q$SBound, &Q$S9')B'49C, &Q$SI'WE'49), &Q$S0&'#@9 )ips , 1. :ere &Q$S0&'#@9 is false, because oracle automatically closed the implicit cursor after e%ecuting &Q$ statements. , 2. All are ?oolean attributes. %%& >ind out nth highest salar. 2ro' e'( ta/le &@$@E) C0&)09E) .a.sal/ BI'M @M# A W:@I@ G9 J .&@$@E) E'49) .C0&)09E) .b.sal// BI'M @M# ? W:@I@ a.salMJb.sal/6 @nter value for n, 2 &A$ +++++++++ 18 %2& To view installed ra!le version in2or'ation &Q$P select banner from vVversion6 %)& Dis(la. the nu'/er value in ?ords &Q$P select sal, .toRchar.toRdate.sal,*;*/, *;sp*// from emp6 the output like, &A$ .)'RE:AI.)'RCA)@.&A$,*(*/,*(&#*// +++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++ < eight hundred 17 one thousand si% hundred 125 one thousand two hundred fifty 0f you want to add some te%t like, Is. )hree )housand only. &Q$P select sal K&alary K, .* Is. *WW .toRchar.toRdate.sal,*;*/, *(sp*//WW * only.*//

K&al in WordsK from emp ! &alary &al in Words +++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++ < Is. @ight :undred only. 17 Is. 'ne )housand &i% :undred only. 125 Is. 'ne )housand )wo :undred Bifty only. %*& Dis(la. dd@ Even nu'/er o2 re!ords 'dd number of records, select N from emp where .rowid,1/ in .select rowid, mod.rownum,2/ from emp/6 1 1 5 @ven number of records, select N from emp where .rowid, / in .select rowid, mod.rownum,2/ from emp/ 2 2 7 %-& ?hi!h date 2un!tion returns nu'/er value, monthsRbetween %0& #n. three PL@SQL E7!e(tions, )ooRmanyRrows, 9oRCataRBound, -alueR@rror, HeroR@rror, 'thers %1& ?hat are PL@SQL Cursor E7!e(tions, EursorRAlreadyR'pen, 0nvalidREursor %;& ther wa. to re(la!e :uer. result null value with a te7t &Q$P &et 94$$ X9!AT to reset &Q$P &et 94$$ XT %=& ?hat are the 'ore !o''on (seudoA!olu'ns, &A&CA)@, 4&@I , 40C, E4I-A$, 9@")-A$, I'W0C, I'W94M 25& ?hat is the out(ut o2 S"GN 2un!tion, 1 for positive value, for Hero, +1 for 9egative value. 21. ?hat is the 'a7i'u' nu'/er o2 triggers4 !an a((l. to a single ta/le, 12 triggers.

JSP
1. ?hat is JSP, Des!ri/e its !on!e(t& (&# is a technology that combines :)M$!"M$ markup languages and elements of (ava programming $anguage to return dynamic content to the Web client, 0t is normally used to handle #resentation logic of a web application, although it may have business logic. 2. ?hat are the li2e!.!le (hases o2 a JSP, (&# page looks like a :)M$ page but is a servlet. When presented with (&# page the (&# engine does the following 8 phases. 1. #age translation, +page is parsed, and a ;ava file which is a servlet is created. 2. #age compilation, page is compiled into a class file 1. #age loading , )his class file is loaded. 2. Ereate an instance ,+ 0nstance of servlet is created 5. ;sp0nit./ method is called 7. R;sp&ervice is called to handle service calls 8. R;spCestroy is called to destroy it when the servlet is not reDuired. 1. ?hat is a translation unit, (&# page can include the contents of other :)M$ pages or other (&# files. )his is done by using the include directive. When the (&# engine is presented with such a (&# page it is converted to one servlet class and this is called a translation unit, )hings 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 ;sp,use?ean cannot declare the same bean twice in one unit. 2. +ow is JSP used in the MBC 'odel, (&# is usually used for presentation in the M-E pattern .Model -iew Eontroller / i.e. it plays the role of the view. )he controller deals with calling the model and the business classes which in turn get the data, this data is then presented to the (&# for rendering on to the client. 5. ?hat are !onte7t initialiCation (ara'eters, Eonte%t initiali=ation parameters are specified by the Mconte%t+paramP in the web.%ml file, these are initiali=ation parameter for the whole application and not specific to any servlet or (&#. 7. ?hat is a out(ut !o''ent, A comment that is sent to the client in the viewable page source. )he (&# engine handles an output comment as un+interpreted :)M$ te%t, returning the comment in the :)M$ output sent to the client. Aou can see the comment by viewing the page source from your Web browser. 8. ?hat is a +idden Co''ent, A comment that documents the (&# page but is not sent to the client. )he (&# 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 (&# page or the :)M$ page source. )he hidden comment is useful when you want to hide or Ucomment outY part of your (&# page. <. ?hat is a E7(ression, @%pressions are act as place holders for language e%pression, e%pression is evaluated each time the page is accessed. >. ?hat is a De!laration, 0t declares one or more variables or methods for use later in the (&# source file. A declaration must contain at least one complete declarative statement. Aou can declare any number of variables or methods within one declaration tag, as long as semicolons separate them. )he declaration must be valid in the scripting language used in the (&# file. 1 . ?hat is a S!ri(tlet, A scriptlet can contain any number of language statements, variable or method declarations, or e%pressions that are valid in the page scripting language. Within

scriptlet tags, you can declare variables or methods to use later in the file, write e%pressions valid in the page scripting language, use any of the (&# implicit ob;ects or any ob;ect declared with a M;sp,use?eanP. 11. ?hat are the i'(li!it o/De!ts, List the'& Eertain ob;ects that are available for the use in (&# documents without being declared first. )hese ob;ects are parsed by the (&# engine and inserted into the generated servlet. )he implicit ob;ects are, o reDuest o response o pageEonte%t o session o application o out o config o page o e%ception ?hatEs the di22eren!e /etween 2orward and sendFedire!t, When you invoke a forward reDuest, the reDuest is sent to another resource on the server, without the client being informed that a different resource is going to process the reDuest. )his process occurs completely with in the web container And then returns to the calling method. When a sendIedirect method is invoked, it causes the web container to return to the browser indicating that a new 4I$ should be reDuested. ?ecause the browser issues a completely new reDuest any ob;ect that are stored as reDuest attributes before the redirect occurs will be lost. )his e%tra round trip a redirect is slower than forward. ?hat are the di22erent s!o(e values 2or the GDs($useBeanH, )he different scope values for M;sp,use?eanP are, o page o reDuest o session o application ?h. are JSP (ages the (re2erred #P" 2or !reating a we/A/ased !lient (rogra', ?ecause no plug+ins or security policy files are needed on the client systems.applet does/. Also, (&# pages enable cleaner and more module application design because they provide a way to separate applications programming from web page design. )his means personnel involved in web page design do not need to understand (ava programming language synta% to do their ;obs. "s JSP te!hnolog. e7tensi/le, Aes, it is. (&# technology is e%tensible through the development of custom actions, or tags, which are encapsulated in tag libraries. ?hat is di22eren!e /etween !usto' JSP tags and /eans, Eustom (&# tag is a tag you defined. Aou 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 (&# files. Eustom tags and beans accomplish the same goals Z encapsulating comple% behavior into simple and accessible forms. )here are several differences, o Eustom tags can manipulate (&# content6 beans cannot. o Eomple% operations can be reduced to a significantly simpler form with custom tags than with beans.

2.

3.

4.

5. -.

o o o

Eustom tags reDuire Duite a bit more work to set up than do beans. Eustom tags usually define relatively self+contained behavior, whereas beans are often defined in one servlet and used in a different servlet or (&# page. Eustom tags are available only in (&# 1.1 and later, but beans can be used in all (&# 1.% versions.

#?T
1. ?hat is an #((let, Should a((lets have !onstru!tors, + Applets are small programs transferred through 0nternet, automatically installed and run as part of web+browser. Applets implements functionality of a client. Applet is a dynamic and interactive program that runs inside a Web page displayed by a (ava+capable browser. We donTt have the concept of Eonstructors in Applets. Applets can be invoked either through browser or through Appletviewer utility provided by (CF. 2. ?hat are the #((letEs Li2e C.!le 'ethods, E7(lain the', + Bollowing are methods in the life cycle of an Applet, o init./ method + called when an applet is first loaded. )his method is called only once in the entire cycle of an applet. )his method usually intiali=e the variables to be used in the applet. o start. / method + called each time an applet is started. o paint./ method + called when the applet is minimi=ed or refreshed. )his method is used for drawing different strings, figures, and images on the applet window. o stop. / method + called when the browser moves off the appletTs page. o destroy. / method + called when the browser is finished with the applet. 1. ?hat is the se:uen!e 2or !alling the 'ethods /. #?T 2or a((lets, + When an applet begins, the AW) calls the following methods, in this seDuence, o init./ o start./ o paint./ When an applet is terminated, the following seDuence of method calls takes place , stop./ destroy./ 2. +ow do #((lets di22er 2ro' #((li!ations, + Bollowing are the main differences, #((li!ation, &tand Alone, doesnTt need web+browser. #((let, 9eeds no e%plicit installation on local machine. Ean be transferred through 0nternet on to the local machine and may run as part of web+browser. #((li!ation, @%ecution starts with main./ method. CoesnTt work if main is not there. #((let, @%ecution starts with init./ method. #((li!ation, May or may not be a 340. #((let, Must run within a 340 .4sing AW)/. )his is essential feature of applets.
o o

5. Can we (ass (ara'eters to an a((let 2ro' +TML (age to an a((let, +ow, + We can pass parameters to an applet using MparamP tag in the following way, o Mparam nameJKparam1[ valueJKvalue1[P o Mparam nameJKparam2[ valueJKvalue2[P Access those parameters inside the applet is done by calling get#arameter./ method inside the applet. 9ote that get#arameter./ method returns &tring value corresponding to the parameter name. 7. +ow do we read nu'/er in2or'ation 2ro' '. a((letEs (ara'eters4 given that #((letEs getPara'eter36 'ethod returns a string, + 4se the parse0nt./ method in the 0nteger Elass, the Bloat.&tring/ constructor or parseBloat./ method in the Elass Bloat, or the Couble.&tring/ constructor or parseCoulbl./ method in the class Couble. 8. +ow !an " arrange 2or di22erent a((lets on a we/ (age to !o''uni!ate with ea!h other, + 9ame your applets inside the Applet tag and invoke AppletEonte%tTs getApplet./ method in your applet code to obtain references to the other applets on the page. <. +ow do " sele!t a IFL 2ro' '. #((let and send the /rowser to that (age, + Ask the applet for its applet conte%t and invoke showCocument./ on that conte%t ob;ect.
Q. 01% t#r&et01%3 1R. Str n& 01%Str n& 11. App$et2onte;t conte;t 5 &etApp$et2onte;t683 12. try 13. 4 14. t#r&et01% 5 ne' 01%601%Str n&83 15. 9 1-. c#tc: 6M#$formed01%.;cept on e8 1S. 4 1?. OO 2ode for recover from t:e e;cept on 1Q. 9 2R. conte;t. s:o'Document 6t#r&et01%83

21. Can a((lets on di22erent (ages !o''uni!ate with ea!h other, + 9o, 9ot Cirectly. )he applets will e%change the information at one meeting place either on the local file system or at remote system. 22. +ow do " deter'ine the width and height o2 '. a((li!ation, + 4se the get&i=e./ method, which the Applet class inherits from the Eomponent class in the (ava.awt package. )he get&i=e./ method returns the si=e of the applet as a Cimension ob;ect, from which you e%tract separate width, height fields. )he following code snippet e%plains this,
23. 24. 25. D mens on d m 5 &etS Te683 nt #pp$et' dt: 5 d m.' dt:683 nt #pp$et:e &:t 5 d m.:e &:t683

27. ?hi!h !lasses and inter2a!es does #((let !lass !onsist, + Applet class consists of a single class, the Applet class and three interfaces, AppletEonte%t, Applet&tub, and AudioElip. 28. ?hat is #((letStu/ "nter2a!e, + )he applet stub interface provides the means by which an applet and the browser communicate. Aour code will not typically implement this interface.

2<. ?hat tags are 'andator. when !reating +TML to dis(la. an a((let,
1. 2. 3. 4.

name, height, width code, name codebase, height, width code, height, width

Eorrect answer is d. 2. ?hat are the #((letEs in2or'ation 'ethods, + )he following are the AppletTs information methods, getApplet0nfo./ method, Ieturns a string describing the applet, its author, copyright information, etc. get#arameter0nfo. / method, Ieturns an array of string describing the appletTs parameters. 1. ?hat are the ste(s involved in #((let develo('ent, + Bollowing are the steps involved in Applet development,
o o o

Ereate!@dit a (ava source file. )his file must contain a class which e%tends Applet class. Eompile your program using ;avac @%ecute the appletviewer, specifying the name of your appletTs source file or html file. 0n case the applet information is stored in html file then Applet can be invoked using ;ava enabled web browser.

2>. ?hi!h 'ethod is used to out(ut a string to an a((let, ?hi!h 2un!tion is this 'ethod in!luded in, + draw&tring. / method is used to output a string to an applet. )his method is included in the paint method of the Applet.

SEFBLET
1. ?hat is a servlet, &ervlets are modules that e%tend reDuest!response+oriented servers,such as (ava+enabled web servers. Bor e%ample, a servlet might be responsible for taking data in an :)M$ order+entry form and applying the business logic used to update a companyTs order database. &ervlets are to servers what applets are to browsers. 4nlike applets, however, servlets have no graphical user interface. 2. ?hats the advantages using servlets over using CG", &ervlets provide a way to generate dynamic documents that is both easier to write and faster to run. &ervlets also address the problem of doing server+side programming with platform+ specific A#0s, they are developed with the (ava &ervlet A#0, a standard (ava e%tension.

1. ?hat are the general advantages and selling (oints o2 Servlets, A servlet can handle multiple reDuests concurrently, and synchroni=e reDuests. )his allows servlets to support systems such as online real+time conferencing. &ervlets can forward reDuests to other servers and servlets. )hus servlets can be used to balance load among several servers that mirror the same content, and to partition a single logical service over several servers, according to task type or organi=ational boundaries. 2. ?hi!h (a!kage (rovides inter2a!es and !lasses 2or writing servlets, ;ava% 5. ?hatEs the Servlet "nter2a!e, )he central abstraction in the &ervlet A#0 is the &ervlet interface. All servlets implement this interface, either directly or, more commonly, by e%tending a class that implements it such as :ttp&ervlet.&ervlets P 3eneric &ervlet P :ttp&ervlet P My&ervlet. )he &ervlet interface declares, but does not implement, methods that manage the servlet and its communications with clients. &ervlet writers provide some or all of these methods when developing a servlet. 7. ?hen a servlet a!!e(ts a !all 2ro' a !lient4 it re!eives two o/De!ts& ?hat are the., &ervletIeDuest .which encapsulates the communication from the client to the server/ and &ervletIesponse .which encapsulates the communication from the servlet back to the client/. &ervletIeDuest and &ervletIesponse are interfaces defined inside ;ava%.servlet package. 8. ?hat in2or'ation does ServletFe:uest allow a!!ess to, 0nformation such as the names of the parameters passed in by the client, the protocol .scheme/ being used by the client, and the names of the remote host that made the reDuest and the server that received it. Also the input stream, as &ervlet0nput&tream.&ervlets use the input stream to get data from clients that use application protocols such as the :))# #'&) and 3@) methods. <. ?hat t.(e o2 !onstraints !an ServletFes(onse inter2a!e set on the !lient, 0t can set the content length and M0M@ type of the reply. 0t also provides an output stream, &ervlet'utput&tream and a Writer through which the servlet can send the reply data. >. E7(lain servlet li2e!.!le, @ach servlet has the same life cycle, first, the server loads and initiali=es the servlet .init.//, then the servlet handles =ero or more client reDuests .service.//, after that the server removes the servlet .destroy.//. Worth noting that the last step on some servers is done when they shut down. 1 . +ow does +TTP Servlet handle !lient re:uests, An :))# &ervlet handles client reDuests through its service method. )he service method supports standard :))# client reDuests by dispatching each reDuest to a method designed to handle that reDuest.

JDBC

1. ?hat are the ste(s involved in esta/lishing a JDBC !onne!tion, )his action involves two steps, loading the (C?E driver and making the connection. 2. +ow !an .ou load the drivers, $oading the driver or drivers you want to use is very simple and involves ;ust one line of code. 0f, for e%ample, you want to use the (C?E+'C?E ?ridge driver, the following code will load it, Elass.for9ame.Ksun.;dbc.odbc.(dbc'dbcCriverK/6 Aour driver documentation will give you the class name to use. Bor instance, if the class name is ;dbc.Criver"AH, you would load the driver with the following line of code, Elass.for9ame.K;dbc.Criver"AHK/6 1. ?hat will Class&2orNa'e do while loading drivers, 0t is used to create an instance of a driver and register it with the CriverManager. When you have loaded a driver, it is available for making a connection with a C?M&. 2. +ow !an .ou 'ake the !onne!tion, )o establish a connection you need to have the appropriate driver connect to the C?M&. )he following line of code illustrates the general idea, &tring url J U;dbc,odbc,BredK6 Eonnection con J CriverManager.getEonnection.url, UBernandaK, U(<?/6 5. +ow !an .ou !reate JDBC state'ents and what are the., A &tatement ob;ect is what sends your &Q$ statement to the C?M&. Aou simply create a &tatement ob;ect and then e%ecute it, supplying the appropriate e%ecute method with the &Q$ statement you want to send. Bor a &@$@E) statement, the method to use is e%ecuteQuery. Bor statements that create or modify tables, the method to use is e%ecute4pdate. 0t takes an instance of an active connection to create a &tatement ob;ect. 0n the following e%ample, we use our Eonnection ob;ect con to create the &tatement ob;ect &tatement stmt J con.create&tatement./6 7. +ow !an .ou retrieve data 2ro' the FesultSet, (C?E returns results in a Iesult&et ob;ect, so we need to declare an instance of the class Iesult&et to hold our results. )he following code demonstrates declaring the Iesult&et ob;ect rs. Iesult&et rs J stmt.e%ecuteQuery.K&@$@E) E'BR9AM@, #I0E@ BI'M E'BB@@&K/6 &tring s J rs.get&tring.KE'BR9AM@K/6 )he method get&tring is invoked on the Iesult&et ob;ect rs, so get&tring./ will retrieve .get/ the value stored in the column E'BR9AM@ in the current row of rs.

8. ?hat are the di22erent t.(es o2 State'ents, Iegular statement .use create&tatement method/, prepared statement .use prepare&tatement method/ and callable statement .use prepareEall/ <. +ow !an .ou use Pre(aredState'ent, )his special type of statement is derived from class &tatement.0f you need a &tatement ob;ect to e%ecute many times, it will normally make sense to use a #repared&tatement ob;ect instead. )he advantage to this is that in most cases, this &Q$ statement will be sent to the C?M& right away, where it will be compiled. As a result, the #repared&tatement ob;ect contains not ;ust an &Q$ statement, but an &Q$ statement that has been precompiled. )his means that when the #repared&tatement is e%ecuted, the C?M& can ;ust run the #repared&tatementTs &Q$ statement without having to compile it first.
Q. +rep#redSt#tement upd#teS#$es 5 1R. con.prep#reSt#tement670+DAT. 2O((..S S.T SA%.S 5 C DE.1. 2O(A,AM. %BF. C783

11. ?hat does set#utoCo''it do, When a connection is created, it is in auto+commit mode. )his means that each individual &Q$ statement is treated as a transaction and will be automatically committed right after it is e%ecuted. )he way to allow two or more statements to be grouped into a transaction is to disable auto+commit mode, con.setAutoEommit.false/6 'nce auto+commit mode is disabled, no &Q$ statements will be committed until you call the method commit e%plicitly.
con.setAuto2omm t6f#$se83 +rep#redSt#tement upd#teS#$es 5 con.prep#reSt#tement6 70+DAT. 2O((..S S.T SA%.S 5 C DE.1. 2O(A,AM. %BF. C783 upd#teS#$es.setBnt61! 5R83 upd#teS#$es.setStr n&62! 72o$om) #n783 upd#teS#$es.e;ecute0pd#te683 +rep#redSt#tement upd#teTot#$ 5 con.prep#reSt#tement670+DAT. 2O((..S S.T TOTA% 5 TOTA% H C DE.1. 2O(A,AM. %BF. C783 upd#teTot#$.setBnt61! 5R83 upd#teTot#$.setStr n&62! 72o$om) #n783 upd#teTot#$.e;ecute0pd#te683 con.comm t683 con.setAuto2omm t6true83

12. +ow do .ou !all a stored (ro!edure 2ro' JDBC, )he first step is to create a Eallable&tatement ob;ect. As with &tatement an and #repared&tatement ob;ects, this is done with an open Eonnection ob;ect. A Eallable&tatement ob;ect contains a call to a stored procedure.
13. 2#$$#)$eSt#tement cs 5 con.prep#re2#$$674c#$$ SEODAS0++%B.1S9783 14. 1esu$tSet rs 5 cs.e;ecute@uery683

15. +ow do " retrieve warnings, &Q$Warning ob;ects are a subclass of &Q$@%ception that deal with database access warnings. Warnings do not stop the e%ecution of an

application, as e%ceptions do6 they simply alert the user that something did not happen as planned. A warning can be reported on a Eonnection ob;ect, a &tatement ob;ect .including #repared&tatement and Eallable&tatement ob;ects/, or a Iesult&et ob;ect. @ach of these classes has a getWarnings method, which you must invoke in order to see the first warning reported on the calling ob;ect,
1-. 1S. 1?. 1Q. 2R. 21. 22. S@%D#rn n& '#rn n& 5 stmt.&etD#rn n&s683 f 6'#rn n& G5 nu$$8 4 System.out.pr nt$n67n---D#rn n&---n783 ': $e 6'#rn n& G5 nu$$8 4 System.out.pr nt$n67Mess#&e: 7 H '#rn n&.&etMess#&e6883 23. System.out.pr nt$n67S@%St#te: 7 H '#rn n&.&etS@%St#te6883 24. System.out.pr nt67Iendor error code: 783 25. System.out.pr nt$n6'#rn n&.&et.rror2ode6883 2-. System.out.pr nt$n67783 2S. '#rn n& 5 '#rn n&.&et,e;tD#rn n&683 2?. 9 2Q. 9

1 . +ow !an .ou 'ove the !ursor in s!rolla/le result sets, 'ne of the new features in the (C?E 2. A#0 is the ability to move a result setTs cursor backward as well as forward. )here are also methods that let you move the cursor to a particular row and check the position of the cursor. &tatement stmt J con.create&tatement.Iesult&et.)A#@R&EI'$$R&@9&0)0-@, Iesult&et.E'9E4IRI@ACR'9$A/6 Iesult&et srs J stmt.e%ecuteQuery.K&@$@E) E'BR9AM@, #I0E@ BI'M E'BB@@&K/6 )he first argument is one of three constants added to the Iesult&et A#0 to indicate the type of a Iesult&et ob;ect, )A#@RB'IWAICR'9$A, )A#@R&EI'$$R09&@9&0)0-@ , and )A#@R&EI'$$R&@9&0)0-@. )he second argument is one of two Iesult&et constants for specifying whether a result set is read+only or updatable, E'9E4IRI@ACR'9$A and E'9E4IR4#CA)A?$@. )he point to remember here is that if you specify a type, you must also specify whether it is read+only or updatable. Also, you must specify the type first, and because both parameters are of type int , the compiler will not complain if you switch the order. &pecifying the constant )A#@RB'IWAICR'9$A creates a nonscrollable result set, that is, one in which the cursor moves only forward. 0f you do not specify any constants for the type and updatability of a Iesult&et ob;ect, you will automatically get one that is )A#@RB'IWAICR'9$A and E'9E4IRI@ACR'9$A. 11. ?hatEs the di22eren!e /etween TJPEKSCF LLK"NSENS"T"BE 4 and TJPEKSCF LLKSENS"T"BE, Aou will get a scrollable Iesult&et ob;ect if you specify one of these Iesult&et constants.)he 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. 3enerally speaking, a result set that is )A#@R&EI'$$R09&@9&0)0-@ does not reflect changes made while it is still open and one that is )A#@R&EI'$$R&@9&0)0-@ does. All three types of result sets will make changes visible if they are closed and then reopened,
32. 33. St#tement stmt 5 con.cre#teSt#tement61esu$tSet.T=+.AS21O%%AB,S.,SBTBI.! 1esu$tSet.2O,201A1.ADAO,%=83 34. 1esu$tSet srs 5 35. stmt.e;ecute@uery67S.%.2T 2O(A,AM.! +1B2. (1OM 2O((..S783 3-. srs.#fter%#st683 3S. ': $e 6srs.prev ous688 3Q. 4R. 41. Str n& n#me 5 srs.&etStr n&672O(A,AM.783 f$o#t pr ce 5 srs.&et($o#t67+1B2.783 System.out.pr nt$n6n#me H 7 7 H

3?. 4

pr ce83

22. +ow to Make I(dates to I(data/le Fesult Sets, Another new feature in the (C?E 2. A#0 is the ability to update rows in a result set using methods in the (ava programming language rather than having to send an &Q$ command. ?ut before you can take advantage of this capability, you need to create a Iesult&et ob;ect that is updatable. 0n order to do this, you supply the Iesult&et constant E'9E4IR4#CA)A?$@ to the create&tatement method.
43. 44. 45. 4-. 2onnect on con 5 Dr verM#n#&er.&et2onnect on67*d)c:mySu)protoco$:mySu),#me783 St#tement stmt 5 con.cre#teSt#tement61esu$tSet.T=+.AS21O%%AS.,SBTBI.! 1esu$tSet.2O,201A0+DATAJ%.83 4S. 1esu$tSet uprs 5 4?. stmt.e;ecute@uery67S.%.2T 2O(A,AM.! +1B2. (1OM 2O((..S783

Java Exception Handling


1) What is the difference between throw and throws ?And its application? Ans : Exceptions that are thrown by java runti e syste s can be handled by !ry and catch bloc"s# With throw exception we can handle the exceptions thrown by the pro$ra itself# %f a ethod is capable of causin$ an exception that it does not handle& it ust specify this behavior so the callers of the ethod can $uard

a$ainst that exception# ') What is the difference between Exception and error in java? Ans : Exception and Error are the subclasses of the !hrowable class# Exception class is used for exceptional conditions that user pro$ra should catch# With exception class we can subclass to create our own custo exception#

Error defines exceptions that are not excepted to be cau$ht by you pro$ra # Exa ple is (tac" )verflow# *) What is +esource lea"? Ans : ,reein$ up other resources that ethod# -)What is the finally bloc"? Ans : ,inally bloc" will execute whether or not an exception is thrown# %f an exception is thrown& the finally bloc" will execute even if no catch state ent atch the exception# Any ti e a ethod is about to return to the caller fro inside try.catch bloc"& via an uncau$ht exception or an explicit return state ent& the finally clause is also execute# /) 0an we have catch bloc" with out try bloc"? %f so when? Ans : 1o# !ry.0atch or !ry.finally for a unit# i$ht have been allocated at the be$innin$ of a

2) What is the difference between the followin$ state ents? 0atch 3Exception e)& 0atch 3Error err)& 0atch 3!hrowable t) Ans : 4) What will happen to the Exception object after exception handlin$? Ans : %t will $o for 5arba$e 0ollector# And frees the 6) 7ow e ory#

any Exceptions we can define in throws clause? ultiple exceptions in throws clause#

Ans : We can define

(i$nature is## type ethod8na e 3para eter8list) throws exception8list atches it#

9) !he finally bloc" is executed when an exception is thrown& even if no catch !rue.,alse Ans : !rue

1:) !he subclass exception should precede the base class exception when used within the catch clause# !rue.,alse Ans : !rue 11) Exceptions can be cau$ht or rethrown to a callin$ !rue.,alse Ans : !rue 1') !he state ents followin$ the throw "eyword in a pro$ra !rue.,alse Ans : !rue 1*) !he to(trin$ 3 ) !rue.,alse Ans : !rue ethod in the user8defined exception class is overridden# are not executed# ethod#

Java Multi Threading


1) What are the two types of Ans : 1#process8based '#!hread8based ') What are the two ways to create the thread? Ans : 1#by i ple entin$ +unnable '#by extendin$ !hread *) What is the si$nature of the constructor of a thread class? Ans : !hread3+unnable threadob&(trin$ thread1a e) -) What are all the Ans : run3) ethods available in the +unnable %nterface? ultitas"in$?

/) What is the data type for the available in which class? Ans : boolean& !hread 2) What are all the Ans : 1#isAlive3) '#join3) *#resu e3) -#suspend3) /#stop3) 2#start3) 4#sleep3) 6#destroy3)

ethod isAlive3) and this

ethod is

ethods available in the !hread class?

4) What are all the ethods used for %nter !hread co which these ethods are defined? Ans :1# wait3)&notify3) ; notifyall3) '# )bject class 6) What is the echanisa !hread at a ti e? Ans : (ynchronisation 9) What is the procedure to own the Ans : not possible 1:) What is the unit for 1::: in the below state ent? ob#sleep31:::) Ans : lon$ illiseconds oniter by

unication and what is the class in

defind by java for the +esources to be used by only one

any threads?

11) What is the data type for the para eter of the sleep3) Ans : lon$ 1') What are all the values for the followin$ level? ax8priority in8priority nor al8priority Ans : 1:&1&/ 1*) What is the Ans : set<riority3) ethod available for settin$ the priority?

ethod?

1-) What is the default thread at the ti e of startin$ the pro$ra ? Ans : ain thread ethod#

1/) !he word synchroni=ed can be used with only a !rue. ,alse Ans : ,alse

12) Which priority !hread can pro pt the lower pri ary !hread? Ans : 7i$her <riority 14) 7ow Ans : one 16) What are all the four states associated in the thread? Ans : 1# new '# runnable *# bloc"ed -# dead 19) !he suspend3) ethod is used to teri inate a thread? !rue .,alse Ans : ,alse any threads at a ti e can access a onitor?

':) !he run3) !rue .,alse Ans : !rue

ethod should necessary exists in clases created as subclass of thread?

'1) When two threads are waitin$ on each other and can>t proceed the pro$ra e is said to be in a deadloc"? !rue.,alse Ans : !rue '') Which Ans : join3) ethod waits for the thread to die ? ethod

'*) Which of the followin$ is true? 1) wait3)&notify3)&notifyall3) are defined as final ; can be called only fro synchroni=ed ethod ') A on$ wait3)&notify3)&notifyall3) the wait3) *) wait3)&notify3)&notifyall3) ; sleep3) are A. ?. E. C. @. 1 ' * 1;' 1&' ; * with in a

ethod only throws %)Exception

ethods of object class

Ans : ? '-) 5arba$e collector thread belon$s to which priority? Ans : low8priority '/) What is eant by ti eslicin$ or ti e sharin$? ethod of allocatin$ 0<@ ti e to individual threads in a priority

Ans : !i eslicin$ is the schedule# '2) What is

eant by dae on thread? %n java runti e& what is it>s role?

Ans : ?ae on thread is a low priority thread which runs inter ittently in the bac"$round doin$ the $arba$e collection operation for the java runti e syste #

Java Inheritance
1) What is the difference between superclass ; subclass? Ans : A super class is a class that is inherited whereas subclass is a class that does the inheritin$# ') Which "eyword is used to inherit a class? Ans : extends *) (ubclasses ethods can access superclass e bers. attributes at all ti es?

!rue.,alse Ans : ,alse -) When can subclasses not access superclass Ans : When superclass is declared as private# /) Which class does be$in Aava class hierarchy? Ans : )bject class 2) )bject class is a superclass of all other classes? !rue.,alse Ans : !rue 4) Aava supports Ans : ,alse 6) What is inheritance? Ans : ?erivin$ an object fro an existin$ class# %n the other words& %nheritance is the process of inheritin$ all the features fro a class 9) What are the advanta$es of inheritance? Ans : +eusability of code and accessibility of variables and subclasses# ethods of the superclass by ultiple inheritance? e bers?

!rue.,alse

1:) Which

ethod is used to call the constructors of the superclass fro

the subclass?

Ans : super3ar$u ent) 11) Which is used to execute any ethod of the superclass fro the subclass?

Ans : super# ethod8na e3ar$u ents) 1') Which ethods are used to destroy the objects created by the constructor ethods?

Ans : finali=e3) 1*) What are abstract classes? Ans : Abstract classes are those for which instances cant be created# 1-) What ust a class do to i ple ent an interface? ethods in the interface and identify the interface in its

Ans: %t ust provide all of the i ple ents clause# 1/) Which

ethods in the )bject class are declared as final?

Ans : $et0lass3)& notify3)& notifyAll3)& and wait3) 12) ,inal Ans : ,alse 14) ?eclaration of Ans: !rue 16) ,inal variables should be declared in the be$innin$? !rue.,alse Ans : !rue 19) 0an we declare variable inside a ethod as final variables? Why? ethods as final results in faster execution of the pro$ra ? ethods can be overridden# !rue.,alse

!rue.,alse

Ans : 0annot because& local variable cannot be declared as final variables# ':) 0an an abstract class ay be final?

Ans : An abstract class

ay not be declared as final#

'1) ?oes a class inherit the constructors of it>s super class? Ans: A class does not inherit constructors fro '') What restrictions are placed on Ans: !wo types# ethods any of it>s super classes#

ethod overloadin$?

ay not have the sa e na e and ar$u ent list but different return ethod overridin$?

'*) What restrictions are placed on

Ans : )verridden ethods ust have the sa e na e & ar$u ent list & and return type# !he overridin$ ethod ay not li it the access of the ethod it overridees#!he overridin$ ethod ay not throw any exceptions that ay not be thrown by the overridden ethod# '-) What odifiers ay be used with an inner class that is a e ber of an outer class?

Ans : a 3non8local) inner class abstract#

ay be declared as public& protected& private& static& final or

'/) 7ow this3) is used with constructors? Ans: this3) is used to invo"e a constructor of the sa e class '2) 7ow super3) used with constructors? Ans : super3) is used to invo"e a super class constructor '4) Which of the followin$ state ents correctly describes an interface? a)%t>s a concrete class b)%t>s a superclass c)%t>s a type of abstract class Ans: c '6) An interface contains BB a)1on8abstract b)% ple ented ethods

c)uni ple ented Ans:c

Frequently Asked Questions (FAQ A!out "ervlets


;aintained 4y "udhir Ancha

Cac" !o ,AD Eist

?hat are Servlets and how !an the. hel( in develo(ing ?e/ #((li!ations,
CServlets are modules that e tend re5uest)response7oriented ser%ers, such as 8a%a7enabled web ser%ers. @or e ample, a ser%let mi$ht be responsible for takin$ data in an ET;' order7 entry form and applyin$ the business lo$ic used to update a company&s order database. Servlets are to ser%ers what applets are to browsers. Fnlike applets, howe%er, servlets ha%e no $raphical user interface. Servlets can be embedded in many different ser%ers because the ser%let A?<, which you use to write servlet assumes nothin$ about the ser%er&s en%ironment or protocol. Servlets ha%e become most widely used within ETT? ser%ers9 many web ser%ers support the "er%let A?<.

?hat is the #dvantage o2 using Servlets over CG" (rogra''ing,


"er%lets are only instantiated when the client first accesses the pro$ram. That is, the first time any client hits the FR' that is used to access the "er%let, the "er%let en$ine instantiates that ob*ect. All subse5uent accesses are done to that instance. This keeps the response time of "er%lets lower than that of :>< pro$rams, which must be run once per hit. Also, because a "er%let is instantiated only once, all accesses are put throu$h that one ob*ect. This helps in maintainin$ ob*ects like internal :onnection ?oolin$ or user session trackin$ and lots of other features. Eere are a few more of the many applications for "er%lets( 3. Allowin$ collaboration between people. A "er%let can handle multiple re5uests concurrently, and can synchroni#e re5uests. This allows "er%lets to support systems such as on7line conferencin$. 6. @orwardin$ re5uests. "er%lets can forward re5uests to other ser%ers and "er%lets. Thus "er%lets can be used to balance load amon$ se%eral ser%ers that mirror the same content, and to partition a sin$le lo$ical ser%ice o%er se%eral ser%ers, accordin$ to task type or or$ani#ational boundaries.

?hat is the Jakarta ProDe!t ,


The $oal of the Jakarta Project is to pro%ide commercial75uality ser%er solutions based on the 8a%a ?latform that are de%eloped in an open and cooperati%e fashion. The fla$ship product, Tomcat, is a world7class implementation of the 8a%a "er%let 6.6 and JavaServer Pages 3.3"pecifications. This implementation will be used in the Apache Web "er%er as well as in other web ser%ers and de%elopment tools.C (The Apache "oftware @oundation).

?here !an i 2ind a good tutorial and 'ore details on Servlets,


These FR'&s are a $ood startin$ point if you want to know more about "er%lets. http())*a%a.sun.com)products)ser%let) http())*a%a.sun.com)docs)books)tutorial)ser%lets) "er%let 'inks !e%elopin$ Applications usin$ "er%lets (Tutorial)

+ow do " !onne!t to a data/ase 2ro' '. Servlet,


8a%a includes support for databases, usin$ 8a%a !atabase :onnecti%ity (8!4:). ;ost modern databases offer 8!4: dri%ers, which allow you to connect any 8a%a application (includin$ "er%lets) directly to your database. <f your database %endor does not offer a 8!4: dri%er, and there are no third party dri%ers a%ailable, you may like to use a 8!4: brid$e. @or e ample, the =!4:78!4: brid$e allows you to connect to any =!4: data source, which many databases support. Also there are four type of !ri%ers Type Type Type Type < ( 8!4:7=!4: brid$e << ( nati%e7A?< partly 8a%aT; technolo$y7enabled dri%er <<< ( net7protocol fully 8a%a technolo$y7enabled dri%er <- ( nati%e7protocol fully 8a%a technolo$y7enabled dri%er

@or a list of currently a%ailable !atabase dri%ers, please %isit this pa$e http())industry.*a%a.sun.com)products)*dbc)dri%ers :reatin$ a new :onnection to !atabase fre5uently could slow down your application. ;ost of the pro*ects use a concept called Connection Pooling. Eere when the "er%let starts up, in the init method , a pool of connections are created and are stored in memory (;ostly in a -ector). When a transaction with !atabase is re5uired, then the ne t free a%ailable connection

is retrie%ed from this -ector and used for that purpose. =nce it&s work is done, it is a$ain put back into :onnections ?ool, indicatin$ it is a%ailable. Today most of the 8!4: !ri%ers support this feature ha%e inbuilt connection poolin$ mechanisms. Please Note : <f you are creatin$ your own :onnection ?oolin$, it is stron$ly recommended to close all the open connections in the destroy method. Else there are chances of your data $ettin$ corrupted.

+ow do " get authenti!ation with '.Servlet,


;any popular "er%let en$ines offer "er%let authentication and the A?< has a call Ettp"er%letRe5uest.$etFser1ame() which is responsible for returnin$ the username of an authenticated user. @or more details please %isit this pa$e http())www.tapsellferrier.co.uk)"er%lets)@AG)authentication.html

?hat is a Session

/De!t ,

"ession =b*ect is used to maintain a user session related information on the "er%er side. Dou can store , retrie%e and remo%e information from a "ession ob*ect accordin$ to your pro$ram lo$ic. A session ob*ect created for each user persists on the ser%er side, either until user closes the browser or user remains idle for the session e piration time, which is confi$urable on each ser%er.

+ow to !reate Session o/De!t and use it 2or storing in2or'ation ,


This code will $et the "ession conte t for the current user and place %alues of count1 and count2 into MyIdentifier1 and MyIdentifier2 respecti%ely Ettp"ession session . re5.$et"ession(true)9 )):reatin$ a "ession instance session.put-alue (C;y<dentifier3C,count3)9 )) "torin$ -alue into session =b*ect session.put-alue (C;y<dentifier6C, count6)9 session.$et-alue(;y<dentifier3)9 )) ?rints %alue of :ount session.remo%e-alue(;y<dentifier3)9 )) Remo%in$ -aluefrom "ession =b*ect

?hat is the Ma7 a'ount o2 in2or'ation that !an/e saved in a Session /De!t ,
As such there is no limit on the amount of information that can be sa%ed in a "ession =b*ect. =nly the RA; a%ailable on the ser%er machine is the limitation. The only limit is the "ession <! len$th(<dentifier) , which should not e ceed more than HA. <f the data to be store is %ery hu$e, then it&s preferred to sa%e it to a temporary file onto hard disk, rather than sa%in$ it in session. <nternally if the amount of data bein$ sa%ed in "ession e ceeds the predefined limit, most of the ser%ers write it to a temporary cache on Eard disk.

?hat are Cookies and how to use the',


A cookie is a bit of information sent by the Web ser%er that can later be read back from the browser. 'imitations for cookies are, browsers are only re5uired to accept 6, cookies per site, /,, total per user , and they can limit each cookie&s si#e to H,IJ bytes (HA). :ookie cookie . new :ookie(Cuser<dC, C6+KJHC)9 )):reatin$ new :ookie response.add:ookie (cookie)9 )) sendin$ cookie to the browser )) ?rintin$ out all :ookies :ookieLM cookies . re5uest.$et:ookies()9 if (cookies N. null) O for (int i.,9 iPcookies.len$th9 iQQ) O "trin$ name . cookiesLiM.$et1ame()9 "trin$ %alue . cookiesLiM.$et-alue()9 R R Note : <f you want to sa%e special characters like C.C, or spaces, in the %alue of the cookie, then makesure you FR' encode the %alue of the cookie , before creatin$ a cookie. ?lease refer to @AG on FR'Encode and !ecodin$.

+ow to !on2ir' that userLs /rowser a!!e(ted the Cookie ,


There&s no direct A?< to directly %erify that user&s browser accepted the cookie. 4ut the 5uick alternati%e would be, after sendin$ the re5uired data tothe users browser, redirect the

response to a different "er%let which would try to read back the cookie. <f this "er%let is able to read back the cookie, then it was successfully sa%ed, else user had disabled the option to accept cookies.

+ow !an i delete or set 'a7 duration 2or whi!h Cookie e7ists,
Dou can set the ma imum a$e of a cookie with the cookie.setMaxAge int seconds! method( Eere are different options to this method, Sero means to delete the cookie A positi%e %alue is the ma imum number of seconds the cookie will li%e, before it e pires A ne$ati%e %alue means the cookie will not be stored beyond this browser session (deleted on browser close)

Eere is a sample code to delete cookie. pri%ate %oid delete:ookie("trin$ cookie1ame) O :ookieLM cookies .re5uest.$et:ookies()9 if (cookies N. null) O for (int i.,9 iPcookies.len$th9 iQQ) O if (cookiesLiM.$et1ame().e5uals(cookie1ame))9 cookiesLiM.set;a A$e(,)9 R R R

?hat are the Servlets E:uivalents o2 CG" 2or !o''onl. re:uested varia/les,
S.1I.1A,AM. S.1I.1ASO(TDA1. S.1I.1A+1OTO2O% S.1I.1A+O1T 1.@0.STAM.TEOD +ATEAB,(O +ATEAT1A,S%AT.D S21B+TA,AM. DO20M.,TA1OOT @0.1=AST1B,P request.&etServer,#me683 request.&etServ$et2onte;t68.&etServerBnfo683 request.&et+rotoco$683 request.&etServer+ort68 request.&etMet:od68 request.&et+#t:Bnfo68 request.&et+#t:Tr#ns$#ted68 request.&etServ$et+#t:68 request.&et1e#$+#t:67O78 request.&et@ueryStr n&68

1.MOT.AEOST 1.MOT.AADD1 A0TEAT=+. 1.MOT.A0S.1 2O,T.,TAT=+. 2O,T.,TA%.,PTE ETT+AA22.+T ETT+A0S.1AAP.,T ETT+A1.(.1.1

request.&et1emoteEost68 request.&et1emoteAddr68 request.&etAut:Type68 request.&et1emote0ser68 request.&et2ontentType68 request.&et2ontent%en&t:68 request.&etEe#der67Accept78 request.&etEe#der670ser-A&ent78 request.&etEe#der671eferer78

@or more details on these %ariables please referto this FR' http())hoohoo.ncsa.uiuc.edu)c$i)en%.html

+ow !an get the entire IFL o2 the !urrent Servlet ,


The followin$ code fra$ment will return the entire FR' of the current "er%let "trin$ current@ile . re5uest.$etRe5uestFR<()9 if (re5uest.$etGuery"trin$() N. null) O current@ile . current@ile Q &?& Q re5uest.$etGuery"trin$()9 R FR' currentFR' . new FR'(re5uest.$et"cheme(), re5uest.$et"er%er1ame(), re5uest.$et"er%er?ort(), current@ile)9 out.println(FR'.to"trin$())9

?hat are di22erent 'ethods in +tt(Servlet , #lso what are advantages o2 Get and P ST 'ethods,
There are two main methods by which data can be sent to "er%lets. They are GET and POST. Eere is the o%er %iew of sample "er%let and the methods youshould be o%er ridin$. public abstract synchroni=ed class 7ttp(ervlet extends5eneric(ervlet i ple ents (eriali=able F protected void do#et 37ttp(ervlet+eGuest reGuest& 7ttp(ervlet+esponse response) throws (ervletException& %)Exception F .. %f fro the ,or & the data is sub itted usin$ 5E! ethod then this ethod .. is called# Also by default when this (ervlet is called fro Crowser then this .. ethod is called#

H protected void do$ost37ttp(ervlet+eGuest reGuest& 7ttp(ervlet+esponse response) throws (ervletException& %)Exception F .. %f fro the ,or & the data is sub itted usin$ <@! ethod then this ethod is called H protected void service37ttp(ervlet+eGuest reGuest& 7ttp(ervlet+esponse response) throws (ervletException& %)Exception F .. %f you ust respond to reGuests ade by a client that is not usin$ the .. 7!!< protocol& you ust use service3)# Iou nor ally should never need .. to override this ethod& except in special cases# H H <f you want to support do?ost and do>et from same ser%let, then in either do?ost or do>et method, which e%er is $ettin$ called, call the other method usin$ doGet(request, response) or doPost(request,response) @or security reasons if the data bein$ submitted is sensiti%e, then it&s always preferred to use ?="T method so that the elements don&t shown up in FR'. When submitted usin$ >ET, then all the elements $et appended to the FR'. <f user clicks on a third party click and if that ser%er is lo$$in$ the Referrer, then the entire FR' is sa%ed, which will also ha%e sensiti%e information. Also there are limitations of amount of data that can be sent throu$h >ET method. "ome =peratin$ "ystems ha%e a limitation on the ;a 'en$th of the FR', which is normally 6TT characters. <f sendin$ throu$h >ET method, then the total len$th of the tar$et "er%let name and all parameters dataneed to be less than 6TT characters.

+ow do " send e'ail 2ro' '. Servlet,


Dou ha%e two options. The first is to write or find a "imple ;ail Transfer ?rotocol (";T?) implementation in 8a%a. The second is to use the 8a%a;ail A?<. Dou can !ownload the 8a%a;ail from this site at http())*a%a.sun.com)products)*a%amail @or a sample implementation of sendin$ E7mail usin$ 8a%a;ail please refer to this Article on "endin$ E7mail usin$ 8a%a;ail.

+ow do " (ass argu'ents to the Servlets,


Ar$uments to the ser%lets can be passed at two le%els. When a client is in%okin$ the ser%let, the client can pass the ar$uments as part of a FR' in form of name)%alue pairs in the 5uery strin$ portion of the FR'. <f a ta$ is used in the

html lan$ua$e to in%oke the ser%let, the ar$uments can be passed throu$h the param name construct( Pser%let code.Cser%let2nameC, stock2symbol.C8:=;CU The ser%er administrator)web7master can pass ar$uments to the ser%let at loadin$)intiali#ation time by specifyin$ the ar$uments as part of the ser%er confi$uration. @or Tomcat and 8"W!A, edit the conf)web. ml file. The re5uired ar$ument (parameter3 in this e ample ) can be retrie%ed this way, getSer letConte!t()"getAttri#ute( $para%ater&$)

+ow !an i set Class Path 2or '. Servlets ,


@or de%elopin$ ser%lets, *ust make sure that the 8AR filecontainin$ *a%a .ser%let.V is in your :'A""?ATE, and use your normal de%elopmenttools @or more details on settin$ :lass?ath , please refer tothis FR' , http())www.mean$ene.com)*a%a)classpath.html

Can .ou (rovide a sa'(le Servlet ,


Eere&s the sample implementation of a "er%let to print CWelcome to the World of "er%lets.C on to the browser class 7ello(ervlet extends 7ttp(ervlet F .JJ J 7andle the 7!!< 5E! ethod bybuildin$ a si ple web pa$e# J. public void do5et 37ttp(ervlet+eGuestreGuest& 7ttp(ervlet+esponse response) throws (ervletException&%)Exception F <rintWriteroutK (trin$ titleL M7ello (ervletMK ..set content type and other response header fields first response#set0ontent!ype3Mtext.ht lM)K .. then write the data of the response out Lresponse#$etWriter3)K out#println3MN7!OEPN7EA?PN!%!EEPM)K out#println3title)K out#println3MN.!%!EEPN.7EA?PNC)?IPM)K

out#println3MN71PMQ title Q MN.71PM)K out#println3MN<PWelco eto the World of (ervlets#M)K out#println3MN.C)?IPN.7!OEPM)K out#close3)K H H

+ow do " get the na'e o2 the !urrentl. e7e!uting s!ri(t,


Fse re5.$etRe5uestFR<() or re5.$et"er%let?ath(). The former returns the path to the script includin$ any e tra path information followin$ the name of the ser%let9 the latter strips the e tra path info. @or e ample(

%&' get&equest%&I get"ervlet$ath get$athIn(o getQuery"tring

http:..www#javasoft#co .servlets.7ello(ervlet.jdata.userinfo?pa$etypeLs*;pa$enu Lservlets.7ello(ervlet.jdata.userinfo servlets.7ello(ervlet. .jdata.userinfo pa$etypeLs*;pa$enu L-

Can .ou (rovide 'e with a List o2 "SPLs who su((ort Servlets ,
Eere is the list of all <"?&s who support"er%lets , )cetus)oo2*a%a2ser%lets.htmlWoo2*a%a2ser%let2hostin$

?hat is IFL En!oding and IFL De!oding ,


FR' encodin$ is the method of replacin$ all the spaces and other e tra characters into their correspondin$ Ee :haracters and !ecodin$ is the re%erse process con%ertin$ all Ee :haracters back their normal form. @or E ample consider this FR', )"er%lets!irectory)Eello&ser%let) When Encoded usin$ FR'Encoder.encode(C)"er%lets!irectory)Eello&ser%let)C) the output is 'ttp()A(*+(*+www",a aco%%erce"co%(*+Ser lets-.irector/(*+0ello (*1ser let(*+ This can be decoded back usin$

234.ecoder"decode($'ttp()A(*+(*+www",a aco%%erce"co% (*+Ser lets-.irector/(*+0ello(*1ser let(*+$)

?hat are Good ?a.s o2 De/ugging a Servlet , #re are "DELs whi!h su((ort Servlet De/ugging ,
There are couple of ;ethods. @irstly ser%ers like 8Run and others pro%ide separate lo$s where all your ?rint re5uests will print their data into. @or e ample re5uests to "ystem.out. and "ystem.err $o to different lo$ files. <f this features is not a%ailable or you want to maintain lo$s separately for each module then you can create a static class called C'o$WriterC and call the method inside the try catch loop. The print method in 'o$ Writer will be writin$ to a custom defined 'o$ @ile. try O .... R catch(E ception e p) O 'o$Writer.print(C!ebu$ ( The followin$ error occurred at function .... &) R Also <nprise 84uilder supports "er%let !ebu$$in$. ?lease refer to 84uilder documentation for details. 8ust as a :autionary note, from your "er%lets, ne%er call S/ste%"e!it(5). The results mi$ht be unpredictable. ;i$ht close down the entire "er%er. The 4est way is to catch the E ception and either send resultant Error ?a$e to the 4rowser or Write to a 'o$ file and inform user about the Error.

"2 i (ut a Servlet on ea!h servers4 and there is a stati! varia/le in thisServlet& Do all the instan!es on these servers share the sa'e stati! varia/le, "2 not4 how !an " share data a'ong these instan!es,
1o you can&t , because on e%ery ser%er there is a different -; runnin$ and a static %ariable is shared only between class instances in the same -;.

+ow !an i !reate "'ages Dire!tl. on 2l. and send the' to /rowser4 also at run ti'e i2 i want to write te7t on to( o2 a i'age 4how to do it ,
Dou can $et the latest ima$e $enerator packa$e from http())www.acme.com

+ow !an i u(load >ile using a Servlet,


Dou can show a 4rowse and Fpload @orm buttonusin$ the followin$ code. P@=R; E1:TD?E.C%ultipart67or%8dataC method.post action.C)utils)@ileFpload"er%letCU P<1?FT TD?E.CfileC 1A;E.CcurrentfilenameCU P<1?FT TD?E.CsubmitC -A'FE.CuploadCU P)@=R;U <t&s easy to use a readily a%ailable class, which you can easily embed into your ser%let for uploadin$ the file. !ownload the most widely used @ile Fpload packa$e written by 8ason Eunter at this FR' http())www.ser%lets.com)resources)com.oreilly.ser%let)inde .html

+ow !an i (revent Browser 2ro' Ca!hing the Page !ontent ,


4efore sendin$ the data to the browser, write thefollowin$ statements, response.setEeader(C:ache7:ontrolC,Cno7storeC)9 response.setEeader(C?ra$maC,Cno7cacheC)9 response.set!ateEeader (CE piresC, ,)9 This also helps in case, when user should not beable to see pre%ious pa$es by clickin$ the 4ack button in the browser. (When%ery sensiti%e information is bein$ displayed and someone else comes back tomachine and tries to see what data was entered)

+ow !an i redu!e the nu'/er o2 writes to Client 2ro' Servlet ,

<t is always recommended to use "trin$4uffer instead of "trin$ e%en for :oncatenatin$ a $roup of "trin$s. A%oid writin$ e%ery small strin$ to client. <nstead store all the strin$s into a "trin$4uffer and after sufficient data is a%ailable, send this data to 4rowser. Eere is some sample code, ?rintWriter out .res.$etWriter()9 "trin$4uffer sb . new "trin$4uffer()9 ))concatenate all te t to "trin$4uffer sb.append(CPhtmlUPbodyU............. P)bodyUP)htmlUC) res.set:ontent'en$th(sb.len$th())9 out.print(sb)9

Can .ou !o'(are the Per2or'an!e o2 Servlets4 JSP and Perl Pages ,
"er%lets will be faster than ?erl :>< ,because the ?erl e ecutable needs to launch as a separate process, then ?erl needs to initiali#e itself, then load in the script, then compile the script, and finally e ecute the script. Eere are some 4enchmarks for runnin$ "er%lets and ?erl under similar conditions http())www.ob*e cel.com)workin$*a%a.htmWWeb "er%er 4enchmarks

+ow !an i !all another Servlet or JSP 2ro' the !urrent Servlet ,
=ne of the pre%ious methods for callin$ another ser%let was Eello"er%let hello . (Eello"er%let)$et"er%let:onfi$().$et"er%let:onte t().$et"er%let(ChelloC)9 @rom "er%let A?< %ersion 6.3, this method has been deprecated and the preferred method is to use Re5uest!ispatcher. Eere is the synta for it, $et"er%let:onte t().$etRe5uest!ispatcher(C)*sp)hello)hello.*spC).forward(re5, res)9

+ow !an i write Data su/'itted 2ro' a #((let into a di22erent 2ile 4 then show users this data on a new (age ,

This is one of the most fre5uently used techni5ues. @rom your applet create a FR' connection the "er%let and send the data usin$ !ata=utput"tream. 1e t in the "er%ice method of "er%let, usin$ ?rintWriter, create a new @ile. =n the other end Applet will be waitin$ for response from "er%let, usin$ !ata<nput"tream. ?ass the newly created filename to the Applet. 1e t @rom applet call "how!ocument() method with new FR'. Eere is some sample code, FR' ticketser%let . new FR'( Chttp())*com.com)ser%let)Ticketser%let C)9 FR':onnection ser%let:onnection . ticketser%let.open:onnection()9 )) inform the connection that we will send output and accept input ser%let:onnection.set!o<nput(true)9 ser%let:onnection.set!o=utput(true)9 )) !on&t use a cached %ersion of FR' connection. ser%let:onnection.setFse:aches (false)9 ser%let:onnection.set!efaultFse:aches (false)9 )) "pecify the content type that we will send binary data ser%let:onnection.setRe5uest?roperty (C:ontent7TypeC, Capplication)octet7 streamC)9 )) send the student ob*ect to the ser%let usin$ seriali#ation =b*ect=utput"tream ticket=utputTo"er%let . new =b*ect=utput"tream(ser%let:onnection.$et=utput"tream())9 )) seriali#e the ob*ect , and sendin$ it to ser%let , ticket!ata should implement "eriali#able interface. ticket=utputTo"er%let .write=b*ect(ticket!ata)9 ticket=utputTo"er%let .flush()9 ticket=utputTo"er%let .close()9 ))readin$ back data from ser%let =b*ect<nput"tream input@rom"er%let . new =b*ect<nput"tream(ser%let:onnection.$et<nput"tream())9 -ector resultant!ata . (-ector) input@rom"er%let.read=b*ect()9 "trin$ filename . ("trin$) resultant!ata.elementAt(,) ))"howin$ the newly created pa$e from Applet $etApplet:onte t().show!ocument(new FR'(Chttp())www.*com.com)profiles)C Q filename))9

?hat are #((li!ation Servers 4 Servlet Engines and ?e/ Servers , +ow are the. di22erent 2ro' ea!h other ,

<nitially when the Web started, then all it needed was a "er%er which would recei%e the re5uests for ET;' pa$es or ima$es and send them back to browsers. These are called Web "er%ers. Then came re5uests for handlin$ hi$h capacity !atabase Transactions, supportin$ latest 8a%a @eatures like "er%lets, 8"?, E84 etc. These re5uests are handled by Application "er%ers. 1ormally for a Application "er%er to e ists and process client re5uests, they need to come throu$h Web ser%ers. All the static data like plain ET;' pa$es etc are placed on Web "er%er. All the !ynamic :ontent $enerators like "er%lets, E84 are placed on application ser%er. "er%let En$ines are similar to Application ser%ers, e cept they support only "er%lets and 8"?. Eere is the "er%let En$ines which support "er%lets and 8"? , http())*a%a.sun.com)products)ser%let)industry.html. Also here is a the list of All Web "er%ers and Application "er%ers. Applications ser%ers are *ust another le%el abo%e "er%let En$ines. 1ormally all the Application ser%ers support "er%lets and 8"?. 1ot all "er%let En$ines support other features like E84 etc, which Application "er%ers support.

?hat are the Latest Develo('ents to Servlets#P" ,


?lease %isit this FR'. http())*a%a.sun.com)about8a%a)communityprocess)*sr)*sr2,T/2*spser%let.html

"s there a Mailing List 2or Servlets related dis!ussions,


Eere is the archi%e of all the "er%lets <nterest discussions maintained by 8a%a"oft http())archi%es.*a%a.sun.com)archi%es)ser%let7interest.html. Dou can also subscribe to this mailin$ list from here.

+ow do i download a /inar. 2ile 2ro' a Servlet or JSP (age ,


Fse the 1ormal Anchor Ta$ from your pa$e. This is the most preferred way and let the browser handle the downloadin$ part. Eere is the "imple synta for it, Pa href.C?rofiler.#ipCU!ownload@ile @rom EereP)aU

Another way to ha%e "er%let do this would be, pro%ide a link to "er%let, and from the "er%let call this function , response.sendRedirect(C)downloads)?rofiler.#ipC)9

+ow do i know when user Session has e7(ired or re'oved,


!efine a class, say SessionTi%eout9ndicator,which implements ,a a!"ser let"'ttp"0ttpSession:inding4istener . :reate a SessionTi%eout9ndicator ob*ect and add it to the user session. When the session is remo%ed, SessionTi%eout9ndicator" alue2n#ound() will be called by the "er%let en$ine. Dou can implement alue2n#ound() to do the re5uired operation.

+ow !an i read data 2ro' an. IFL4 whi!h !an /ea /inar. data or 2ro' a #!tive Server Page ,
Fsin$ the @ollowin$ code, you can download any data. <f it connects to either "er%let or A"? pa$e, then the data $et&s processed if re5uired and the resultant data is read back. )):onnect to any FR', can be to a ima$e, to a static FR' like www.yahoo.com or any A"? pa$e. FR' url . new FR'(Chttp())www.aspkit.com)*data)transaction)transact.aspC)9 FR':onnection connection . url.open:onnection()9 <nput"tream stream . connection.$et<nput"tream()9 4uffered<nput"tream in . new 4uffered<nput"tream(stream)9 @ile=utput"tream file . new @ile=utput"tream(Cresult.t tC)9 4uffered=utput"tream out . new 4uffered=utput"tream(file)9 ))Readin$ !ata from the abo%e FR' int i9 while ((i . in.read()) N. 73)O out.write(i)9 R

+ow !an i stress test '. Servlets ,


Dou can use one of the followin$ products to stress test your "er%lets.

"er%letAiller @rom Allaire "oftware (@ree ?roduct) E7'oad from R"W "oftware Web Application "tress Tool @rom ;icrosoft 8;eter from Apache

?hat is Servlet Changing ,


"er%let :hainin$ is the process of chainin$ the output of one "er%let to another "er%let. Dou need to confi$ure your ser%let en$ine 8a%a Web ser%er, 8Run, , 8"er% ... for this process to work. @or e ample to confi$ure 8Run for ser%let chainin$, "elect the 8"E ser%ice (8Run ser%let en$ine) to access to the 8"E "er%ice :onfi$ panel. Dou ha%e *ust to define a new mappin$ rule where you define your chainin$ ser%let. 'et&s say 6ser lets6Tic;etC'ainSer let for the %irtual path and a comma separated list of ser%lets as Custo%erSer let ,Tic;etSer let. "o when you in%oke a re5uest like 'ttp:66,a aco%%erce"co%6ser lets6c'ainSer let , internally the ser%let Custo%erSer let will be in%oked first and its results will be piped into the ser%let Tic;etSer let.

The :ustomer"er%let ser%let code should look like( public class :ustomer"er%lete tends Ettp"er%let O public %oid do>et (Ettp"er%letRe5uest re5uest, Ettp"er%letResponseresponse) O ?rintWriter out .res.$etWriter()9 rest.set:ontentType(Cte t)htmlC)9 ... out.println(C:ustomer 1ame ( TomC)9 R

Ticket"er%let has to do is to open an inputstream to the re5uest ob*ect and read the data into a 4ufferedReader ob*ect. 4ufferedReader b . new4ufferedReader( new <nput"treamReader(re5.$et<nput"tream() ) )9 "trin$ data . b.read'ine()9 b.close()9 Eere in data %ariable you would $et C:ustomer1ame ( TomC 1ote ( 1ot many "er%let En$ines support "er%let:hainin$. Also it has been remo%ed from the standard specifications for "er%lets.

+ow !an i 'ake sure Iser had logged in when a!!essing Se!ure Pages ,
At the be$innin$ of each pa$e , place this small code, or include it in a common file Ettp"ession session .re5uest.$et"ession(true)9 if (session.$et-alue(CusernameC) .. null) O response.sendRedirect (response.encodeRedirectFrl(C'o$in?a$e.*sp? currentFR'.productdata.*spC))9 R else O )) >o ahead and show the pa$e R <n 'o$in?a$e.*sp once the user has pro%ided the correct lo$on credentials( session.put-alue(CusernameC,currentuser)9 response.sendRedirect(response.encodeRedirectFrl(re5uest.$et?arameter(CcurrentFR'C)))9

?h. a' i not seeing the 'ost re!ent u(dates 'ade to the servlet4 2ro' '. /rowser even though i a' !li!king on Fe2resh /utton and re'oved all the !a!he 2ro' the /rowser,
This is actually one of the features of "er%let. The first time when the "er%let is in%oked, then the init() method is called. "o once the "er%let is loaded into memory, it will stay there until the ser%er is restarted. Accordin$ to specs, the "er%let should reload itself when there is a chan$e in the code or new class is created. 4ut because of performance reasons, most of the "er%ers don&t check for this option and the "ame old "er%let is used which is currently in memory for all re5uests. <n 8Run, you need to click on the restart button. Any other solutions to this one are welcome. Tomcat re5uires you to *ust replace the WAR file.

+ow !an i li'it the nu'/er o2 Si'ultaneous !onne!tions to the sa'e Servlet,
This option is confi$urable on the "er%er. @or e ample 8Run allows you to setup the number of ma imum concurrent connections from Admin option.

?hat is Server Side Push and how is it i'(le'ented and when is it use2ul ,
"er%er "ide push is useful when data needs to chan$e re$ularly on the clients application or browser , without inter%ention from client. "tandard e amples mi$ht include apps like "tock&s Tracker, :urrent 1ews etc. As such ser%er cannot connect to client&s application automatically. The mechanism used is, when client first connects to "er%er, (Either throu$h lo$in etc..), then "er%er keeps the T:?)<? connection open. <t&s not always possible or feasible to keep the connection to "er%er open. "o another method used is, to use the standard ETT? protocols ways of refreshin$ the pa$e, which is normally supported by all browsers. P;ETA ETT?7EGF<-.CRefreshC :=1TE1T.CT9FR'.)ser%let)stock5uotes)CU This will refresh the pa$e in the browser automatically and loads the new data e%ery T seconds.

?hat Servlet engines su((ort sharing o2 session data a!ross 'ulti(le loadA/alan!ed we/ servers4 also re2erred to as Clustering,
The followin$ ser%ers support :lusterin$, <4; Web"phere ( Web"phere Application "er%er Ad%anced Edition, by enablin$ persistent sessions 4EA Web'o$ic 8Run /., (@rom %ersion /.,)

?hat is the di22eren!e /etween Multi(le "nstan!es o2 Browser and Multi(le ?indows& +ow does this a22e!t Sessions ,
@rom the current 4rowser window, if we open a new Window, then it referred to as ;ultiple Windows. "essions properties are maintained across all these windows, e%en thou$h they are operatin$ in multiple windows.

<nstead, if we open a new 4rowser, by either double clickin$ on the 4rowser "hortcut icon or shortcut link, then we are creatin$ a new <nstance of the 4rowser. This is referred to as ;ultiple <nstances of 4rowser. Eere each 4rowser window is considered as different client. "o "essions are not maintained across these windows.

Data/ase Questions
1# '# *# -# /# 2# 4# 6# 9# 1:# 11# 1'# 1*# 1-# 1/# 12# 14# 16# 19# ':# '1# ''# '*# '-# '/# '2# '4# '6# '9# *:# *1# What are the different types of joins? Explain nor ali=ation with exa ples# What cursor type do you use to retrieve ultiple recordsets? ?iffrence between a MwhereM clause and a Mhavin$M clause What is the difference between MprocedureM and MfunctionM? 7ow will you copy the structure of a table without copyin$ the data? 7ow to find out the database na e fro (DEJ<E@( co and pro pt? !adeoffs with havin$ indexes !al" about MException 7andlin$M in <E.(DE? What is the diference between M1@EE in 0M and M1@EE in )racle?M What is <roJ0? What is )0%? 5ive so e exa ples of Analytical functions# What is the difference between MtranslateM and MreplaceM? What is ?I1AO%0 (DE ethod -? 7ow to re ove duplicate records fro a table? What is the use of A1AEIRin$ the tables? 7ow to run (DE script fro a @nix (hell? What is a MtransactionM? Why are they necessary? Explain 1or ali=ationa dn ?enor ali=ation with exa ples# When do you $et contraint violtaion? What are the types of constraints? 7ow to convert +AW datatype into !ES!? ?ifference 8 <ri ary Tey and A$$re$ate Tey 7ow functional dependency is related to database table desi$n? What is a Mtri$$erM? Why can a M$roup byM or Morder byM clause be expensive to process? What are M7%1!(M? What is Mindex coverin$M of a Guery? What is a U%EW? 7ow to $et script for a view? What are the Ear$e object types suported by )racle? What is (DEJEoader? ?ifference between MUA+07A+M and MUA+07A+'M datatypes# What is the difference a on$ Mdroppin$ a tableM& Mtruncatin$ a tableM and Mdeletin$ all recordsM fro table# *'# ?ifference between M)+A0EEM and MO%0+)(),! A00E((M databases# **# 7ow to create a database lin" ? http:..www#ones artclic"#co .interviews.interviews8databases#ht lV!)<

)*+ Ho, ,ould you deter-ine the ti-e .one under ,hich a data!ase ,as operating/ select ?C!%OER)1E fro dualK

))+ Explain the use o( setting #'01A'23AME" equal to T&%E+ (ettin$ #'01A'23AME" dictates how you i$ht connect to a database# !his variable is either !+@E or ,AE(E and if it is set to !+@E it enforces database lin"s to have the sa e na e as the re ote database to which they are lin"in$# )4+ 5hat co--and ,ould you use to encrypt a $'6"Q' application/ W+A< )7+ Explain the di((erence !et,een a F%38TI039 $&08E:%&E and $A8;A#E+ A function and procedure are the sa e in that they are intended to be a collection of <E.(DE code that carries a sin$le tas"# While a procedure does not have to return any values to the callin$ application& a function will return a sin$le value# A pac"a$e on the other hand is a collection of functions and procedures that are $rouped to$ether based on their co onality to a business function or application# )<+ Explain the use o( ta!le (unctions+ !able functions are desi$ned to return a set of rows throu$h <E.(DE lo$ic but are intended to be used as a nor al table or view in a (DE state ent# !hey are also used to pipeline infor ation in an E!E process# )=+ 3a-e three advisory statistics you can collect+ Cuffer 0ache Advice& (e$ ent Eevel (tatistics& ; !i ed (tatistics )>+ 5here in the 0racle directory tree structure are audit traces placed/ %n unix W)+A0EEB7)OE.rdb s.audit& in Windows the event viewer )?+ Explain -ateriali.ed vie,s and ho, they are used+ Oateriali=ed views are objects that are reduced sets of infor ation that have been su ari=ed& $rouped& or a$$re$ated fro base tables# !hey are typically used in data warehouse or decision support syste s# )@+ 5hen a user process (ails9 ,hat !ackground process cleans up a(ter it/ <O)1 4A+ 5hat !ackground process re(reshes -ateriali.ed vie,s/ !he Aob Dueue <rocesses# 4*+ Ho, ,ould you deter-ine ,hat sessions are connected and ,hat resources they are ,aiting (or/ @se of UW(E((%)1 and UW(E((%)1BWA%! 4)+ :escri!e ,hat redo logs are+

+edo lo$s are lo$ical and physical structures that are desi$ned to hold all the chan$es and are intended to aid in the recovery of a database# 44+ Ho, ,ould you (orce a log s,itch/ AE!E+ (I(!EO (W%!07 E)5,%EEK

ade to a database

47+ #ive t,o -ethods you could use to deter-ine ,hat ::' changes have !een -ade+ Iou could use Eo$ iner or (trea s 4<+ 5hat does coalescing a ta!lespace do/ 0oalescin$ is only valid for dictionary8 ana$ed tablespaces and de8fra$ ents space by co binin$ nei$hborin$ free extents into lar$e sin$le extents# 4=+ 5hat is the di((erence !et,een a TEM$0&A&B ta!lespace and a $E&MA3E3T ta!lespace/ A te porary tablespace is used for te porary objects such as sort structures while per anent tablespaces are used to store those objects eant to be used as the true objects of the database# 4>+ 3a-e a ta!lespace auto-atically created ,hen you create a data!ase+ !he (I(!EO tablespace# 4?+ 5hen creating a user9 ,hat per-issions -ust you grant to allo, the- to connect to the data!ase/ 5rant the 0)11E0! to the user# 4@+ Ho, do you add a data (ile to a ta!lespace/ AE!E+ !ACEE(<A0E NtablespaceBna eP A?? ?A!A,%EE NdatafileBna eP (%RE Nsi=eP 7A+ Ho, do you resi.e a data (ile/ AE!E+ ?A!ACA(E ?A!A,%EE NdatafileBna eP +E(%RE NnewBsi=ePK 7*+ 5hat vie, ,ould you use to look at the si.e o( a data (ile/ ?CAB?A!AB,%EE( 7)+ 5hat vie, ,ould you use to deter-ine (ree space in a ta!lespace/ ?CAB,+EEB(<A0E 74+ Ho, ,ould you deter-ine ,ho has added a ro, to a ta!le/ !urn on fine $rain auditin$ for the table# 77+ Ho, can you re!uild an index/

AE!E+ %1?ES NindexBna eP +EC@%E?K 7<+ Explain ,hat partitioning is and ,hat its !ene(it is+ <artitionin$ is a pieces# ethod of ta"in$ lar$e tables and indexes and splittin$ the into s aller& ore ana$eable

7=+ Bou have Cust co-piled a $'6"Q' package !ut got errors9 ho, ,ould you vie, the errors/ (7)W E++)+( 7>+ Ho, can you gather statistics on a ta!le/ !he A1AEIRE co and#

7?+ Ho, can you ena!le a trace (or a session/ @se the ?CO(B(E((%)1#(E!B(DEB!+A0E or @se AE!E+ (E((%)1 (E! (DEB!+A0E L !+@EK 7@+ 5hat is the di((erence !et,een the "Q'D'oader and IM$0&T utilities/ !hese two )racle utilities are used for loadin$ data into the database# !he difference is that the i port utility relies on the data bein$ produced by another )racle utility ES<)+! while the (DEJEoader utility allows data to be loaded that has been produced by other utilities fro different data sources just so lon$ as it confor s to A(0%% for atted or deli ited files# <A+ 3a-e t,o (iles used (or net,ork connection to a data!ase+ !1(1AOE(#)+A and (DE1E!#)+A http:..databasejournal#co .features.oracle.article#php.*11-*61

Technical E %3IF Every ?CA should "now so ethin$ about the operatin$ syste that the database will be runnin$ on# !he Guestions here are related to @1%S but you should eGually be able to answer Guestions related to co on Windows environ ents# *+ Ho, do you list the (iles in an %3IF directory ,hile also sho,ing hidden (iles/ ls 8ltra )+ Ho, do you execute a %3IF co--and in the !ackground/ @se the M;M 4+ 5hat %3IF co--and ,ill control the de(ault (ile per-issions ,hen (iles are created/ @ as" 7+ Explain the read9 ,rite9 and execute per-issions on a %3IF directory+ +ead allows you to see and list the directory contents# Write allows you to create& edit and delete files and subdirectories in the directory# Execute $ives you the previous read.write per issions plus allows you to chan$e into the directory and execute pro$ra s or shells fro the directory# <+ the di((erence !et,een a so(t link and a hard link/ A sy bolic 3soft) lin"ed file and the tar$eted file can be located on the sa e or different file syste a hard lin" they ust be located on the sa e file syste # =+ #ive the co--and to display space usage on the %3IF (ile syste-+ df 8l" >+ Explain iostat9 v-stat and netstat+ %ostat reports on ter inal& dis" and tape %.) activity# U stat reports on virtual e ory statistics for processes& dis"& tape and 0<@ activity# while for

1etstat reports on the contents of networ" data structures# ?+ Ho, ,ould you change all occurrences o( a value using GI/ @se :LsOKo$dNOKne'NO& @+ #ive t,o %3IF kernel para-eters that e((ect an 0racle install

(7OOAS ; (7OO1% *A+ 1rie(ly9 ho, do you install 0racle so(t,are on %3IF+ Casically& set up dis"s& "ernel para eters& and run orainst# http:..databasejournal#co .features.oracle.article#php.*11-*61

/De!tA rientation Con!e(ts4 IML interview Questions


1# '# *# -# /# 2# 4# 6# 9# 1:# 11# 1'# 1*# 1-# 1/# 12# 14# 16# 19# ':# '1# ''# '*# '-# '/# '2# '4# '6# '9# *:# *1# *'# **# *-# */# *2# What is inheritance? ?ifference between 0o position and A$$re$ation# ?ifference: (eGuence ?ia$ra s& 0ollaboration ?ia$ra s# ?ifference: >uses>& >extends>& >includes> What shall % $o for <ac"a$e ?ia$ra ? What is <oly orphis ? %s class an )bject? %s object a class? 0o ent: 0QQ MincludesM behavior and java Mi portsM What do you ean by M+eali=ationM? What is a <resistent& !ransient )bject? What is the use of )perator )verloadin$? ?oes @OE $uarantee project success? ?ifference: Activity ?ia$ra and (eGuence ?ia$ra # What is association? 7ow to resolve any to any relationship? 7ow do you represent static e bers and abstract classes in 0lass ?ia$ra ? 0an we use @OE for user interface 3@%) desi$n? Every object has : state& behavior and identity 8 explain 7ow to reverse en$ineer 0QQ code in @OE? What are the tools you used for ))A?? ?ifference: )bject )riented Analysis 3))A) and )bject )riented ?esi$n 3))?)? What are the four phases of the @nified <rocess ? 7ow do you convert uses cases into test cases? Explain 0lass ?ia$ra in ?etail# What are the ?esi$n <atterns you "now# When do you prefer to use co position than a$$re$ation? @OE: %( it a process& ethod or notation? ?oes a concept 7AUE to beco e a class in ?esi$n? What are the $ood practices to use while desi$nin$ for reuse? 0an you thin" of so e nice exa ples where J ultipleJ actors are associated with a use case ? 7ow to use 0+0 0ards for 0lass ?esi$n? What is the difference between static and dyna ic 0lassificaition#5ive so e exa ples# Explian followin$ ter s: 0onstraint +ules& ?esi$n by contract# What is )bject 0onstraint Ean$ua$e 3)0E)? ?ifference Cetween Attribute and Association# What are associative classes?

1# 5hat gives Java its H,rite once and run any,hereI nature/ 8 Aava is co piled to be a byte code which is the inter ediate lan$ua$e between source code and achine code# !his byte code is not plator specific and hence can be fed to any platfor # After bein$ fed to the AUO& which is specific to a particular operatin$ syste & the code platfor specific achine code is $enerated thus a"in$ java platfor independent# '# 5hat are the (our corner stones o( 00$/ 8 Abstraction& Encapsulation& <oly orphis and %nheritance# *# :i((erence !et,een a 8lass and an 0!Cect/ 8 A class is a definition or prototype whereas an object is an instance or livin$ representation of the prototype# -# 5hat is the di((erence !et,een -ethod overriding and overloading/ 8 )verridin$ is a ethod with the sa e na e and ar$u ents as in a parent& whereas overloadin$ is the sa e ethod na e but different ar$u ents# /# 5hat is a HstatelessI protocol/ 8 Without $ettin$ into len$thy debates& it is $enerally accepted that protocols li"e 7!!< are stateless i#e# there is no retention of state between a transaction which is a sin$le reGuest response co bination# 2# 5hat is constructor chaining and ho, is it achieved in Java/ 8 A child object constructor always first needs to construct its parent 3which in turn calls its parent constructor#)# %n Aava it is done via an i plicit call to the no8ar$s constructor as the first state ent# 4# 5hat is passed !y re( and ,hat !y value/ 8 All Aava ethod ar$u ents are passed by value# 7owever& Aava does anipulate objects by reference& and all object variables the selves are references 6# 8an &MI and 8or!a !ased applications interact/ 8 Ies they can# +O% is available with %%)< as the transport protocol instead of A+O<# 9# Bou can create a "tring o!Cect as "tring str J Ha!cKL 5hy cant a !utton o!Cect !e created as 1utton !t J Ha!cKL/ Explain 8 !he ain reason you cannot create a button by Cutton bt1L XabcMK is because XabcY is a literal strin$ 3so ethin$ sli$htly different than a (trin$ object& by the way) and bt1 is a Cutton object# !he only object in Aava that can be assi$ned a literal (trin$ is java#lan$#(trin$# % portant to note that you are 1)! callin$ a java#lan$#(trin$ constuctor when you type (trin$ s L XabcMK 1:# 5hat does the Ha!stractI key,ord -ean in (ront o( a -ethod/ A class/ 8 Abstract "eyword declares either a ethod or a class# %f a ethod has a abstract "eyword in front of it&it is called abstract ethod#Abstract ethod hs no body#%t has only ar$u ents and return type#Abstract ethods act as placeholder ethods that are i ple ented in the subclasses# Abstract classes cant be instantiated#%f a class is declared as abstract&no objects of that class can be created#%f a class contains any abstract ethod it ust be declared as abstract# 11# Ho, -any -ethods do u i-ple-ent i( i-ple-ent the "eriali.a!le Inter(ace/ 8 !he (eriali=able interface is just a X ar"erY interface& with no ethods of its own to i ple ent# )ther ar"er interfaces are java#r i#+e ote java#util#EventEistener 1'# 5hat are the practical !ene(its9 i( any9 o( i-porting a speci(ic class rather than an entire package (e+g+ i-port Cava+net+D versus i-port Cava+net+"ocket / 8 %t a"es no difference in the $enerated class files since only the classes that are actually used are referenced by the $enerated class file# !here is another practical benefit to i portin$ sin$le classes& and this arises when two 3or ore) pac"a$es have classes with the sa e na e# !a"e java#util#!i er and javax#swin$#!i er& for exa ple# %f % i port java#util#J and javax#swin$#J and then try to use X!i erM& % $et an error while co pilin$ 3the class na e is a bi$uous between both pac"a$es)# Eets say what you really wanted was the javax#swin$#!i er class& and the only classes you plan on usin$ in java#util are 0ollection and 7ashOap# %n this case& so e people will prefer to i port java#util#0ollection and i port java#util#7ashOap instead of i portin$ java#util#J# !his will now allow the to use !i er& 0ollection& 7ashOap& and other javax#swin$ classes without usin$ fully Gualified class na es in# 1*# 5hat is the di((erence !et,een logical data independence and physical data independence/ 8 Eo$ical ?ata %ndependence 8 eanin$ i unity of external sche as to chan$eds in conceptual sche a# <hysical ?ata %ndependence 8 eanin$ i unity of conceptual sche a to chan$es in the internal sche a#

1-# 5hat is a userEde(ined exception/ 8 Apart fro the exceptions already defined in Aava pac"a$e libraries& user can define his own exception classes by extendin$ Exception class# 1/# :escri!e the visitor design pattern/ 8 +epresents an operation to be perfor ed on the ele ents of an object structure# Uisitor lets you define a new operation without chan$in$ the classes of the ele ents on which it operates# !he root of a class hierarchy defines an abstract ethod to accept a visitor# (ubclasses i ple ent this ethod with visitor#visit3this)# !he Uisitor interface has visit ethods for all subclasses of the baseclass in the hierarchy# http:..www#techinterviews#co .index#php?pL1*9 What is a Mtri$$erM? A tri$$er is a database object directly associated with a particular table# %t fires whenever a specific state ent.type of state ent is issued a$ainst that table# !he types of state ents are insert&update&delete and Guery state ents# Casically& tri$$er is a set of (DE state ents that execute in response to a data odification.retrieval event on a table# What is a (DE Uiew ? Uiew is a preco plied (DE Guery which is used to select data fro one or ore tables# A view is li"e a table but it doens>t physically ta"e any space# Uiw is a $ood way to present data in a particualr for at if you use that Guery Guite often# Uiew can also be used to restrict users fro accessin$ the tables directly# What is a Mpri ary "eyM? <ri ary Tey is a type of a constraint enforcin$ uniGueness and data inte$rity for each row of a table# All colu ns participatin$ in a pri ary "ey constraint ust possess the 1)! 1@EE property# What is a MconstraintM? A constraint allows you to apply si ple referential inte$rity chec"s to a table# !here are four pri ary types of constraints that are currently supported by (DE (erver: <+%OA+I.@1%D@E 8 enforces uniGueness of a particular table colu n# ?E,A@E! 8 specifies a default value for a colu n in case an insert operation does not provide one# ,)+E%51 TEI 8 validates that every value in a colu n exists in a colu n of another table# 07E0T 8 chec"s that every value stored in a colu n is in so e specified list Each type of constraint perfor s a specific type of action#

What is a MjoinM? Aoins er$e the data of two related tables into a sin$le result set& presentin$ a denor ali=ed view of the data#

What is a Mfunctional dependencyM? 7ow does it relate to database table desi$n?

Assu e that a table exists in the database called !ACEE with a co posite pri ary "ey 3A& C) and other non8"ey attributes 30& ?& E)# ,unctional dependency in $eneral& would ean that any non8"ey attribute 8 0 ? or E bein$ dependent on the pri ary "ey 3A and C)in our table here# <artial functional dependency& on the other hand& is another corollary of the above& which states that all non8 "ey attributes 8 0 ? or E 8 if dependent on the subset of the pri ary "ey 3A and C) and not on it as a whole# Exa ple : 8888888888 ,ully ,unctional ?ependent : 0 ? E 88P A C <artial ,unctional dependency : 0 88P A ? E 88P C What is Mindex coverin$M of a Guery? %ndex coverin$ eans that M?ata can be found only usin$ indexes& without touchin$ the tablesM

0racle "Q' FAQ


W?ate: :*8)ct8'::* W W+evision: 1#91 W WAuthor: ,ran" 1audZ W Topics [ What is (DE and where does it co e fro ? [ What are the difference between ??E& ?OE and ?0E co ands? [ 7ow does one escape characters when buildin$ (DE Gueries? [ 7ow does one eli inate duplicate rows fro a table? [ 7ow does one $enerate pri ary "ey values for a table? [ 7ow does one $et the ti e difference between two date colu ns? [ 7ow does one add a day.hour. inute.second to a date value? [ 7ow does one count different data values in a colu n? [ 7ow does one count.su +A15E( of data values in a colu n? [ 0an one retrieve only the 1th row fro a table? [ 0an one retrieve only rows S to I fro a table? [ 7ow does one select EUE+I 1th row fro a table? [ 7ow does one select the !)< 1 rows fro a table? [ 7ow does one code a tree8structured Guery? [ 7ow does one code a atrix report in (DE? [ 7ow does one i ple ent %,8!7E18EE(E in a select state ent? [ 7ow can one du p. exa ine the exact content of a database colu n? [ 0an one drop a colu n fro a table? [ 0an one rena e a colu n in a table? [ 7ow can % chan$e y )racle password? [ 7ow does one find the next value of a seGuence? [ Wor"around for snapshots on tables with E)15 colu ns [ Where can one $et ore info about (DE? Cac" to )racle ,AD %ndex 5hat is "Q' and ,here does it co-e (ro-/

(tructured Duery Ean$ua$e 3(DE) is a lan$ua$e that provides an interface to relational database syste s# (DE was developed by %CO in the 194:s for use in (yste +& and is a de facto standard& as well as an %() and A1(% standard# (DE is often pronounced (ED@EE# %n co on usa$e (DE also enco passes ?OE 3?ata Oanipulation Ean$ua$e)& for %1(E+!s& @<?A!Es& ?EEE!Es and ??E 3?ata ?efinition Ean$ua$e)& used for creatin$ and odifyin$ tables and other database structures# !he develop ent of (DE is $overned by standards# A ajor revision to the (DE standard was co pleted in 199'& called (DE'# (DE* support object extensions and are 3partially?) i ple ented in )racle6 and 9# [ Cac" to top of file

5hat are the di((erence !et,een ::'9 :M' and :8' co--ands/ ::' is :ata :e(inition 'anguage state-ents+ "o-e exa-plesM 0+EA!E 8 to create objects in the database AE!E+ 8 alters the structure of the database ?+)< 8 delete objects fro the database a table& includin$ all spaces allocated for the records are

!+@10A!E 8 re ove all records fro re oved 0)OOE1! 8 add co

ents to the data dictionary

5+A1! 8 $ives user>s access privile$es to database +EU)TE 8 withdraw access privile$es $iven with the 5+A1! co and

:M' is :ata Manipulation 'anguage state-ents+ "o-e exa-plesM (EEE0! 8 retrieve data fro the a database %1(E+! 8 insert data into a table @<?A!E 8 updates existin$ data within a table ?EEE!E 8 deletes all records fro a table& the space for the records re ain 0AEE 8 call a <E.(DE or Aava subpro$ra ES<EA%1 <EA1 8 explain access path to data E)0T !ACEE 8 control concurrency

:8' is :ata 8ontrol 'anguage state-ents+ "o-e exa-plesM 0)OO%! 8 save wor" done (AUE<)%1! 8 identify a point in a transaction to which you can later roll bac" +)EECA0T 8 restore database to ori$inal since the last 0)OO%! (E! !+A1(A0!%)1 8 0han$e transaction options li"e what rollbac" se$ ent to use

[ Cac" to top of file

Ho, does one escape special characters ,hen !uilding "Q' queries/ !he E%TE "eyword allows for strin$ searches# !he >B> wild card character is used to atch exactly one character& >\> is used to atch =ero or ore occurrences of any characters# !hese characters can be escaped in (DE# Exa ple: (EEE0! na e ,+)O e p W7E+E id E%TE >\]B\> E(0A<E >]>K @se two Guotes for every one displayed# Exa ple: (EEE0! >,ran"s>>s )racle site> ,+)O ?@AEK (EEE0! >A >>Guoted>> word#> ,+)O ?@AEK (EEE0! >A >>>>double Guoted>>>> word#> ,+)O ?@AEK [ Cac" to top of file Ho, does one eli-inate duplicates ro,s (ro- a ta!le/ 0hoose one of the followin$ Gueries to identify or re ove duplicate rows fro records in the table: Method *M (DEP ?EEE!E ,+)O tableBna e A W7E+E +)W%? P 3 ' (EEE0! in3rowid) ,+)O tableBna e C * W7E+E A#"eyBvalues L C#"eyBvalues)K Method )M (DEP create table tableBna e' as select distinct J fro tableBna e1K (DEP drop tableBna e1K (DEP rena e tableBna e' to tableBna e1K (DEP 88 +e e ber to recreate all indexes& constraints& tri$$ers& etc on table### Method 4M (thanks to :ennis #urnick (DEP delete fro yBtable t1 (DEP where exists 3select >x> fro yBtable t' (DEP where t'#"eyBvalue1 L t1#"eyBvalue1 (DEP and t'#"eyBvalue' L t1#"eyBvalue' (DEP and t'#rowid P t1#rowid)K 1ote: )ne can eli inate 1^' unnecessary operations by creatin$ an index on the joined fields in the inner loop 3no need to loop throu$h the entire table on each pass by a record)# !his will speed8up the deletion process# 1ote ': %f you are co parin$ 1)!81@EE colu ns& use the 1UE function# +e e ber that 1@EE is not eGual to 1@EE# !his should not be a proble as all "ey colu ns should be 1)! 1@EE by definition# [ Cac" to top of file Ho, does one generate pri-ary key values (or a ta!le/ 0reate your table with a 1)! 1@EE colu n 3say (ED1))# !his colu n can now be populated with uniGue values: (DEP @<?A!E tableBna e (E! seGno L +)W1@OK or use a seGuences $enerator: a table leavin$ only uniGue

(DEP 0+EA!E (ED@E10E seGuenceBna e (!A+! W%!7 1 %10+EOE1! CI 1K (DEP @<?A!E tableBna e (E! seGno L seGuenceBna e#1ES!UAEK ,inally& create a uniGue index on this colu n# [ Cac" to top of file Ho, does one get the ti-e di((erence !et,een t,o date colu-ns/ Eoo" at this exa ple Guery: select floor333date18date')J'-J2:J2:).*2::) __ > 7)@+( > __ floor3333date18date')J'-J2:J2:) 8 floor333date18date')J'-J2:J2:).*2::)J*2::).2:) __ > O%1@!E( > __ round3333date18date')J'-J2:J2:) 8 floor333date18date')J'-J2:J2:).*2::)J*2:: 8 3floor3333date18date')J'-J2:J2:) 8 floor333date18date')J'-J2:J2:).*2::)J*2::).2:)J2:))) __ > (E0( > ti eBdifference fro ### %f you don>t want to $o throu$h the floor and ceilin$ ath& try this ethod 3contributed by Eri" Wile):

select toBchar3toBdate3>::::::::>&>77'-:O%:((>) Q 3date1 8 date')& >77'-:O%:((>) ti eBdifference fro ### 1ote that this Guery only uses the ti e portion of the date and i$nores the date itself# %t will thus never return a value bi$$er than '*:/9:/9# [ Cac" to top of file Ho, does one add a day6hour6-inute6second to a date value/ !he (I(?A!E pseudo8colu n shows the current syste date and ti e# Addin$ 1 to (I(?A!E will advance the date by 1 day# @se fractions to add hours& inutes or seconds to the date# Eoo" at these exa ples: (DEP select sysdate& sysdateQ1.'-& sysdate Q1.1--:& sysdate Q 1.62-:: fro dualK (I(?A!E (I(?A!EQ1.'(I(?A!EQ1.1--: (I(?A!EQ1.62-:: 88888888888888888888 88888888888888888888 88888888888888888888 88888888888888888888 :*8Aul8'::' :6:*':1' :*8Aul8'::' :9:*':1' :*8Aul8'::' :6:**:1' :*8Aul8'::' :6:*':1* !he followin$ for at is freGuently used with )racle +eplication: select sysdate 1)W& sysdateQ*:.3'-J2:J2:) 1)WB<E@(B*:B(E0( fro dualK 1)W 1)WB<E@(B*:B(E0( 88888888888888888888 88888888888888888888 :*8A@E8'::' 12:-4:'* :*8A@E8'::' 12:-4:/* Here are a couple o( exa-plesM :escription 1ow !o orow. next day (even days fro now (I(?A!E (I(?A!E Q 1 (I(?A!E Q 4 :ate Expression

)ne hour fro

now now now now now idni$ht

(I(?A!E Q 1.'(I(?A!E Q *.'(I(?A!E Q 1.-6 (I(?A!E Q 1:.1--: (I(?A!E Q *:.62-:: !+@103(I(?A!E Q 1) !+@103(I(?A!E Q 1) Q 6.'1ES!B?AI3!+@103(I(?A!E)& >O)1?AI>) Q 1'.'!+@103EA(!B?AI3(I(?A!E ) Q 1)

!hree hours fro An half hour fro 1: inutes fro *: seconds fro !o orrow at 1'

!o orrow at 6 AO 1ext Oonday at 1'::: noon ,irst day of the idni$ht onth at 1'

!he next Oonday& !+@103EEA(!31ES!B?AI3sysdate&>>O)1?AI>> )&1ES!B?AI3sysdate&>>WE?1E Wednesday or ,riday at 9 (?AI>>)& 1ES!B?AI3sysdate&>>,+%?AI>> ))) Q 39.'-) a# [ Cac" to top of file Ho, does one count di((erent data values in a colu-n/ @se this si ple Guery to count the nu ber of data values in a colu n: select yBtableBcolu n& count3J) fro yBtable $roup by yBtableBcolu nK A ore sophisticated exa ple### select dept& su 3 decode3sex&>O>&1&:)) OAEE& su 3 decode3sex&>,>&1&:)) ,EOAEE& count3decode3sex&>O>&1&>,>&1)) !)!AE fro yBe pBtable $roup by deptK [ Cac" to top of file Ho, does one count6su- &A3#E" o( data values in a colu-n/ A value x will be between values y and = if 5+EA!E(!3x& y) L EEA(!3x& =)# Eoo" at this exa ple: select f'& su 3decode3$reatest3f1&/9)& least3f1&1::)& 1& :)) M+an$e 2:81::M& su 3decode3$reatest3f1&*:)& least3f1& /9)& 1& :)) M+an$e *:8/9M& su 3decode3$reatest3f1& :)& least3f1& '9)& 1& :)) M+an$e ::8'9M fro yBtable $roup by f'K ,or eGual si=e ran$es it i$ht be easier to calculate it with ?E0)?E3!+@103value.ran$e)& :& rateB:& 1& rateB1& ###)# E$# select ena e M1a eM& sal M(alaryM& decode3 trunc3f'.1:::& :)& :& :#:& 1& :#1& '& :#'& *& :#*1) M!ax rateM fro yBtableK [ Cac" to top of file 8an one retrieve only the 3th ro, (ro- a ta!le/

+upa" Oohan provided this solution to select the 1th row fro (EEE0! J ,+)O t1 a W7E+E n L 3(EEE0! 0)@1!3rowid) ,+)O t1 b W7E+E a#rowid PL b#rowid)K (hai" Thaleel provided this solution:

a table:

(EEE0! J ,+)O 3 (EEE0! E1AOE&+)W1@O +1 ,+)O EO< W7E+E +)W1@O N 1:1 ) W7E+E +1 L 1::K 1ote: %n this first Guery we select one ore than the reGuired row nu ber& then we select the reGuired one# %ts far better than usin$ a O%1@( operation# +avi <achalla provided these solutions: (EEE0! f1 ,+)O t1 W7E+E rowid L 3 (EEE0! rowid ,+)O t1 W7E+E rownu NL 1: O%1@( (EEE0! rowid ,+)O t1 W7E+E rownu N 1:)K (EEE0! rownu &e pno ,+)O scott#e p a 5+)@< CI rownu &e pno 7AU%15 rownu L -K Alternatively### (EEE0! J ,+)O e p W7E+E rownu L1 A1? rowid 1)! %1 3(EEE0! rowid ,+)O e p W7E+E rownu N 1:)K <lease note& there is no explicit row order in a relational database# 7owever& this Guery is Guite fun and even help in the odd situation# [ Cac" to top of file 8an one retrieve only ro,s F to B (ro- a ta!le/ (hai" Thaleel provided this solution to the proble : (EEE0! J ,+)O 3 (EEE0! E1AOE&+)W1@O +1 ,+)O EO< W7E+E +)W1@O N 1:1 ) W7E+E +1 between 91 and 1:: K 1ote: the 1:1 is just one $reater than the axi u row of the reGuired rows 3 eans xL 9:& yL1::& so the inner values is yQ1)# +avi <achalla provided this solution: (EEE0! rownu & f1 ,+)O t1 5+)@< CI rownu & f1 7AU%15 rownu

ay

CE!WEE1 ' A1? -K

Another solution is to use the O%1@( operation# ,or exa ple& to display rows / to 4& construct a Guery li"e this: (EEE0! J ,+)O tableS W7E+E rowid in 3 (EEE0! rowid ,+)O tableS W7E+E rownu NL 4

O%1@( (EEE0! rowid ,+)O tableS W7E+E rownu N /)K <lease note& there is no explicit row order in a relational database# 7owever& this Guery is Guite fun and even help in the odd situation# [ Cac" to top of file Ho, does one select EGE&B 3th ro, (ro- a ta!le/ )ne can easily select all even& odd& or 1th rows fro Method *M @sin$ a subGuery a table usin$ (DE Gueries li"e this:

ay

(EEE0! J ,+)O e p W7E+E 3+)W%?&:) %1 3(EEE0! +)W%?& O)?3+)W1@O&-) ,+)O e p)K Method )M @se dyna ic views 3available fro )racle4#'): (EEE0! J ,+)O 3 (EEE0! rownu rn& e pno& ena e ,+)O e p ) te p W7E+E O)?3te p#+)W1@O&-) L :K Method 4M @sin$ 5+)@< CI and 7AU%15 8 provided by +avi <achalla (EEE0! rownu & f1 ,+)O t1 5+)@< CI rownu & f1 7AU%15 O)?3rownu &n) L : )+ rownu L '8n <lease note& there is no explicit row order in a relational database# 7owever& these Gueries are Guite fun and ay even help in the odd situation# [ Cac" to top of file Ho, does one select the T0$ 3 ro,s (ro- a ta!le/ ,or )racle6i one can have an inner8Guery with an )+?E+ CI clause# Eoo" at this exa ple: (EEE0! J ,+)O 3(EEE0! J ,+)O yBtable )+?E+ CI colBna eB1 ?E(0) W7E+E +)W1@O N 1:K @se this wor"around with prior releases: (EEE0! J ,+)O yBtable a W7E+E 1: PL 3(EEE0! 0)@1!3?%(!%10! axcol) ,+)O yBtable b W7E+E b# axcol PL a# axcol) )+?E+ CI axcol ?E(0K [ Cac" to top of file Ho, does one code a treeEstructured query/ !ree8structured Gueries are definitely non8relational 3enou$h to "ill 0odd and this feature is not often found in other database offerin$s# a"e hi roll in his $rave)# Also&

!he (0)!!.!%5E+ database sche a contains a table EO< with a self8referencin$ relation 3EO<1) and O5+ colu ns)# !his table is perfect for tesin$ and de onstratin$ tree8structured Gueries as the O5+ colu n contains the e ployee nu ber of the McurrentM e ployee>s boss# !he EEUEE pseudo8colu n is an indication of how deep in the tree one is# )racle can handle Gueries with a depth of up to '// levels# Eoo" at this exa ple: select EEUEE& EO<1)& E1AOE& O5+ fro EO< connect by prior EO<1) L O5+ start with O5+ is 1@EEK )ne can produce an indented report by usin$ the level nu ber to substrin$ or lpad3) a series of spaces& and concatenate that to the strin$# Eoo" at this exa ple: select lpad3> >& EEUEE J ') __ E1AOE ######## )ne uses the Mstart withM clause to specify the start of the tree# Oore than one record can atch the startin$ condition# )ne disadvanta$e of havin$ a Mconnect by priorM clause is that you cannot perfor a join to other tables# !he Mconnect by priorM clause is rarely i ple ented in the other database offerin$s# !ryin$ to do this pro$ra atically is difficult as one has to do the top level Guery first& then& for each of the records open a cursor to loo" for child nodes# )ne way of wor"in$ around this is to use <E.(DE& open the drivin$ cursor with the Mconnect by priorM state ent& and the select atchin$ records fro other tables on a row8by8row basis& insertin$ the results into a te porary table for later retrieval# [ Cac" to top of file Ho, does one code a -atrix report in "Q'/ Eoo" at this exa ple Guery with sa ple output: (EEE0! J ,+)O 3(EEE0! job& su 3decode3deptno&1:&sal)) ?E<!1:& su 3decode3deptno&':&sal)) ?E<!':& su 3decode3deptno&*:&sal)) ?E<!*:& su 3decode3deptno&-:&sal)) ?E<!-: ,+)O scott#e p 5+)@< CI job) )+?E+ CI 1K A)C ?E<!1: ?E<!': ?E<!*: 888888888 8888888888 8888888888 8888888888 8888888888 A1AEI(! 2::: 0EE+T 1*:: 19:: 9/: OA1A5E+ '-/: '94/ '6/: <+E(%?E1! /::: (AEE(OA1 /2:: [ Cac" to top of file ?E<!-:

Ho, does one i-ple-ent IFETHE3EE'"E in a select state-ent/ !he )racle decode function acts li"e a procedural state ent inside an (DE state ent to return different values or colu ns based on the values of other colu ns in the select state ent# "o-e exa-plesM

select decode3sex& >O>& >Oale>& >,>& >,e ale>& >@n"nown>) fro e ployeesK select a& b& decode3 abs3a8b)& a8b& >a P b>& :& >a L b>& >a N b>) fro tableSK select decode3 5+EA!E(!3A&C)& A& >A is $reater )+ ED@AE than C>& >C is $reater than A>)### select decode3 5+EA!E(!3A&C)& A& decode3A& C& >A 1)! 5+EA!E+ !7A1 C>& >A 5+EA!E+ !7A1 C>)& >A 1)! 5+EA!E+ !7A1 C>)### 3oteM !he decode function is not A1(% (DE and is rarely i ple ented in other +?CO( offerin$s# %t is one of the $ood thin$s about )racle& but use it sparin$ly if portability is reGuired# ,ro )racle 6i one can also use 0A(E state ents in (DE# Eoo" at this exa ple:

(EEE0! ena e& 0A(E W7E1 salP1::: !7E1 >)ver paid> EE(E >@nder paid> E1? ,+)O e pK [ Cac" to top of file Ho, can one du-p6 exa-ine the exact content o( a data!ase colu-n/ (EEE0! ?@O<3col1) ,+)O tab1 W7E+E cond1 L val1K ?@O<30)E1) 8888888888888888888888888888888888888 !ypL92 EenL-: 2/&22&24&*' ,or this exa ple the type is 92& indicatin$ 07A+& and the last byte in the colu n is *'& which is the A(0%% code for a space# !his tells us that this colu n is blan"8padded# [ Cac" to top of file 8an one drop a colu-n (ro- a ta!le/ ,ro )racle6i one can ?+)< a colu n fro a table# Eoo" at this sa ple script& de onstratin$ the ALTER TABLE table_name DROP COLUMN column_name; co and# )ther wor"arounds: 1# (DEP update t1 set colu nBtoBdrop L 1@EEK (DEP rena e t1 to t1BbaseK (DEP create view t1 as select Nspecific colu nsP fro '# (DEP create table t' as select Nspecific colu nsP fro (DEP drop table t1K (DEP rena e t' to t1K [ Cac" to top of file 8an one rena-e a colu-n in a ta!le/ 1o& this is listed as Enhance ent +eGuest 12*/19# (o e wor"arounds:

t1BbaseK t1K

1# 88 @se a view with correct colu n na es### rena e t1 to t1BbaseK create view t1 Ncolu n list with new na eP as select J fro '# 88 +ecreate the table with correct colu n na es### create table t' Ncolu n list with new na eP as select J fro drop table t1K rena e t' to t1K *# 88 Add a colu n with a new na e and drop an old colu n### alter table t1 add 3 newcola e datatype )K update t1 set newcolna eLoldcolna eK alter table t1 drop colu n oldcolna eK [ Cac" to top of file Ho, can I change -y 0racle pass,ord/ %ssue the followin$ (DE co O

t1BbaseK t1K

and: A%T.1 0S.1 Kusern#meN BD.,TB(B.D J= Kne'Ap#ss'ordN

,ro )racle6 you can just type MpasswordM fro password& type Mpassword userBna eM# [ Cac" to top of file

(DEJ<lus& or if you need to chan$e another user>s

Ho, does one (ind the next value o( a sequence/ <erfor an MAE!E+ (ED@E10E ### 1)0A07EM to unload the unused cached seGuence nu bers fro the )racle library cache# !his way& no cached nu bers will be lost# %f you then select fro the @(E+B(ED@E10E( dictionary view& you will see the correct hi$h water ar" value that would be returned for the next 1ES!UAEE call# Afterwards& perfor an MAE!E+ (ED@E10E ### 0A07EM to restore cachin$# Iou can use the above techniGue to prevent seGuence nu ber loss before a SHUTDOWN ABORT& or any other operation that would cause $aps in seGuence values# [ Cac" to top of file 5orkaround (or snapshots on ta!les ,ith '03# colu-ns Iou can use the (DEJ<lus 0)<I co and instead of snapshots if you need to copy E)15 and E)15 +AW variables fro one location to another# E$: 0)<I !) (0)!!.!%5E+`+EO)!E 8 0+EA!E %OA5EB!ACEE @(%15 8 (EEE0! %OA5EB1)& %OA5E 8 ,+)O %OA5E(K 1ote: %f you run )racle6& convert your E)15s to E)Cs& as it can be replicated# 0:]?ocu ents and (ettin$s]pc-]?es"top])0!B:6])racle ,AD (DE#ht

Вам также может понравиться