which one is to use when?
give some examples
Q2: Which is more advantageous Abstract Class or Interface?
Q3: Can we execute servlet or JSP without using container? What is the difference between Web Server and Container
Q4: If the constructor is declared private what will happen?
Q5:how we can change the context-innitialization parameters before stopping the server?
Answer 1: No Idea
Answer 2: Interface is more advantageous than abstract class because Inteface provide strong polymorphism.
Answer 3: we can not execute either servlet or jsp without container because it is the container which call the lifecycle methods of servlets and jsp; the difference between web server and container is web-server contains container the request from the client first of all goes to web server then server passes the request to the container.
Anser 4: if the constructor is declared as private then we can not call that constructor in the subclass constructor.
Answer 5 and Answer 6: No idea
please do reply where i am wrong in answerd questions
also do reply the questions in which i m having no idea
Campbell Ritchie wrote:That is a very poor equals method. Please explain why it will give inconsistent and possibly incorrect results.
deca leni wrote:
insert this method inside the class
but as I know hash code also must be overide to take effect this.
I gave this code according to match your previous code.so it is not code that can give good result .I have shown only way of overriding it.
Really? If you tried your equals method like this, you would doubtless get the wrong result. Even after you get it to compile, by putting "o" in the appropriate location. I think you have unbalanced () too.
deca leni wrote:public boolean equals(Object o) method is used to check if the tow object are meaningfully equal .so if we check more instant variable equality then we get the exact result.
The idea of the equals() method is to allow you to define circumstances under which two objects are regarded as equal. you should by now know that using the == operator on reference types will produce inconsistent and misleading results. It is even worse with Strings because they are interned. Try serialising two A objects and comparing them for equality before and after serialisation. You will then see how your equals() method becomes inconsistent.
And it is poor style to write if (...) return true; else return false;
deca leni wrote:what do you mean by serializing. you mean implementing the Serializable interfaces.but as I know, Serialization involves saving the current state of an object to a stream, and restoring an equivalent object from that stream.for an object to be serialized, it must be an instance of a class that implements either the Serializable or Externalizable interface.here we are not going write this object to a file.so we don't want to implements Serializable interface as I think.
so if it is not what you mean.
then tell me about what you mean by serializing and how it involves with equals() write the correct Code to get the good result
Why are you quoting Java 1.4.2 documentation?
deca leni wrote:String class
And what has serialisation to do with it? Well, try this modification . . . and as you know, serialisation and deserialisation produces an object identical to the original. So you can tell what the result of the second printf statement will be . . .
By the way: only use spaces, not tabs for indentation. And your if(...)return true; else return false; is very poor style. It should read
And we haven't been anywhere near the hashCode method yet.
Campbell Ritchie wrote:
. . .
and as you know, serialisation and deserialisation produces an object identical to the original. So you can tell what the result of the second printf statement will be . . .
hey your serialisation and deserialisation is not perfect as I know.
try this and see what has happen
Not sure, but I think canEqual() is a non-standard API method, which one of those sites describes.
Also have a look at these two methods expected to be available in Java7, which Rob Spoor drew my attention to.
Why getting rid of the if(...) return true; else return false; is good style? Look here. I don't follow all those conventions, but that one is good.
How would I write that equals() method? Like thisNote
Ans2: Depends on which sense you mean "ADVANTAGEOUS" . But the rule is, if you implement an interface, you have to implement ALL the methods provided by it. If using Abstract class - provide definition for only those your class needs.
Ans4: The class can't be instantiated. - other words , NO OBJECT CAN BE CREATED FOR THE CLASS. This is the basic idea of singelton pattern. Only one object will be created and everytime you need an object of the class, you use an accessor method (some get() method) to return you the instance.
Have a look at my Blog
What do you mean about multiple inheritance DIRECTLY? Java™ doesn't allow multiple inheritance directly, indirectly, vertically, obliquely, tangentially, ethereally, horizontally or anythingelsely.
I am afraid I disagree with you about No 4. You can instantiate a class with a private constructor. And it doesn't have to be a singleton. There is something else you can't do with such a class, however.
Not convinced. All the methods must be implemented in a concrete class. In an abstract class, you would provide implementations of those methods which are unlikely to change in subclasses. Those which are likely to be different in subclasses should be left abstract. And we have an FAQ or two about abstract classes.
Dic pari wrote: . . .
Ans2: . . . If using Abstract class - provide definition for only those your class needs.
. . .
. . . Agreed... I meant to say, if the subclass is going to provide an implementation of the method, leave it abstract in the Parent class (Abstract class).
Campbell Ritchie wrote:Not convinced. All the methods must be implemented in a concrete class. In an abstract class, you would provide implementations of those methods which are unlikely to change in subclasses. Those which are likely to be different in subclasses should be left abstract. And we have an FAQ or two about abstract classes.
Dic pari wrote:Ans2: . . . If using Abstract class - provide definition for only those your class needs.
. . .