SIDE-BANNERSIDE-BANNER * Oh God! Let there be PEACE. Make them calm, gentle, humble and stable. Make them realize their mistakes. Make them to confess, seek and pray for forgiveness. Let there be forgiveness for true hearts. Show them the right path on which they can walk. Let there be justice, satisfaction and happiness. Let them know that you are the justice and truth. Let them know that the innocent is never punished. Give them the strength, courage and wisdom to quit bad and to achieve good purpose. Let there be leaders who are followed by goodness. Make them competitive to achieve good. Remove their greed, wickedness and bad ambitions. Let them know that your love is infinite. Speak to them in simple ways so they understand. May your heart hear their pure hearts. * Never say die.Live and let live.* Accept Good if not, it Perishes.* What you Sow is what you Reap.* United we Stand divided we Fall.* Where there is a Will there is a Way.* Love is the strongest Power on earth.* When going gets Tough the Tough gets going.* For every problem created there is a perfect Solution.* When your hand starts paining you don't Cut it, Cure it.* A good purpose of life is the persistence to be constructive.* The arch of justice is wide, but it bends towards freedom and justice.* Lion king says he wants all the Power but none of the Responsibilities.* Life is a puzzle which can be solved by Hard work, Character and Discipline.* Money is like Manure, Spread it and it does good.* Pile it up in one place and it Stinks.* When a man wants to be a King he should exactly know the responsibilities of a King.* The only thing necessary for evil to triumph is for good men to do nothing - Edmund Burke.* Face is the reflection of mind.* A purpose of life is a life of purpose.* Beauty lies in the eyes of the beholder.* Necessity is the mother of all inventions. Real friends are those who help us in troubles.* Freedom and Power are lost if it’s miss utilized. Repeating mistakes will lead to sin and blunders.* Quantity is appreciated only when it has Quality.* Everyday is a new day, which brings hope with it.* Ego of superiority is the destruction of individuality.* We cannot learn to swim without going into the water.* Everything happens for good and thus leads to destiny.* Every problem has a perfect solution, we need to find them.* A good purpose of life is the persistence for constructiveness.* It’s hard to create good things where as it’s easy to break them.* Ideas are appreciated and respected only when we express them.* Mistakes do happen by humans, they are forgiven when we pray.* Freedom means giving others the right to achieve good purposes.* We have to put our efforts and leave the rest for destiny to decide.* All big things start with a first step.* First step is sometimes difficult.* Prayers come true when the purpose is good, thus pray for everyone.* Dreams come true when we have faith and pray for good things in life.* We got to have strength, courage and wisdom to achieve good things in life.* Every relationship has a meaning; we have to give them the proper meaning.* The only thing necessary for the triumph of evil is for good men to do nothing.* If wealth is lost, nothing is lost. If health is lost, something is lost. But, if character is lost, everything is lost.* “Stand up, be bold, be strong. Take the whole responsibility on your own shoulders, and know that you are the creator of your own destiny.” - Swami Vivekananda.
HOME-PAGEREALIZATIONQUOTESPUZZLESPRAYERSPERCEPTIONSMUSIC-DOWNLOADSTORIESJOKES
BOOKSBITTER-TRUTHANCIENT-SCRIPTURESBEAUTIFUL-LIFETHOUGHTSFRIENDSHIPPRAYERS-TO-WORSHIPWinning-Publications

QUANTITY is appreciated only when it has QUALITY. Recitation is the mother of Memory. Necessity is the mother of Invention. Knowledge grows when distributed. Enrichment for Information Technology. Persistence to be constructive is the key to success.

Thursday, February 14, 2008

CORE-JAVA (Abstarct, Interface)

*[READ: Why-JAVA] *[Start-Learning-JAVA] *[Why-Java's-Hot] *[Start-Using-LINUX] *[Java-Q-&-A] *[Question] *[Java-SE-6-Doc] *[Struts-Doc] *[Java-Tutorial-Index] *[Java-Certification]
*[Tech.] *[Struts.] *[Servlet.] *[JSP.] *[EJB.] *[JNDI-JMS] *[SQL.] *[JDBC.]
CORE-JAVA: *[OOP] *[CLASS] *[ABSTRACT] *[EXCEPTIONS] *[THREADS] *[UTILS] *[PACKAGES] *[JVM] *[CASTING] *[NETWORKING] *[RMI-XML] * Add to Google

* What is the difference between an Interface and an Abstract class?
* [INTERFACE] An Interface can only declare constants and instance methods, but cannot implement default behavior.
All the methods and properties defined in Interface are by default public and abstract.
Interfaces are recommended to be used when something in design will change frequently
We use abstract class and Interface for the base class in our application.
An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class.

* [ABSTRACT] An abstract class can have instance methods that implement a default behavior.
An abstract class is a class that is declared abstract.
It may or may not include abstract methods.
An abstract method is a method that is declared without an implementation (without braces, and followed by a semicolon). Ex: abstract void moveTo(double deltaX, double deltaY);
Abstract classes cannot be instantiated.
Abstract classes can only be subclassed.
If a class includes abstract methods, the class itself must be declared abstract.
Ex: public abstract class GraphicObject {
// declare fields and non-abstract methods
abstract void moveTo(double deltaX, double deltaY);
abstract void draw(); } (compile online)
An abstract class may have the usual flavors of class members (private, protected, etc.)

* What modifiers are allowed for methods in an Interface? (Interface)
A: Only public and abstract modifiers are allowed for methods in interfaces.

* What is meant by "Abstract Interface"? (Interface)
A: First, an interface is abstract. That means you cannot have any implementation in an interface. All the methods declared in an interface are abstract methods or signatures of the methods.

* Why it is not recommended to have instance variables in Interface. (interface)
By Default, All data members and methods in an Interface are public. Having public variables in a class that will be implementing it will be violation of the Encapsulation principal. Although its possible to have variables.

* What are the characteristics of an interface? (interface)
An interface can extend any number of interfaces. (Ex.)
public interface GroupedInterface extends Interface1, Interface2, Interface3 {
--// constant declarations
are implicitly public, static, and final. (cannot be private)
--double E = 2.718282; // base of natural logarithms
--// method signatures
are implicitly public (cannot be private)
--void doSomething (int i, double x);
--int doSomethingElse(String s); } (compile online)
If access specifier is not indicated before an interface as public, then by default the interface will be accessible only to classes defined in the same package as the interface.
All methods declared in an interface are implicitly public, thus the public modifier can be omitted.
An interface can contain constant declarations. All constant values defined in an interface are implicitly public, static, and final. Thus, specifying these modifiers in the code can be omitted. Interfaces can have inner classes.

* What must a class do to implement an interface? (interface)
It MUST implement all of the methods of the interface and identify the interface in its implements clause. All methods defined by that interface must appear in its source code.

* What modifiers may be used with an interface declaration? (interface)
An interface may be declared as public or abstract or default (no modifier).

* Can an Interface be final? (interface)
No, an Interface cannot be final, private or protected. It can only be either public, abstract or default (when access is not specified). Public is available in any package, and default is in the same package.

* Can an Interface have an inner class? (interface)
Yes it can. Ex:
public interface abc
{ static int i=0; void dd(); // constant variable and public method.
class a1 // it cannot be private
-{
--a1()
---{ int j; System.out.println("inside"); };
--public static void main(String a1[])
---{ System.out.println("in interfia"); }
-}
}
(compile online)

*
What is an abstract class? (abstract)
A: Abstract class MUST be extended/subclassed. It serves as a template.
An abstract class must NOT be instantiated (ie, you may not call its constructor)
Abstract class must NOT be declared as PRIVATE or FINAL.
An abstract class MAY contain PRIVATE and STATIC data.
Any class with an abstract method MUST be declared as abstract.
An abstract method must NOT be PRIVATE or STATIC.
An NON-abstract method MAY be PRIVATE STATIC or public.
This prevents it from being instantiated but non-abstract methods can be used in its inherited subclasses. (Ex:)
abstract class Abstract1 { // cannot be private
--private static int x, y; // private static variable.
--private static void moveTo(int newX, int newY) { // private static method.
---System.out.println("in abstract class, non-abstract method"); }
--abstract void draw(); // cannot be PRIVATE or STATIC.
}
(compile online)
Note: non-abstract methods can be static but not abstract methods.

* Can we make an instance of an abstract class? For example - java.util.Calender is an abstract class with a method getInstance() which returns an instance of the Calender class. (abstract)
A: No! We cannot make an instance of an abstract class. An abstract class has to be sub-classed. If we have an abstract class and we want to use a method which has been implemented, we may need to subclass that abstract class, instantiate our subclass and then call that method.

* Can an abstract class be final? (abstract)
An abstract class may not be declared as final NOR private.

* Can there be an abstract class with no abstract methods in it? (abstract)
Yes, it is possible.

* What is an abstract method? (abstract)
An abstract method is a method whose implementation is deferred to a subclass.

* What does the "abstract" keyword mean in front of a method? A class? (abstract)
Abstract keyword declares either a method or a class.
Abstract method may have only arguments and return types.
Abstract methods act as placeholder methods that are implemented in the subclasses.
Abstract classes can't be instantiated.
If a class contains any abstract method it must be declared as abstract.

* What does it mean that a method or class is abstract? (abstract)
An abstract class cannot be instantiated. Only its subclasses can be instantiated. You indicate that a class is abstract with the abstract keyword like this:
public abstract class Container extends Component {
Abstract classes may contain abstract methods. A method declared abstract is not actually implemented in the current class. It exists only to be overridden in subclasses. It has no body. For example,
public abstract float price();
Abstract methods may only be included in abstract classes. However, an abstract class is not required to have any abstract methods, though most of them do. Each subclass of an abstract class must override the abstract methods of its superclasses or itself be declared abstract.

* Can an ABSTRACT class implement an INTERFACE?
Yes we can! It is possible, to define a class that does not implement all of the interface methods, provided that the class is declared to be abstract. For example:
abstract class X implements Y { // implements all but one method of Y }
class XX extends X { // implements the remaining method in Y }
Note that class XX is not abstract, thus it has to implement all methods of Y.

* Can an nested Anonymous class be declared as implementing an interface and extending a class? (interface) (nested)
An anonymous class may implement an interface OR extend a superclass, but may NOT be declared to do BOTH.

* How can we take decision about when we have to use Interface and when Abstract Class? When should we use both? Interfaces and abstract classes seem superficially to provide almost the same capability. How do we decide which to use?
* ABSTRACT class is a abstract view of any real word entity and INTERFACE is a more abstract one. When we thinking about the entity there are two things one is intention and one is implementation. Intention is we know about the entity and also may have the idea about its state as well as behavior but don't know about how its looks or works or may know partially. Implementation means actual state and behavior of entity.
Consider this example. In a Content Management System where CONTENT is a generalize form of ARTICLES, REVIEWS, BLOGS etc.
So CONTENT is our base class now we have to decide whether CONTENT class should be an ABSTRACT class, INTERFACE or REGULAR class.
Consider REGULAR class vs other types (abstract and interface). If CONTENT is not a core entity of this application. As per the business logic if ARTICLES, BLOGS and REVIEWS are the core parts of business logic, then CONTENT class should not be a REGULAR class because we will never make instance of that class. Thus ABSTRACT class and INTERFACE are the more appropriate choices.
Between Interface and Abstract Class.
As we can see CONTENT having behavior method named PUBLISH. According to our business logic if PUBLISH is having some default behavior which is applicable to other classes then we prefer CONTENT class as an ABSTRACT class. If there is no default behavior for the PUBLISH and if every drive class makes its own implementation, then there is no need to implement PUBLISH behavior in the base class, thus we prefer INTERFACE. These are the in general ideas of deciding between ABSTRACT class, INTERFACE and REGULAR class.
If we make CONTENT class as INTERFACE then it is difficult to make changes in the base class, as if we add a new method or property in CONTENT interface then we may have to implement this new method in every drive class. These problems may be avoided if we are using ABSTRACT CONTENT class and the new method is not of an ABSTRACT type. So we can replace INTERFACE with ABSTRACT class. This will restrict the multiple inheritance of the base class.
CAN-DO and IS-A relationship will also define the difference between INTERFACE and ABSTRACT class. As discuss INTERFACE can be use for multiple inheritance. For example if we have another INTERFACE named ICOPY which is having a behavior method named COPY and if every drive class has to implement its own implementation of COPY. If ARTICLE class is derived from ABSTRACT class CONTENT as well as ICOPY then ARTICLE "CAN-DO" COPY also.
IS-A is for "generalization" and "specialization". If CONTENT is a generalized form of Articles, Blogs, Reviews and if Articles, Blogs, Reviews are a specialized forms of CONTENT. So, ABSTRACT class defines core identity. If we are thinking in term of speed then ABSTRACT is quicker then INTERFACE, as interface requires extra in-direction.
As per the example, as ABSTRACT class is having upper-hand if compared to an INTERFACE. The only advantage of INTERFACE is multiple inheritance.
An INTERFACE facilitates us to start from scratch to implement our interface in some other code whose original/primary purpose was quite different from our interface. For others, our interface is only incidental, something that has to be added on to the their code to use our package.
An ABSTRACT class, in contrast, provides more structure. It usually defines some default implementations and provides some tools useful for a full implementation. It may be inconvenient to extent the class if the programmers using our package who have already developed the class hierarchy. As in Java, a class can inherit from only one base class.


*Read:
*[ Religion of the Universe.] *[The piercing-of-the-ears-(Karnavedha).] *[Nature-Cure/Therapy.]

"WE" has More Power than "I". Please leave a comment if you encounter any problems or have any suggestions.

Read: Peace Home Download Music Prayers Life Is Beautiful
The Bitter Truth.
*Duty, Responsibility, Law and Order. *"Happy Kingdom" proudly proclaimed as "Paradise" *Trying to learn something for the first time. *Time is the only solution. *For every Action there is an Equal and Opposite Reaction. *Logic of Good and Bad. *Duties, Responsibilities verses Luxuries and Pleasures. *Beggars!

No comments:

About Me

My photo
Simple guy who believes in being Competitive rather than being Ambitious. Persistence to be constructive, without frustrations, is a good purpose of life.
.

* * * * * * * * * * * * *

MeetUp Message Board:
Read: Wishes-and-Prayers. *Issue-of-Illegal-Immigration-&-Happy-Kingdom. *The-New-York-Hillary-Rodham-Clinton *Cast-God-Religion! *Barack-Obama-Meetup *Duty- Responsibility-Law-and-Order *John-Edwards-One-America *Good-Wishes-Life-is-Meaningful-&-Beautiful *Dennis-Kucinich-Meetup *Let-there-be-peace! *Bill-Richardson-for-President-2008 *Logic-of-Good-and-Bad-convert-bad-to-good *MORAL-STORY-Elephants-held-by-small-ropes.
* * * * * * * * * * * * *

Realizations.
*Realizations-In-Real-Life-Please-be-gentle-and-humble. *Manoj-D-Kargudri. *Amazing-Constructive-Vibrations. *Astrology. *Creating-Leaders. *How-ideas-are-concluded-and-decisions-are-materialized. *“Relationships-in-Life”-“Partnerships-in-Life”. *The-path-of-victory-the-path-of-life-winning-in-looseing. *An-attempt-for-definition. *Speak-with-a-heart. *These-are-contagious. *Key-to-happy-kingdom. *MIRACLES. *Better-to-create-one! *Cast-God-and-Religion! *Manoj-Kargudri. *Things-become-inevitable! *We-are-all-looking-for! *Phase-of-Life. *Destiny-Karma-and-God. *Struggle-perfection-and-Money. *Independence-and-Freedom. *Relationships-and-Happiness.
* * * * * *

Quotes.
*Love-Compassion-Tolerance-Forgiveness-Courtesy. *Manoj-D-Kargudri. *True-to-Heart-going-back-to-Basics!
* * * * * *

Puzzles-Riddles-Think.
*River-Crossing-Puzzles-Brain-Teasers. *Manoj-Kargudri. *Perpetual-Motion-Gravity-and-Kinetics. *Illusions-Paradoxes-Perpetually-ascending-staircase. *Milk-man-with-no-measureing-jar. *Amazing-Horoscope-Mind-Reader. *Find-the-hidden-images-in-these-STEREOGRAMS. *Are-they-12-or-13? *What-would-U-do? *ABCD-Four-Digit-Number. *10-Digit-Number. *4-QUESTIONS...GOOD-LUCK! *Think-Wise.
* * * * * *

Prayers.
*God-gave-us-everything-we-ever-needed. *Good-Wishes. *Manoj-Kargudri. *Love-Compassion-Tolerance-Forgiveness-Courtesy. *Interview-With-God! *He-is-the-one! *Candle-of-Hope! *Let-there-be-Peace! *Manoj-Kargudri.
* * * * * *

Perceptions.
*Issue-of-Illegal-Immigration. *To-which-religion-does-this-universe-belongs-to? *Law-and-order-helps-to-maintain-justice. *Implementing-regulations-by-justice. *Putting-our-sincere-efforts. *Religion-and-cast. *Impact-of-reservation-based-on-religion-and-cast. *Free-and-Fare-Education-system-Electoral-system.
* * * * * *

Stories.
*The-Monkey’s-Justice-for-two-cats. *The-Blind-Men-And-The-Elephant. *Manoj-Kargudri. *Two-rich-merchants-and-a-thief. *Healing-is-contagious. *Two-saints-in-a-market-place. *A-Terrible-Fight-Between-Two-Wolves. *Hen-that-laid-golden-eggs. *Healing-forgiveness-and-affection. *Elephants-held-by-small-ropes. *Story-of-Punyakoti-the-strength-of-truth. *What-is-the-reason? *Reply-Depends-on-the-Question. *Critical-mass-Experiment. *The-Brahman's-Wife-and-the-Mongoose. *The-Boy-Who-Cried-Wolf. *Difference-between-Heaven-and-Hell! *Freedom-and-Prison! *It's-in-Your-Eyes!
* * * * * *

Jokes.
*Please-listen-to-me. *The-Silent-Treatment! *Surgeon-Vs-Mechanic. *Manoj-Kargudri. *God's-doing-a-lot-better-job-lately.
* * * * * *

The-Bitter-Truth.
*Duty-Responsibility-Law-and-Order. *"Happy-Kingdom"-proudly-proclaimed-as-"Paradise". *Trying-to-learn-something-for-the-first-time. *Time-is-the-only-solution. *For-every-Action-there-is-an-Equal-and-Opposite-Reaction. *Logic-of-Good-and-Bad. *Manoj-Kargudri. *Duties-Responsibilities-verses-Luxuries-and-Pleasures. *Beggars!
* * * * * *

Life-is-Beautiful.
*Creating-successful-constructive-personality. *Why-God-Gave-Us-Friends? *Way-to-Paradise. *Creating-the-Beautiful-World. *Doing-the-job-of-goodness. *Life-is-Meaningful. *Manoj-Kargudri. *The-A-to-Z-for-Goodness. *Life-is-full-of-Tests. *History-Proves-That. *Love-in-different-forms. *True-to-the-heart.
* * * * * *

Prayers-To-Worship.
*Please-do-not-leave-me-ever. *Let’s-make-it-happen. *Faith-in-Patience. *The-only-one-I've-got. *Someone-somewhere. *How-I-Love-You. *Will-You? *Successful-Life. *Manoj-Kargudri. *Please-say-something. *Way-to-Paradise. *My-Everything.
* * * * * *

Friendship.
*Life-Still-Has-A-Meaning. *Heavenly-Garden. *GOD-SPEAK-TO-ME! *Why-God-Made-Friends? *I-asked-the-Lord! *A-Best-Friend! *Why-GOD-Gave-Us-Friends? *Portrait-of-a-Friend. *Friends-till-the-end. *Some-Assorted! *Forever-Friends. *What-is-a-friend!
* * * * * *

Winning-Publications.
*Significance-of-Nava-ratna (Nava-Graha). *Amazing-Constructive-Vibrations. *Manoj-Kargudri. *The-piercing-of-the-ears (karnavedha) . *Nature-Cure. *Steps-to-improve-work-place. *Steps-Involved-In-Relationships. *Some-of-the-aspects-which-materialize-the-relationships.
* * * * * *

Music-Download.
*Bhakti-Songs. *Manoj-Kargudri. *English-Songs. *Gazal-Bhajan-Hindi. *Hindi-Life. *Hindi-Love. *Hindi-Old-Kishore. *Hindi-Old-Mukesh. *Hindi-Old-Songs. *Hindi-Rock. *Hindi-Pops. *Instrumental. *Vocal-Ragas.
* * * * * *

Technology.
*READ: Why-JAVA *Manoj-Kargudri. *Start-Learning-JAVA *Why-Java's-Hot *Start-Using-LINUX *Java-Q-&-A *Question *Java-SE-6-Doc *Struts-Doc *Java-Tutorial-Index *Java-Certification *Tech. *Struts. *Manoj-Kargudri. *Servlet. *JSP. *EJB. *JNDI-JMS *SQL. *JDBC. *CORE-JAVA: *OOP *CLASS. *Manoj-Kargudri. *ABSTRACT *EXCEPTIONS *THREADS *UTILS *PACKAGES *JVM *CASTING *NETWORKING *RMI-XML
* * * * * *

MUSIC-DOWNLOAD.
*Hindi-Vocal-Raga. *Hindi-Remix-Rock. *Hindi-Old-Songs. *Hindi-Mukesh-Mohd-Rafi-Songs. *Hindi-LOVE-Songs. *Hindi-Remix-LIFE. *English-Rock-Songs. *Kannada-Janapada-Geete. *Kannada-Film-Songs. *Kannada-Devotional-Songs. *Instrumental-Music. *Manoj-Kargudri. *Hindi-Pop-Songs. *Hindi-Bhakti-Songs. *Hindi-Kishore-Kumar-SAD. *Hindi-Kishore-Kumar-JOY. *Hindi-R-D-Burman. *Hindi-Gazals. *English-Soft-Songs.
* * * * * *

Add to Google