Sahid Khan

Ranch Hand
+ Follow
since Jun 27, 2007
Merit badge: grant badges
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sahid Khan

For a second request from a different browser, will a unique session id be created?

I think more appropriate question to be asked, is "will server create a new session for second request"?
First of all server will not know whether it's second or first request. For server, every request is afresh. But to make the request-response conversational, server creates a http session and attaches a unique id for that session with the particular response. And server does it implicitly by setting a cookie. So when a request comes in, server will check if there is any session id with the request, if not server will create one.

Does that help?
maybe I am saying same thing again and again, but I find it difficult to put it in any other way .

Did you read this ?

In java there are three kinds of Exceptions:
1. Error
2. RunTimeExceptions
3. Exceptions (but not RuntimeExceptions)

First two kinds of exceptions are called unchecked exception, whereas third kind of exception is called checked exception. The reason being, compiler forces you to anticipate/handle checked exception. So if your code throws third kind of exceptions, you must catch them or throw them explicitly.

15 years ago
Hi Padma priya,

Session is totally a server side object. When a client sends a request. Server checks if there is any sessionid attached with the request.
For server every request is different, it doesn't matter if it is coming from same browser, different browsers or different machines.
Server only looks for a sessionid in the request. If it finds one, it knows this request is part of which session, if not it creates a new session and attaches with the request.

Basically, when you call request.getSession(), container creates a session and attaches with that request, that is if the request is not already associated with any session. While sending the response, container adds a cookie which contains the sessionid. Now when the user sends next request, container gets the sessionid from cookie, and retrieves the session it created in first request.
perhaps, you can use jmimemagic
15 years ago
I do not know why this error is coming for you. With version >= 1.5 this autoboxing should work. And for you version is showing 1.5.
To use source in place of

C:\SCJP Samples\Chapter3>javac


C:\SCJP Samples\Chapter3>javac -source 1.5

ah.. that is strange! It compiles fine with me! While compiling, are you using any argument called source? In fact for me the error comes only when I use javac -source 1.4.

Can you try with javac -source 1.5
It's not clear what is your problem? Do you want to reverse a string? However..

String does not have any method to reverse itself. But StringBuilder has a reverse function, refer to the apidoc.

String has a method length() which returns length of it, refer to the apidoc.

The code you have given, has no such method called length()?
15 years ago
what error you are getting? Which version of jdk you are using?
yes output will be aaabbb.
To know why you need to understand the difference between <% %> and <%! %>
<% %> is scriplet which appears inside jspService method as it is. Whereas <%! %> is a declaration which acts like instance variable declaration. So here you hide the variable "a" and "b" locally.
In fact compiled java file will look like..

request.getSession(false) will return a session if there is any session associated with the requested, if not it will return null.

request.getSession() will create a session if there is no session associated with the request. request.getSession() is same as request.getSessin(true)

I hope you know, ?: is a conditional ternary operator in java. It uses boolean value of the first operand to decide which of two other expressions should be evaluated. If first expression is true, second expression is evaluated, otherwise third one gets evaluated.

So (flag)? true:false is equivalent to just flag.

15 years ago
let me add my 2 cents

spec says return statement with an expression, first evaluates the expression and then tries to return the value of the expression. But if there exists any associated finally block, it executes that before returning. So when you are returning some immutable object or primitive, changed value in finally block will not be reflected in return value, since that is already computed. For the same reason if you return some (immutable/mutable) object o and assign some other object in o in finally block, then that will also not be reflected in return type.

I hope all this make sense. thanks.
[ August 20, 2007: Message edited by: Sahid Khan ]

oops...I realized my mistake, as I was explicitly initializing the static variables (though to their default values), they were not getting overridden.

Actually they were getting overwritten by variable initializer.

is in some sense similar to

So what happens, the values modified in the constructor get rewritten by initializer which comes after the invocation of the constructor.

Another work around can be calling the constructor after the variable initializer. Like this..

15 years ago