java4all@1986 java. Powered by Blogger.

When to use an Abstract Class And an Interface?

>> Sunday, May 29, 2011

Abstract:In case where you want to use implementation inheritance then it is
usually provided by an abstract base class. Abstract classes are excellent candidates inside of application
frameworks. Abstract classes let you define some default behavior and force subclasses to provide any specific
behavior.
Inheritance: For polymorphic interface inheritance, where the client wants to only deal with a
type and does not care about the actual implementation use interfaces. If you need to change your design
frequently, you should prefer using interface to abstract. CO Coding to an interface reduces coupling and
interface inheritance can achieve code reuse with the help of object composition

Read more...

What is difference between an Abstract Class and an Interface?

In design, you want the base class to present only an interface for its derived classes. This means, you don’t want
anyone to actually instantiate an object of the base class. You only want to upcast to it (implicit upcasting, which
gives you polymorphic behavior), so that its interface can be used. This is accomplished by making that class
abstract using the abstract keyword. If anyone tries to make an object of an abstract class, the compiler prevents
it.
The interface keyword takes this concept of an abstract class a step further by preventing any method or function
implementation at all. You can only declare a method or function but not provide the implementation. The class,
which is implementing the interface, should provide the actual implementation. The interface is a very useful and
commonly used aspect in OO design, as it provides the separation of interface and implementation and
enables you to:
1. Capture similarities among unrelated classes without artificially forcing a class relationship.
2. Declare methods that one or more classes are expected to implement.
3. Reveal an object's programming interface without revealing its actual implementation.
4. Model multiple interface inheritance in Java, which provides some of the benefits of full on multiple
inheritances, a feature that some object-oriented languages support that allow a class to have more than one
superclass.

Read more...

What is meant by Polymorphism,Inheritance,Encapsulation and Dynamic Binding?

Polymorphism – means the ability of a single variable of a given type to be used to reference objects of
different types, and automatically call the method that is specific to the type of object the variable references. In a
nutshell, polymorphism is a bottom-up method call. The benefit of polymorphism is that it is very easy to add new
classes of derived objects without breaking the calling code (i.e. getTotArea() in the sample code shown
below) that uses the polymorphic classes or interfaces. When you send a message to an object even though you
don’t know what specific type it is, and the right thing happens, that’s called polymorphism. The process used by
object-oriented programming languages to implement polymorphism is called dynamic binding. Let us look at
some sample code to demonstrate polymorphism

Inheritance – is the inclusion of behavior (i.e. methods) and state (i.e. variables) of a base class in a derived class so
that they are accessible in that derived class. The key benefit of Inheritance is that it provides the formal mechanism for
code reuse. Any shared piece of business logic can be moved from the derived class into the base class as part of
refactoring process to improve maintainability of your code by avoiding code duplication. The existing class is called the
superclass and the derived class is called the subclass. Inheritance can also be defined as the process whereby one
object acquires characteristics from one or more other objects the same way children acquire characteristics from their
parents
Encapsulation – refers to keeping all the related members (variables and methods) together in an object. Specifying
member variables as private can hide the variables and methods. Objects should hide their inner workings from the
outside view. Good encapsulation improves code modularity by preventing objects interacting with each other in
an unexpected way, which in turn makes future development and refactoring efforts easy.
Being able to encapsulate members of a class is important for security and integrity.

Read more...

What i difference between "is a " relationalship and "has a" relationalship?

The ‘is a’ relationship is expressed with inheritance and ‘has a’ relationship is expressed with composition. Both
inheritance and composition allow you to place sub-objects inside your new class. Two of the main techniques for
code reuse are class inheritance and object composition.


Inheritance [ is a ] Vs Composition [ has a ]
Building
Bathroom
House

Building to House is a relationship;;
House to Bathroom has a relationship
class Building{
.......
}
class House extends Building{              //is a [House is a Building]
.........
}

class House {
Bathroom room = new Bathroom() ;
....
public void getTotMirrors(){           //has a bathroom
room.getNoMirrors();
....
}
}
Inheritance is uni-directional. For example House is a Building. But Building is not a House. Inheritance uses
extends key word. Composition: is used when House has a Bathroom. It is incorrect to say House is a Bathroom. Composition simply means using instance variables that refer to other objects. The class House will
have an instance variable, which refers to a Bathroom object

Read more...

How do we call the super class Constructor?

If a class called “SpecialPet” extends your “Pet” class then you can
use the keyword “super” to invoke the superclass’s constructor.

public SpecialPet(int id) {
super(id); //must be the very first statement in the constructor.
}

To call a regular method in the super class use: “super.myMethod( );”. This can be called at any line. Some
frameworks based on JUnit add their own initialization code, and not only do they need to remember to invoke

Read more...

Can we call one constructor from another Constructor?

Yes ,We can call one constructor from another Constructor by using this.() method.

Look the below Example:



class  Pet
{
    int id=9;
    String type="check";
    public Pet(int id) {
this.id = id;           // “this” means this object
}
public Pet (int id, String type) {
this(id);                      // calls constructor public Pet(int id)
this.type = type;               // ”this” means this object
}
    public static void main(String[] args)
    {
        Pet p=new Pet(9,"check");
    }
}


Read more...

What is the main difference between the Java platform and the other software platforms?



Java platform is a software-only platform, which runs on top of other hardware-based platforms like UNIX, NT etc.








The Java platform has 2 components:
 Java Virtual Machine (JVM) – ‘JVM’ is a software that can be ported onto various hardware platforms. Byte
codes are the machine language of the JVM.Java

Read more...

Which type of DataBase Management System we are using in our Application?

We are using Relational Data Base Management System in our apllication
Relational Data Base Management System:  It is a Data Base Management System,which stores data in the form of Tables.This Data Base Management System understands only Query Language.

Read more...

What is meant by Query Processing?

Query Processing:   When we sent an sql Query from Sql Command Prompt to Data Base,then Database Engine we perform the following steps.

1.)Query Tokenization: In this phase it will take the provided Sql Query as input and divide into number of tokens,and generate stream of tokens as output.

2.)Query Parsing:T his phase will take stream of token as input and trying to construct a tree,If the tree is constructed successfully means there is no syntactical errors in provided SQL Query.

3.)Query Optimization:This phase will take the constructed tree as i/p and perform n.o optimization mechanisms in order to decrease the execution time and memory utilization.

4.)Query Execution:  This phase will take Query Optimization as i/p and execute by using n.o of interceptors internally.

Read more...

FaceBook Login

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

Total Pageviews

STATCOUNTER

  © Blogger template Simple n' Sweet by Ourblogtemplates.com 2009

Back to TOP