You are on page 1of 118

Servlet interview questions

There is a list of 30 servlet interview questions for beginners and professionals. If you
know any servlet interview question that has not been included here, kindly post your
question in the Ask Question section.

1) How many objects of a servlet is created?

Only one object at the time of first request by servlet or web container.

2) What is the life-cycle of a servlet?

1. Servlet is loaded
2. servlet is instantiated
3. servlet is initialized
4. service the request
5. servlet is destroyed

3) What are the life-cycle methods for a servlet?

public void init(ServletConfig config)

It is invoked only once when first
request comes for the servlet. It
is used to initialize the servlet.

public void service(ServletRequest

It is invoked at each request.The


service() method is used to


service the request.

public void destroy()

It is invoked only once when

servlet is unloaded.

more details...

4) Who is responsible to create the object of servlet?

The web container or servlet container.

5) When servlet object is created?

At the time of first request.

6) What is difference between Get and Post method?



1) Limited amount of data can be sent

Large amount of data can be sent

because data is sent in header.

because data is sent in body.

2) Not Secured because data is exposed in

Secured because data is not exposed in

URL bar.

URL bar.

3) Can be bookmarked

Cannot be bookmarked

4) Idempotent


5) It is more efficient and used than Post

It is less efficient and used

more details...

7) What is difference between PrintWriter and

PrintWriter is a character-stream class where as ServletOutputStream is a byte-stream
class. The PrintWriter class can be used to write only character-based information
whereas ServletOutputStream class can be used to write primitive values as well as
character-based information.

8) What is difference between GenericServlet and HttpServlet?

The GenericServlet is protocol independent whereas HttpServlet is HTTP protocol specific.
HttpServlet provides additional functionalities such as state management etc.

9) What is servlet collaboration?

When one servlet communicates to another servlet, it is known as servlet collaboration.

There are many ways of servlet collaboration:

RequestDispacher interface

sendRedirect() method etc.

10) What is the purpose of RequestDispatcher Interface?

The RequestDispacher interface provides the facility of dispatching the request to another
resource it may be html, servlet or jsp. This interceptor can also be used to include the
content of antoher resource.

11) Can you call a jsp from the servlet?

Yes, one of the way is RequestDispatcher interface for example:


copy to clipboard
RequestDispatcher rd=request.getRequestDispatcher("/login.jsp");
RequestDispatcher rd=request.
rd.forw ard(request,response);

12) Difference between forward() method and sendRedirect()

method ?
forward() method

sendRedirect() method

1) forward() sends the same

1) sendRedirect() method sends new request

request to another resource.

always because it uses the URL bar of the browser.

2) forward() method works at

2) sendRedirect() method works at client side.

server side.
3) forward() method works

3) sendRedirect() method works within and outside

within the server only.

the server.

13) What is difference between ServletConfig and

The container creates object of ServletConfig for each servlet whereas object of
ServletContext is created for each web application.

14) What is Session Tracking?

Session simply means a particular interval of time.
Session Tracking is a way to maintain state of an user.Http protocol is a stateless
protocol.Each time user requests to the server, server treats the request as the new
request.So we need to maintain the state of an user to recognize to particular user.

15) What are Cookies?

A cookie is a small piece of information that is persisted between the multiple client
requests. A cookie has a name, a single value, and optional attributes such as a
comment, path and domain qualifiers, a maximum age, and a version number.

16) What is difference between Cookies and HttpSession?

Cookie works at client side whereas HttpSession works at server side.

17) What is filter?

A filter is an object that is invoked either at the preprocessing or postprocessing of a
request. It is pluggable.

18) How can we perform any action at the time of deploying the
By the help of ServletContextListener interface.

19) What is the disadvantage of cookies?

It will not work if cookie is disabled from the browser.

20) How can we upload the file to the server using servlet?
One of the way is by MultipartRequest class provided by third party.
more details...

21) What is load-on-startup in servlet?

The load-on-startup element of servlet in web.xml is used to load the servlet at the time
of deploying the project or server start. So it saves time for the response of first request.

22) What if we pass negative value in load-on-startup?

It will not affect the container, now servlet will be loaded at first request.

23) What is war file?

A war (web archive) file specifies the web elements. A servlet or jsp project can be
converted into a war file. Moving one servlet project from one place to another will be
fast as it is combined into a single file.

24) How to create war file?

The war file can be created using jar tool found in jdk/bin directory. If you are using
Eclipse or Netbeans IDE, you can export your project as a war file.
To create war file from console, you can write following code.


copy to clipboard
jar -cvf abc.war *
jar -cvf abc.w ar *

Now all the files of current directory will be converted into abc.war file.

25) What are the annotations used in Servlet 3?

There are mainly 3 annotations used for the servlet.
1. @WebServlet : for servlet class.
2. @WebListener : for listener class.
3. @WebFilter : for filter class.

26) Which event is fired at the time of project deployment and


27) Which event is fired at the time of session creation and


28) Which event is fired at the time of setting, getting or

removing attribute from application scope?

29) What is the use of welcome-file-list?

It is used to specify the welcome file for the project.

30) What is the use of attribute in servlets?

Attribute is a map object that can be used to set, get or remove in request, session or
application scope. It is mainly used to share information between one servlet to another.

Java Basics Interview Questions

Java OOPs Interview Questions

Java Multithreading Questions

Java String & Exception Questions

Java Collection Interview Questions

JDBC Interview Questions

Servlet Interview Questions

JSP Interview Questions

Spring Interview Questions

Hibernate Interview Questions

PL/SQL Interview Questions

SQL Interview Questions

Oracle Interview Questions

Android Interview Questions

SQL Server Interview Questions

MySQL Interview Questions

1) What is difference between JDK,JRE and JVM?

JVM is an acronym for Java Virtual Machine, it is an abstract machine which provides the
runtime environment in which java bytecode can be executed. It is a specification.
JVMs are available for many hardware and software platforms (so JVM is platform

JRE stands for Java Runtime Environment. It is the implementation of JVM.

JDK is an acronym for Java Development Kit. It physically exists. It contains JRE +
development tools.
more details...

2) How many types of memory areas are allocated by JVM?

Many types:
1. Class(Method) Area
2. Heap
3. Stack
4. Program Counter Register
5. Native Method Stack
more details...

3) What is JIT compiler?

Just-In-Time(JIT) compiler:It is used to improve the performance. JIT compiles parts
of the byte code that have similar functionality at the same time, and hence reduces the
amount of time needed for compilation.Here the term compiler refers to a translator
from the instruction set of a Java virtual machine (JVM) to the instruction set of a specific

4) What is platform?
A platform is basically the hardware or software environment in which a program runs.
There are two types of platforms software-based and hardware-based. Java provides
software-based platform.

5) What is the main difference between Java platform and other


The Java platform differs from most other platforms in the sense that it's a softwarebased platform that runs on top of other hardware-based platforms.It has two
1. Runtime Environment
2. API(Application Programming Interface)

6) What gives Java its 'write once and run anywhere' nature?
The bytecode. Java is compiled to be a byte code which is the intermediate language
between source code and machine code. This byte code is not platform specific and
hence can be fed to any platform.

7) What is classloader?
The classloader is a subsystem of JVM that is used to load classes and interfaces.There
are many types of classloaders e.g. Bootstrap classloader, Extension classloader, System
classloader, Plugin classloader etc.

8) Is Empty .java file name a valid source file name?

Yes, save your java file by .java only, compile it by javac .java and run by java
yourclassname Let's take a simple example:


copy to clipboard
//save by .java only
class A{
public static void main(String args[]){
System.out.println("Hello java");
//compile by javac .java
//run by
java A

//save by .java only

class A{
public static void main(String arg
System.out.println("Hello java");

compile it by javac .java

run it by java A

9) Is delete,next,main,exit or null keyword in java?


10) If I don't provide any arguments on the command line, then

the String array of Main method will be empty or null?
It is empty. But not null.

11) What if I write static public void instead of public static void?
Program compiles and runs properly.

12) What is the default value of the local variables?

The local variables are not initialized to any default value, neither primitives nor object

Core Java - OOPs Concepts: Initial OOPs Interview Questions

There is given more than 50 OOPs (Object-Oriented Programming and System) interview
questions. But they have been categorized in many sections such as constructor
interview questions, static interview questions, Inheritance Interview questions,
Abstraction interview question, Polymorphism interview questions etc. for better

13) What is difference between object oriented programming

language and object based programming language?
Object based programming languages follow all the features of OOPs except Inheritance.
Examples of object based programming languages are JavaScript, VBScript etc.

14) What will be the initial value of an object reference which is

defined as an instance variable?
The object references are all initialized to null in Java.

Core Java - OOPs Concepts: Constructor Interview Questions

15) What is constructor?

Constructor is just like a method that is used to initialize the state of an object. It
is invoked at the time of object creation.

more details...

16) What is the purpose of default constructor?

The default constructor provides the default values to the objects. The java
compiler creates a default constructor only if there is no constructor in the
class.more details...

17) Does constructor return any value?

Ans:yes, that is current instance (You cannot use return type yet it returns a
value).more details...

18)Is constructor inherited?

No, constructor is not inherited.

19) Can you make a constructor final?

No, constructor can't be final.

Core Java - OOPs Concepts: static keyword Interview Questions

20) What is static variable?

static variable is used to refer the common property of all objects (that is not
unique for each object) e.g. company name of employees,college name of
students etc.

static variable gets memory only once in class area at the time of class loading.

more details...

21) What is static method?

A static method belongs to the class rather than object of a class.

A static method can be invoked without the need for creating an instance of a

static method can access static data member and can change the value of it.

more details...

22) Why main method is static?

because object is not required to call static method if It were non-static method,jvm
creats object first then call main() method that will lead to the problem of extra memory
allocation.more details...

23) What is static block?

Is used to initialize the static data member.

It is excuted before main method at the time of classloading.

more details...

24) Can we execute a program without main() method?

Ans) Yes, one of the way is static block.more details...

25) What if the static modifier is removed from the signature of

the main method?
Program compiles. But at runtime throws an error "NoSuchMethodError".

26) What is difference between static (class) method and

instance method?
static or class method

instance method

1)A method i.e. declared as static is known as

A method i.e. not declared as

static method.

static is known as instance


2)Object is not required to call static method.

Object is required to call

instance methods.

3)Non-static (instance) members cannot be

static and non-static variables

accessed in static context (static method, static

both can be accessed in

block and static nested class) directly.

instance methods.

4)For example: public static int cube(int n){ return

For example: public void msg()



Core Java - OOPs Concepts: Inheritance Interview Questions

27) What is this in java?

It is a keyword that that refers to the current object.more details...

28)What is Inheritance?
Inheritance is a mechanism in which one object acquires all the properties and behaviour
of another object of another class. It represents IS-A relationship. It is used for Code
Resusability and Method Overriding.
more details...

29) Which class is the superclass for every class.

Object class.

30) Why multiple inheritance is not supported in java?

To reduce the complexity and simplify the language, multiple inheritance is not
supported in java in case of class.more details...

31) What is composition?

Holding the reference of the other class within some other class is known as composition.

32) What is difference between aggregation and composition?

Aggregation represents weak relationship whereas composition represents strong
relationship. For example: bike has an indicator (aggregation) but bike has an engine

33) Why Java does not support pointers?

Pointer is a variable that refers to the memory address. They are not used in java
because they are unsafe(unsecured) and complex to understand.

34) What is super in java?

It is a keyword that refers to the immediate parent class object.more details...

35) Can you use this() and super() both in a constructor?

No. Because super() or this() must be the first statement.

36)What is object cloning?

The object cloning is used to create the exact copy of an object. more details...

Core Java - OOPs Concepts: Method Overloading Interview Questions

37) What is method overloading?

If a class have multiple methods by same name but different parameters, it is known as
Method Overloading. It increases the readability of the program.more details...

38) Why method overloading is not possible by changing the

return type in java?
Becauseof ambiguity.more details...

39) Can we overload main() method?

Yes, You can have many main() methods in a class by overloading the main method.
more details...

Core Java - OOPs Concepts: Method Overriding Interview Questions

40) What is method overriding:

If a subclass provides a specific implementation of a method that is already provided by
its parent class, it is known as Method Overriding. It is used for runtime polymorphism
and to provide the specific implementation of the method.more details...

41) Can we override static method?

No, you can't override the static method because they are the part of class not object.

42) Why we cannot override static method?

It is because the static method is the part of class and it is bound with class whereas
instance method is bound with object and static gets memory in class area and instance
gets memory in heap.

43) Can we override the overloaded method?


44) Difference between method Overloading and Overriding.

Method Overloading

Method Overriding

1) Method overloading

Method overriding provides the specific

increases the readability of the

implementation of the method that is already


provided by its super class.

2) method overlaoding is

Method overriding occurs in two classes that have

occurs within the class.

IS-A relationship.

3) In this case, parameter

In this case, parameter must be same.

must be different.

45) Can you have virtual functions in Java?

Yes, all functions in Java are virtual by default.

46) What is covariant return type?

Now, since java5, it is possible to override any method by changing the return type if the
return type of the subclass overriding method is subclass type. It is known as covariant
return type. more details...

Core Java - OOPs Concepts: final keyword Interview Questions

47) What is final variable?

If you make any variable as final, you cannot change the value of final variable(It will be
constant).more details...

48) What is final method?

Final methods can't be overriden.more details...

49) What is final class?

Final class can't be inherited. more details...

50) What is blank final variable?

A final variable, not initalized at the time of declaration, is known as blank final
variable.more details...

51) Can we intialize blank final variable?

Yes, only in constructor if it is non-static. If it is static blank final variable, it can be
initialized only in the static block.more details...

52) Can you declare the main method as final?

Yes, such as, public static final void main(String[] args){}.

53) What is Runtime Polymorphism?

Runtime polymorphism or dynamic method dispatch is a process in which a call to an
overridden method is resolved at runtime rather than at compile-time.
In this process, an overridden method is called through the reference variable of a super
class. The determination of the method to be called is based on the object being referred
to by the reference variable.
more details...

54) Can you achieve Runtime Polymorphism by data members?


more details...

55) What is the difference between static binding and dynamic

In case of static binding type of object is determined at compile time whereas in dynamic
binding type of object is determined at runtime.
more details...

Core Java - OOPs Concepts : Abstraction Interview Questions

56) What is abstraction?

Abstraction is a process of hiding the implementation details and showing only
functionality to the user.
more details...
Abstraction lets you focus on what the object does instead of how it does it.

57) What is the difference between abstraction and

Abstraction hides the implementation details whereas encapsulation wraps code and data
into a single unit.
more details...

58) What is abstract class?

A class that is declared as abstract is known as abstract class. It needs to be extended

and its method implemented. It cannot be instantiated.
more details...

59) Can there be any abstract method without abstract class?

No, if there is any abstract method in a class, that class must be abstract.

60) Can you use abstract and final both with a method?
No, because abstract method needs to be overridden whereas you can't override final

61) Is it possible to instantiate the abstract class?

No, abstract class can never be instantiated.

62) What is interface?

Interface is a blueprint of a class that have static constants and abstract methods.It can
be used to achieve fully abstraction and multiple inheritance.
more details...

63) Can you declare an interface method static?

No, because methods of an interface is abstract by default, and static and abstract
keywords can't be used together.

64) Can an Interface be final?

No, because its implementation is provided by another class.

65) What is marker interface?

An interface that have no data member and method is known as a marker interface.For
example Serializable, Cloneable etc.

66) What is difference between abstract class and interface?

Abstract class


1)An abstract class can have method body (non-

Interface have only abstract

abstract methods).


2)An abstract class can have instance variables.

An interface cannot have instance


3)An abstract class can have constructor.

Interface cannot have


4)An abstract class can have static methods.

Interface cannot have static


5)You can extends one abstract class.

You can implement multiple


67) Can we define private and protected modifiers for variables

in interfaces?
No, they are implicitly public.

68) When can an object reference be cast to an interface

An object reference can be cast to an interface reference when the object implements
the referenced interface.

Core Java - OOPs Concepts : Package Interview Questions

69) What is package?

A package is a group of similar type of classes interfaces and sub-packages. It provides
access protection and removes naming collision.
more details...

70) Do I need to import java.lang package any time? Why ?

No. It is by default loaded internally by the JVM.

71) Can I import same package/class twice? Will the JVM load
the package twice at runtime?
One can import the same package or same class multiple times. Neither compiler nor
JVM complains about it.But the JVM will internally load the class only once no matter how
many times you import the same class.

72) What is static import ?

By static import, we can access the static members of a class directly, there is no to
qualify it with the class name.
more details...
Next TopicException and String interview Questions

it in the comment section.

73) What is Exception Handling?

Exception Handling is a mechanism to handle runtime errors.It is mainly used to handle
checked exceptions.
more details...

74) What is difference between Checked Exception and

Unchecked Exception?
1)Checked Exception
The classes that extend Throwable class except RuntimeException and Error are known
as checked exceptions e.g.IOException,SQLException etc. Checked exceptions are
checked at compile-time.

2)Unchecked Exception
The classes that extend RuntimeException are known as unchecked exceptions e.g.
ArithmeticException,NullPointerException etc. Unchecked exceptions are not checked at
more details...

75) What is the base class for Error and Exception?


76) Is it necessary that each try block must be followed by a

catch block?
It is not necessary that each try block must be followed by a catch block. It should be
followed by either a catch block OR a finally block. And whatever exceptions are likely to
be thrown should be declared in the throws clause of the method.

77) What is finally block?

finally block is a block that is always executed.more details...

78) Can finally block be used without catch?

Yes, by try block. finally must be followed by either try or catch.more details...

79) Is there any case when finally will not be executed?

finally block will not be executed if program exits(either by calling System.exit() or by
causing a fatal error that causes the process to abort).more details...

80) What is difference between throw and throws?

throw keyword

throws keyword

1)throw is used to explicitly

throws is used to declare an exception.

throw an exception.
2)checked exceptions can not

checked exception can be propagated with throws.

be propagated with throw

3)throw is followed by an

throws is followed by class.

4)throw is used within the

throws is used with the method signature.

5)You cannot throw multiple

You can declare multiple exception e.g. public void


method()throws IOException,SQLException.

more details...

81) Can an exception be rethrown?


82) Can subclass overriding method declare an exception if

parent class method doesn't throw an exception ?
Yes but only unchecked exception not checked.
more details...

83) What is exception propagation ?

Forwarding the exception object to the invoking method is known as exception
more details...

Core Java: String Handling Interview Questions

There is given a list of string handling interview questions with short and pointed
answers. If you know any string handling interview question, kindly post it in the
comment section.

84) What is the meaning of immutable in terms of String?

The simple meaning of immutable is unmodifiable or unchangeable. Once string object
has been created, its value can't be changed.
more details...

85) Why string objects are immutable in java?

Because java uses the concept of string literal. Suppose there are 5 reference
variables,all referes to one object "sachin".If one reference variable changes the value of
the object, it will be affected to all the reference variables. That is why string objects are
immutable in java.
more details...

86) How many ways we can create the string object?

There are two ways to create the string object, by string literal and by new keyword.
more details...

87) How many objects will be created in the following code?


copy to clipboard
String s1="Welcome";


String s2="Welcome";
String s3="Welcome";
String s1="Welcome";
String s2="Welcome";
String s3="Welcome";

Only one object.

more details...

88) Why java uses the concept of string literal?

To make Java more memory efficient (because no new objects are created if it exists
already in string constant pool).
more details...

89)How many objects will be created in the following code?


copy to clipboard
String s = new String("Welcome");
String s = new String("Welcome

Two objects, one in string constant pool and other in non-pool(heap).

more details...

90) What is the basic difference between string and stringbuffer

String is an immutable object. StringBuffer is a mutable object.

91) What is the difference between StringBuffer and

StringBuilder ?
StringBuffer is synchronized whereas StringBuilder is not synchronized.

92) How can we create immutable class in java ?

We can create immutable class as the String class by defining final class and
more details...

93) What is the purpose of toString() method in java ?

The toString() method returns the string representation of any object. If you print any
object, java compiler internally invokes the toString() method on the object. So
overriding the toString() method, returns the desired output, it can be the state of an
object etc. depends on your implementation.
more details...

Core Java : Nested classes and Interfaces Interview Questions

94)What is nested class?

A class which is declared inside another class is known as nested class. There are 4 types
of nested class member inner class, local inner class, annonymous inner class and static
nested class.
more details...

95) Is there any difference between nested classes and inner

Yes, inner classes are non-static nested classes i.e. inner classes are the part of nested
more details...

96) Can we access the non-final local variable, inside the local
inner class?
No, local variable must be constant if you want to access it in local inner class.
more details...

97) What is nested interface ?

Any interface i.e. declared inside the interface or class, is known as nested interface. It is
static by default.
more details...

98) Can a class have an interface?

Yes, it is known as nested interface.
more details...

99) Can an Interface have a class?

Yes, they are static implicitely.
more details...

Next TopicJava IO and Networking Interview Questions

prev next

117) What is Garbage Collection?

Garbage collection is a process of reclaiming the runtime unused objects.It is performed
for memory management.
more details...

118) What is gc()?

gc() is a daemon thread.gc() method is defined in System class that is used to send
request to JVM to perform garbage collection.

119) What is the purpose of finalize() method?

finalize() method is invoked just before the object is garbage collected.It is used to
perform cleanup processing.

120) Can an unrefrenced objects be refrenced again?


121)What kind of thread is the Garbage collector thread?

Daemon thread.

122)What is difference between final, finally and finalize?

final: final is a keyword, final can be variable, method or class.You, can't change the
value of final variable, can't override final method, can't inherit final class.
finally: finally block is used in exception handling. finally block is always executed.
finalize():finalize() method is used in garbage collection.finalize() method is invoked

just before the object is garbage collected.The finalize() method can be used to perform
any cleanup processing.

123)What is the purpose of the Runtime class?

The purpose of the Runtime class is to provide access to the Java runtime system.

124)How will you invoke any external process in Java?

By Runtime.getRuntime().exec(?) method.

I/O Interview Questions

125)What is the difference between the Reader/Writer class

hierarchy and the InputStream/OutputStream class hierarchy?
The Reader/Writer class hierarchy is character-oriented, and the
InputStream/OutputStream class hierarchy is byte-oriented.

126)What an I/O filter?

An I/O filter is an object that reads from one stream and writes to another, usually
altering the data in some way as it is passed from one stream to another.

Serialization Interview Questions

127) What is serialization?

Serialization is a process of writing the state of an object into a byte stream.It is mainly
used to travel object's state on the network.
more details...

128) What is Deserialization?

Deserialization is the process of reconstructing the object from the serialized state.It is
the reverse operation of serialization.

129) What is transient keyword?

If you define any data member as transient,it will not be serialized.more details...

130)What is Externalizable?
Externalizable interface is used to write the state of an object into a byte stream in
compressed format.It is not a marker interface.

131)What is the difference between Serializalble and

Externalizable interface?
Serializable is a marker interface but Externalizable is not a marker interface.When you
use Serializable interface, your class is serialized automatically by default. But you can
override writeObject() and readObject() two methods to control more complex object
serailization process. When you use Externalizable interface, you have a complete control
over your class's serialization process.

Networking Interview Questions

132)How do I convert a numeric IP address like

into a hostname like

By InetAddress.getByName("").getHostName() where is the

IP address.

Reflection Interview Questions

133) What is reflection?

Reflection is the process of examining or modifying the runtime behaviour of a class at
runtime.It is used in:

IDE (Integreted Development Environment) e.g. Eclipse, MyEclipse, NetBeans.


Test Tools etc.

134) Can you access the private method from outside the
Yes, by changing the runtime behaviour of a class if the class is not secured.
more details...
Next TopicJava Miscellaneous interview Questions

148)What are wrapper classes?

Wrapper classes are classes that allow primitive types to be accessed as objects.

149)What is a native method?

A native method is a method that is implemented in a language other than Java.

150)What is the purpose of the System class?

The purpose of the System class is to provide access to system resources.

151)What comes to mind when someone mentions a shallow

copy in Java?
Object cloning.

152)What is singleton class?

Singleton class means that any given time only one instance of the class is present, in
one JVM.

AWT and SWING Interview Questions

153)Which containers use a border layout as their default

The Window, Frame and Dialog classes use a border layout as their default layout.

154)Which containers use a FlowLayout as their default layout?

The Panel and Applet classes use the FlowLayout as their default layout.

155)What are peerless components?

The peerless components are called light weight components.

156)is the difference between a Scrollbar and a ScrollPane?

A Scrollbar is a Component, but not a Container. A ScrollPane is a Container. A ScrollPane
handles its own events and performs its own scrolling.

157)What is a lightweight component?

Lightweight components are the one which doesn?t go with the native call to obtain the
graphical units. They share their parent component graphical units to render them. For
example, Swing components.

158)What is a heavyweight component?

For every paint call, there will be a native call to get the graphical units.For Example,

159)What is an applet?
An applet is a small java program that runs inside the browser and generates dynamic

160)Can you write a Java class that could be used both as an

applet as well as an application?
Yes. Add a main() method to the applet.

Internationalization Interview Questions

161)What is Locale?
A Locale object represents a specific geographical, political, or cultural region.

162)How will you load a specific locale?

By ResourceBundle.getBundle(?) method.

Java Bean Interview Questions

163)What is a JavaBean?
are reusable software components written in the Java programming language, designed
to be manipulated visually by a software development environment, like JBuilder or
VisualAge for Java.

RMI Interview Questions

164)Can RMI and Corba based applications interact?

Yes they can. RMI is available with IIOP as the transport protocol instead of JRMP.
Next TopicJava Multithreading interview Questions

Java Multithreading Interview Questions

Multithreading and Synchronization is considered as the typical chapter in java
programming. In game development company, mulithreading related interview questions
are asked mostly. A list of frequently asked java multithreading interview questions are
given below.

1) What is multithreading?
Multithreading is a process of executing multiple threads simultaneously. Its main
advantage is:

Threads share the same address space.

Thread is lightweight.

Cost of communication between process is low.

more details...

2) What is thread?
A thread is a lightweight subprocess.It is a separate path of execution.It is called
separate path of execution because each thread runs in a separate stack frame.
more details...

3)What is the difference between preemptive scheduling and

time slicing?
Under preemptive scheduling, the highest priority task executes until it enters the
waiting or dead states or a higher priority task comes into existence. Under time slicing,
a task executes for a predefined slice of time and then reenters the pool of ready tasks.
The scheduler then determines which task should execute next, based on priority and
other factors.

4) What does join() method?

The join() method waits for a thread to die. In other words, it causes the currently
running threads to stop executing until the thread it joins with completes its task.
more details...

5) What is difference between wait() and sleep() method?



1) The wait() method is defined in Object

The sleep() method is defined in Thread



2) wait() method releases the lock.

The sleep() method doesn't releases the


6) Is it possible to start a thread twice?

No, there is no possibility to start a thread twice. If we does, it throws an exception.
more details...

7) Can we call the run() method instead of start()?

yes, but it will not work as a thread rather it will work as a normal object so there will not
be context-switching between the threads.
more details...

8) What about the daemon threads?

The daemon threads are basically the low priority threads that provides the background
support to the user threads. It provides services to the user threads.
more details...

9)Can we make the user thread as daemon thread if thread is

No, if you do so, it will throw IllegalThreadStateException
more details...

10)What is shutdown hook?

The shutdown hook is basically a thread i.e. invoked implicitely before JVM shuts down.
So we can use it perform clean up resource.
more details...

11)When should we interrupt a thread?

We should interrupt a thread if we want to break out the sleep or wait state of a thread.
more details...

12) What is synchronization?

Synchronization is the capabilility of control the access of multiple threads to any shared
resource.It is used:

1. To prevent thread interference.

2. To prevent consistency problem.
more details...

13) What is the purpose of Synchronized block?

Synchronized block is used to lock an object for any shared resource.

Scope of synchronized block is smaller than the method.

more details...

14)Can Java object be locked down for exclusive use by a given


Yes. You can lock an object by putting it in a "synchronized" block. The locked object is
inaccessible to any thread other than the one that explicitly claimed it.

15) What is static synchronization?

If you make any static method as synchronized, the lock will be on the class not on
object. more details...

16)What is the difference between notify() and notifyAll()?

The notify() is used to unblock one waiting thread whereas notifyAll() method is used to
unblock all the threads in waiting state.

17)What is deadlock?
Deadlock is a situation when two threads are waiting on each other to release a resource.
Each thread waiting for a resource which is held by the other waiting thread.
more details...
Next TopicJava Collections interview Questions

20 Java Collections Interview Questions

In java, collection interview questions are mostly asked by the interviewers. Here is the
list of mostly asked collections interview questions with answers.

1) What is the difference between ArrayList and Vector?





ArrayList is not synchronized.

Vector is synchronized.


ArrayList is not a legacy class.

Vector is a legacy class.


ArrayList increases its size by 50% of

Vector increases its size by doubling

the array size.

the array size.

2) What is the difference between ArrayList and LinkedList?




ArrayList uses a dynamic array.

LinkedList uses doubly

linked list.



ArrayList is not efficient for manipulation

LinkedList is efficient for

because a lot of shifting is required.


ArrayList is better to store and fetch data.

LinkedList is better to
manipulate data.

3) What is the difference between Iterator and ListIterator?

Iterator traverses the elements in forward direction only whereas ListIterator traverses
the elements in forward and backward direction.





Iterator traverses the elements

ListIterator traverses the elements in

in forward direction only.

backward and forward directions both.

Iterator can be used in List, Set

ListIterator can be used in List only.

and Queue.

4) What is the difference between Iterator and Enumeration?





Iterator can traverse legacy and non-

Enumeration can traverse only

legacy elements.

legacy elements.


Iterator is fail-fast.

Enumeration is not fail-fast.


Iterator is slower than Enumeration.

Enumeration is faster than Iterator.

5) What is the difference between List and Set?

List can contain duplicate elements whereas Set contains only unique elements.

6) What is the difference between HashSet and TreeSet?

HashSet maintains no order whereas TreeSet maintains ascending order.

7) What is the difference between Set and Map?

Set contains values only whereas Map contains key and values both.

8) What is the difference between HashSet and HashMap?

HashSet contains only values whereas HashMap contains entry(key,value). HashSet can
be iterated but HashMap need to convert into Set to be iterated.

9) What is the difference between HashMap and TreeMap?

HashMap maintains no order but TreeMap maintains ascending order.

10) What is the difference between HashMap and Hashtable?





HashMap is not synchronized.

Hashtable is synchronized.


HashMap can contain one null key and

Hashtable cannot contain any null

multiple null values.

key or null value.

11) What is the difference between Collection and Collections?

Collection is an interface whereas Collections is a class. Collection interface provides
normal functionality of data structure to List, Set and Queue. But, Collections class is to
sort and synchronize collection elements.

12) What is the difference between Comparable and




Comparable provides only one sort of

Comparator provides multiple


sort of sequences.

It provides one method named

It provides one method named




It is found in java.lang package.

it is found in java.util package.


If we implement Comparable interface,

Actual class is not modified.


actual class is modified.

13) What is the advantage of Properties file?

If you change the value in properties file, you don't need to recompile the java class. So,
it makes the application easy to manage.

14) What does the hashCode() method?

The hashCode() method returns a hash code value (an integer number).
The hashCode() method returns the same integer number, if two keys (by calling
equals() method) are same.
But, it is possible that two hash code numbers can have different or same keys.

15) Why we override equals() method?

The equals method is used to check whether two objects are same or not. It needs to be
overridden if we want to check the objects based on property.
For example, Employee is a class that has 3 data members: id, name and salary. But, we
want to check the equality of employee object on the basis of salary. Then, we need to
override the equals() method.

16) How to synchronize List, Set and Map elements?

Yes, Collections class provides methods to make List, Set or Map elements as
public static List synchronizedList(List l){}
public static Set synchronizedSet(Set s){}
public static SortedSet synchronizedSortedSet(SortedSet s){}
public static Map synchronizedMap(Map m){}
public static SortedMap synchronizedSortedMap(SortedMap m){}

17) What is the advantage of generic collection?

If we use generic class, we don't need typecasting. It is typesafe and checked at compile

18) What is hash-collision in Hashtable and how it is handled in

Two different keys with the same hash value is known as hash-collision. Two different
entries will be kept in a single hash bucket to avoid the collision.

19) What is the Dictionary class?

The Dictionary class provides the capability to store key-value pairs.

20) What is the default size of load factor in hashing based

The default size of load factor is 0.75. The default capacity is computed as initial capacity
* load factor. For example, 16 * 0.75 = 12. So, 12 is the default capacity of Map.
Next TopicJDBC interview Questions

JDBC Interview Questions

A list of frequently asked jdbc interview questions with answers are given below.

1) What is JDBC?

JDBC is a Java API that is used to connect and execute query to the database. JDBC API
uses jdbc drivers to connects to the database.
more details...

2) What is JDBC Driver?

JDBC Driver is a software component that enables java application to interact with the
database.There are 4 types of JDBC drivers:
1. JDBC-ODBC bridge driver
2. Native-API driver (partially java driver)
3. Network Protocol driver (fully java driver)
4. Thin driver (fully java driver)
more details...

3) What are the steps to connect to the database in java?

Registering the driver class

Creating connection

Creating statement

Executing queries

Closing connection

more details...

4) What are the JDBC API components?

The java.sql package contains interfaces and classes for JDBC API.







CallableStatement etc.






SQLException etc.

5) What are the JDBC statements?

There are 3 JDBC statements.
1. Statement
2. PreparedStatement
3. CallableStatement

6) What is the difference between Statement and

PreparedStatement interface?

In case of Statement, query is complied each time whereas in case of

PreparedStatement, query is complied only once. So performance of PreparedStatement
is better than Statement.
more details...

7) How can we execute stored procedures and functions?

By using Callable statement interface, we can execute procedures and functions.

8) What is the role of JDBC DriverManager class?

The DriverManager class manages the registered drivers. It can be used to register
and unregister drivers. It provides factory method that returns the instance of
more details...

9) What does the JDBC Connection interface?

The Connection interface maintains a session with the database. It can be used for
transaction management. It provides factory methods that returns the instance of
Statement, PreparedStatement, CallableStatement and DatabaseMetaData.
more details...

10) What does the JDBC ResultSet interface?

The ResultSet object represents a row of a table. It can be used to change the cursor
pointer and get the information from the database.
more details...

11) What does the JDBC ResultSetMetaData interface?

The ResultSetMetaData interface returns the information of table such as total number of
columns, column name, column type etc.
more details...

12) What does the JDBC DatabaseMetaData interface?

The DatabaseMetaData interface returns the information of the database such as
username, driver name, driver version, number of tables, number of views etc.
more details...

13) Which interface is responsible for transaction management

in JDBC?
The Connection interface provides methods for transaction management such as
commit(), rollback() etc.
more details...

14) What is batch processing and how to perform batch

processing in JDBC?
By using batch processing technique in JDBC, we can execute multiple queries. It makes
the performance fast.
more details...

15) How can we store and retrieve images from the database?
By using PreparedStatement interface, we can store and retrieve images

SQL Interview Questions

1) What is SQL Server?
SQL Server is DBMS system provided by Microsoft. Sometimes it is mistakenly referred
as SQL but both are totally different, as SQL is a language whereas SQL Server is a
Microsoft product that supports SQL.

2) What is normalization?
In RDBMS, the process of organizing data to minimize redundancy is called
normalization. In normalization database is divided in two or more tables and a
relationship is defined among the tables.

3) What is De-Normalization?
It is a process of attempting to optimize the performance of a database by adding
redundant data. Actually redundancy is introduced intentionally in a table to improve
performance and it is called de-normalization.

4) What is the difference between function and stored

Function must return a value while stored procedure can return zero or n value.
Functions can have only input parameter while procedures can have input/ output

Functions take one mandatory input parameter while stored procedures may take 0 to n
input parameter.
Exceptions can be handled by try-catch block in stored procedure while you can't use trycatch in functions.

5) What is collation sensitivity? Explain different types.

Collation sensitivity is used to define the rules for sorting and comparing the strings of
character data.
Different types of collation sensitivity:

Case sensitivity

Accent sensitivity

Kana sensitivity

Width sensitivity

6) What is standby server?

Standby server is the type of server which is brought online when primary server goes
offline and the application needs continuous availability of the server.
There are three types of standby servers:
Hot standby:Hot standby method is a method of redundancy in which the primary and
secondary backup systems run simultaneously so the data also present in secondary
server in a real time and this way both system contains identical information.
Warm standby:Warm standby is a method of redundancy in which the secondary
system runs in the background of the primary system . data is mirrored in the secondary
server at regular interval, so in this method sometimes both servers don't contain the
exact same data.

Cold standby:Cold standby is the method of redundancy in which the secondary server
is only called when the primary server fails. Cold standby systems are used in cases
where data is changed infrequently or for nor critical applications.

7) In which TCP/IP port does SQL Server run? Can it be

SQL Server runs on port 1433. Yes, it can be changed from the network utility TCP/IP

8) What are the authentication modes in SQL Server? How can

it be changed?
SQL Server supports two authentication modes:
Window authentication mode and mixed mode.
Window authentication mode: This authentication mode is used to connect through a
Microsoft NT 4.0 or window 2000 user account.
Mixed mode: It is used to connect with the instance of SQL Server using window
authentication or SQL Server authentication.

9) What is SQL Server Profiler?

Microsoft SQL Server profiler is a graphical user interface that allows system
administrators to monitor events of database engine.
You can do the following things with a SQL Server Profiler You can create a trace.

You can watch the trace results when the trace runs.
You can store the trace results in a table.
If it is necessary, you can start, stop, pause and modify the trace results.

10) What is SQL Server agent?

SQL Server agent is a component of Microsoft SQL Server. It is a background tool of
Microsoft SQL Server so it runs continuously in the background as a window service. SQL
Server agent allows the database administrator to handles automated tasks and
schedules jobs. It runs a window service so can start automatically when the system
boots or you can start it manually.

11) What is scheduled jobs or scheduled tasks?

Scheduled tasks let you manage the tasks in an automated manner that runs on regular
or predictable cycles. You can schedule administrative tasks and also determine the order
in which tasks will run.

12) What is DBCC command and why is it used?

DBCC stands for database consistency checker. This command is used to check the
consistency of the database. For example:
It makes sure that table in the database and the indexes are correctly linked.
It checks all pages in the database and make sure that all are correctly allocated.

It checks all table file group for any damage.

13) What command is used to rename the database?

sp_renamedb 'oldname', 'newname';

14) Can SQL Server be linked with other Servers like Oracle?
Yes, it can be linked to any Sever. It has OLE-DB provider from Microsoft which allow

15) What is the difference between abstract and interface?

Abstract class:
It provides a set of rules to implement next class. Rules are provided through abstract
Abstract method does not contain any definition.
When a class contains all functions without body, it is called as Fully Abstract Class.
If a class contains all abstract methods then that class is called Interface. Interface
support like multiple inheritance.

16)What is the difference between application object and

session object?

The session object is used to maintain the session of each user. If a user enters into an
application, he gets session id and when he leaves application then the session id is
deleted. If he enters again in to the application he gets a different session id but for
application object once ad id is generated it maintains whole application.

17)Is there any difference between primary key and unique with
NOT NULL condition?
There is no difference between primary key and unique key with not null.

18)What is the difference between value type and reference

Value type and reference type may be similar in terms of declaration syntax and usage
but their semantics are distinct
Value type are stored on stack while reference type are stored on heap.
Value type store real data while reference type store reference to the data.
Accessing is faster in value type on comparison to reference type.
Value type can contain null value while reference type can't contain null value.
Value types are derived from System.ValueType while Reference type is derived from

19)What is the Boxing and Unboxing concept in .net?

Boxing:Implicit conversion of a value type (integer, character etc.) to a reference type
(object) is called boxing. In boxing process a value type(which generally stores on stack)
is being allocated on the heap rather than the stack.

Unboxing:explicit conversion of that same reference type (which is created by boxing

process) back to a value type is known as unboxing. In unboxing process boxed value
type is unboxed from the heap and allocated on the stack.

20)What is the difference between GET and POST methods?

GET and POST methods are form submission method. Both are used to send the
data from client side to server side. These are some differences between GET
and POST method In GET method caching is possible while it is not possible in POST method.
Only ASCII character data types are allowed in GET method while in POST method there
is no restriction, it allows binary data also.
In GET method length of the string is restricted while in POST method length of the
string is not restricted.

21)What is Log Shipping?

Log shipping is the process of automating the backup of a database and transaction log
file on a primary database server, and then restoring them onto a standby server.
The primary purpose of log shipping is to increase database availability just like

22)What are the different type of replication in SQL Server?

There are three type of replication in SQL Server.
1.snapshot replication:snapshot replication distributes data exactly as it appears at a
specific moment. Snapshot replication is best method for replicating data that changes

2.transactional replication:transactional replication is generally used in server to

server environment. It is more appropriate when you want incremental change
propagated to subscriber.
3.merge replication:snapshot replication is a process of distributing data from publisher to
subscriber. It is generally used in server to client environment. Merge replication is
appropriate when multiple subscribers might update the same data at various time

Hibernate Interview Questions

Hibernate interview questions are asked to the students because it is a widely used ORM
tool. The important list of top 20 hibernate interview questions and answers for freshers
and professionals are given below.

1) What is hibernate?
Hibernate is an open-source and lightweight ORM tool that is used to store, manipulate
and retrieve data from the database.
more details...

2) What is ORM?
ORM is an acronym for Object/Relational mapping. It is a programming strategy to map
object with the data stored in the database. It simplifies data creation, data manipulation
and data access.

3) Explain hibernate architecture?

Hibernate architecture comprises of many interfaces such as Configuration,
SessionFactory, Session, Transaction etc.

more details...

4) What are the core interfaces of Hibernate?

The core interfaces of Hibernate framework are:







5) What is SessionFactory?
SessionFactory provides the instance of Session. It is a factory of Session. It holds the
data of second level cache that is not enabled by default.
more details...

6) Is SessionFactory a thread-safe object?

Yes, SessionFactory is a thread-safe object, many threads cannot access it

7) What is Session?
It maintains a connection between hibernate application and database.
It provides methods to store, update, delete or fetch data from the database such as
persist(), update(), delete(), load(), get() etc.
It is a factory of Query, Criteria and Transaction i.e. it provides factory methods to return
these instances.
more details...

8) Is Session a thread-safe object?

No, Session is not a thread-safe object, many threads can access it simultaneously. In
other words, you can share it between threads.

9) What is the difference between and

session.persist() method?





returns the identifier (Serializable) of

return nothing because its return

the instance.

type is void.

Syn: public Serializable save(Object o)

Syn: public void persist(Object o)

10) What is the difference between get and load method?

The differences between get() and load() methods are given below.




Returns null if object is not found.

Throws ObjectNotFoundException if
object is not found.


get() method always hit the

load() method doesn't hit the database.


It returns real object not proxy.

It returns proxy object.


It should be used if you are not

It should be used if you are sure that

sure about the existence of

instance exists.


11) What is the difference between update and merge method?

The differences between update() and merge() methods are given below.


update() method
Update means to edit something.

merge() method
Merge means to combine


update() should be used if session doesn't

merge() should be used if you

contain an already persistent state with

don't know the state of the

same id. It means update should be used

session, means you want to

inside the session only. After closing the

make modification at any time.

session it will throw error.

Let's try to understand the difference by the example given below:


copy to clipboard
SessionFactory factory = cfg.buildSessionFactory();
Session session1 = factory.openSession();

Employee e1 = (Employee) session1.get(Employee.class, Integer.valueOf(101));//pa

ssing id of employee
Session session2 = factory.openSession();
Employee e2 = (Employee) session1.get(Employee.class, Integer.valueOf(101));//pa
ssing same id
Transaction tx=session2.beginTransaction();
SessionFactory factory = cfg.b
Session session1 = factory.ope
Employee e1 = (Employee) sess

After closing session1, e1 is in detached state. It will not be in session1 cache. So if you
call update() method, it will throw an error.
Then, we opened another session and loaded the same Employee instance. If we call
merge in session2, changes of e1 will be merged in e2.

12) What are the states of object in hibernate?

There are 3 states of object (instance) in hibernate.
1. Transient: The object is in transient state if it is just created but has no primary
key (identifier) and not associated with session.
2. Persistent: The object is in persistent state if session is open, and you just saved
the instance in the database or retrieved the instance from the database.

3. Detached: The object is in detached state if session is closed. After detached

state, object comes to persistent state if you call lock() or update() method.

13) What are the inheritance mapping strategies?

There are 3 ways of inheritance mapping in hibernate.
1. Table per hierarchy
2. Table per concrete class
3. Table per subclass
more details...

14) How to make a immutable class in hibernate?

If you mark a class as mutable="false", class will be treated as an immutable class. By
default, it is mutable="true".

15) What is automatic dirty checking in hibernate?

The automatic dirty checking feature of hibernate, calls update statement automatically
on the objects that are modified in a transaction.
Let's understand it by the example given below:


copy to clipboard
SessionFactory factory = cfg.buildSessionFactory();
Session session1 = factory.openSession();
Transaction tx=session2.beginTransaction();
Employee e1 = (Employee) session1.get(Employee.class, Integer.valueOf(101));


SessionFactory factory = cfg.b
Session session1 = factory.ope
Transaction tx=session2.beginT

Here, after getting employee instance e1 and we are changing the state of e1.
After changing the state, we are committing the transaction. In such case, state will be
updated automatically. This is known as dirty checking in hibernate.

16) How many types of association mapping are possible in

There can be 4 types of association mapping in hibernate.
1. One to One
2. One to Many
3. Many to One
4. Many to Many

17) Is it possible to perform collection mapping with One-to-One

and Many-to-One?
No, collection mapping can only be performed with One-to-Many and Many-to-Many

18) What is lazy loading in hibernate?

Lazy loading in hibernate improves the performance. It loads the child objects on

Since Hibernate 3, lazy loading is enabled by default, you don't need to do lazy="true". It
means not to load the child objects when parent is loaded.

19) What is HQL (Hibernate Query Language)?

Hibernate Query Language is known as an object oriented query language. It is like
structured query language (SQL).
The main advantage of HQL over SQL is:
1. You don't need to learn SQL
2. Database independent
3. Simple to write query

20) What is the difference between first level cache and second
level cache?


First Level Cache

Second Level Cache

First Level Cache is associated

Second Level Cache is associated with

with Session.


It is enabled by default.

It is not enabled by default.

Spring Interview Questions

Spring interview questions and answers are frequently asked because it is now widely
used framework to develop enterprise application in java. There are given a list of top 40
frequently asked spring interview questions.

1) What is Spring?

It is a lightweight, loosely coupled and integrated framework for developing enterprise

applications in java.

2) What are the advantages of spring framework?

1. Predefined Templates
2. Loose Coupling
3. Easy to test
4. Lightweight
5. Fast Development
6. Powerful Abstraction
7. Declarative support
More details...

3) What are the modules of spring framework?

1. Test
2. Spring Core Container
3. AOP, Aspects and Instrumentation
4. Data Access/Integration
5. Web
More details...

4) What is IOC and DI?

IOC (Inversion of Control) and DI (Dependency Injection) is a design pattern to provide
loose coupling. It removes the dependency from the program.

Let's write a code without following IOC and DI.


copy to clipboard
public class Employee{
Address address;
address=new Address();//creating instance
public class Employee{
Address address;
address=new Address();//crea

Now, there is dependency between Employee and Address because Employee is forced to
use the same address instance.
Let's write the IOC or DI code.


copy to clipboard
public class Employee{
Address address;
Employee(Address address){
this.address=address;//not creating instance
public class Employee{
Address address;
Employee(Address address){
this.address=address;//not crea

Now, there is no dependency between Employee and Address because Employee is not
forced to use the same address instance. It can use any address instance.

5) What is the role of IOC container in spring?

IOC container is responsible to:

create the instance

configure the instance, and

assemble the dependencies

More details...

6) What are the types of IOC container in spring?

There are two types of IOC containers in spring framework.
1. BeanFactory
2. ApplicationContext
More details...

7) What is the difference between BeanFactory and

BeanFactory is the basic container whereas ApplicationContext is the advanced
container. ApplicationContext extends the BeanFactory interface. ApplicationContext
provides more facilities than BeanFactory such as integration with spring AOP, message
resource handling for i18n etc.

8) What is the difference between constructor injection and

setter injection?

Constructor Injection

Setter Injection


No Partial Injection

Partial Injection


Desn't override the setter

Overrides the constructor property if both


are defined.

Creates new instance if any

Doesn't create new instance if you change

modification occurs

the property value



Better for too many properties

Better for few properties.

More details...

9) What is autowiring in spring? What are the autowiring

Autowiring enables the programmer to inject the bean automatically. We don't need to
write explicit injection logic.
Let's see the code to inject bean using dependency injection.


copy to clipboard
<bean id="emp" class="com.javatpoint.Employee" autowire="byName" />
<bean id="emp" class="com.jav

The autowiring modes are given below:






this is the default mode, it means autowiring is not enabled.



injects the bean based on the property name. It uses setter




injects the bean based on the property type. It uses setter




It injects the bean using constructor

The "autodetect" mode is deprecated since spring 3.

10) What are the different bean scopes in spring?

There are 5 bean scopes in spring framework.



The bean instance will be only once and same instance will be
returned by the IOC container. It is the default scope.



The bean instance will be created each time when requested.



The bean instance will be created per HTTP request.



The bean instance will be created per HTTP session.



The bean instance will be created per HTTP global session. It

can be used in portlet context only.

11) In which scenario, you will use singleton and prototype

Singleton scope should be used with EJB stateless session bean and prototype scope
with EJB stateful session bean.

12) What are the transaction management supports provided by

Spring framework provides two type of transaction management supports:
1. Programmatic Transaction Management: should be used for few transaction
2. Declarative Transaction Management: should be used for many transaction

Spring JDBC Interview Questions

13) What are the advantages of JdbcTemplate in spring?

Less code: By using the JdbcTemplate class, you don't need to create
connection,statement,start transaction,commit transaction and close connection to
execute different queries. You can execute the query directly.
More details...

14) What are classes for spring JDBC API?

1. JdbcTemplate
2. SimpleJdbcTemplate
3. NamedParameterJdbcTemplate
4. SimpleJdbcInsert
5. SimpleJdbcCall
More details...

15) How can you fetch records by spring JdbcTemplate?

You can fetch records from the database by the query method of JdbcTemplate. There
are two interfaces to do this:
1. ResultSetExtractor
2. RowMapper

16) What is the advantage of NamedParameterJdbcTemplate?

NamedParameterJdbcTemplate class is used to pass value to the named parameter. A
named parameter is better than ? (question mark of PreparedStatement).
It is better to remember.

More details...

17) What is the advantage of SimpleJdbcTemplate?

The SimpleJdbcTemplate supports the feature of var-args and autoboxing.
More details...

Spring AOP Interview Questions

18) What is AOP?
AOP is an acronym for Aspect Oriented Programming. It is a methodology that divides
the program logic into pieces or parts or concerns.
It increases the modularity and the key unit is Aspect.
More details...

19) What are the advantages of spring AOP?

AOP enables you to dynamically add or remove concern before or after the business
logic. It is pluggable and easy to maintain.
More details...

20) What are the AOP terminology?

AOP terminologies or concepts are as follows:






Target Object


AOP Proxy


More details...

21) What is JoinPoint?

JoinPoint is any point in your program such as field access, method execution, exception
handling etc.

22) Does spring framework support all JoinPoints?

No, spring framework supports method execution joinpoint only.

23) What is Advice?

Advice represents action taken by aspect.

24) What are the types of advice in AOP?

There are 5 types of advices in spring AOP.
1. Before Advice

2. After Advice
3. After Returning Advice
4. Throws Advice
5. Around Advice

25) What is Pointcut?

Pointcut is expression language of Spring AOP.

26) What is Aspect?

Aspect is a class in spring AOP that contains advices and joinpoints.

27) What is Introduction?

Introduction represents introduction of new fields and methods for a type.

28) What is target object?

Target Object is a proxy object that is advised by one or more aspects.

29) What is interceptor?

Interceptor is a class like aspect that contains one advice only.

30) What is weaving?

Weaving is a process of linking aspect with other application.

31) Does spring perform weaving at compile time?

No, spring framework performs weaving at runtime.

32) What are the AOP implementation?

There are 3 AOP implementation.
1. Spring AOP
2. Apache AspectJ
3. JBoss AOP

Spring MVC Interview Questions

33) What is the front controller class of Spring MVC?
The DispatcherServlet class works as the front controller in Spring MVC.
More details...

34) What does @Controller annotation?

The @Controller annotation marks the class as controller class. It is applied on the

35) What does @RequestMapping annotation?

The @RequestMapping annotation maps the request with the method. It is applied on
the method.

36) What does the ViewResolver class?

The View Resolver class resolves the view component to be invoked for the request. It
defines prefix and suffix properties to resolve the view component.

37) Which ViewResolver class is widely used?

The org.springframework.web.servlet.view.InternalResourceViewResolver class
is widely used.

38) Does spring MVC provide validation support?


PL/SQL Interview Questions

PL/SQL is an advance version of SQL. There are given top list of PL/SQL interview
questions with answer.

1) What is PL/SQL?

PL/SQL stands for procedural language extension to SQL. It supports procedural features
of programming language and SQL both. It was developed by Oracle Corporation in early
of 90's to enhance the capabilities of SQL.

2) What is PL/SQL table? Why it is used?

Objects of type tables are called PL/SQL tables that are modeled as database table. We
can also say that PL/SQL tables are a way to providing arrays. Arrays are like temporary
tables in memory that are processed very quickly. PL/SQL tables are used to move bulk
data. They simplifies moving collections of data.

3) What are the datatypes available in PL/SQL?

There are two types of datatypes in PL/SQL:
1. Scalar datatypes Example are NUMBER, VARCHAR2, DATE, CHAR, LONG,
2. Composite datatypes Example are RECORD, TABLE etc.

4) What is the basic structure of PL/SQL?

PL/SQL uses BLOCK structure as its basic structure. Each PL/SQL program consists of
SQL and PL/SQL statement which form a PL/SQL block.
PL/SQL block contains 3 sections.
1. The Declaration Section (optional)
2. The Execution Section (mandatory)
3. The Exception handling Section (optional)

5) What is the difference between FUNCTION, PROCEDURE

Function: The main purpose of a PL/SQL function is generally to compute and return a
single value. A function has a return type in its specification and must return a value
specified in that type.
Procedure: A procedure does not have a return type and should not return any value
but it can have a return statement that simply stops its execution and returns to the
caller. A procedure is used to return multiple values otherwise it is generally similar to a
Package: A package is schema object which groups logically related PL/SQL types ,
items and subprograms. You can also say that it is a group of functions, procedure,
variables and record type statement. It provides modularity, due to this facility it aids
application development. It is used to hide information from unauthorized users.

6) What is exception? What are the types of exceptions?

Exception is an error handling part of PL/SQL. There are two type of exceptions:
pre_defined exception and user_defined exception.

7) How exception is different from error?

Whenever an Error occurs Exception arises. Error is a bug whereas exception is a
warning or error condition.

8) What is the main reason behind using an index?

Faster access of data blocks in the table.

9) What are PL/SQL exceptions? Tell me any three.

1. Too_many_rows
2. No_Data_Found
3. Value_error
4. Zero_error etc.

10) What is the maximum number of triggers, you can apply on

a single table?
12 triggers.

11) How many types of triggers exist in PL/SQL?

There are 12 types of triggers in PL/SQL that contains the combination of BEFORE,





12) What is stored Procedure?

A stored procedure is a sequence of statement or a named PL/SQL block which performs
one or more specific functions. It is similar to a procedure in other programming
languages. It is stored in the database and can be repeatedly executed. It is stored as
schema object. It can be nested, invoked and parameterized.

13) How to execute a stored procedure?

There are two way to execute a stored procedure.
From the SQL prompt, write EXECUTE or EXEC followed by procedure_name.


copy to clipboard
EXECUTE or [EXEC] procedure_name;
EXECUTE or [EXEC] procedure_

Simply use the procedure name


copy to clipboard

14) What are the advantages of stored procedure?

Modularity, extensibility, reusability, Maintainability and one time compilation.

15) What are the cursor attributes used in PL/SQL?

%ISOPEN: it checks whether the cursor is open or not.
%ROWCOUNT: returns the number of rows affected by DML operations:

%FOUND: it checks whether cursor has fetched any row. If yes - TRUE.
%NOTFOUND: it checks whether cursor has fetched any row. If no - TRUE.

16) What is consistency?

Consistency simply means that each user sees the consistent view of the data.
Consider an example: there are two users A and B. A transfers money to B's account.
Here the changes are updated in A's account (debit) but until it will be updated to B's
account (credit), till then other users can't see the debit of A's account. After the debit of
A and credit of B, one can see the updates. That?s consistency.

17) What is cursor and why it is required?

A cursor is a temporary work area created in a system memory when an SQL
statement is executed.
A cursor contains information on a select statement and the row of data accessed by it.
This temporary work area stores the data retrieved from the database and manipulate
this data. A cursor can hold more than one row, but can process only one row at a time.
Cursor are required to process rows individually for queries.

18) How many types of cursors are available in PL/SQL?

There are two types of cursors in PL/SQL.
1. Implicit cursor, and
explicit cursor

Oracle Interview Questions

Oracle is a secured database that is widely used in multinational companies. The

frequently asked questions from oracle database are given below.

1) What are the components of physical database structure of

Oracle database?
Components of physical database structure are given below.

One or more data files.

Two or more redo log files.

One or more control files.

2) What are the components of logical database structure in

Oracle database?
Components of logical database structure.


Database's schema objects

3) What is a tablespace?
A database contains Logical Storage Unit called tablespaces. A tablespace is a set of
related logical structures. Actually a tablespace groups related logical structures together.

4) What is a SYSTEM tablespace and when it is created?

When the database is created in Oracle database system, it automatically generate a

SYSTEM named SYSTEM tablespace. The SYSTEM tablespace contains data dictionary
tables for the entire database.

5) What is an Oracle table?

A table is basic unit of data storage in Oracle database. A table contains all the accessible
information of a user in rows and columns.

6) In the Oracle version, what does each number

Oracle version number refers:

9 - Major database release number

3 - Database maintenance release number

0 - Application server release number

5 - Component Specific release number

0 - Platform Specific release number

7) What is bulk copy or BCP in Oracle?

Bulk copy or BCP in Oracle, is used to import or export data from tables and views but it
does not copy structure of same data.
The main advantage of BCP is fast mechanism for coping data and you can also take the
backup of data easily.

8) What is the relationship among database, tablespace and

data file?
An Oracle database contains one or more logical storage units called tablespaces. These
tablespaces collectively store whole data of databases and each tablespace in Oracle
database consists of one or more files called datafiles. These datafiles are physical
structure that confirm with the operating system in which Oracle is running.

9) What is a snapshot in Oracle database?

A snapshot is a replica of a target master table from a single point-in-time. In simple
words you can say, snapshot is a copy of a table on a remote database.

10) What is the difference between hot backup and cold backup
in Oracle? Tell about their benefits also.
Hot backup (Online Backup): A hot backup is also known as online backup because it
is done while the database is active. Some sites can not shut down their database while
making a backup copy, they are used for 24 hour a day, 7 days a week.
Cold backup (Offline Backup): A cold backup is also known as offline backup because
it is done while the database has been shutdown using the SHUTDOWN normal
command. If the database is suddenly shutdown with a uncertain condition it should be
restarted with RESTRICT mode and then shutdown with NORMAL option.
For a complete cold backup the following files must be backed up.
All datafiles, All control files, All online redo log files(optional) and the init.ora file (you
can recreate it manually).

11) How many memory layers are in the Oracle shared pool?

Oracle shared pools contains two layers:

1. library cache
2. data dictionary cache

12) What is save point in Oracle database?

Save points are used to divide a transaction into smaller parts. It allows rolling back of a
transaction. Maximum five save points are allowed. It is used to save our data, whenever
you encounter an error you can roll back from the point where you save your

13) What is hash cluster in Oracle?

Hash cluster is a technique to store a data in hash table and improve the performance of
data retrieval. Hash function is applied on table row's cluster key value and store in hash

14) What are the various Oracle database objects?

Tables: This is a set of elements organized in vertical and horizontal fashion.
Tablespaces: This is a logical storage unit in Oracle.
Views: It is virtual table derived from one or more tables.
Indexes: This is a performance tuning method to process the records.
Synonyms: This is a name for tables.

15) What is the difference between pre-select and pre-query?

A pre-query trigger fire before the query executes and fire once while you try to query.
With the help of this trigger you can modify the where clause part dynamically.
Pre-select query fires during the execute query and count query processing after Oracle
forms construct the select statement to be issued, but before the statement is actually
Pre-query trigger fires before Pre-select trigger.

16) How to convert a date to char in Oracle? Give one example.

The to_char() function is used to convert date to character. You can also specify the
format in which you want output.


copy to clipboard
SELECT to_char ( to_date ('12-12-2012', 'DD-MM-YYYY') , 'YYYY-MM-DD') FROM du
SELECT to_char ( to_date ('12-1



copy to clipboard
SELECT to_char ( to_date ('12-12-2012', 'DD-MM-YYYY') , 'DD-MM-YYYY') FROM du
SELECT to_char ( to_date ('12-1

17) What are the extensions used by Oracle reports?

Oracle reports are use to make business enable with the facility to provide information of
all level within or outside in a secure way. Oracle report uses REP files and RDF file

18) How to convert a string to a date in Oracle database?

Syntax: to_date (string , format)
Let us take an example :


copy to clipboard
to_date ('2012-12-12', 'YYYY/MM/DD')
to_date ('2012-12-12', 'YYYY/M

It will return December 12, 2012.

19) How do you find current date and time in Oracle?

The SYSDATE() function is used in Oracle to find the current date and time of
operating system on which the database is running.


copy to clipboard

20) What will be the syntax to find current date and time in
format "YYYY-MM-DD"?
copy to clipboard

Jsp Interview questions

There is a list of 25 jsp interview questions for freshers and professionals. If you know
any jsp interview question that has not been included here, post your question in the Ask
Question section.

1)What is JSP?
Java Server Pages technology (JSP) is used to create dynamic web page. It is an
extension to the servlet technology. A JSP page is internally converted into servlet.
more details...

2) What are the life-cycle methods for a jsp?

public void jspInit()

It is invoked only once,
same as init method of

public void _jspService(ServletRequest

It is invoked at each


request, same as service()


method of servlet.

public void jspDestroy()

It is invoked only once,

same as destroy() method
of servlet.

3)What is difference between hide comment and output

The jsp comment is called hide comment whereas html comment is called output
comment. If user views the source of the page, the jsp comment will not be shown
whereas html comment will be shown.

4)What are the JSP implicit objects ?

JSP provides 9 implicit objects by default. They are as follows:



1) out


2) request


3) response


4) config


5) session


6) application


7) pageContext


8) page


9) exception


more details...

5)What is difference between include directive and include

include directive

include action

1) The include directive includes the

1) The include action includes the content at

content at page translation time.

request time.

2) The include directive includes the

2) The include action doesn't include the

original content of the page so page

original content rather invokes the include()

size increases at runtime.

method of Vendor provided class.

3) It's better for static pages.

3) It's better for dynamic pages.

6) Is JSP technology extensible?

Yes. JSP technology is extensible through the development of custom actions, or tags,
which are encapsulated in tag libraries.

7) How can I implement a thread-safe JSP page? What are the

advantages and Disadvantages of using it?
You can make your JSPs thread-safe by having them implement the SingleThreadModel
interface. This is done by adding the directive <%@ page isThreadSafe="false" %>
within your JSP page.

8) How can I prevent the output of my JSP or Servlet pages

from being cached by the browser?
(OR) How to disable caching on back button of the browser?

copy to clipboard
response.setHeader ("Expires", "0"); //prevents caching at the proxy server

response.setHeader ("Expires",

9) How can we handle the exceptions in JSP ?

There are two ways to perform exception handling, one is by the errorPage element of
page directive, and second is by the error-page element of web.xml file.
more details...

10) What are the two ways to include the result of another page.
There are two ways to include the result of another page:

By include directive

By include action

11) How can we forward the request from jsp page to the
servlet ?
Yes ofcourse! With the help of forward action tag, but we need to give the url-pattern of
the servlet.
forward action tag

12) Can we use the exception implicit object in any jsp page ?

No. The exception implicit object can only be used in the error page which defines it with
the isErrorPage attribute of page directive.
more details...

13) How is JSP used in the MVC model?

JSP is usually used for presentation in the MVC pattern (Model View Controller ) i.e. it
plays the role of the view. The controller deals with calling the model and the business
classes which in turn get the data, this data is then presented to the JSP for rendering on
to the client.
forward action tag

14) What are context initialization parameters?

Context initialization parameters are specified by the <context-param> in the web.xml
file, these are initialization parameter for the whole application and not specific to any
servlet or JSP.
more details...

15) What are the different scope values for the <jsp:useBean>
There are 4 values:
1. page
2. request
3. session
4. application
more details...

16)What is the difference between ServletContext and

PageContext?ServletContext gives the information about the container whereas PageContext gives the
information about the Request.

17)What is the difference in using

request.getRequestDispatcher() and
request.getRequestDispatcher(path) is used in order to create it we need to give the
relative path of the resource whereas context.getRequestDispatcher(path) in order to
create it we need to give the absolute path of the resource.

18) What is EL in JSP?

The Expression Language(EL) is used in JSP to simplify the accessibility of objects. It
provides many objects that can be used directly like param, requestScope, sessionScope,
applicationScope, request, session etc.

19)What is basic differences between the JSP custom tags and

java beans?

Custom tags can manipulate JSP content whereas beans cannot.

Complex operations can be reduced to a significantly simpler form with custom

tags than with beans.

Custom tags require quite a bit more work to set up than do beans.

Custom tags are available only in JSP 1.1 and later, but beans can be used in all
JSP 1.x versions.

20) Can an interface be implemented in the jsp file ?


21) What is JSTL?

JSP Standard Tag Library is library of predefined tags that ease the development of JSP.
more details...

22) How many tags are provided in JSTL?

There are 5 type of JSTL tags.
1. core tags
2. sql tags
3. xml tags
4. internationalization tags
5. functions tags
more details...

23) Which directive is used in jsp custom tag?

The jsp taglib directive.

24) What are the 3 tags used in JSP bean development?

1. jsp:useBean

2. jsp:setProperty
3. jsp:getProperty
more details...

25) How to disable session in JSP?

copy to clipboard
<%@ page session="false" %>

SQL Interview Questions

There is given sql interview questions and answers that has been asked in many
companies. For PL/SQL interview questions, visit our next page.

1) What is SQL?
SQL stands for structured query language. It is a database language used for database
creation, deletion, fetching rows and modifying rows etc. sometimes it is pronounced as

2) When SQL appeared?

It appeared in 1974.

3) What are the usages of SQL?

To execute queries against a database

To retrieve data from a database

To inserts records in a database

To updates records in a database

To delete records from a database

To create new databases

To create new tables in a database

To create views in a database

4) Does SQL support programming?

No, SQL doesn't have loop or Conditional statement. It is used like commanding
language to access databases.

5) What are the subsets of SQL?

1. Data definition language (DDL)
2. Data manipulation language (DML)
3. Data control language (DCL)

6) What is data definition language?

Data definition language(DDL) allows you to CREATE, ALTER and DELETE database
objects such as schema, tables, view, sequence etc.

7) What is data manipulation language?

Data manipulation language makes user able to access and manipulate data. It is used to
perform following operations.

Insert data into database

Retrieve data from the database

Update data in the database

Delete data from the database

8) What is data control language?

Data control language allows you to control access to the database. It includes two
commands GRANT and REVOKE.
GRANT: to grant specific user to perform specific task.
REVOKE: to cancel previously denied or granted permissions.

9) What are the type of operators available in SQL?

1. Arithmetic operators
2. Logical operators
3. Comparison operator

10) What is the difference between clustered and non clustered

index in SQL?
There are mainly two type of indexes in SQL, Clustered index and non clustered index.
The differences between these two indexes is very important from SQL performance
1) One table can have only one clustered index but it can have many non clustered
index. (approximately 250).

2) clustered index determines how data is stored physically in table. Actually clustered
index stores data in cluster, related data is stored together so it makes simple to retrieve
3) reading from a clustered index is much faster than reading from non clustered index
from the same table.
4) clustered index sort and store data rows in the table or view based on their key value,
while non cluster have a structure separate from the data row.

11) What is the SQL query to display current date?

There is a built in function in SQL called GetDate() which is used to return current

12) Which types of join is used in SQL widely?

The knowledge of JOIN is very necessary for an interviewee. Mostly used join is INNER
JOIN and (left/right) OUTER JOIN.

13) What is "TRIGGER" in SQL?

Trigger allows you to execute a batch of SQL code when an insert, update or delete
command is executed against a specific table.
Actually triggers are special type of stored procedures that are defined to execute
automatically in place or after data modifications.

14) What is self join and what is the requirement of self join?

Self join is often very useful to convert a hierarchical structure to a flat structure. It is
used to join a table to itself as like if that is the second table.

15) What are set operators in SQL?

Union, intersect or minus operators are called set operators.

16) What is a constraint? Tell me about its various levels.

Constraints are representators of a column to enforce data entity and consistency. There
are two levels :
1. column level constraint
2. table level constraint

17) Write an SQL query to find names of employee start with


copy to clipboard
SELECT * FROM Employees WHERE EmpName like 'A%'
SELECT * FROM Employees WH

18) Write an SQL query to get third maximum salary of an

employee from a table named employee_table.

copy to clipboard
SELECT TOP 1 salary


SELECT TOP 3 salary
FROM employee_table
ORDER BY salary DESC ) AS emp
ORDER BY salary ASC;
SELECT TOP 1 salary
SELECT TOP 3 salary
FROM employee_table
ORDER BY salary DESC ) AS em

19) What is the difference between DELETE and TRUNCATE

statement in SQL?
The main differences between SQL DELETE and TRUNCATE statements are given below:





DELETE is a DML command.

TRUNCATE is a DDL command.


We can use WHERE clause in

We cannot use WHERE clause with

DELETE command.


DELETE statement is used to

TRUNCATE statement is used to remove

delete a row from a table

all the rows from a table.

DELETE is slower than TRUNCATE

TRUNCATE statement is faster than


DELETE statement.

You can rollback data after using

It is not possible to rollback after

DELETE statement.

using TRUNCATE statement.




20) What is ACID property in database?

ACID property is used to ensure that the data transactions are processed reliably in a
database system.
A single logical operation of a data is called transaction.

ACID is an acronym for Atomicity, Consistency, Isolation, Durability.

Atomicity: it requires that each transaction is all or nothing. It means if one part of the
transaction fails, the entire transaction fails and the database state is left unchanged.
Consistency: the consistency property ensure that the data must meet all validation
rules. In simple words you can say that your transaction never leaves your database
without completing its state.
Isolation: this property ensure that the concurrent property of execution should not be
met. The main goal of providing isolation is concurrency control.
Durability: durability simply means that once a transaction has been committed, it will
remain so, come what may even power loss, crashes or errors.

MySQL Interview Questions

1) What is MySQL?
MySQL is a multithreaded, multi-user SQL database management system which has
more than 11 million installations. This is the world's second most popular and widely
used open source database.

2) In which language MySQL is written?

MySQL is written in C and C++ and its SQL parser is written in yacc.

3) What are the technical specification of MySQL?

MySQL has the following technical specifications

Flexible structure

High performance

Manageable and easy to use

Replication and high availability

Security and storage management

4) How many Triggers are possible in MySQL?

There are only six Triggers allowed to use in MySQL database.
1. Before Insert
2. After Insert
3. Before Update
4. After Update
5. Before Delete
6. After Delete

5) What is heap table?

Tables that are present in memory is known as HEAP tables. When you create a heap
table in MySQL, you should need to specify the TYPE as HEAP. These tables are
commonly known as memory tables. They are used for high speed storage on temporary
basis. They do not allow BLOB or TEXT fields.

6) What is BLOB and TEXT in MySQL?

BLOB is an acronym stands for binary large object. It is used to hold a variable amount
of data.

There are four types of BLOB.

The differences among all these are the maximum length of values they can hold.
TEXT is case-insensitive BLOB. TEXT values are non-binary strings (character string).
They have a character set and values are stored and compared based on the collation of
the character set.
There are four types of TEXT.

7) What is a trigger in MySQL?

A trigger is a set of codes that executes in response to some events.

8) What is the difference between heap table and temporary

Heap tables:
Heap tables are found in memory. They are used for high speed storage on temporary
basis. They do not allow BLOB or TEXT fields.

Heap tables do not support AUTO_INCREMENT.

Indexes should be NOT NULL.
Temporary tables:
The temporary tables are used to keep the temporary data. Sometimes it is very useful
in cases to keep temporary data. Temporary table is deleted after current client session
Main differences:
The heap tables are shared among clients while temporary tables are not shared.
Heap tables are just another storage engine, while for temporary tables you need a
special privilege (create temporary table).

9) What is the difference between FLOAT and DOUBLE?

FLOAT stores floating point numbers with accuracy up to 8 places and allocates 4 bytes,
on the other hand DOUBLE stores floating point numbers with accuracy up to 18 places
and allocates 8 bytes.

10) What are the advantages of MySQL in comparison to

1. MySQL is a free, fast, reliable, open source relational database while Oracle is
expensive, although they have provided Oracle free edition to attract MySQL
2. MySQL uses only just under 1 MB of RAM on your laptop while Oracle 9i
installation uses 128 MB.
3. MySQL is great for database enabled websites while Oracle is made for
4. MySQL is portable.

11) What are the disadvantages of MySQL?

1. MySQL is not so efficient for large scale databases.
2. It does not support COMMIT and STORED PROCEDURES functions version less
than 5.0.
3. Transactions are not handled very efficiently.

12) What is the difference between CHAR and VARCHAR?

1) CHAR and VARCHAR are differ in storage and retrieval.
2) CHAR column length is fixed while VARCHAR length is variable.
3) The maximum no. of character CHAR data type can hold is 255 character while
VARCHAR can hold up to 4000 character.
4) CHAR is 50% faster than VARCHAR.
5) CHAR uses static memory allocation while VARCHAR uses dynamic memory allocation.

13) What is the difference between MySQL_connect and

1. It opens a new connection to the database.
2. Every time you need to open and close database connection, depending on the
3. Opens page every time when it loaded.

1. In Mysql_pconnect, "p" stands for persistent connection so it opens the persistent

2. the database connection can not be closed.
3. it is more useful if your site has more traffic because there is no need to open and
close connection frequently and every time when page is loaded.

14) What does " i_am_a_dummy flag" do in MySQL?

The " i_am_a_dummy flag" enables MySQL engine to refuse any UPDATE or DELETE
statement to execute if the WHERE clause is not present.

15) How to get the current date in MySQL?

To get current date, use the following syntax:


copy to clipboard

16) What are the security alerts while using MySQL?

Install antivirus and configure the operating system's firewall.
Never use the MySQL Server as the UNIX root user.
Change root username and password
Restrict or disable remote access.

17) How to change a password for an existing user via


Mysqladmin -u root -p password "newpassword".

18) What is the difference between Unix timestamps and

MySQL timestamps?
Actually both Unix timestamp and MySQL timestamp are stored as 32-bit integers but
MySQL timestamp is represented in readable format of YYYY-MM-DD HH:MM:SS format.

19) How to display Nth highest salary from a table in a MySQL

Let us take a table named employee.
To find Nth highest salary is:


copy to clipboard
select distinct(salary) from employee order by salary desc limit n-1,1
if you want to find 3rd largest salary:


copy to clipboard
select distinct(salary) from employee order by salary desc limit 2,1

20) What is MySQL default port number?

MySQL default port number is 3306.

21) What is REGEXP?

REGEXP is a pattern match using regular expression. Regular expression is a powerful
way of specifying a pattern for a complex search.

22) How many columns can you create for an index?

You can create maximum of 16 indexed columns for a standard table.

23) What is the difference between NOW() and

NOW() command is used to show current year, month, date with hours, minutes and
seconds while CURRENT_DATE() shows the current year with month and date only.

24) What is the query to display top 20 rows?


copy to clipboard
SELECT * FROM table_name LIMIT 0,20;

25) Write a query to display current date and time?

If you want to display current date and time, use -


copy to clipboard
If you want to display current date only, use SELECT CURRENT_DATE();

26) What is save point in MySQL?

A defined point in any transaction is known as savepoint.
SAVEPOINT is a statement in MySQL which is used to set a named transaction save point
with a name of identifier.

27) What is SQLyog?

SQLyog program is the most popular GUI tool for admin. It is the most popular MySQL
manager and admin tool. It combines the features of MySQL administrator, phpMyadmin
and others MySQL front ends and MySQL GUI tools.

28) How do you backup a database in MySQl?

It is easy to backing up data with phpMyAdmin. Select the database you want to backup
by clicking the database name in the left hand navigation bar. Then click the export
button and make sure that all tables are highlighted that you want to backup. Then
specify the option you want under export and save the output.

Android Interview Questions

Android programming is growing day by day. The questions asked by interviewers in
android is given below.

1) What is Android?
Android is an open-source, linux-based operating system that is used in mobiles, tablets,
televisions etc.

2) Who is the founder of Android?

Andy Rubin.

3) What are the code names of android?

1. Aestro
2. Blender
3. Cupcake
4. Donut
5. Eclair
6. Froyo
7. Gingerbread
8. Honycomb
9. Ice Cream Sandwitch
10. Jelly Bean
11. Kitkat
More details...

4) What are the advantages of android?

Open-source: It means no licence, distribution and development fee.
Platform-independent: It supports windows, mac and linux platforms.
Supports various technologies: It supports camera, bluetooth, wifi, speech, EDGE etc.
Highly optimized Virtual Machine: Android uses highly optimized virtual machine for
mobile devices, called DVM (Dalvik Virtual Machine).

5) Does android support other language than java?

Yes, android app can be developed in C/C++ also using android NDK (Native
Development Kit). It makes the performance faster. It should be used with android SDK.

6) What are the core building blocks of android?

The core building blocks of android are:





Content Provider

Fragment etc.

More details...

7) What is activity?
Activity is like a frame or window in java that represents GUI. It represents one screen of

8) What are the life cycle methods of android activity?

There are 7 life-cycle methods of activity. They are as follows:
1. onCreate()
2. onStart()
3. onResume()

4. onPause()
5. onStop()
6. onRestart()
7. onDestroy()
More details...

9) What is intent?
It is a kind of message or information that is passed to the components. It is used to
launch an activity, display a web page, send sms, send email etc. There are two types of
intents in android:
1. Implicit Intent
2. Explicit Intent

10) What is implicit intent in android?

Implicit intent is used to invoke the system components.

11) What is explicit intent in android?

Explicit intent is used to invoke the activity class.

12) How to call another activity in android?


copy to clipboard
Intent i = new Intent(getApplicationContext(), ActivityTwo.class);

Intent i = new Intent(getApplicat


13) What is service in android?

A service is a component that runs in the background. It is used to play music, handle
network transaction etc.
More details...

14) What is the name of database used in android?

SQLite: An opensource and lightweight relational database for mobile devices.
More details...

15) What is AAPT?

AAPT is an acronym for android asset packaging tool. It handles the packaging process.

16) What is content provider?

Content providers are used to share information between android applications.

17) What is fragment?

Fragment is a part of Activity. By the help of fragments, we can display multiple screens
on one activity.

18) What is ADB?

ADB stands for Android Debug Bridge. It is a command line tool that is used to
communicate with the emulator instance.

19) What is NDK?

NDK stands for Native Development Kit. By using NDK, you can develop a part of app
using native language such as C/C++ to boost the performance.

20) What is ANR?

ANR stands for Application Not Responding. It is a dialog box that appears if the application
is no longer responding.

5 Steps to connect to the database in java

1. 5 Steps to connect to the database in java

Register the driver class


Create the connection object


Create the Statement object


Execute the query


Close the connection object

There are 5 steps to connect any java application with the database in java using JDBC.
They are as follows:
Register the driver class

Creating connection

Creating statement

Executing queries

Closing connection

1) Register the driver class

The forName() method of Class class is used to register the driver class. This method is
used to dynamically load the driver class.

Syntax of forName() method


copy to clipboard
public static void forName(String className)throws ClassNotFoundException
public static void forName(String

Example to register the OracleDriver class


copy to clipboard

2) Create the connection object

The getConnection() method of DriverManager class is used to establish connection with
the database.

Syntax of getConnection() method


copy to clipboard
1) public static Connection getConnection(String url)throws SQLException
2) public static Connection getConnection(String url,String name,String password)
throws SQLException
1) public static Connection getC
2) public static Connection getC
throw s SQLException

Example to establish connection with the Oracle


copy to clipboard
Connection con=DriverManager.getConnection(
Connection con=DriverManager

3) Create the Statement object

The createStatement() method of Connection interface is used to create statement. The
object of statement is responsible to execute queries with the database.

Syntax of createStatement() method


copy to clipboard
public Statement createStatement()throws SQLException
public Statement createStateme

Example to create the statement object


copy to clipboard
Statement stmt=con.createStatement();
Statement stmt=con.createState

4) Execute the query

The executeQuery() method of Statement interface is used to execute queries to the
database. This method returns the object of ResultSet that can be used to get all the
records of a table.

Syntax of executeQuery() method


copy to clipboard
public ResultSet executeQuery(String sql)throws SQLException
public ResultSet executeQuery(

Example to execute query


copy to clipboard
ResultSet rs=stmt.executeQuery("select * from emp");
System.out.println(rs.getInt(1)+" "+rs.getString(2));
ResultSet rs=stmt.executeQuer
w hile({

5) Close the connection object

By closing connection object statement and ResultSet will be closed automatically. The
close() method of Connection interface is used to close the connection.

Syntax of close() method


copy to clipboard
public void close()throws SQLException
public void close()throw s SQLE

Example to close connection

copy to clipboard