Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!

Dragos Nica

Ranch Hand
+ Follow
since Oct 25, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Dragos Nica

vijay tidake wrote:But ,Why line 6 is giving me the values as 1.0 1.0

If Im printing the objects it should give me something like Double@hashcode, right.


And if you print the hashcode for both the 'd' and 'e'.They are same




Maybe because Double provide a default implementaion of method toString() that return the value...

Matthew Sessoms wrote:Sure, thanks for the reply.




Your implementation for compareTo is not complete. You checked only if two objects of type AggTuples are equals or not, but the implementation of compare To should be able to provide addtional info as which object should be inserted before another, because lements inside a treeSet should be sorted.

This is a possible implementation of compareTo:

Parag P Kulkarni wrote:hi,

I understand the explanations and thank you for that; but I am still confused about one thing....

I have a function "addString(List<? super String> myList) and inside I am adding few String to myList. But when I try to traverse through the list (using enhanced for loop "for (List s: myList)", I am getting compiler error stating following
Type mismatch: cannot convert from element type capture-of ? super String to String

I also tried to use ArrayList like below


But still its throwing compiler error. How would I print what is added?




You get the compilation error, because "myList" reference has type List<? super String>, this means that your method addString can get as a parameter a list of String or a list of supertype of String.
It is not important that inside the method you create an instance of type ArrayList<String> and myList is pointing to it, because the compiler is looking what is the type of myList and it is List<? super String>, so as far as compiler is concerned <? super String> is not <String>

You have two posibilities:
- use a reference of type Object inside enhanced for to iterate through myList elements.
- inside addString method use a different reference not myList.

Campbell Ritchie wrote:Was it line 92? That compiler obviously can't count.



I think it was at line 107, closing bracket for function print()
9 years ago

Andreas Svenkson wrote:Hi guys.

I've been playing around a bit with the CLASSPATH env variable and the command line option and I've come to a conclusion, for which I would like to have confirmed if it is unversal or not (across different OSes).

Basically, I have found the following to be true, for both java and javac:

1) If -cp / -classpath is used at the commandline it will override the CLASSPATH env-variable (no news, this is true according to K&B too).
2) If -cp / -classpath is NOT used, and CLASSPATH is set, this will (obviously) be the classpath used.
3) If neither of the above are used/set (CLASSPATH is not set, nor is -cp used at the command line) then the classpath will default to your current working directory.

Number 3 has caused me a little headache. Since I had no idea it would be set to the current workingdirectory under the aforementioned circumstances, I kept wondering how the heck the class files could be found. This is also the rule I would like to have confirmed.

Basically, imagine we are given a test-question where CLASSPATH is not explicitly set, and nor is -cp/-classpath used. Is it then guaranteed that the current working directory will be used as classpath? Is this a guaranteed behaviour across different plattforms?

Regards,
Andreas.




Your first 2 points are correct.
For 3rd, thinks are a little bit different. Your assumption is correct but only for javac. If neither CLASSPATH env variable is set, nor command line -classpatch/ -cp is used , the java command will return an error as by default it doesn't "look" into working directory. This should be specified explicitly.

Regards,
Dragos

Maybe I don't understand correctly your question , but how do you expect to return TRUE when you didn't put that key into the map?
You put it into hMap and you verify if it exist in map?





You get a "1" at the end , because you typed an ENTER after last line in file dvdinfo.txt
Double check your file to be sure there is no newline char after last line.
You can do something like this:

using a new temp variable that is incrementing for each iteration:

Hi Chinmaya,

Thanks for your explanations but I already tried this and don't work for me.
As I said in my previous post:

4)
- I've set an attribute in request scope (this is done by a servlet before forwarding the request to the JSP
- In JSP I put only
+ getProperty
- Result is org.apache.jasper.JasperException: jsp:getProperty for bean with name 'person'. Name was not previously introduced as per JSP.5.3

Could be container dependent?

Thank you
I cleared the browser's cookies before test it.
It is exactly how Ankit explained above.

Thanks guys for explanations
This work, but at the end we have two cookies with the same name and same values.
After the browser restart, the original JSESSIONID cookie is deleted and the other one is used that it's fine and is exactly what we wanted.
The strange behavior is having 2 JSESSIONID cookies before browser restart.Is it the normal behavior?

Thanks!
Thanks Ankit. Understood now ..
Still is confusing why after setting the maxAge of the JSESSIONID cookie to a bigger value, we are seeing two cookies in the browser with the same name , same value ..
After browser restart there is only one and container uses it.
It's interesting

Thanks you!
Hello rancers,

I'm learning about sessions and cookies and I'm doing many examples in order to understand better.
I know that sessions and cookies are two things completely different, I know that sessions are "server side"

As we know when we want to create a new sessions we use request.getSession() and the container takes care of the rest ( creates a new session if one doesn't already exist, create a cookie and puts the session into the cookie, and then adds the cookie to the response object.

My question is how can we set the age for the cookie that contain the information about session id ? Is that possible? all this work is done by the container.
I know that the default age for a cookie is -1 that means that cookie will be deleted when the browser is closed.

The scenario that I tied is the following:
- in the servlet I put
HttpSession sess = request.getSession()
sess.setMaxInactiveInterval(5*60);

the container takes care for creating the session and adding the session Id to a cookie.
The session will be active on the server for 5 minutes.

If I close the browser and open it again the cookie that contain the sessionId information is deleted (but on the server side the session is still active 5 minutes)
How can I set the maxAge for the cookie thus it should "persisit" when I close the browser?

Hi guys,

I'm bringing this thread of discussions back to live
I read this topic many times and tried lot of different tests but I still don't understand some aspects. Here are some of my tests and their results:

1)
- I've set an attribute in request scope (this is done by a servlet before forwarding the request to the JSP
- In JSP I put in this order:
+ getProperty
+ useBean with scope set to request
- Result : Everything worked fine and the name of the person was displayed

2)
- No attribute set in any scope in servlet
- In JSP I put in this order:
+ getProperty
+ useBean with scope set to request
- Result: Null pointer exception

3)
- No attribute set in any scope in servlet
- In JSP I put only
+ getProperty
- Result rg.apache.jasper.JasperException: jsp:getProperty for bean with name 'person'. Name was not previously introduced as per JSP.5.3

4)
- I've set an attribute in request scope (this is done by a servlet before forwarding the request to the JSP
- In JSP I put only
+ getProperty
- Result rg.apache.jasper.JasperException: jsp:getProperty for bean with name 'person'. Name was not previously introduced as per JSP.5.3

From the above results i conclude that:
- In neighter cases I can use only getProperty without a useBean . See 3) 4)
- I don't understand why first experiment worked properly ( point 1) as the object named by the name had been “introduced” to the JSP processor using the
jsp:useBean after I used jsp:getProperty . This is in contradiction with what specs says. How does the container know that there is an object named
"person" because it was "introduced" later?Does it use somethink like a "forward reference" and manage to "sees" the object ?


Chinmaya Chowdary wrote:
We can use jsp:getProperty without using jsp:useBean. All we have is set the specified attribute in any one of the scopes(application, session, request, page).



Can you please give an example to confirm your statement?

thanks a lot!