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.

October 28, 2010

Mean - Median - Mode

Mean - Median - Mode are three words which I often confuse.

Mean : Average 
  • Arithmetic Mean (AM) : (a+b+c+....+n)/n 
  •                                                               1/n
  • Geometric Mean (GM) : (a*b*c*.....*n)

  • Harmonic Mean (HM) 
     AM >= GM >= HM

Median : Middle Value
     If we have a set of values, then mean of those can be found by arranging those values in ascending/      descending order and the middle value will be median.

Mode : Most frequently occuring value. Mode may / may not be unique.

September 29, 2010

MaxEmail : Send and Receive Fax by Email

With MaxEmail, you can send and receive fax on your email account.You do not need any Fax machine or dedicated phone line for this. The Fax would come as a PDF in the email. You can also receive an audio file, which will be stored as wav file.

With this, you can also ask for a dedicated Fax number.

September 6, 2010

ECF : Eclipse Communication Framework - Installation

Got to explore ECF - Eclipse Communication Framework (Introduces the concept of communications container)
It is a framework build to integrate Communication into projects. It includes various tools like Instant Messenger, Chat Client , File Sharing, Project Sharing, Simultaneous edits to a file by various developers, Real Time Collaboration etc.
Really nice Communication Framework with plenty of features.


Installation steps :


1. Open Eclipse 3.5 or higher.
2. Open Help -> Install New Software...


3. Then click on Add button on 'Install' window and add the following details:


Name : ECF 3.3
Location : http://download.eclipse.org/rt/ecf/3.3/helios/site.p2





4. Click 'OK'.
This would start the installation. This might take several minutes.

After the installation , you are ready to communicate :)

August 26, 2010

Important points : java.util.Logger

The Logger class implements Factory patter to return logger instance.
The getLogger() method will either create a new logger instance or return a suitable(having same name as specified) existing instance. Each logger has a level associated with it, which specifies the minimum level the logger takes care of. If a  logger level is null, then its level is inherited from its parent.So, if the log level is changed for a class, the change would effect its child loggers which have the log level set as null.

Also, all methods in a logger are thread-safe.

RequestDispatcher : forward()

The argument to forward method is the name of the resource we want the request to be forwarded to. This can be a jsp file or a Servlet. In case it is a servlet, the argument should be whatever we have specified in the url-pattern for that servlet declaration in web.xml.

So, the point to be noted here is that in case we want to forward the request to some other servlet, the argument to forward method should be the url-pattern of that servlet.

Also, as we (probably) already know, the URL in the browser is not changed in case of forward. i.e. the client does not get to know that internally the request has been forwarded to some other resource.

August 2, 2010

Response : sendRedirect()

sendRedirect() method takes String as an argument. This string can start with a forward slash.

E.g.

Lets say the current URL we are accessing is : http://localhost:8080/MyApp/MyServlet/welcome.do

Now in our Servlet, we can do either :
response.sendRedirect("thanks.jsp");
OR
response.sendRedirect("/thanks.jsp");

Both of these would hit differnet URLs

In first case, i.e. response.sendRedirect("thanks.jsp");
The server will hit URL that is relative to the original URL, i.e http://localhost:8080/MyApp/MyServlet/thanks.jsp

and in second case,
the server builds the complete URL, relative to the web application itself.(instead of relative to original URL)
i.e.  http://localhost:8080/MyApp/thanks.jsp

One more thing to note here is that the argument to sendRedirect() is a String only and not an object and the URL should be something that the server can generate a complete URL from the relative. i.e. it should be relative to something (be it relative to current URL or to the web-app).
So, any argument like "www.pragyarawal.tk/welcome.jsp" would not work as the server would try to create a complete URL from it. and in this case, the server would throw an "IllegalStateException".

PrintWriter : print() vs write()

Today while reading Servlets, I came across the class PrintWriter.


I found that there we have two methods (both with various overloaded versions) : write() and print()
and I saw that print() internally calls write() only. So I was wondering that why there are different methods although they are doing the same thing. So, this seemed to be kind of redundancy to me.


Then I realized that print() is actually used as a utility method there, to which u can pass any literal value say whether it is boolean/char/int/float/double (to its overloaded versoins), but in write u have a limitaion of using only int /char array or string.So print() is just encapsulating the implementation of write() method by providing number of overlaoded method by which u can call the write().



August 1, 2010

HttpServletRequest

Some not very frequently used methods :

getServerPort():  Returns the port number to which the request was sent. (8080 in my case)
getServerName(): Name of the server (I used localhost)
getLocalAddr(): I got 0.0.0.0
getLocalPort() : This returns the port at which the request actually ends up. This is as the requests are made to the same port, but the server forwards them to different ports so that the application it can handle multiple threads.
getRemotePort(): Since the server asks for remote port, it is the client that is remote for the server. So, it returns the port number on the client on which the request was sent.