File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes some interview questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "some interview questions" Watch "some interview questions" New topic
Author

some interview questions

Durga Krishna
Greenhorn

Joined: Jul 10, 2006
Posts: 11
1)How much data the session object can store?
2)what can you do in program in order to make browser not to keep your pages in cache?
3) what is action servlet?
4) How to call a method in the EJB from a servlet ?
5) How to get pop-up window while clicking on the button ?
6) which one is best amoung cookies,url rewriting,hidden fields,http seesion ? and why?
7)what is the difference between PrintWriter and jsp writer
[ July 12, 2006: Message edited by: Bear Bibeault ]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

What were your answers?
Durga Krishna
Greenhorn

Joined: Jul 10, 2006
Posts: 11
I din't answered....i dont know... thats why i am asking...
Please tell me the answers
Steve McClintic
Greenhorn

Joined: Jul 03, 2006
Posts: 14
Originally posted by Durga Krishna:
1)How much data the session object can store?
2)what can you do in program in order to make browser not to keep your pages in cache?
3) what is action servlet?
4) How to call a method in the EJB from a servlet ?
5) How to get pop-up window while clicking on the button ?
6) which one is best amoung cookies,url rewriting,hidden fields,http seesion ? and why?
7)what is the difference between PrintWriter and jsp writer


If you want a good book on the subjects, I recommend Head First Servlets/JSP. Refer to Struts documentation for number 3. Number 4 requires you to get a reference to the EJB Home, and accessing the method via the bean's component interface. Number 5 can be done in Javascript.

For more info, Google is your good friend.
ak pillai
author
Ranch Hand

Joined: Feb 11, 2006
Posts: 288
1) How much data the session object can store?
A. There is no limit, but huge data can adversely affect performance.

2) what can you do in program in order to make browser not to keep your pages in cache?

A. You can set some HTTP headers in your servlet or JSP telling browser not to cache the pages.




3) what is action servlet? Read up on STRUTS.

A. Controller (ActionServlet class and Request Processor class): The controller receives the request from the browser, and makes the decision where to send the request based on the struts-config.xml.


4) How to call a method in the EJB from a servlet ? read up on EJBs
A.
1. Make A JNDI Lookup to get the Home interface in your Servlet's init() method.
2. Create the remote interface from your Home stub.
3. invoke your business methods on the remote interface within your doGet() or doPost() method.

5) How to get pop-up window while clicking on the button ?

Using some JavaScript code in Your HTML code.



6) which one is best amoung cookies,url rewriting,hidden fields,http seesion ? and why?

A. HTTP session. Because

-- it is more secured (due to privacy, data are kept on the server and not sent to the prowser. Only session id is sent to the browser).

-- HttpSession mechanisms gives better performance when compared to other mechanims because it stores the session data in memory and reduces overhead on network. Only session id will be passed between client and the server. But it does not scale well when the session data is huge and the concurrent number of users are more because of increase in memory overhead and also increase in overhead on garbage collection.

-- No limit on size of data that can be stored.

7) what is the difference between PrintWriter and jsp writer

A. The JSP abstract class is similar in some of the functionality found in java.io.PrintWriter classes, however it differs in that it throws java.io.IOException from the print methods which PrintWriter does not.The advantage of throwing an exception is that if your HTTP connection is broken for some reason, your JSP won't sit there trying to send characters to a broken connection.

Hope it helps. But as was suggested, learn the fundamentals by reading books/articles.


java j2ee job interview questions with answers | Learn the core concepts and the key areas
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by ak pillai:

6) which one is best amoung cookies,url rewriting,hidden fields,http seesion ? and why?

A. HTTP session. Because....


The question only asks "which is best" without saying "what for" or what conditions exist.
The only correct answer for an absurd question like this is "it depends".
All of the things mentioned serve different purposes. In some areas, those purposes may overlap but not enough to make a blanket statement, declaring one is better than the other.

It's like trying to answer the question: "Which is better, a brush, a roller, a pencil, or a spray can?".


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
ak pillai
author
Ranch Hand

Joined: Feb 11, 2006
Posts: 288
You are right Ben.

1. HttpSession
--There is no limit on the size of the session data kept.
--The performance is good.
--This is the preferred way of maintaining state. If we use the HTTP session with the application server´┐Żs persistence mechanism (server converts the session object into BLOB type and stores it in the Database) then the performance will be moderate to poor.

Note: When using HttpSession mechanism you need to take care of the following points:

--Remove session explicitly when you no longer require it.
--Set the session timeout value.
--Your application server may serialize session objects after crossing a certain memory limit. This is expensive and affects performance. So decide carefully what you want to store in a session.

2. Hidden fields

-- There is no limit on size of the session data.
-- May expose sensitive or private information to others (So not good for sensitive information).
-- The performance is moderate.

3. URL rewriting
-- There is a limit on the size of the session data.
-- Should not be used for sensitive or private information.
-- The performance is moderate.

4. Cookies
-- There is a limit for cookie size.
-- The browser may turn off cookies.
-- The performance is moderate.

The benefit of the cookies is that state information can be stored regardless of which server the client talks to and even if all servers go down. Also, if required, state information can be retained across sessions.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

My point is that you can't answer a question like that without asking more questions. He only asked 'what is better'. He never said, 'what for'.
You made the assumption that this was for simulating a statefull environment and stated the pros and cons of each.

What if the interviewer was talking about a 'remember me' feature that keeps a user from having to log into a site everytime they go to it?

What if they're talking about maintaing state for machines that don't support session cookies?

What if all that is needed is a way to pass a student id through a form without displaying it on the screen?


Suppose you were interviewing someone for a carpenter's position, and you asked him: "what's better, a hammer, a saw, or a screwdriver?".
Would you hire that person if he told you which was better, without inquiring about the actual task at hand? I would hope not.

It was either a stupid question or a trick question designed to see if the interviewee was really paying attention. In either case the question, as it was asked, didn't have a correct answer.



Also cookies (session cookies) and url re-writing are two of the ways that containers distinguish clients in order to maintain an http ession.
This is another reason why it is absurd to ask whether either is better than an http session; They are part of an http session.
 
wood burning stoves
 
subject: some interview questions