Welcome Message

Hi, welcome to my website. This is a place where you can get all the questions, puzzles, algorithms asked in interviews and their solutions. Feel free to contact me if you have any queries / suggestions and please leave your valuable comments.. Thanks for visiting -Pragya.

May 24, 2012

Defining priority / order of advice in Spring AOP

We can use @Order annotation to define the Order of advice

February 22, 2012

Webservices - Basics

1. Service over web
2. Language independent
3. Communicate mostly over HTTP, but can communicate over other transfer protocols as well
4. Two types : SOAP(Simple Object Access Protocol) based and REST(representational State Transfer) style
5. The client of webservices is generally an application without any user interface.
6. In a SOAP based webservice, a client generally sends SOAP document as request and gets SOAP based document as response. In a REST style WS, a client might send a standard http request and get an XML document as response.
7. Java 6 supports JAX-WS which supports both REST and SOAP webservices.

December 29, 2011

Strategy Pattern

Key points :

1. Also known as Policy pattern
2. Collection of Algos (Behavuours)
3. Algo can be selected at runtime
4. Uses composition instead of inheritance

e.g. a class used for validation of incoming data may use strategy pattern in which the validation algo will be decided on the basis of data set

June 20, 2011

LimeSpot interview Question (Telephonic Interview)

Currently there are three projects in LimeWire :
1. LimeWire
2. Lime Domain : Hosts domain for users
3. LIme Exchange

Q1: What in an outer join and what is an Inner join?
A: Inner Join returns a row when there is at-least one match in one match in both the tables. e.g.
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
FROM Persons
INNER JOIN Orders
ON Persons.P_Id=Orders.P_Id
ORDER BY Persons.LastName

http://www.w3schools.com/sql/sql_join_inner.asp

Outer JOin :
Returns a row even if there is no match.
An outer join does not require each record in the two joined tables to have a matching record. The joined table retains each record—even if no other matching record exists. Outer joins subdivide further into left outer joins, right outer joins, and full outer joins, depending on which table(s) one retains the rows from (left, right, or both).

Q2. What is Normalisation and what is BCNF?
A: Boyce Codd Normal Form

March 13, 2011

Volatile variable in java

According to Kathy Sierra :

" The volatile modifier tells the JVM that a thread accessing the variable must
always reconcile its own private copy of the variable with the master copy in
memory "

My understanding :
In normal scenario, In a multi-threaded environment, every thread keeps a local copy of instance variable and if a thread makes some change to the variable, the changed value would be visible to that thread only.

But if we declare a variable as volatile, the variable is stored in main memory and not in local memory of any thread. So, if the value of the variable is changed by any thread, it will be changed in the main memory and would be visible to all threads accessing that variable.

March 9, 2011

The Java Class Loading Mechanism


The Java platform uses a delegation model for loading classes. The basic idea is that every class loader has a "parent" class loader. When loading a class, a class loader first "delegates" the search for the class to its parent class loader before attempting to find the class itself.

Constructors in java.lang.ClassLoader and its subclasses allow you to specify a parent when you instantiate a new class loader. If you don't explicitly specify a parent, the virtual machine's system class loader will be assigned as the default parent.
The loadClass method in ClassLoader performs these tasks, in order, when called to load a class:
If a class has already been loaded, it returns it.
Otherwise, it delegates the search for the new class to the parent class loader.
If the parent class loader does not find the class, loadClass calls the method findClass to find and load the class.
The findClass method of ClassLoader searches for the class in the current class loader if the class wasn't found by the parent class loader. You will probably want to override this method when you instantiate a class loader subclass in your application.
The class java.net.URLClassLoader serves as the basic class loader for extensions and other JAR files, overriding the findClass method of java.lang.ClassLoader to search one or more specified URLs for classes and resources.

forward vs sendRedirect

RequestDispatcher.forward() :

1) Forwards the request to some other servlet/jsp within the same application.
2) The URL in the browser does not change so the client does not get to know that the request is being sent to some other servlet. The process occurs completely within the web container
3) Request attributes are maintained
4) Faster, since everything is at the server side only

Response.sendRedirect()
1) Can forward request to a resource in some other application as well
2) The URL in the browser changes. So the web container returns to the browser indicating that the a new URL should be requested.
3)  Since a new request object is created, any request attributes already stored will be destroyed.
4) Slower, since the round trip to client is involved

java.lang.Error

Error extends Throwable.

It indicates that some serious and abnormal condition has occurred and the application should not try to catch it.