Play and learn 300 000+ tabs online

Thursday, March 18, 2010

JAVA Servlet Interview Questions

        Interview Based Questions

1. What are the types of ServletEngines?
Standalone ServletEngine:A standalone engine is a server that includes built-in support for servlets.

Add-on ServletEngine:Its a plug-in to an existing server.It adds servlet support to a server that was not originally designed with servlets in mind.

Embedded ServletEngine:

2.What is the difference between a Generic Servlet and Http Servlet?

Generic Servlet                    Http Servlet
Class which internally implements     An abstract class which acts as a child class both for Servlet and ServletConfig     GenericServlet and in addition provides interfaces. some additional methods
like doGet(),doPost(),doDelete() &
doPut().

3.What is a Session Id?

It is a unique id assigned by the server to the user when a user first accesses a site or an application ie. when a request is made.

4. List out Differences between CGI Perl and Servlet?

Servlet                            CGI

Platform independent                Platform dependent.
Language dependent                Language independent.

5. What is Bootstrapping in RMI?

Dynamic loading of stubs and skeletons is known as Boot Strapping.

6. What are different types of Exceptions?.
Runtime exceptions, Errors, Program Exceptions

7. What are types of applets?.
Trusted Applets: Applets with predefined security
Untrusted Applets: Applets without any security

8. When does an Exception occur?.

Whenever an error occurs in an Application,(either at compile time)or runtime,it raises an Exception.

9. What is servlet tunnelling?.
Used in applet to servlet communications, a layer over http is built so as to enable object serialization.

10. What is a cookie?.

Cookies are a way for a server to send some information to a client to store and for the server to later retrieve its data from that client.Web browser supports 20 cookies/host of 4kb each.

11.What is the frontend in Java?.Also what is Backend?.
Frontend: Applet
Backend : Oracle, Ms-Access(Using JDBC).

12. Define a JSP?.
Java Server Pages includes scripplets of Servletcode in an Html page.This creates dynamism in the other-wise static HTML.A JSP is a document that describes how to process a request to creeate response.

13. The length of an identifier is

14. Stored procedures can be called by Callable Statement.

15. Stack class implements LIFO(Last In First Out).

16. Servlet Class defines init.

17. Reference of any instance variable inside a static method is legal if declared static.

18. What will a read() function do?.
A method in Input Stream.It reads a single byte or an array of bytes.Returns no of bytes read or -1 if EOF(End of file)is reached.

19.To implement a Throwable array,which class is used.
Vector
LinkedList
Stack
ArrayList - Answer(To be Confirmed)

20. The method for precompiled SQL Statement in JDBC is prepareStatement().

21. Static binding occurs at
Compile Time
Runtime
Both at compile and runtime.

22. Virtual Methods are default in
Java
C
C++ - Answer
All

23. Storage space in java is of the form
Stack
Queue
Heap
List

24. What is java code embedded in a web page known as
Applets
Servlets
scriptlets
snippets

25. Which of the following attributes are compulsory with an <applet> tag?.
code,height & width.

26. What does 'CODEBASE' in an applet tag specify?.
Files absolute path.

27. What are AccessSpecifiers & Access Modifiers.
Access Specifiers: Give access previleges to outside applications or users. They are :-
Public: any one can access
private:only class members can access.cannot be inherited.
protected: can be accessed by a derived class.
default: can access data from the current directory.

Access Modifiers: Which gives additional meaning to data, methods and classes.
(i) Final: cannot be modified at any point of time.

28. Tools provided by JDK
(i)    javac - compiler
(ii)    java - interpretor
(iii)    jdb - debugger
(iv)    javap - Disassembles
(v)    appletviewer - Applets
(vi)    javadoc - documentation generator
(vii)    javah - 'C' header file generator

29.Hostile Applets:Its an applet which when downloaded attempts to exploit your system's resources in an inappropriate manner.It performs or causes you to perform an action which you would not otherwise care to perform.

30.RemoteObjects: Objects that have methods that can be called accross virtual machines are 0000000000000000Remote Objects.An object becomes Remote by implementing Remote Interface.

31.Compiling: Conversion of Programmer-readable Text into Bytecodes,which are platform independent,is known as Compiling.

32.Java Primitive Data Types:
Byte-8-bit
short-16-bit
int-32-bit
Long-64-bit
Float-32-bit floating point
Double-64-bit floating point
Char-16-bit Unicode

33.What is a unicode?
Unicode is a standard that supports International Characters.

34. What are blocks?.
They are statements appearing within braces {}.

35. What are types of Java applications?.

(i) Standalone applications(No browser).
(ii) Applets(Browser).

36. What is the method that gets invoked first in a stand alone application?.

The main()method.

37. What is throwing an Exception?.
The act of passing an Exception Object to the runtime system is called Throwing an Exception.

38. What are the packages in JDK?.

There are 8 packages
(i) java.lang(ii)java.util(iii)java.io(iv)java.applet(v) java.awt
(vi) java.awt.image(vii)java.awt.peer(viii)java.awt.net

39. What is a thread?.
Its a single sequential stream of execution.

40. What is runnable?.
Its an Interface through which Java implements Threads.The class can extend from any class but if it implements Runnable,Threads can be used in that particular application.

41. What is preemptive and Non-preemptive Time Scheduling?.
 Preemptive: Running tasks are given small portions of time to execute by using time-slicing.
Non-Preemptive: One task doesn't give another task a chance to run until its finished or has normally yielded its time.

42. What is synchronization?.
Two or more threads trying to access the same method at the same point of time leads to synchronization.If that particular method is declared as synchronized only one thread can access it at a time. Another thread can access it only if the first thread's task is complete.

43. What are the various thread priorities?.

(i)  Min-Priority-value(1).
(ii) Normal-Priority-value(5).
(iii)Max-Priority-value(10).

44.What is Inter-Thread communication?.
To exchange information between two threads.

45.The package java.applet.* has only one class.

46.BorderLayout is the default layout of Dialog object.

47.executeQuery() returns ResultSet.

48.Throwable class is a sub-class of object and implements Serializable.

49.Super class of TextArea and TextField is TextComponent.

50. Skeletons are server side proxies and stubs are client side proxies.

51. GridBagConstraints class helps in positioning of parameters of a
component within an object laidout using GridBagLayout.

52. Netscape introduced JScript language - True

53. EventDelegation model was introduced by JDK 1.1 - False

54. StringTokenizer provides two constructors - False

55. java.applet is one of the smallest package in Java API - True

56. Drag and Drop API consist of java.awt.dnd package - False

57. What is IP?.
IP is Internet Protocol. It is the network protocol which is used to send information from one computer to another over the network over the internet in the form of packets.

58. What is a port?.
A port is an 16-bit address within a computer.Ports for some common Internet Application protocols.

File Transfer Protocol-21.
Telnet Protocol-23.
Simple Mail Transfer Protocol-25.
Hypertext Transfer Protocol-80.

59.What is hypertext?.
Sockets are endpoints of Internet Communication.They are associated with a host address and a port address.
Clients create client sockets and connect them to server sockets.UDP is a connectionless protocol.

MIME(Multipurpose Internet Mail Extension) is a general method by which the content of different types of Internet objects can be identified.

61. What is an abstract class?.
A class which cannot be Instantiated.

62.ServletRunner options are:
-p-port number(8080).
-b-backlog connections(50).
-m-maximum no.of connection handlers(100).
-t-connection timeout in milliseconds
-d-servlet directory (current directory)
-s-servlet properties file

63.How many standard ports are available?.
1024.

64.What is a policy?.
It's an abstract class for representing the system security policy for a Java application environment(specifying which permissions are available for code from various sources). Java security properties file resides in <JAVA-HOME>/lib/security/java.security directory. Value of "policy.provider" should be changed.

65. What are different ways of Session-Tracking?.
(i) User-Authorization
(ii) Hidden Files
(iii) Persistant Cookies
(iv) URL Rewriting.

66. If the browser does not support cookies or if they are disabled, how is session tracking done?.

Session tracking is done by URL Rewriting.
* Multiple requests can be handled by a servlet and it also can synchronize them.ex: On-line conferencing.
* Servlets have no Graphic User Interface.
* We can synchronize the service() method for a major performance impact as multiple requests are involved in case of servlets.
* We can make a servlet handle a single client/request by implementing single threadmodel interface.

67. What is a Swing?.
It is a GUI component with a pluggable look and feel.

68. What is default Look-and-Feel of a Swing Component?.
Java Look-and-Feel.

69. Awt Components and Swing Components can be inter-mingled in an Application - False

70. What are the features coming with JFC?.
(i) Pluggable Look-and-Feel
(ii) Accessibility API
(iii) Java 2D/API(JDK 1.2).
(iv) Drag and Drop Support(JDK 1.2)

71. What does x mean in javax.swing?.       
Extension of java.
72. Images can be displayed on Swing Components
- True
73. Borders can be changed or added for a LightWeight Components
- True
74. Swing Components are always rectangular
- False
75. When Swing components overlap with Heavyweight components, it is the latter that is on the top
 - True

76. What are the components which are termed to be Heavy-weight, available in Light-weight component?.

77. What are invisible components?.
They are light weight components that perform no painting, but can take space in the GUI.

78. What is the default layout for a ContentPane in JFC?.
BorderLayout.

79. What are the borders provided by Swing?.
(i) Simple        (ii) Matte        iii) Titled    iv) Compound.

80. What does Realized mean?.
Realized mean that the component has been painted on screen or that is ready to be painted. Realization can take place by invoking any of these methods.
setVisible(true), show() or pack().

81. What is a convertor?.
Its an application that converts distance measurements between metric and U.S units.

82. What is the return type of interrupt method?.        void.
83. What is the superclass of exception?.        Throwable.
84. What is servlet exception?.            It indicates that there is a problem in the servlet.
85. What is the difference between a Canvas and a Scroll Pane?.
=====================================================================
Canvas                    ScrollPane
=====================================================================
Its a component                             Its a container.
------------------------------------------------------------------------------------------------------------------------------
A rectangular area where the application        Implements horizontal and vertical
can draw or trap input events.            scrolling.
=====================================================================
86. What are the restrictions imposed by a Security Manager on Applets?.

i) cannot read or write files on the host that's executing it.
ii) cannot load libraries or define native methods.
iii) cannot make network connections except to the host that it came from
iv) cannot start any program on the host that's executing it.
v) cannot read certain system properties.
vi) windows that an applet brings up look different than windows that an application brings up.

87. Can we access a database using applets?.            Yes.
88. What is the default HttpRequest method?.            doGet().
89. What is the life cycle of a servlet?.
Removing Handling zero or more client requests.Loading and Initializing.
90. RPC stands for Remote Procedure Call.
91. The three layers in RMI are Application Layer,RemoteReferenceLayer and Network Layer.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.