1> I have a Employee class with six employee objects{e1,e2,e3,e4,e5,e6} added to it.How do i sort it using Tree Set ?Code example please
2> What is load factor in HashMap.?
3> Can i subclass a singleton class ?
4> what is lazy loading of Servlets ?
5> how do you intialize a session in Servlets ?
6>what is the pros and cons os using jsp:use bean tag
7> what is scope in use bean tag
8> give an example where you can use DynaAction form.Code example please
Thanks and Regards,
Deepak Lal
When The Going Gets Tougher,The Tougher gets Going
Rob,i will be thanful if you help me this time.because few of the answers to questions are confusing and im unaware of the correct answer.Need help Ranchers
Try posting your answers to the questions once you've done some research--if you have specific questions about anything you discovered we'll be happy to help!
Something about posting eight questions in a single post on topics which are relatively well covered makes me less inclined to give large amounts of time responding. But I will however direct you to another post which 1/8th of your post was inquiring about.
Bobby Smallman wrote:Something about posting eight questions in a single post on topics which are relatively well covered makes me less inclined to give large amounts of time responding. But I will however direct you to another post which 1/8th of your post was inquiring about.
Deepak Lal wrote:2> Can we subclass singleton class ...Please help me ?
Why don't you write a simple singleton class - there are plenty of examples of how to do this here on javaranch and elsewhere - and then write a second class that extends it. Then see if it compiles. If it does then see if it runs. Then you have your answer.
David Newton wrote:I'm still not satisfied with the level of effort shown, and this still smacks *loudly* of homework and/or interview questions.
Regarding TreeSet: have you read the documentation? If not, go do so now. If you have, what does it say about ordering and the iterator?
1> David i have read the documentation of TreeSet and it says you need to implement Comparator interface and thats what i have done in the code..Could you please please render help.
2> Regarding subclassing a singleton class,it gets subclassed.but i want to know why it is possible because a singleton by definition itself gives a single instance of class which has a private constructor,so whats the use of
subclassing a singleton class.Please clarify me on this point ?
//I'm stuck here.can you help me out now
SortedSet s = Collections.synchronizedSortedSet(new TreeSet());
// i dont know how to proceed at this step.Please help me now.
you were looking for a example of sorting using TreeSet, but the line you are stuck ,indicates you are trying to synchronize access to your treeSet
Deepak Lal wrote: 1> David i have read the documentation of TreeSet and it says you need to implement Comparator interface and thats what i have done in the code..Could you please please render help.
Help with what? If you have a comparator, and you have a TreeSet, it's sorted. Re-read the documentation.
Joanne Neal
Rancher
Joined: Aug 05, 2005
Posts: 3011
9
posted
0
Deepak Lal wrote:Regarding subclassing a singleton class,it gets subclassed.but i want to know why it is possible because a singleton by definition itself gives a single instance of class which has a private constructor,so whats the use of
subclassing a singleton class.Please clarify me on this point ?
Show us the code for your singleton class and subclass.
A constructor will always call a constructor from its super class. This is called constructor chaining. But to be able to call that constructor it must be visible for the subclass. Private constructors aren't.
Joanne Neal
Rancher
Joined: Aug 05, 2005
Posts: 3011
9
posted
0
Deepak Lal wrote:Singleton class and subclass -->Can you check whats wrong.
You've correctly implemented a singleton class and when you tried to write another class that extended it you got an error.
Your original question was
Deepak Lal wrote:Can i subclass a singleton class ?
So, based on what you found, what do you think the answer is ?
Although that allows you to subclass a class it will no longer be a singleton - the class can be instantiated from anywhere. Singletons that are designed to be subclassed usually have protected constructors.
Joanne Neal
Rancher
Joined: Aug 05, 2005
Posts: 3011
9
posted
0
Rob Prime wrote:Although that allows you to subclass a class it will no longer be a singleton - the class can be instantiated from anywhere. Singletons that are designed to be subclassed usually have protected constructors.
I wasn't talking about the constructor in the singleton class.
Deepak said that the reason you couldn't subclass a singleton was because the constructor in the subclass was private. I was just suggesting he tried making it public and he would have noticed that it made no difference i.e. the access modifier of the subclass constructor has nothing to do with not being able to extend a singleton class. It is, as you said earlier, the fact that the singleton class constructor is private that means you can't extend it.
Hi Rancers and Bartenders,
I have few queries in Java Collections framework as well.
1>Suppose i have 5 elements added to a ArrayList and Vector.? suppose i now add 6th element to ArrayList and Vector.How will it be internally added in both the cases.Please explain
2>In which scenario would i use a List and a Map except for the normal differences being that list is being used for sequential addition of elements and Map is for (Key,Value) Pair ?
Deepak Lal wrote:1>Suppose i have 5 elements added to a ArrayList and Vector.? suppose i now add 6th element to ArrayList and Vector.How will it be internally added in both the cases.Please explain
In your JDK folder there is a file called src.zip. Unpack it, then look for files java/util/ArrayList.java and java/util/LinkedList.java. That's the source of these classes.
2>In which scenario would i use a List and a Map except for the normal differences being that list is being used for sequential addition of elements and Map is for (Key,Value) Pair ?
You've already given the answer yourself, haven't you?
1> i asked for ArrayList which implies ArrayList.java and i asked for Vector ,does the Vector implementation refer to LinkedList.java as you have pointed out.
2> More differences,The interviewer was not happy with this answer,He wanted more differences from a realistic point of view.he said thats a common answer.
Deepak Lal wrote:1> i asked for ArrayList which implies ArrayList.java and i asked for Vector ,does the Vector implementation refer to LinkedList.java as you have pointed out.
Sorry, that should have been java/util/Vector.java of course.
Rob,
what about the answer to second question.COuld you help me with that please. More differences required with respect to List and a Map.
Regards
Deepak Lal
I believe that searching around in this forum, Beginning Java, the Java tutorials and Google, you should be able to find more than enough answers on that question. We do require everyone to ShowSomeEffort.
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32830
4
posted
0
Rob Prime wrote: . . . We do require everyone to ShowSomeEffort.
Deepak Lal: this site is not some sort of substitute for your reading your textbook, turning up to lectures, looking at web tutorials, or doing any work at all.