• RELEVANCY SCORE 5.84

    DB:5.84:Java Interfaces And Abstract Classed fc




    what is the difference between interface and abstract class?

    DB:5.84:Java Interfaces And Abstract Classed fc

    I suggest you try writing some code and see.

  • RELEVANCY SCORE 3.71

    DB:3.71:Re: Interface m8




    Java Glossary : interface vs abstract class
    Abstract classes vs. interfaces: When does it make sense to choose an abstract class over an interface?
    Abstract classes and interfaces practicum: Move from theory to practice on when to employ abstract classes vs. interfaces
    Tech Tips: ABSTRACT CLASSES VS. INTERFACES

    DB:3.71:Re: Interface m8

    I'm still entertained by the fact that some folks will
    spell out words like "multiple", "inheritance",
    "interface", and "implement", but not "because".

    :o)LOL!

    This kills me - just bcuz.

    %

  • RELEVANCY SCORE 3.43

    DB:3.43:Help! 37




    Hello! Everybody
    I am new to programming
    I am learning java
    i am interested to know the difference between interfaces and abstract classes in java

    DB:3.43:Help! 37

    JavaIsMyThing wrote:
    If you create a class that implements an interface, you are required to supply an implementation for ALL of the methods that are declared in the interface you implement.Not if the class is declared abstract.

    ~

  • RELEVANCY SCORE 3.41

    DB:3.41:Re: Why An Interface Is Used In A Java Program pc


    These are fair comments as per as interface is concern.... we need interface to declare the methods without implementing the methods. Basically interfaces help implementing classes in a organised way.
    Now We got abstract class also, which has got more or less same features like interfaces. In abstract class also we can declare a method without implementation.
    If we use abstract class and extend that abstract class, we don't have implement all the abstract methods in that particular class,which would extend the abstract class, but if we implement an interface in a class, we have to define all the methods with their body. Now, can anyone tell me , in a generic way, when do we use interface and when do we use abstract class. I don't need the differences between abstract class and interface...that i know...thanks in advance
    take it easy
    RD
    l

    DB:3.41:Re: Why An Interface Is Used In A Java Program pc

    For Ex: 5 years down the line, .........I always wondered why it is said "down the
    line" and not up the line.
    What's so downish about the future ?People degrade as the years pass by. :P

  • RELEVANCY SCORE 3.41

    DB:3.41:Re: Instanciate Interface cm


    So I suppose I can also assign an abstract class to an interface then.. but
    abstract classes cannot be instanciated...so cant do that right?As you already noticed, abstract classes as well as interfaces can not be instantiated,
    but nothing forbids you to instantiate a concrete class, derived from the abstract
    class or an interface and just refer to it as if it were just the abstract class or
    interface, e.g.interface Something { void doSomething(); }
    public abstract class AbstractSomething implements Something { }
    public class DoesIt extends AbstractSomething {
    public void doSomething() { System.out.println("doing something ..."); }
    }
    ...
    Something a= new DoesIt(); // fine
    AbstractSomething b= new DoesIt(); // fine
    DoesIt c= new DoesIt(); // fine
    Something d= new Something(); // error: can't instantiate interfaces
    Something e= new AbstractSomething(); // error: can't instantiate abstract classkind regards,

    Jos

    DB:3.41:Re: Instanciate Interface cm

    Hi Jos,

    My question was

    so I am assigning the Collection's variable a
    reference to the ArrayList object.or
    Something a= new DoesIt(); // fine
    AbstractSomething b= new DoesIt(); // fine

    I am assigning Something's variable, a reference to
    the DoesIt.... so Somthing hold a reference of type
    DoesIT but it just sounded a little wierd because
    Something was an interface...

    I get it now though... one can assign a variable a
    reference as long as the reference is of a concrete
    class.... even if that variable belongs to an
    interface.Your terminology is really wonky, so it's hard to guage whether you really understand.

    The variables we're talking about here hold references. Those references point to objects.

    The reference variable has an associated type, indicated where it's decleared--Collection, List, String, etc.

    The object that you point the reference variable at must be of a type that is assignment compatible with the declared type of the variable.

    That's all there is to it, unless you're not clear on the rules about assignment compatibility (subclasses, implementing classes, etc.)

  • RELEVANCY SCORE 3.40

    DB:3.40:Abstract Classes And Interfaces??? xa


    Recently i have been asked a question in interview..
    '" What is the difference between abstract classes and interfaces.. I mean wut is the advantage of using one over the other"
    Can anyone please gimme a precise answer in few lines..
    Thanks much
    suresh akula

    DB:3.40:Abstract Classes And Interfaces??? xa

    You can also define "constants" (static final fields) within an interface, not just methods.

    Another noteworthy differences between interfaces and abstract classes is that within an interface, all methods and fields are implicitly public in scope. Abstract classes have no such constraint.

    Of course, there are the obvious differences: interfaces provide NO implementations, whereas abstract classes may; a class may implement multiple interfaces, but may only extend one class.

  • RELEVANCY SCORE 3.28

    DB:3.28:Re: What Good Are Interfaces j1


    Multiple inheritance in java is implemented using interface, You can't inherit
    more than one classes(using extends ). but u can inherit many interfaces(using implements ). In interfaces all the methods are abstract.

    DB:3.28:Re: What Good Are Interfaces j1

    yawmark's explanation is perfect.Indeed. But just because I like the sound of my own voice (internetally speaking) allow me to provide an analogy.

    When someone tells you what a car is--you make it go by pressing here, make it stop by pressing there, make it turn by turning the wheel, etc.--you know how to drive any car (more or less--not a perfect analogy, I know, but roll with it). You don't care if they strip off every logo and nameplate. You know that this thing IS-A car, and therefore, you can make it go by pressing here, etc.

    An interface is like the description of what every Car has in common. When you take driver's ed, the class is giving you the Car interface. Later, when you get a concrete Car instance, you don't care what kind of Car it is--you know what it can do and how to make it do it because of the interface. You get in the Car, turn the key, put it in gear, press the accelerator, and so on. Simply referring to it as a Car is enough to tell you that you can do those things and what the results will be.

  • RELEVANCY SCORE 3.28

    DB:3.28:Interfaces Vs Abstract Classes kp


    hi,
    i have some kind of general idea about interfaces and abstract classes.but what are the situations that are most suitable for use interfaces and abstract classes..if u have any idea pls help me
    thanx and best regards,
    Kelum

    DB:3.28:Interfaces Vs Abstract Classes kp

    hi all,
    thanx for u all for the given support..now i have an idea abbt how to use those
    thanx and best regards,
    kelum

  • RELEVANCY SCORE 3.28

    DB:3.28:Re: Abstract Class And Interface 81


    You should never, ever, ever, ever use abstract classes. NEVER!

    You should always program to interfaces.

    So sayeth the uj.

    Like OMG, HTH, TTYL.

    DB:3.28:Re: Abstract Class And Interface 81

    georgemc wrote:
    filestream wrote:
    You should never, ever, ever, ever use abstract classes. NEVER!

    You should always program to interfaces.

    So sayeth the uj.

    Like OMG, HTH, TTYL.Apart from when I say that, in which case she seems obliged to take the opposite stance. Seriously, recently she was both arguing for and against preferring composition over inheritance in two threads simultaneously, simply in order to gainsay my points. Quite bizarre behaviour, albeit quite revealingRight. That's what I was referring to.

  • RELEVANCY SCORE 3.21

    DB:3.21:Example cx


    hi,
    General (life) examples for Abstract class,inhertance,interfaces and encapsulation ,,can u tell me?

    DB:3.21:Example cx

    hii,

    i appreciate with ur example can u give me more examples regarding to that.

  • RELEVANCY SCORE 3.12

    DB:3.12:Interfaces Vs Abstract Classes 1d


    Hi All !!!
    Can any body please tell the difference between Interfaces and Abstract Classes in terms of Third Party Convince, Homogenous and HAS-A Relation Ship.
    Regards,

    DB:3.12:Interfaces Vs Abstract Classes 1d

    do your own homework. had you just asked for the differences, you would probably have gotten an answer, but you've just dumped your homework on the forum and said "do this for me" which we won't

    search the forums for this, it's asked almost every day. but those homework questions? that's your own problem

  • RELEVANCY SCORE 3.11

    DB:3.11:1) Interface 2) Response.Sendredirect And Jsp:Forward am


    Hi Frens

    I got few questions to clarify..
    1) Why we have interfaces and abstract classes both? What are the advantages of interface?
    Whatever the abstraction I want I can implement in Abstract class na! Then why interfaces are needed?
    Like the example...

    interface Ai {
    void method1();
    void method2();
    }
    class Ac extends SomeClass implements Ai {
    void method1 {
    //some implementation
    }
    void method2() {
    //some...
    }
    }
    Now I can design this without using interface also right?

    abstract class Aa extends SomeClass{
    abstract void method1();
    abstract void method2();
    }
    class Ac extends Aa {
    void method1 {
    //some implementation
    }
    void method2() {
    //some...
    }
    }
    Like this I can do with abstract classes also na! Then why interfaces are needed?
    plz give except the answer - "for Implementing Multiple Inheritance in java", say other. :)

    What is alternative for interface in C++?

    2) what is the exact difference between
    jsp:forward and
    response.sendRedirect and
    RequestDespatcher rd = new RequestDespatcher(URL);
    rd.forward()
    Which is preferred? when? why?
    Why there are 3 ways? cant one among them suffice?

    Hope Im clear.. If not mail me I'll clarify regarding this qns. :)

    DB:3.11:1) Interface 2) Response.Sendredirect And Jsp:Forward am

    1. Ever tried extending 2 abstract classes?

    2. Read the API.

  • RELEVANCY SCORE 3.11

    DB:3.11:C#: What Is Difference Between Abstract Class And Interface? How To Decide To Use Which One? 18


    I have been asked a question: how to decide to use Abstract class or Interface?
    We know that the Interface is special Abstract. All definitationsare default public and without implemetion. Classed inherit from interface has to implement all definitions.

    Abstract class does not need to implement all the methods and it can not be instantiated.
    Classes inheritfrom abstract classmay sharecommon logic (properties or methods) with abstract class and also override some methods' behavior.
    How to clearily answer this question? Thx!

    JaneC

    DB:3.11:C#: What Is Difference Between Abstract Class And Interface? How To Decide To Use Which One? 18

    Hello JJChen,
    Interface class can be implement in small units of data but abstraction class can be implemented in large units of data.
    1. Here is explanation of
    Interface class
    2. Here is explained
    Abstraction class.
    3.
    Difference betweenAbstraction andInterface class.
    Hope it will help you a lot.
    thanks,

  • RELEVANCY SCORE 3.10

    DB:3.10:Abstract And Interface? cm


    why do we need abstract class?
    why do we need interface in java?

    DB:3.10:Abstract And Interface? cm

    Oh please, do some research of your own.

  • RELEVANCY SCORE 3.09

    DB:3.09:Java Generics Problem 7j


    abstract class ABSK extends Number
    {
    public abstract K K useMe(Object k);// understood ..
    public abstract K ABS? extends Number useMe(ABS? super K k); //1
    public abstract K ABS? super Number useMe(ABS? extends K k); //2
    public abstract K ABSK useMe(ABSK k);// understood ..
    }

    1 and 2 this both should not work because K can be anything here....

    can anyone please explain???

    Thanks in advance...

    DB:3.09:Java Generics Problem 7j

    user13384537 wrote:
    Firstly thanks for your kind reply .....
    can you please elaborate it more ???? because i am confused too much in generic methods especially ....i am preparing for OCPJP and i am not getting reply for this question any where. You are first to reply this question...Both "? super Number" and "? super K" (indeed, "? super {anything}") represent unknown types with no upper bound. While it's true that they could both, in fact, be 'Number's, the compiler has no way of knowing this, which is why it's invalid for an ABS (because you've already defined it as taking a type that extends Number).

    I'll be flamed if I'm wrong; but that's the way I understand it.

    My suggestion would be to look at the [url http://download.oracle.com/javase/tutorial/extra/generics/index.html]Gilad Bracha tutorial. It's quite long in the tooth, but it's still the best one around, I reckon.

    Winston

  • RELEVANCY SCORE 3.08

    DB:3.08:Java Interface Variables. m8


    Hi,

    I have an doubt about Java Interfaces. The methods declared in interfaces are public abstract. The variable declared in the interfaces are public static final.

    I wanted to confirm that the methods and variable are public because the private,protected and default access control levels are mainly for securing data. As interfaces have no data in them hence the methods variables are declared as public right ? Am i thinking in the right direction. ?

    Also Can anyone please let me know why the variable are implicitly static ?

    Thanks in advance.

    DB:3.08:Java Interface Variables. m8

    Hi,

    I have an doubt about Java Interfaces. The methods
    declared in interfaces are public abstract. The
    variable declared in the interfaces are public static
    final.That is correct.

    I wanted to confirm that the methods and variable are
    public because the private,protected and default
    access control levels are mainly for securing data.
    As interfaces have no data in them hence the methods
    variables are declared as public right ? Am i
    thinking in the right direction. ? Sort of, but what you really need to understand is the purpose of an interface (with a lowercase I), as the word interface applies to object oriented programming in general.

    An important concept in OOP is that of encapsulation. An object is designed with a public interface that gives a general set of controls that clients can use to cause the object to perform the required tasks. However, the underlying details of how this is done are kept private for the purpose of being able to swap out two similar objects and use them in the same manner.

    For example, consider a universal remote control that you may have at home that is programmed for your VCR, DVD player, Tape Cassette Deck, CD Player, and Laser Disc Player. The remote control has common buttons that work for all five devices: play, stop, fast forward, rewind, and pause.

    You may notice that there is no button for Start Motor, or Turn on Laser, or Turn on Magnet, etc. These details are hidden, not necessarily for security reasons, but rather because they are part of the implementation of the device that can change from device to device, and do not apply to all devices (i.e. there's no laser in a tape deck).

    Now, the whole point of an Interface (with a capital I) is to provide the details that will be made available to the user of the device (i.e. to provide the remote control). This is why all methods are implicitly public: because these are the methods that are intended to be accessible to clients. That's what an Interface is used for.

    Think about what would happen if you did define a method: private void startLaser() in your Interface MediaPlayingDevice. Then, because all methods in an interface are abstract, you would be forcing any object using that interface to implement the startLaser() method, even though a tape deck doesn't have a laser to start. You only want to put in the interface the methods used by the clients, to prevent this sort of thing from happening.

    Also Can anyone please let me know why the variable
    are implicitly static ?This has to do with another very important design principle in object oriented programming. In almost all cases, a well designed object does not provide clients with direct access to its instance variables. Usually, that object should provided defined accessors and mutators to those variables instead. For example:

    private int weight = kirsteyAlley.getWeight( );
    public void setWeight( int w ) { weight = w; }
    public int getWeight( ) { return weight; }This way, the designer could then apply reasonable restrictions on those variables:

    private int wieght = 0; // lazily initialized

    public void setWeight( int w ) throws InvalidWeightException {
    if ( w 0 ) throw new InvalidWeightException( "Weight must be greater than zero" );
    wieght = w;
    }

    public void getWeight( ) throws EmbarrasingWeightException {
    if ( weight == 0 ) kirsteyAlley.getWeight( );
    if ( weight 180 ) throw new EmbarrassingWeightException( "I'm not telling!" );
    return weight;
    }So, the point is, public instance variables are typically NOT part of a well defined interface. Hence they cannot be defined in a java Interface (this was a design decision made by Sun, and I would encourage you to consider this when you write all of your objects). However, the public static final modifier is used to define constants in java. Since those constants cannot change, its okay to expose them directly in the public interface of the class. This is why variables in an Interface are required to be static (as well as public and final).

    Thanks in advance.np.

    - Adam

  • RELEVANCY SCORE 3.04

    DB:3.04:Interfaces V/S Abstract Classes???? m3


    Hi Every1
    Can anybody plz tell me the difference b/w "INTERFACE ABSTRACT CLASSES" from design prospective. I have sufficient knowledge on Interfaces and abstract classes in general, but unable to make out when should I use which one? I have read few topics on Java World and from some other sites too, but unable to makeout the difference.
    Topic on "Abstract Classes v/s Interfaces" on Java World says that if your design changes frequently then go for "Interfaces". Why?????
    That tutorial also says "Interfaces are generally used for making Framework. "HOW"????
    I have different thinking...
    Lets say there is one interface called I_Animal and an abstract class called C_Animal, which are as follows:

    interface I_Animal{
    public void move(); // Which tells how different animals move
    }

    Now my Abstract class

    class abstract C_Animal{
    public void move(); // Which tells how different animals move
    }

    Now there 2 classes namely(C1 and C2), C1 implements I_Animal to provide the functionality of move() method.
    C2 extends C_Animal(abstract class) to provide the functionality of move() method.

    class C1 implements I_Animal{
    public void move(){
    // Some functionality
    }
    }

    class C2 extends C_Animal{
    public void move(){
    // Some functionality
    }

    Now what i want to know is which approach is better and "WHY"??
    My thinking is....
    Sometimes using interfaces is advantegeous while sometimes abstract calsses are better, depending upon the requirement and situation

    Lets say in the above example, in future we want to add one more method called eat(). If we r adding eat() method in interface then we have to add the method in the class (which implements that interface) also. So in this case we have to make changes at two different places(namely interface and the implementing class), but if we are adding the move() method in abstract class, we can add it in the abstract class with blank implementation(i.e opening and closing the curly braces like this {}). Here we are not changing the code at two different places. so in this case abstract classes are advantegeous.
    Lets think of a different senario where my class is already extending some other class, then in that case I can't use abstract class because Java doesn't support Multiple Inheritance. So the only way round is to use Interfaces.
    So this is how I differentiate b/w interfaces and abstract classes. Do anyone of you have different thought on this. Plz tell me.

    Any help will be appreciated

    Tx in Advance
    Jam

    DB:3.04:Interfaces V/S Abstract Classes???? m3

    Why are interfaces useful from a design perspective? Because they are less intrusive.

    For instance, take a look at the interface Action and the abstract class AbstractAction in Swing. Say you want to add a button to a toolbar (using JToolBar). The add method accept any object that has type Action. This means that you can add any instances of your own classes with the only requirement that they implement the Action interface. However, if add was designed to take an instance of type AbstractAction, then you would be forced to make your own class inherit from AbstractAction. That is a very intrusive requirement because classes can only inherit from one other class. Requiring that a class implement an interface, on the other hand, is not intrusive because classes can implement more than one interface.

  • RELEVANCY SCORE 2.99

    DB:2.99:Need Some Concept Clearence!!! pd


    1- what is the purpose of java interfaces ... Dont you think that with only abstract classes we can build an application. In that case we dont require interfaces

    [b ]2- what if java interfaces were not there, would a complex java application be possible ?

    3- Suppose there are no interfaces in java, which functionality in particular will be missing?

    4- why abstract classes? As we cannot instantiate abstract classes then what is the purpose behind all this..

    5- Is overloading a form of polymorphism? If yes, why? Because concept of polymorphism is, i believe, only possible in inheritance.

    DB:2.99:Need Some Concept Clearence!!! pd

    yeah i knw that u can implement many interfaces, but
    when u inherit classes, u . actually inherit all the
    functionality as well Use real words with proper spelling, punctuation, and capitalization.

    But in the case of interfaces, they have no
    functionality, so wats the purpose...??Inheritance is not about "functionality." It's about type. The fact that you also get to inherit implementation in the case of classes is just a bonus.

  • RELEVANCY SCORE 2.98

    DB:2.98:Abstract Classes Vs Interfaces xz


    What is the use of an abstract class when we have interfaces?As far as i know abstract classes cannot be inherited and yes they do provide you the facility of implementing all or some of the concrete methods defined in them.Can anyone define this concept please

    DB:2.98:Abstract Classes Vs Interfaces xz

    I experienced the love of god in reply#8 of this thread: http://forum.java.sun.com/thread.jspa?forumID=31threadID=5182308

    And I got a bit crazy in reply#9. Ah well.

    Steve Vai has a song called For The Love Of God. Where's filestream? He must be slipping.

  • RELEVANCY SCORE 2.98

    DB:2.98:Diamond Problem jd


    interface A
    {
    void foo();
    }

    abstract class B
    {
    public void foo()
    {
    System.out.println("B");
    }
    }

    class C extends B implements A
    {
    public void foo()
    {
    System.out.println("C");
    }
    }

    class Demo
    {
    public static void main(String args[])
    {
    A c = new C();
    B b = new C();
    b.foo();// prints C
    c.foo();// prints C
    }
    }If there were 2 interfaces that were implemented in a class, i would have not complained because none has its seperate implementation defined, so which path my class followed in the inheritence hierarchy doesnt actually matter to me, since both are equivalent.

    But the case i m discussing here, one of my abstract class actually has the implementation for foo(), so now I do give heed to the path followed.

    Moreover, the foo() implementation in my concrete class, actually overloads both foo()'s , since inheritence and abstract class reference call to foo both print C

    so does java still not experience Diamond Problem, because path followed is actually still unknown?

    DB:2.98:Diamond Problem jd

    interface A
    {
    void foo();
    }

    abstract class B
    {
    public void foo()
    {
    System.out.println("B");
    }
    }

    class C extends B implements A
    {
    public void foo()
    {
    System.out.println("C");
    }
    }

    class Demo
    {
    public static void main(String args[])
    {
    A c = new C();
    B b = new C();
    b.foo();// prints C
    c.foo();// prints C
    }
    }If there were 2 interfaces that were implemented in a
    class, i would have not complained because none has
    its seperate implementation defined, so which path my
    class followed in the inheritence hierarchy doesnt
    actually matter to me, since both are equivalent.

    But the case i m discussing here, one of my abstract
    class actually has the implementation for foo(), so
    now I do give heed to the path followed.

    Moreover, the foo() implementation in my concrete
    class, actually overloads both foo()'s , since
    inheritence and abstract class reference call to foo
    both print CThe C class does not overload the foo() method, it overrides it.

    so does java still not experience Diamond Problem,
    because path followed is actually still unknown?The path is not unknown; it is always the one for the actual instance that is being referenced. This is meant to be a "feature" of Java's polymorphism (all polymorphism?) - if your reference is of a type higher in the class hierarchy you do not need to know the runtime type of the instance; that instance?s method will be the one called at runtime.

  • RELEVANCY SCORE 2.97

    DB:2.97:Can Anybody Tell Me The Real Time Application For Interfaces And Abstract Classes??Plz a3


    can anybody tell me the real time application for interfaces and abstract classes??plz..thanks in advancehashna

    DB:2.97:Can Anybody Tell Me The Real Time Application For Interfaces And Abstract Classes??Plz a3

    @David, He actually wants to know the differences between interfaces and abstract classes in a real world applications and not real time computing. :p
    Eyal (http://shilony.net), Regards.

  • RELEVANCY SCORE 2.97

    DB:2.97:Abstract Interfaces fa


    hello all,

    What is an abstract interface?

    Thanx in advance.

    DB:2.97:Abstract Interfaces fa

    There is one other important difference between an interface and an abstract class: Interfaces can be multiply inherited.

  • RELEVANCY SCORE 2.94

    DB:2.94:Static Methods In Interfaces 3z


    Java cognoscenti,

    Anyone know why I can't declare a method as static in an interface, but I can in an abstract class. Surely, semantically it's the same - defering the implementation of a static method, not an abstract class and an interface. By the way, I'm using JDK 1.2.2 if that makes a difference

  • RELEVANCY SCORE 2.93

    DB:2.93:Java.Lang.Assertionerror: Can Not Find Generic Method Public Abstract 7c


    I just downloaded the JDev 11g and trying to test the JEE web app. Below is my install:

    JDeveloper 11g
    JEE Web Project
    EJB 3.0

    Steps taken:
    1. Created an entity bean from a table.
    2. Created a session facade
    3. Create sample Java client to use the facade (Right-click on the session facade, and choose New sample Java Client from the context menu)
    4. Run the session facade
    5. Run the Java client

    I got the following error.

    java.lang.AssertionError: Can not find generic method public abstract java.util.Listcom.oracle.orm.model.ejb.persistence.Hosttags queryHosttagsFindAll() in EJB Object

    I checked the methods in the beans and interfaces, they are all there. Any idea?

    Thanks.

    DB:2.93:Java.Lang.Assertionerror: Can Not Find Generic Method Public Abstract 7c

    I just downloaded the JDev 11g and trying to test the JEE web app. Below is my install:

    JDeveloper 11g
    JEE Web Project
    EJB 3.0

    Steps taken:
    1. Created an entity bean from a table.
    2. Created a session facade
    3. Create sample Java client to use the facade (Right-click on the session facade, and choose New sample Java Client from the context menu)
    4. Run the session facade
    5. Run the Java client

    I got the following error.

    java.lang.AssertionError: Can not find generic method public abstract java.util.Listcom.oracle.orm.model.ejb.persistence.Hosttags queryHosttagsFindAll() in EJB Object

    I checked the methods in the beans and interfaces, they are all there. Any idea?

    Thanks.

  • RELEVANCY SCORE 2.92

    DB:2.92:Abstract Class X Interfaces 3a


    1.The Java language has two similar concepts : Abstract Classes and Interfaces. So, When its better to use one or other technique and the advantages and disadvantages of each one ?

    DB:2.92:Abstract Class X Interfaces 3a

    http://www.javaworld.com/javaworld/javaqa/2001-08/03-qa-0831-interface.html

  • RELEVANCY SCORE 2.92

    DB:2.92:Abstract Classes And Interfaces? dp


    Can someone tell me whats the difference between abstract classes and interfaces?

    DB:2.92:Abstract Classes And Interfaces? dp

    ...alhough an abstract class doesn't have to have any abstract methods, or any methods at all for that matter. If it has an abstract method (or doesn't implement something from an interface it claims to implement) then it must be declared abstract, but the reverse is not true--any class may be declared abstract.

  • RELEVANCY SCORE 2.92

    DB:2.92:What Is Real Time (Inpoint Of Project) Example, Where We Can Use Abstract And Interfaces 7k


    What is real time (inpoint of project) example, where we can use abstract and interfaces?

    DB:2.92:What Is Real Time (Inpoint Of Project) Example, Where We Can Use Abstract And Interfaces 7k

    There are lots of examples in the framework and any design pattern book or website has plenty of examples of when this is a good idea. It is not the correct
    approach for every problem. In the framework refer toDbDataReader
    which provides a base impl of IDataReader and IDataRecord,
    ComparerT for IComparer, and
    TemplateControl for INamingContainer.
    Michael Taylor
    http://msmvps.com/blogs/p3net

  • RELEVANCY SCORE 2.90

    DB:2.90:Jpublisher And Java Abstract Class 8z


    Has anyone wrote PL/SQL package then use JPublisher to generate Java abstract class? If so, please provide an example.

    Thanks,

    DCW

    DB:2.90:Jpublisher And Java Abstract Class 8z

    Create a PL/SQL package:

    SQL create package otn is
    2 procedure test1 (a number, b clob);
    3 end;
    4 /

    % jpub -user=scott/tiger -url=jdbc:oracle:oci8:@ -sql=otn:OTN
    SCOTT.OTN

    % cat OTN.sqlj
    import java.sql.SQLException;
    import sqlj.runtime.ref.DefaultContext;
    import sqlj.runtime.ConnectionContext;
    import java.sql.Connection;

    public class OTN
    {

    /* connection management */
    protected DefaultContext __tx = null;
    protected Connection __onn = null;
    public void setConnectionContext(DefaultContext ctx) throws SQLException
    { release(); __tx = ctx; }
    public DefaultContext getConnectionContext() throws SQLException
    { if (__tx==null)
    { __tx = (__onn==null) ? DefaultContext.getDefaultContext() : new DefaultContext(__onn); }
    return __tx;
    };
    public Connection getConnection() throws SQLException
    { return (__onn==null) ? ((__tx==null) ? null : __tx.getConnection()) : __onn; }
    public void release() throws SQLException
    { if (__tx!=null __onn!=null) __tx.close(ConnectionContext.KEEP_CONNECTION);
    __onn = null; __tx = null;
    }

    /* constructors */
    public OTN() throws SQLException
    { __tx = DefaultContext.getDefaultContext();
    }
    public OTN(DefaultContext c) throws SQLException
    { __tx = c; }
    public OTN(Connection c) throws SQLException
    {__onn = c; __tx = new DefaultContext(c); }

    public void test1 (
    java.math.BigDecimal a,
    oracle.sql.CLOB b)
    throws SQLException
    {
    #sql [getConnectionContext()] { CALL SCOTT.OTN.TEST1(
    :a,
    :b) };
    }
    }

    Use the command

    % sqlj OTN.sqlj

    to get OTN.java.

  • RELEVANCY SCORE 2.89

    DB:2.89:Abstract Classes Vs. Interfaces 3d


    An abstract method can only be implemented by a virtual method, while this is not necessarily so for a method declared in an interface.  Why must it be this way for abstract methods, and if so why is it not this way for methods declared in interfaces?
     
    Thanks!

    DB:2.89:Abstract Classes Vs. Interfaces 3d

    That was very informative, thank you.
     

  • RELEVANCY SCORE 2.89

    DB:2.89:Re: Interfaces And Abstract Classes 1f


    Does this mean that the classes on which i implement those interfaces can be extended and reused further

  • RELEVANCY SCORE 2.89

    DB:2.89:Abstract Interface For Idoc Proxy 8z



    Hi All,

    Do we need to make Abstract interfaces for IDocs and Proxys too if we want to use them in BPM?

    XIer

    DB:2.89:Abstract Interface For Idoc Proxy 8z


    Hey Xier

    please have a look at the below blog

    /people/pooja.pandey/blog/2005/07/27/idocs-multiple-types-collection-in-bpm

    this collects IDOCs and merge them,ur case is only to merger them so u dont need to have a loop in BPM ,just use the multimapping in BPM,but i guess ur more concerned with the interfaces and mappings so this blog will definitely help you.

    let us know if u have any problems

    Thanx

    Aamir suhail

  • RELEVANCY SCORE 2.88

    DB:2.88:Abstract Class And Interfaces jf


    Hi,

    In which senarios, we can choose abstract class and interfaces

    Thanks

    DB:2.88:Abstract Class And Interfaces jf

    Hi,

    The most important scenario of deciding when to use Abstract Class or an Interface comes by trying to establish an IS-A relationship (abstract class) or CAN-DO relationship (Interface) is found between the related objects.

    1. e.g.
    A "Manager" IS AN "Employee" and a "SoftwareEngineer" IS ALSO AN "Employee"
    so for this relationship we can create an "Employee" Abstract class and the other classes "Manager" and "SoftwareEngineer" should derive from it and may provide their own implementations...........

    2. e.g.
    There will an annual appraisal for all types of Employees in an Organization. so, all employees must establish a certain kind of contract to fulfill for Appraisal which is done by an "IAppraisal" interface which has 2 methods - viz. a). public void IncreaseGrade();
    b). public void IncreaseSalary(double percentage);

    Hope this clarifies the scenario.

    Other aspects to decide are Versioning and Ease of Use between the 2.

    For more: pl. refer Applied .Net Framework book by Jeffry Richter

  • RELEVANCY SCORE 2.88

    DB:2.88:Exposing Multiple Abstract Classes Or Interfaces j1


    I have client applications that need to have various interfaces (or I can use abstract classes if I have to) to inherit from. The issue is that others on the development team do not want to have endpoints for each of these interfaces/abstract classes. I've tried passing them as parameters and setting them as KnownTypes for the WCF service, but neither works. Does anyone have a solution of how to expose multiple interfaces or abstract classes through one endpoint that the client and inherit from.Thanks

    DB:2.88:Exposing Multiple Abstract Classes Or Interfaces j1

    Hi Dennis,
    Thanks for such a prompt reply :).
    With your solution I will need two services exposed on two different endpoints. However, I want to expose MathService as IAdderService on a single endpoint and only some of the client'sshould be able to access the extra services provided by IMathService onthat single endpoint.
    Below is server side implementation:
    //MathService implements IMathService and IMathService implements IAdderService
    MathService mathService = new MathService();
    ServiceHost host = new ServiceHost(mathService);
    host.Open();
    Servcer side Configuration:
    configuration
    system.serviceModel
    services
    service name=IAdderService
    behaviorConfiguration=AdderServiceServiceBehavior
    endpoint address=net.pipe://localhost/AdderService
    binding=netNamedPipeBinding
    bindingConfiguration=Binding1
    contract=TestApp.IAdderService /
    endpoint address=mex
    binding=mexNamedPipeBinding
    contract=IMetadataExchange /
    host
    baseAddresses
    add baseAddress=net.pipe://localhost/AdderService/
    /baseAddresses
    /host
    /service
    /services
    bindings
    netNamedPipeBinding
    binding name=Binding1
    security mode = None
    /security
    /binding
    /netNamedPipeBinding
    /bindings

    behaviors
    serviceBehaviors
    behavior name=AdderServiceServiceBehavior
    serviceMetadata /
    serviceDebug includeExceptionDetailInFaults=True /
    /behavior
    /serviceBehaviors
    /behaviors
    /system.serviceModel
    /configuration
    Client Side imeplementation:
    IAdderService adderService = new ChannelFactoryIAdderService(AdderService).CreateChannel();
    int result = adderService.Add(10, 11);

    IMathService mathService = adderService as IMathService;
    result = mathService.Substract(100, 9);
    Client side configuration:
    configuration
    system.serviceModel
    client
    endpoint name=AdderService
    address=net.pipe://localhost/AdderService
    binding=netNamedPipeBinding
    bindingConfiguration=Binding1
    contract=TestApp.IAdderService /
    /client

    bindings
    netNamedPipeBinding
    binding name=Binding1
    maxBufferSize=65536
    maxConnections=10
    security mode = None
    /security
    /binding
    /netNamedPipeBinding
    /bindings
    /system.serviceModel
    /configuration
    Using above code and configuration I am not able to typecast IAdderService instnace to IMathService, it fails and I get null instance of IMathService at client side.
    My observationis ifserver exposes IMathService to client then client can safely typecast to IAdderService and vice versa is also possible.Howeverif server exposes IAdderService then the typecast fails.
    I hope now the requirement is very clear.Vaibhav Gawali

  • RELEVANCY SCORE 2.88

    DB:2.88:Multiple Inheritance m9


    1) Why in Java, the concept of Multiple Inheritance is achieved thru interfaces ????
    Why it is not like C++ ???.. What is the exact significance of arresting multiple inheritance........????
    Why they have made like this ????

    2) When to use abstract class .....and when to use interfaces???tell me with scenario's.....

    DB:2.88:Multiple Inheritance m9

    1) Why in Java, the concept of Multiple Inheritance is achieved thru interfaces ????
    Why it is not like C++ ???.. What is the exact significance of arresting multiple inheritance........???? Why they have made like this ????It is much simpler to implement and you can achieve much the same result through delegation.

    2) When to use abstract class .....and when to use interfaces???tell me with scenario's.....If you can use an interface, use an interface. If you use an abstract class, you may still want to specify an interface for the abstract class.

  • RELEVANCY SCORE 2.88

    DB:2.88:Instantiating An Interface ????!!!!!!!!! zp


    as i can recall interfaces are pure abstract classes and agin as i know we can not instantiate abstract classes, then when programming a servlet how do we instantiate the two interfaces: httpServletRequest and httpServletResponse ?
    thank you
    Ali

    DB:2.88:Instantiating An Interface ????!!!!!!!!! zp

    The data (Headers as well as user submitted data) comes to the server from the browser (ex. IE, another Java App, J2ME app, etc).
    The servlet container automatically encapsulates the received data into the HTTPServletRequest object.
    The container also creates a HttpServletResponse Object, which encapsulates "things" required to send information back to the browser, like handle to send response, handle to set cookies, etc

  • RELEVANCY SCORE 2.88

    DB:2.88:Interfaces And Abstract Classes 7k


    Hi! All,

    I have had a small doubt about Interfaces and Abstract Classes ... and
    I would like to discuss it with you
    In Case of Java do we only have interfaces to support multilple
    inheritance(indirectly though). I mean all other functionalities of
    interface can be provided by abstract classes. So is there any other use
    in JAva for interfaces except of course providing multiple inheritance.

    Regards

    vikram

    DB:2.88:Interfaces And Abstract Classes 7k


    To not side step the question, I would say that there
    is no other reason. It can be a nice way of sharing constants accross a program (when they really are constant).

  • RELEVANCY SCORE 2.87

    DB:2.87:Abstract Vs. Interfaces j1


    I wanna know that when we should use abstract classes and when we should use interfaces(from a design view).

    regards,

    DB:2.87:Abstract Vs. Interfaces j1

    I wanna know that when we should use abstractclasses
    and when we should use interfaces(from a design
    view). Who said it's "either or"? Use interfaces if you have
    common contracts and abstract classes if you have
    common implementation.Indeed. In 8-10 years of almost nonstop Java programming, I don't think I've ever asked myself, "Should I make an interface or an abstract class?"

    Look at the javadocs and source code for java.util....

    Collection
    List
    Set
    AbstractCollection
    AbstractList
    ArrayList
    LinkedList
    AbstractSet
    HashSet

    ...

    etc.

    ...

  • RELEVANCY SCORE 2.86

    DB:2.86:Interface m9


    Hi,
    I'm not able to understand the actual use of interfaces.

    For eg I have Class A extends b implements c,d
    I have 2 interfaces(c,d) which has got 4 methods and one abstract class 'b'.
    What if I remove the 2 interfaces c,d and write all the methods in the Abstract class 'b' so that I dont have the burden of the two interfaces c,d.
    Can someone explain me this.

    Thanks.

    DB:2.86:Interface m9

    [url http://www.javaworld.com/javaworld/jw-09-2001/jw-0921-interface.html]Design with interfaces and abstract classes to satisfy both type and implementation issues

  • RELEVANCY SCORE 2.85

    DB:2.85:Core Java 83


    what is differernce between abstract class and interface?

    DB:2.85:Core Java 83

    jwenting wrote:
    maybe an attempt at counting only posts which make any kind of sense at all?Where did the '1' come from then?

  • RELEVANCY SCORE 2.84

    DB:2.84:Interfaces And Abstract Classes 1a


    Iam new to java.i always confuse in using interfaces and abstract classes.
    when do we use interfaces and when do we use abstract classes.if possible give small scenario.

    thanq,regards
    venkat.a

    DB:2.84:Interfaces And Abstract Classes 1a

    njoy wrote:
    i agree you can also consider interfaces like moulds that the class calls on

    abstract methods moulds which the caller has to fill inHow can you call on a mould? I don't know what you are even trying to say here, but your analogy still seems misplaced. You seem to be remarking on the difference between a client using a type:

    void f(Type t) {
    t.method();
    }and defining a class that extends a class/implements an interface.

  • RELEVANCY SCORE 2.82

    DB:2.82:Interfaces And Abstract Classes ck


    Hello,

    I am confused between an Interface and an abstract class. I would cite an example:

    I consider various shape objects esp. square, rectangle etc. and consider a common behavior area which I need to determine for each of these shapes. Should I consider an Interface or an abstract class and why?

    DB:2.82:Interfaces And Abstract Classes ck

    Hint: Interfaces say what objects must do; abstract classes say (partially) how to do them (i.e., it can provide implementations).

    Two shapes are circles and squares.

    To what extent do you think you'll reuse an area() calculation between them?

  • RELEVANCY SCORE 2.82

    DB:2.82:Abstract Classes, Interfaces - When, Why? 13


    Hi,
    I was facing a question in an interview that why interfaces or abstract classes are needed? when will you go with them?
    why cannt we just create simple classes and achieve the functionality?

    Can anyone help?

    DB:2.82:Abstract Classes, Interfaces - When, Why? 13

    Well Excuuuuuuuuuuuuuuuuuuuse us;
    People are bending over backward to help you and you can't even say thanks for any of the responders by voting them a point or two.

    Benefits of interface 1) Well defined contracts 2) Doesn't care about implementation

    Benefits of Abstract Class 1) Abstracts commonality as a base class 2) Auto inherited properties, fields and methods, 3) Can define implementation.

    Now is that the right answer?

    JP Cowboy Coders Unite!

  • RELEVANCY SCORE 2.82

    DB:2.82:Interfaces And Abstract Classes cd


    Interfaces and Abstract Classes

    I read the paragragh bellow in a java book, it explains the question that many people asked in the forum.

    If you read the section about abstract classes in Chapter 5, you may wonder why the designers of the Java programming language bothered with introducing the concept of interfaces. Why can't Comparable simply be an abstract class:

    abstract class Comparable // why not?
    {
    public abstract int compareTo(Object other);
    }The Employee class would then simply extend this abstract class and supply the compareTo method:
    class Employee extends Comparable // why not?
    {
    public int compareTo(Object other) { . . . }
    }There is, unfortunately, a major problem with using an abstract base class to express a generic property. A class can only extend a single class. Suppose that the Employee class already extends a different class, say, Person. Then it can't extend a second class.

    class Employee extends Person, Comparable // ERROR

    But each class can implement as many interfaces as it likes:

    class Employee extends Person implements Comparable // OK

    Other programming languages, in particular C++, allow a class to have more than one superclass. This feature is called multiple inheritance. The designers of Java chose not to support multiple inheritance, because it makes the language either very complex (as in C++) or less efficient (as in Eiffel).

    Instead, interfaces afford most of the benefits of multiple inheritance while avoiding the complexities and inefficiencies.

    DB:2.82:Interfaces And Abstract Classes cd

    However the answer he gave is very clear :) so next time some one ask a question we can just post a link to this post, instead of writing the all same thing again or tell him go search in google.

    regards,
    sim085

  • RELEVANCY SCORE 2.81

    DB:2.81:Interface And Abstract Classes cz


    Hi! All,

    I have had a small doubt about Interfaces and Abstract Classes ... and
    I would like to discuss it with you
    In Case of Java do we only have interfaces to support multilple
    inheritance(indirectly though). I mean all other functionalities of
    interface can be provided by abstract classes. So is there any other use
    in JAva for interfaces except of course providing multiple inheritance.

    Regards

    vikram

    DB:2.81:Interface And Abstract Classes cz

    I'll give you a short and powerful answer for the need of interfaces: polymorphism.

    Nikita

  • RELEVANCY SCORE 2.81

    DB:2.81:Why Abstract Classes df


    Pals,

    Abstract classes help us in abstracting common code. The same can be achieved by using a plain java class with static methods and extending them. What extra does this abstract keyword provides

    DB:2.81:Why Abstract Classes df

    Thanks fro the reply , but still im confused ,
    partial implementations can also be done using the
    Plain class (say class A)and having a non static
    method in it (say methA(). Another class can can
    extend this class A and use / override this(methA())
    partial implementation of class A. I googled but
    couldnt find an explaining answerIn the JDK that you downloaded is src.zip. Unzip it. Look at the source code for some of the abstract classes and the concrete classes that extend them.

    For example, in List implementations, how you implement the add method is very much dependent on how the list is implemented. It's very different for a LinkedList vs. an ArrayList. It's highly dependent on the data structure that holds the list's elments. There's no reasonable way to implement it in the base class, so it's abstract.

    The addAll method, on the other hand, can be implemented completely in terms of other methods and is not dependent on the implementation details. You simply iterate over the collection that's passed in as an arg, and for each of its elements, you call this list's add() method. So addAll can be implemented in the base class--all subclasses can use the same implementation.

  • RELEVANCY SCORE 2.81

    DB:2.81:Scenarios For Abstract Classes And Interfaces jm


    Would please tell me the exact scenarios when we should use abstract classes and interfaces.

    this question disturbing me for a long time....dont think its a simple basic question, it seems to be easy and to satisy any person by explaining it's litttle bit complicated....

    thanks

    DB:2.81:Scenarios For Abstract Classes And Interfaces jm

    In short: always prefer interfaces for reference types, and always prefer interfaces versus fully abstract classes. If the class has some implementation, you have no choice anyway.

  • RELEVANCY SCORE 2.80

    DB:2.80:Abstract Class 13


    Difference between abstract class and interface
    use of abstract class

    DB:2.80:Abstract Class 13

    This question has been asked here about a billion times:

    http://search.java.sun.com/search/java/index.jsp?qt=interfacenh=10qp=st=11rf=0since=country=language=charset=variant=col=javaforums

  • RELEVANCY SCORE 2.80

    DB:2.80:Abstract Class And Interfaces s7


    I'm learning java on my own right now, but I still don't understand interfaces and abstract methods.What's the difference between an abstract class and interfaces? Why are interfaces important? Why can you not just create your own methods?

    Thanks

    DB:2.80:Abstract Class And Interfaces s7

    This question is asked and answered very often in this forum. Do a search.

  • RELEVANCY SCORE 2.80

    DB:2.80:Designing With Interfaces fc


    hello all

    I wanted feedback on a basic java question and design. specifically interfaces and when to use them. in my mind i see two reasons to use them.

    1) to decouple classes when using call back functionality. you could do this with inheritance
    but as we all know you can only extend one class so its not a great idea for this.
    Runnable is a classic example of this call back use case.

    2) when you have many implementations with common functionality but no shared code then an
    interface is a very generic data type that will suit this purpose.
    The collection API is an example(actually using simultaneously abstract classes and interfaces).

    I see these two as the reason for designing interfaces. And no other. #1 is the by far the most common one in my mind.

    Am I missing more?

    DB:2.80:Designing With Interfaces fc

    Encephalopathic:
    I think I agree with you. Either I should term 'decoupling' more generically as to cover
    decoupling classes(e.g. callbacks) and decoupling entire layers(e.g. db layer from business layer).
    I remember doing this for many situations
    So I will add as number 3: decoupling logical layers. this is different from 1. for example I remember testing servlets by extending the HttpRequest and HttpResponse interfaces. In this way I was able to abstract the container for the servlet with my own standalone app.

    I though of a 4th: late binding. you can have derived classes that have common base functionality but no different implementations. and you may have alot of these instances at runtime but you do not know until the code is executed which type you need. this is a different case i promise. as an example we wrote a game server which had as a base class player. the 2 implementations were human and robot. the server did not know you would show up for a game. of course this is polymorphism. and we did it with inheritance at the time. but could also be a use case for interfaces.

    so to sum up:
    1) decouple classes(e.g. for call back funtionality)
    2) give opportunity for others to extend your code from scratch by giving them no implementation but only blueprint(method signatures)
    3) decouple layers(great for tons of reasons)
    4) late binding functionality - when you need to defer the implementation until runtime

    all of the above could be solved using an abstract class but without multiple inheritance we look at interfaces as the appropriate solution.

    eclow:
    That's an interesting suggestion. Have you had the need for this in past?

  • RELEVANCY SCORE 2.79

    DB:2.79:Is There A Worth Of A Pain To Create Interfaces Over An Abstract Class? pf


    hi friends,
    An Abstract class contains declaration of members and must inherit class in order use it, an interface is also contains declaration of member and must implement and override members touse it. So there is no visible difference between them. But while
    i was at a class my tutor pointed out that it would be better to create interfaces than classes becuase MS kneen on interfaces (UNOFFICALLY). Well, since interfaces seems bit odd in my opinion i would give priority to creating abstract classes than interfaces.
    So am i correct in there, is there worth of pain to create interfaces over abstract classes?
    thanks

    DB:2.79:Is There A Worth Of A Pain To Create Interfaces Over An Abstract Class? pf

    Splitting a design up into Interfaces Implementations is the way to go I think, and if you look at any MS SDK (or even COM as a whole) you will see this is pretty much the official MS stance on it.
    See also the Bridge Pattern.SDET, Lync SDK Team

  • RELEVANCY SCORE 2.79

    DB:2.79:Serializable &Amp; Cloneable ff


    Hi all,

    I am new to java. When I looked into the API, I found that both Serializable and Cloneable interfaces don't have any methods.

    My question is: Shouldn't both of them be a keyword(just like abstract, final, synchronized, etc.) instead of a dummy interface? What is the need for going for an interface in this kind of scenario?

    --Palani

    Message was edited by:
    Palani@java

    DB:2.79:Serializable &Amp; Cloneable ff

    Because it is a marker interface.
    -EdwinThere's something very zen about that answer.....

  • RELEVANCY SCORE 2.79

    DB:2.79:What Is An Interface &Amp; Abstract Class ? zm


    hi ,
    i am new to java,
    pls give the answer for this question,

    what is an interface abstract class ?
    why we go for interfaces and abstract classes?

  • RELEVANCY SCORE 2.79

    DB:2.79:Re: Difference Between Abstract Class Ans Interface 39


    Abstract classes have atleast one method abstract and interfaces have all abstract methods.

    If you are developing some application in which any entity can have more than one implementation, it is good practice to use an interface and implement the classes using interfaces.

    If some of the functionality of an entity is already known and other methods can have different implementations, then creating an abstract class is better.

    It's all a part of having a good design. Look around in the API docs and you'd find lots of abstract classes and interfaces. Try to figure out why they are so... I hope I didn't confuse you.

    Read the URL for better View

    http://java.sys-con.com/read/36250.htm

  • RELEVANCY SCORE 2.79

    DB:2.79:What Is The Actual Difference Between Interfaces &Amp; Abstract Classes..? 73


    Hi Friends..!

    Please let me know what is the actual difference between Interfaces and Abstract Classes. All we can do in Abstract classes(ofcourse, except method definitions), is still possible to do in Interfaces. Then, why the concept of Abstract classes..?

    In which situation, we need Interfaces rather than Abstract classes and Vice-Versa..?

    Regards,
    k.suresh

  • RELEVANCY SCORE 2.79

    DB:2.79:Bpm kj



    Hi all,

    Can we create a BPM using just two Abstract interfaces or we need to have one inbound, one outbound and a abstract interfaces as Krishna Moorthy has specified in this url

    https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/1822. [original link is broken] [original link is broken] [original link is broken] [original link is broken] I just want to know if we can create a interface with just Abstract interfaces.

    Thankx

  • RELEVANCY SCORE 2.79

    DB:2.79:Abstract Classes And Interfaces ak


    Can anyone help me in understanding the concepts of Abstract Classes And Interfaces? What is the real application in Java Programming?

    I shall be thankful if anyone can answer this question by supplying a simple sample code that solves my problem.

    Thanks.

    DB:2.79:Abstract Classes And Interfaces ak

    Hi !

    Just a few words about an Abstract classes:
    Abstract means - INCOMPLETE, it means that some methods of this class are not realized these methodes called Abstract because it does nothing.
    You can use the abstract classes as a common classes or parent classes for descendants. And descendants itself may or may not realize the abstract methods each in defferent manners. For example:
    You have a common abstract class called Shape which is have an abstract method draw(), and You can now make for example two descendants Poly and Triangle.

    Here is a couple of code:

    abstract class Shape{
    ...
    abstract protected void draw(Graphics g);

    public void paint(Graphics g){
    .....
    draw(g);
    ......
    }
    ...
    }

    // The descendant of Shape
    class Poly extends Shape{
    .....
    protected void draw(Graphics g){
    .......
    // Here is the realization of this method specific for Polygons
    }
    .....
    }

    // Another descendant of Shape
    class Triangle extends Shape{
    .....
    protected void draw(Graphics g){
    .......
    // Here is the realization of this method specific for Triangles
    }
    .....
    }
    Remember that the descendant classes are inherit all the methods and properties of a parent class, this means that you can freely use them.
    It is called Inheritance.
    So the Abstract classes is for inheritance.

    Now about an interfaces:

    Interface it is just a declaration of methods and properties without realization. It means that some class can implement one or more interfaces, it is like a mask in a theatre, and class here is an actor with a different masks depending on situation. Also it is like connectors to methods. Another class can call the methods of the first class via the casting mechanizm to Interface.

    for example:
    public interface One{
    public int one();
    }

    // This class implements Interface One
    public class Foo implements One{
    ...
    public int one(){
    int res;
    ....
    // some calculations on res
    ....
    return res;
    }
    ...
    }

    //This class calls the methods of Interface one
    public class Doo{
    Vector objs;// here is the different objects which is implements interface One

    public void addObj(Object o){
    objs.add(o);
    }
    ....
    public void somethingToDo(){
    One o;
    int res;
    for(int i=0;iobjs.size();i++){
    o = (One)objs.elementAt(i);
    res+=o.one();
    }
    .....
    // something else with res
    System.out.println(res);
    }
    ....

    }

    public class Three{
    ....
    Doo doo = new Doo(); // something like that
    .....
    public void do(){
    Foo foo = new Foo();
    doo.add(foo);
    }
    ......
    private void show(){
    doo.somethingToDo();
    }
    ......
    }
    In this example class Doo know nothing about the class Foo. But it knows that the objects in his internal vector objs implements interface One.
    So he can freely cast it to that interface and call its method public int one().

    All of this called Polymorphism. It is like a Genie from the lamp. "Whom do you want me to be, master?"

    I hope this helps You to understand.

    Regards, Alex

  • RELEVANCY SCORE 2.79

    DB:2.79:Java Programming 33


    what is the difference between 'abstract' class and 'interface'

    DB:2.79:Java Programming 33

    Hey, get back in line. Don't jump the queue :)Well I guess I haven't qualified myself for this
    year's hunt. Maybe I could get a free-card because I
    was always on the Most Arrogant List a few years ago.Ok. I'll be nice. You'll get a free pass.

    Kaj

  • RELEVANCY SCORE 2.78

    DB:2.78:Re: Problems With Abstract And Interfaces xp


    I want to do this:

    One principal abstract class that has two methods
    abstract method 1
    abstract method 2

    two secoundary class
    class A implements method 1
    class B implements method 2

    How can I do this?
    Abstract force me to implemenst all the methods in a
    class?Abstract classes can declare non-abstract methods. Declare
    method1() and method2() in the abstract class, and, neither
    extending class will be required to implement it.

    Also, ==puckstopper. Consider hard if this problem
    is properly solved by inheritance.

    DB:2.78:Re: Problems With Abstract And Interfaces xp

    Then you don't need ten different methods not at all you need one method, and now I think I understand your problem. Inheritance from an abstract class isn't the answer to your problem.

    Consider the following:

    public abstract class SuperClass
    {
    public void methodA()
    {
    // ... Method A functionality
    }

    public void methodB()
    {
    // ... Method A functionality
    }

    public void methodC()
    {
    // ... Method A functionality
    }
    }

    class A extends SuperClass
    {
    public void doStuff()
    {
    methodA() ;
    methodB() ;
    methodC() ;
    }
    }

    class B extends SuperClass
    {
    public void doStuff()
    {
    methodA() ;
    methodB() ;
    methodC() ;
    }
    }You have two classes that inherit from SuperClass and they ALL have access to all of its member functions (methodA() ... methodC()). Since methodA() ... methodC() all do the same thing there's absolutely no point to this at all.

    So, if methodA() ... methodX() all have the same functionality then you only need it in one place [SuperClass] and this is a case where inheritance is the answer that you want.

    Or, if methodA() ... methodX() have different functionality but the same method signature and have NO default behavior then you want an interface which the other developers would implement.

    Or, if methodA() ... methodX() have default behavior but MIGHT be changed by the developer implementing the functionality then a superclass which you would override in the subclass is the correct answer.

    Making sense now?

    PS.

  • RELEVANCY SCORE 2.78

    DB:2.78:Api En Imp z7


    Hi,

    I am relative new to Java. I know the syntax and semantics.
    I am interested in J2EE, therefore looking at JSF

    I downloaded JSF from Sun. I got 2 jar files: jsf-api andf jsf-imp

    My question(s):
    - the jsf-api --- to me it appears as a set of interfaces, real classes and abstract classes. Is this the way an java 'api' is 'delivered' generally?
    - jsf-api --- why are there both real classes AND abstract classes in it? (I would say an api just contains specifications (interfaces and abstract classes) and no implementations (=real classes))
    - jsf-imp --- can someone tell me what an implementation really means? Is it required to implement all the abstract classes which are in the api?

    Thanks for your help.

    Regards
    Stephan

    DB:2.78:Api En Imp z7

    Worry about those things after you have learned JSF basics, its design and architecture.
    You will naturally understand them, then.

  • RELEVANCY SCORE 2.77

    DB:2.77:Doubt - Urgent p7


    hi

    i have a doubt in java. do java have any classed to list the drives, files and folder in a GUI format.. as windows does. i know there are controls in VB for listing the drives, folders and file. is there any class in java of this sort

    charles

    DB:2.77:Doubt - Urgent p7

    is that posible to get the drives and display as a GUI component as windows OS does..

    Charles

  • RELEVANCY SCORE 2.77

    DB:2.77:Connection ms


    The other day i tried to build the struts source tree using java 1.4, but I got an error: GenericConnection should be declared abstract. The problem is a redefined java.sql.Connection interface. I'm not completely impressed by this change,
    And I'm wondering if any other interfaces have changed by definition
    where can i find information on this?
    regards,
    jeroen.

    DB:2.77:Connection ms

    Take a look at this thread:
    http://forum.java.sun.com/thread.jsp?forum=41thread=156364
    There is a link where you can see the javadoc differences between e.g. 1.3 and 1.4.

  • RELEVANCY SCORE 2.77

    DB:2.77:Difference Between Interface And Abstract Class mj


    hello friends give me the difference between interface and abstract class
    and link to find java material

    Thanx

  • RELEVANCY SCORE 2.76

    DB:2.76:Pragmatic Review Of Java Interfaces, Abstract Classes Etc. fj


    Hi,

    I have a pretty good idea of all the basics in java programming, but I really want to learn more about how to design/construct high quality programs with a good use of encapsulation, interfaces and so on. Is there a good book which emphazises on these topics?

    Thank you.

    Nicolai

    DB:2.76:Pragmatic Review Of Java Interfaces, Abstract Classes Etc. fj

    Getting experience is probably the best thing, but there are also some good books, e.g. Refactoring Improving the design of existing code by Martin Fowler and Beyond Software Architecture creating and sustaining winning solutions by Luke Hohmann.

    Kaj

  • RELEVANCY SCORE 2.75

    DB:2.75:Concrete Class Overriding Abstract Method With Inherted Type 3m


    Hey, I'd love some advice on a little problem i have.

    I have something like this in my code:

    abstract class ABase {...}

    class AConcrete : ABase {...}

    abstract class CBase

    {

    bool func(A param);

    }

    class CConcrete : CBase

    {

    bool func2(AExtended param)

    {

    return func(param);

    }

    }

    The problem is that the abstract class must know what type it gets (into func) , because theinteriorcode needs a specific class for creation of an instance.
    Currently i gave up and moved my func to the concrete classed instead of the abstract class, is there some other way around this?

    DB:2.75:Concrete Class Overriding Abstract Method With Inherted Type 3m

    Never mind i used your answer to switch my code up a bit and it works like a charm.

  • RELEVANCY SCORE 2.75

    DB:2.75:Oop Resources c9


    Hello all...I'm currently working on learning Java, and I was wondering if anybody knew any good resources (i.e. online tutorials, actual books, etc.) that do a really good job of explaining objects, including inheritance, abstract classes, interfaces, etc. ... I just finished a Java class in college, and the book that we have isn't explaining it too well for me... Thanks a lot!

    --
    Josh

    DB:2.75:Oop Resources c9

    Try the free electronic book "Thinking in Java" by Bruce Eckel. http://www.bruceeckel.com

  • RELEVANCY SCORE 2.74

    DB:2.74:Interfaces And Abstract Classes fk


    hi,

    Can anyone help me regarding the difference between interfaces and abstract classes. What is the advantage of interface over abstract classes and viceversa. Obout the possibities of multple inheritance I know. I found allmost all people are talking some external answers.
    Why an abstract class cant we do it with concrete class.
    regards,

    Jayaprasad Viswanathan

    DB:2.74:Interfaces And Abstract Classes fk

    Abstarct class can never be instantiated. Same as interfaces.

    Can be
    subclassed.Same as interfaces.

  • RELEVANCY SCORE 2.74

    DB:2.74:Some Conceptual Questions?? p8


    1- what is the purpose of java interfaces ... Dont you think that with only abstract classes we can build an application. In that case we dont require interfaces

    2- what if java interfaces were not there, would a complex java application be possible ?

    3- Suppose there are no interfaces in java, which functionality in particular will be missing?

    4- why abstract classes? As we cannot instantiate abstract classes then what is the purpose behind all this..

    5- Is overloading a form of polymorphism? If yes, why? Because concept of polymorphism is, i believe, only possible in inheritance.

    DB:2.74:Some Conceptual Questions?? p8

    Hi Ali,

    1- what is the purpose of java interfaces ... Dont you think that with only abstract classes we can build an application. In that case we dont require interfaces

    Interfaces in concept are contracts between tow entities, it means that one entity says to the other if you want to speak to me you must speak in this language. So the other entity will speak in that language and chooses what words to say based on the situation.

    In the Java world it means that one entitiy will require the other to implement the given interface so it will be sure that its contract (set of methods) will not be violated and the implementor entity is free in how to provide the implementation for these methods.

    4- why abstract classes? As we cannot instantiate abstract classes then what is the purpose behind all this

    Abstract classes are used for the same reason as Interfaces (it is a contract) but it has some more restriction, Meaning that it might provide concrete implementations for parts of that contract sothat the implementor (or in this case the extending class) can provide implementations only for the rest of the contract.

    Abstract classes can't replace interfaces, remember in java you have single-inhertance, so if you extended the abstract class you wasted your opportunity and you can't extend another one.

    5- Is overloading a form of polymorphism? If yes, why? Because concept of polymorphism is, i believe, only possible in inheritance.

    Yes, polymorphism means you have diffrent METHODS to perform the same FUNCTION.

    So assume you have a function named getPrice and you can return the price in USD or GBP, then you need to have 2 overloaded methods, one takes no-args and return USD and the other takes a string arg and returns price in given currency.

    Hope this will help you understand the concepts.

    ---------------------------------------------------------
    Only by helping each other, we can grow

  • RELEVANCY SCORE 2.74

    DB:2.74:Re: Does Abstract Class Really Faster Than Interfaces mm


    938864 wrote:
    Abstract class vs interface is common question and I have been hearing from time and time that abstract class are slightly faster than interfaces Please cite a reference to this.

    P.S. You will not notice any difference so who cares.

    DB:2.74:Re: Does Abstract Class Really Faster Than Interfaces mm

    In what respect have I not just answered exactly that question?

  • RELEVANCY SCORE 2.74

    DB:2.74:Implementing Interfaces kc


    I have an interface A

    public interface A{
    ....
    .....

    public static void method methodAlpha();
    }

    I have two classed B and C both implementing the methodAlpha.

    Is it possible to write code in a way that it can call the respective methods with A.methodAlpha() depending on how things are going forward.

    DB:2.74:Implementing Interfaces kc

    I am trying to figure out exactly what your question is here. If you are asking can you have a static method in an interface definition call all methods from classes that implement that interface, you can't. There is no way for an interface (or class) to know it's implementors (or extendors).

    If this is not what you are asking please try to ask again, maybe put some more examples (and/or code) in the question

  • RELEVANCY SCORE 2.73

    DB:2.73:Abstract Class Vs Interface ? 9d


    hi all,

    can anybody help me.

    if i have an abstract class (full of abstract method definitions) and an interface(having same definitions).

    Now the question is in which situation we go for an ABSTRACT CLASS with full of abstract method definitions and in which situation we go for an INTERFACE.

    and other differences between ABSTRACT CLASSES and INTERFACES except Multiple Inheritence ?

    DB:2.73:Abstract Class Vs Interface ? 9d

    Hi,
    All the variable inside the interface are static and final(You can't change it).While in case of abstract class it is not so. And in abstract class you can have concrete method also while in interface all the method must be non concrete So its depends on your requirement.

    Regards,
    Alok

  • RELEVANCY SCORE 2.72

    DB:2.72:Need Help - When To You Interface Or Abstract Class? cp


    All the design books I have say that you should design with composition instead of inheritance. They go on to say things like Dont create an abstract class unless the subclass is a 'kind' of the base class rather just reusing the code in the base class. If the subclass is playing a 'role' then use interfaces. They war about the ripple and transmuting problems with inheritance but here is where I get confused: If you have an Abstract/base class and change things it will affect the entire set of class inheriting from it but they dont say the same thing would happen if you change anything in an Interface, it would screw up all classes implementing it as well. So, other that the point that java is a single inheritance language why would I pick interfaces of abstract classes, I though one of the main point OO was that you could reuse code fro super classes but with interfaces you may have the same signatures but you to code each method???

    any clarification would help
    Ryan

    DB:2.72:Need Help - When To You Interface Or Abstract Class? cp

    An interface is just a promiss. Runnable for example: If I promiss that I can run, you dont need to know if I am a Show or a HumanBeeing if all you want is to ask me to run(). You can refere to me as a Runnable without having to wory.

    An abstract method in an abstract class fills the same need. If you have no common behavour to put in the superclass, you can still make its decendants promiss that they can do a specific task.

    If you make a promiss on behalf of all your decendants, thats a serious thing to do. But it is powerfull as well. An you will discover many possible problems allready at the time of recompiling...

    When you do some thiny change in just the right place, you affect the whole world (or at least the whole "helloWorld". That is powerfull and efective and definetly a nice thing...
    Enough philosophy
    Regards,
    Ragnvald Barth

  • RELEVANCY SCORE 2.71

    DB:2.71:Regarding The Abstract And Interface km


    hai,
    I am new to java programming

    I want to difference between abstract interface,interface and abstract class

    public abstract interface Test{}

    public interface Test{}

    public abstract class Test{}

    which kind of situations use the above interfaces and abstract classes

    It would be helpfull if explain with example....

    Thanks

    DB:2.71:Regarding The Abstract And Interface km

    shashikumar, please don't multipost and don't use the browser's back button to edit your post. This creates multiple posts. I've removed the other thread you started a minute after this one.

    db

  • RELEVANCY SCORE 2.71

    DB:2.71:Basic Java Mcq! d7


    I came accros a scjp quesion that is

    Which of the following are legal declerations for non nested classes and interfaces?
    A) final abstract class Test{}
    B) public static interface Test{}
    C) final public class Test{}
    D) protected abstract class Test{}
    E) protected interface Test{}
    F) abstract public class Test{}

    I think B,C,D,E,F are correct.I know that first one is wrong because final and abstract can not be used at the same time.Am i right or wrong?Can any one give me a explanation if i am wrong.

    DB:2.71:Basic Java Mcq! d7

    Also, a good site to see...

    http://www.uni-bonn.de/~manfear/javamodifiers.php

    Regards,
    Sidath.

  • RELEVANCY SCORE 2.71

    DB:2.71:Re: Abstract Class 81


    georgemc wrote:
    jverd wrote:
    georgemc wrote:
    YoungWinston wrote:
    georgemc wrote:
    Scorpiongiri wrote:
    yesActually, if you want to give a simple yes/no answer to the original question, the correct answer would be "no", since, by definition, a concrete class cannot be declared using the 'abstract' keywordI'll pitch in for Scorpiongirl here. According to OP's initial question, the answer is 'yes'. Arguing about Java semantics, while important, is secondary.I'm not talking about Java semantics, and I respectfully disagree that this is secondary. Although there is a Java keyword abstract, the concepts of abstract and concrete in this context are not specific to Java, or even software engineering. The OP needs to know that something concrete cannot also be abstract. Sure, the answer to the first question is "yes", but as qualified by the second question, the OP clearly misunderstands what concrete class means. Answering one question whilst ignoring the other is misinformingSo, your definition of "abstract" is "contains at least one abstract method," rather than "is declared abstract"?Nope. Where do I imply that? " the concepts of +abstract+ and +concrete+ in this context are not specific to Java, or even software engineering. The OP needs to know that something concrete cannot also be abstract."

    I assumed your concrete/abstract definitions for this context were based on the presence or absence of unimplemented methods. If that's not it, what is it? Clearly it can't be "declared abstract", since obviously a fully implemented class can be declared abstract.

    Can I have an abstract class in which all the methods are defined. I mean can i make a concrete class (which has all it's methods well defined ) preceded by the abstract keyword.Answer: yes and no, respectivelySo, for the first one, what is your definition of "abstract class"? Above you say that it's NOT that the class contains at least one abstract method, so, what kind of class in Java is abstract, other than "one which has at least one abstract method"?

    DB:2.71:Re: Abstract Class 81

    YoungWinston wrote:
    georgemc wrote:
    Answer: yes and no, respectivelyWhich leaves the OP no better off than when s/he started. How about this:
    In answer to your question: yes; however you are misusing the word 'concrete' as understood by Java programmers.Good point. Best go tell ScorpionGirl

  • RELEVANCY SCORE 2.70

    DB:2.70:Abstract Method And Class x3


    I'm a beginner in Java and just learn about abstract method and class.
    However, i am wondering what is the point of using abstract method/class?
    Because when I delete the abstract method and change the class name to public class XXXX( changed from "abstract class XXXX), my program still runs well, nothing goes different.
    Is it because I haven't encountered any situation that abstract method is necessary or ?

    Thanks!

    DB:2.70:Abstract Method And Class x3

    excellent explanation jverd....I was struggling with this issue too- the way my book explains it was not clear....thanks!!!!

  • RELEVANCY SCORE 2.70

    DB:2.70:Abstract Classes And Interfaces 8s


    Why would you use these? Why not make a concrete class and extend them? I see why JAVA doesn't use mutiple inheritance but I don't see how allowing interfaces correctes that, after all what happens if two interfaces implemented by one class have two fully defined methods with the same signature but differant outputs?

    I tryed googleing this but just got articles on when to use Abstract over interface and interface over abstract, which should have helped some but it didn't.

    Can someone explain or post a link for a good example.

    DB:2.70:Abstract Classes And Interfaces 8s

    Okay thank you all. I check those out once I get home (I don't have the src.zip, or even JAVA on this computer (It's the schools)).

  • RELEVANCY SCORE 2.69

    DB:2.69:Abstract Interfaces 7m



    Hello XIers

    In an Integration Process, can I only use abstract interfaces (Can't I use inbound/outbound interfaces?) ???

    thanks

    Julio

    DB:2.69:Abstract Interfaces 7m


    bHi Julio,/b

    BPM understands only abstract interface. So you will have to define a abstract interface for each message going into BPM and inbound interface going out of BPM.

    So for example if you have a bpm scenario where in data is passed from file adapter to BPM to file adapter. If your outbound message is bVendor_Outbound/b you have to create a new message interface bVendor_Abstract/b. This message will pass through BPM and undergo transformation to become bVendor_Abstract_after_Mapping/b. This message again can't be undertstood by communication channels and hence needs to be mapped to a similar message inbound interface structure. So the final message outside the BPM would be bVendor_Inbound_after_Mapping/b

    Also you can only declare asynchronous abstarct interface as the container elements. So no synchronous abstract interfaces can be defined as container element.

    bRegards,

    Ashish/b

  • RELEVANCY SCORE 2.69

    DB:2.69:Difference Between Abstract Classes And Interfaces And When To Use Each a1


    Hi,
    I want to know the exact implementation differences between an abstract classes and Interfaces.
    When would we use each of them..
    Its seems that each does the same kind of functionality...but we need to just extend an abstract class in one and implement an Interface in another.

    Do let me know.

    Thanks,
    Ravi

    DB:2.69:Difference Between Abstract Classes And Interfaces And When To Use Each a1

    Hi,
    I want to know the exact implementation differences
    between an abstract classes and Interfaces.
    When would we use each of them..
    Its seems that each does the same kind of
    functionality...but we need to just extend an abstract
    class in one and implement an Interface in another.

    Do let me know.

    Thanks,
    RaviHi Ravi,
    A class must be declared abstract if one or more of its method is abstract. In case of an Interface, ALL the methods MUST be abstract. As java does not support multiple inheritence, Interface comes handy. In java, a class cannot extend from more than one class. To incorporate multiple inheritance, one can extend a class from another class and implement interface.

    public TestClass extends AbsClass implements Inter {
    }

    Thanks,
    Hope this helps,
    Karthick

  • RELEVANCY SCORE 2.69

    DB:2.69:Instatiated Interface??? mx


    I'm working on teaching myself Java by picking apart the code from an open source java project (www.alicebot.net). So far it all makes sense, except that there are functions that return interfaces and interfaces getting instantiated.

    I thought that interfaces were just sets of abstract functions and variables that a class that implemented them had to use...How then could one be instantiated?

    If it helps, here's a line where one is instantiated:

    Nodemapper rec = Graphmaster.match(input, nthat, ntopic);

    And here's the interface:

    public interface Nodemapper {
    public Object put(Object key, Object value);
    public Object get(Object key);
    public Set keySet();
    public boolean containsKey(Object key);
    }

    This code compiles and runs fine, and is freely available for download here: http://www.alicebot.org/downloads/programD.html

    DB:2.69:Instatiated Interface??? mx

    There are two ways to create instances of Interfaces (that I can think of). One way is to create a concrete class that implements an Interface and instantiate that object:

    public interface MyInterface {

    public void doSomething();

    }

    public class MyClass implements MyInterface {

    public void doSomething() {
    // implement doSomething method
    }
    }

    ...
    MyClass mc = new MyClass(); // - an instance of MyInterface!

    ...Another way is to create it an anonymously:

    MyInterface mi = new MyInterface() {
    public void doSomething() {
    // implement doSomething method
    }
    };Hope this doesn't create more questions than it answers.

  • RELEVANCY SCORE 2.69

    DB:2.69:Java Oop Question- Interfaces Vs Abstract Classes xm


    In a situation such as the following what would be better OOP practice to do:
    Basically, I want to add a series of panels with different types of information stored on them that can be changed to a TabPane. At the bottom of the screen there would be ok/cancel buttons and the ok button would call the SaveData method on each panel in the pane. Which of the following approaches would be more OOP correct.

    abstract class SavePanel extends JPanel
    {
    public abstract void SaveData(); //method to save information in panel
    public abstract void SetPanel(); //method to add components into itself
    }
    and do:
    class SomeClass extends SavePanel
    {
    bla bla bla
    }
    or
    interface Save
    {
    public void SaveData(); //method to save information in panel
    public void SetPanel(); //method to add components into itself
    }
    and then do:
    class SomeClass extends JPanel implements Save
    {
    bla bla bla
    }

    DB:2.69:Java Oop Question- Interfaces Vs Abstract Classes xm

    If your "SavePanel" will only define those two methods: no gui, default functionality, or anything else like that, an interface would definitely be better.

    Think about this scenario: what if you would some day want to make a text or awt based "save panel"? With abstract super classes you are confined to JPanels.

    But on the other hand, if you'd like some default functionality or GUI...

  • RELEVANCY SCORE 2.69

    DB:2.69:Re: Inteface Vs Abstract Class dd


    interfaces are implented, abstract classes are extended. In an interface ther is no code or variables only methods and any class that implements the interface must provide code implementation for all the methods. An abstract class has code. Why you would use them i have no idea or i jsut fogot

    DB:2.69:Re: Inteface Vs Abstract Class dd

    Joshua Bloch has something to say about this... see the book "Effective Java" - one of the best Java books once you no longer consider yourself a beginner

  • RELEVANCY SCORE 2.69

    DB:2.69:Abstract Class And Constructor fz


    Hi all,

    I am relatively new to Java and have some doubts on Abstract class and its constructor and subclass from it. Can someone help?

    Q1. Can abstract class have constructor? As it cannot be instantiated, can it still have constructor?

    Q2. I saw an example which has an abstract class and a subclass which extends from this abstract class. In the abstract class, there is a constructor with implementation. But in the subclass, the author only provide an empty constructor. My question is, when the subclass gets instantiated, will it execute the constructor in the abstract class?

    Confused.

    Message was edited by:
    han

    DB:2.69:Abstract Class And Constructor fz

    Thanks everyone for the knowledge shared. I fully understand it now.

    Han

  • RELEVANCY SCORE 2.69

    DB:2.69:Abstraction Vs Interfacing d7


    I'm pretty sure you guys are going to think that this must be the stupidest question....!!!

    Ok. This is it.

    I find it hard to differentiate between the concept of abstract classes and interfaces. In the end when either of them are implemented the functionality they provide is more or less the same. If that is the case why does java provide both interfaces and abstract classes when either one of them would do the job gracefully. I'm sorry if I'm mistaken I'm totally confused.

    Whoever it is that ends up clarifying my doubt......thanks in advance :)

    DB:2.69:Abstraction Vs Interfacing d7

    In an interface, all methods are abstract and public
    in an abstract class, some methods can be defined in the abstract class yet some can be blank abstract methods left to be defined by subclasses

    Interface just means EVERY method must be declared public and abstract
    Advantages to this = you can implement multiple interfaces

    You cant implement an abstract class, you can implement an interface however

  • RELEVANCY SCORE 2.68

    DB:2.68:Interfaces, Abstract Classes &Amp; Polymorphism af


    I have a friend taking a Java course as part of a larger degree program, and she's asked for some help with an assignment. The assignment is as follows:

    This assignment is to write a simple encryption/decryption application. There will be a single application
    that the user can use to encrypt or decrypt a phrase passed in on the command line, with the user deciding
    which encryption/decryption scheme to use.

    The first scheme is to add 1 to each character that is in the phrase, the other is to subtract 1 from each
    character that is in the phrase.

    To encrypt, you must be able to use the follwing syntax:

    java Crypto encrypt Additive "hello"

    Output:
    "hello" encrypts to: "ifmmmp"

    To decrypt:

    java ca.bcit.cst.comp2256.a###### decrypt Additive "ifmmp"

    Output:
    "ifmmp" decrypts to: "hello"

    Use Additive or Subtractive as the arguments to choose which encryption/decryption to
    use. The problem is, I'm not entirely sure how to use abstract classes and interfaces to do what is being asked. I'm pretty sure I could do the whole program in a single for-loop, but apparently her teacher doesn't want people coming up with their own solutions for the problem. I don't need any code for how to do it, per se, I'm just wondering how one would structure a program like that to include interfaces, polymorphism and abstract classes.

    Anyone have any ideas?

    DB:2.68:Interfaces, Abstract Classes &Amp; Polymorphism af

    with the user deciding which encryption/decryption scheme to use.This is the key sentence. encryption/decryption can be done using multiple schemes. The contract for any given scheme can be defined using
    public String encrypt(String input);
    public String decrypt(String input);There can be multiple implementations for these methods, one set for each scheme.

    The contract therefore becomes the interface and each implementation is a concrete implementation of this interface.

    The problem doesn't delve deep into the kind of schemes available. If it does and there is a significant overlap between 2 schemes, an abstract class that takes care of the shared logic among 2 schemes comes into picture.

    Hope this helps!

  • RELEVANCY SCORE 2.68

    DB:2.68:Protected Constructor And Factory Classes For Interfaces And Abstract Class mp


    Hi, In J2SE specification, many protected constructors are defined in abstract class with below sentence

    'Default constructor is protected on purpose'

    I use private constructor very often to disallow instanciate of classes.

    Is it same purpose? Is the reason defined as protected that specification does not show private method?

    Another question is,

    There are many factory classes also in J2SE.
    The factory classes usally has a static method to create certain instance
    like newInstance(). But in many case, the instance created by factory is
    type of interfaces or abstract classes, for example JMXConnector
    JMXConnectorFactory . As you know implementation classes of interfaces or abstract classes can have constructor, thus
    factory class can't guarantee all instances are created by factory class.
    Can anyone tell me what is reason to define factory class for interfaces and abstract classes?

    DB:2.68:Protected Constructor And Factory Classes For Interfaces And Abstract Class mp

    So nobody has to know what the implementation class even is, and
    they can't find out easily whether it has extra public methods for its
    own convenience.
    This is Object Oriented Programming 101 really. I agree the good thing when using factory for interfaces.
    What I really want to do is, for certain interface A, I want all
    its sub classes are created through a Factory class to register
    all instances of the interface to manage in centralized location.
    For my case, factory class can't guarantee it, right? Do you know
    any way to guarantee it ?

    I want you ask from a point of specification writer view.

  • RELEVANCY SCORE 2.68

    DB:2.68:Interfaces And Abstract Classes 73


    can anyone pls tell me where exactly an abstract class is used and where exactly an interface is to be used.

    i think the main difference between an abstract class and an interface is that an interface will have all the abstract methods whereas an abstract class can have one or more abstract methods--- if i am not wrong.
    anything to add? -- pls let me know on this....

    and also how they might be useful for us....

    DB:2.68:Interfaces And Abstract Classes 73

    The differences are already quoted. In addition of that
    the abstract class will come in the class/system hierarchy, but interface will not.

  • RELEVANCY SCORE 2.68

    DB:2.68:Documentation Formats For Interfaces, Classes, Abstract Classes 1c


    I am writing docs and want to make sure it conforms to best practices. Here is what I am doing:

    interfaces = [italics, not bold]
    classes = [not italics, bold]
    abstract classes = [italics, bold]

    I am most unsure of abstract classes?
    That is important to me, so please help me get this straight. thanks.

    DB:2.68:Documentation Formats For Interfaces, Classes, Abstract Classes 1c

    Everybody knows that interfaces are blue, classes are red, and abstract classes use jumpy text.

    (that was a joke by the way)

    To my mind, using bold for abstract classes would be misleading. Just on an intuitive level, bold seems more concrete. But that's just me. I think the best thing to do is just to decorate the names with "interface" or "abstract" so there's no confusion.

  • RELEVANCY SCORE 2.67

    DB:2.67:Instanceof Operator Question sx


    Can you use instance of (successfully) on interfaces and abstract classes?
    I am confused because if class A implements interface B (or extends abstract class B) it is a type of B but it is not an instance of B, since interfaces/abstract classes cannot be instantiated.

    DB:2.67:Instanceof Operator Question sx

    Sorry, the reason I ask is because on weekdays I have limited internet time so if I ask it here I can work on my projects and get the answer without taking time away from working on my project. Thanks for the answers.

  • RELEVANCY SCORE 2.66

    DB:2.66:Abstract Classes And Interfaces 97


    HiCan anyone explain me the difference betweeen the abstract class and interfaces?What is the use of the interfaces?How can we inherit multiple Interfaces?Can anyone please explain my above questions in simple words.?

    DB:2.66:Abstract Classes And Interfaces 97

    David,You are correct, I did not notice that he was inheriting from the other interfaces. My bad. I should have paid more attention in my answer.Of course, the next step in all of this would be to explain explicitly implementing the interface, and what would happen if IOne and IThree (for example) each had methods named someOperation. But I think the OP is good for now :)ChrisChris Snyder, Stumbling through code one day at a time

    If your question was answered, please mark it.

  • RELEVANCY SCORE 2.66

    DB:2.66:Difference Between Abstract Class And Interfaces 9a


    Hi,

    Any body can tell me In which scenarios we use abstract class and in which scenario we use interfaces.

    In real time applications.

    DB:2.66:Difference Between Abstract Class And Interfaces 9a

    [url http://www.javaworld.com/javaworld/jw-09-2001/jw-0921-interface.html] maximizing flexibility

  • RELEVANCY SCORE 2.66

    DB:2.66:Abstract Classes Vs Interfaces ma


    hi all
    Can any one explain me when to use abstract classes and when to use interfaces. I get confused on this

    pl help

    regards
    sundar

    DB:2.66:Abstract Classes Vs Interfaces ma

    hi,
    thanx a lot for your help

    regards
    sundar

  • RELEVANCY SCORE 2.66

    DB:2.66:Need Assistance To Know How To Map An Interface In Web Service(Wsdd) zd


    Hi,

    I am writing a Web Service which has a Bean Class, this Bean Class implements a lot of interface and other Bean Classes extends Abstract Class.

    I want to know is it possible in Axis to map these Interfaces and Abstract Class in the WSDD file. I am Mapping the Bean Class but doesnt have any idea about interfaces and abstract classes.

    DB:2.66:Need Assistance To Know How To Map An Interface In Web Service(Wsdd) zd

    Hi,

    I am writing a Web Service which has a Bean Class, this Bean Class implements a lot of interface and other Bean Classes extends Abstract Class.

    I want to know is it possible in Axis to map these Interfaces and Abstract Class in the WSDD file. I am Mapping the Bean Class but doesnt have any idea about interfaces and abstract classes.

  • RELEVANCY SCORE 2.66

    DB:2.66:Re: Abstract Classes Versus Interfaces 37


    This concept of a 'conceptual object' is plain confusing, much safer to restrict the term Object to mean an instance of a Class, a Class can implement an interface.

    Having said that I think I'm with daFei on this if I've unsterstood you right. Logically it seems a HashSet is not a cloneable or a serialiable but is is a Set yet we are using the same mechanism for all three relationships. Interfaces should be used for only clonebale and Serializable which is how java code used to normally be written.

    DB:2.66:Re: Abstract Classes Versus Interfaces 37

    [...]
    1The Collection classes are generally going via the
    interface route, providing Abstract classes where
    they may be useful. For example AbstractSet
    implements Set, and it is extended by HashSet,TreeSet
    and EnumSet. So this seems to be using an 'is a'
    relationship between AbstractSet and Set, and between
    HashSet and AbstractSet.

    2Whereas the Swing framework take a different
    approach , for example JTree extends JComponent but
    does not implement a Tree interface.

    These seem to be to be fundamentally different
    approaches, and I cant see why it was right to use
    one method for one and one for another.The major difference could be that the AbstractSet (or its implementations) represents what is called a model in the MVC architecture,
    while JTree represents the controller. If you dig a little, you will find that JTree instances use an instance of TreeModel to hold the data.
    Of course, TreeModel is an interface, which gives some warranties on the independence between the model and the controller.

    Personnally, I don't see abstract classes and interfaces as identical.
    Ideally, abstract classes give an inheritance in terms of structure, while interfaces bring the behavior.

    A creature is composed of a corpse, a brain, a heart and members.
    members give a creature the ability to move.
    some objects can move, which doesn't mean they belong to the creatures family.
    some creatures won't be able to make deductions, while others will.
    abstract class Creature implements Thought, Movement, ... {
    private Organ brain, heart, ...;
    private Member[] arms, legs, ...;
    ...
    }

    interface Thought {
    storeIdea(Idea idea);
    makeDeduction(Rule[] rules, Fact[] facts, Variable[] variables);
    ...
    }

    interface Movement {
    moveForward();
    moveBackward();
    turn(Direction direction);
    moveToPoint(Point point);
    ...
    }Take the above only for a (non serious) sample, of course :)

  • RELEVANCY SCORE 2.65

    DB:2.65:Swcv And Namespace Messagesinterfaces jp



    Hello all,

    I have some doubts about Messages Interface used in BPM.

    BPM just used Abstract Message Interfaces, but to expose the Interface to sender aplication, XI need the same Message Interfaces that is declared abstract but no abstract.

    My question is how the Business Process Engine that the Outbound Message Interface, that my application is using, is the Abstract Interface that activate my Integration Process???

    Regards,

    Luiz

    DB:2.65:Swcv And Namespace Messagesinterfaces jp


    Hi,

    Just to add on , this blog may help u -- /people/krishna.moorthyp/blog/2005/06/09/walkthrough-with-bpm

    Regards,

    moorthy

  • RELEVANCY SCORE 2.65

    DB:2.65:Abstract Classes Vs Interfaces 3x


    Why do we need Interfaces when we have Abstract Classes?Please give me a simple example and a real usage of Interfaces.
    Thanx

    DB:2.65:Abstract Classes Vs Interfaces 3x

    I don't think interfaces are trying to cover the multiple inheritance of C++. And there is no issue about abstract classes and interfaces, but inheritance and implementation. Even, they have a very different use.

    Inheritance should be used to specialize an object, instead implementation is more oriented to container issues. I mean, when you write any kind of container you don't want to be forced to use a unique kind of specialized objects, but objects that reponds at your container needs. Inheritance will improve the objects of your container, but the interface is the suitable solution to meet those container needs.

    Supose you write a Desktop that should own docked windows. Supose that you will talk to some well-known methods of this windows and you will implement them in the base class JDockedWindow, which inherits from JFrame. As long as all your needs fit into JDockedWindow this solution is good enough, but what if JFrame is not a right base class for something new you want to do?

    Supose now that you have created an interface called DockedWindow with the well-known methods used by Desktop to talk to the owned windows. Now you implement this interface in the JDockedWindow. Everything seems to be the same, but instead of adding an instance of JDockedWindow class to the Desktop you add an instance of the implemented interface DockedWindow. Just with change you become free to implement this interface to the new thing you want to do. See, inheritance helps you on improving docked windows, while implementation is letting you to add new and totally different specialized objects.

    Sorry, this is too large and my english isn't good enough. But I couldn't stop it.

  • RELEVANCY SCORE 2.65

    DB:2.65:Implementing Interfaces cp


    Hi,

    I have an interface and 3 implementations of it.
    All the 3 implementations have a method which is common.
    Generally what i would do is i would implement the interface in a abstract class and
    all the 3 implementations can extend the abstract class.

    But my problem is i dont want to abstract the class...as i dont my 3 implementations to extend this class as it has to extend some other class..

    is there any way by which i can do it... any java pattern which allows me to do it...

    I guess my question is clear.. waiting for a reply...

    DB:2.65:Implementing Interfaces cp

    First, this is a forum on Generics not for generic questions. Your question belongs to one of the essential forums.
    And second, no, it's not clear what you want. Having your 3 classes extending an abstract class without extending it?

  • RELEVANCY SCORE 2.65

    DB:2.65:Abstract Attribute.....? xz


    HiI have imported RFC into my Integration Repository... when i am creating message interfaces apart from inbound and outbound i got one more option Abstract... in what scenarios we will use abstract?Thanks RegardsRavi Shankar B

    DB:2.65:Abstract Attribute.....? xz

    Hi Ravi,As earlier mentioned Abstract interfaces are used in BPM.See this link for additional details..http://help.sap.com/saphelp_nw04/helpdata/en/55/c5633c3a892251e10000000a114084/frameset.htmRegards,Sumit

  • RELEVANCY SCORE 2.65

    DB:2.65:Re: Interfaces Are Slower Than Abstract Class s1


    java methods are dynamically bound, no matter what source object they appear to belong to. I really hope you're not making design decisions such as "we'll use concrete classes here because they're faster"

    you won't get an explaination of when to use abstract classes or interfaces. it gets asked every day, and it's such a tiresome explaination to write out. google for it, but you won't find much of use. deciding when to use which is a judgement call, there isn't a handy rule-of-thumb, other than the one the language constructs themselves imply quite loudly

    DB:2.65:Re: Interfaces Are Slower Than Abstract Class s1

    Are u software engg or automobile engg. You canwrote
    aanswer to my question in same line u worte allthis.

    ok then. use interfaces when dealing with a database
    on another machine, and abstract classes when it's
    local. Except for the mauve ones, obviously, because they have more RAM.

  • RELEVANCY SCORE 2.65

    DB:2.65:Interfaces And Abstract Classes 8x


    Whats the difference between an interface and an abstract class.

    DB:2.65:Interfaces And Abstract Classes 8x

    Another trait that is often overlooked is that the abstract methods and constants declared in an interface are always public; with abstract classes, you can declare them (package) and protected scope as well.

  • RELEVANCY SCORE 2.64

    DB:2.64:Abstract Classes Vs. Interfaces zd


    Hi,
    I have 2 basic questions that I'd like answers for:
    1) What is the exact difference(s) between abstract classes and interfaces? --
    2) Where are they used, and why are they preferred in their respective areas of usage?
    I've gone through some books (CORE JAVA, THE COMPLETE REFERENCE,etc.) as well as some online documentation (by Bill Venners, Paul Rogers, Peter Kriens, etc.) and I'm stil confused.
    I'd be glad if someone could shed a little light on this with as little ambiguity as possible.
    Thanx a ton!!!!!!!!!
    TheJavaKid

    DB:2.64:Abstract Classes Vs. Interfaces zd

    Hi,
    I have 2 basic questions that I'd like answers for:
    1) What is the exact difference(s) between abstract
    classes and interfaces? -- The first answer gives a good description, but it may be useful to understand the distinction in terms of an example. One class can implement multiple interfaces, that is, present different views on itself to various objects. I might have some GUI class that implemented ActionListener, KeyEventListener, ListSelectionListener etc etc. As such it registers itself with the various "observables" (ie. a JButton, a JTextField and a JList). The JList should no more be able to call keyTyped() than it should any of the other methods on the GUI class - it can only see the view of the class encapsulated by its valueChanged() method. This has advantageous implications for all sorts of things, in particular the authors of javax.swing implemented the Listeners as interfaces (not abstract classes) so that objects could be more than one thing at a time - remember of course that there is no multiple inheritance in Java.

    However, if you are writing an application, you may feel that it violates encapsulation that a single object implements more than one interface and hence may instead define some type as an abstract class, even if the class has no implementation details whatsoever. By this I mean that you may have 2 "types" within your system which you could define as interfaces but of which you would rather restrict users from defining a class that is simultaneously "both" of these things.

  • RELEVANCY SCORE 2.64

    DB:2.64:Re: What Is Abstract Insterface What Is The Use Of This aa


    whats does it means if i declare interface as
    abstract.See this link for more info, but here's the important part.

    http://java.sun.com/docs/books/tutorial/java/interpack/createinterface.html

    Note: Previous releases of the Java platform allowed you to use the abstract modifier on interface declarations and on method declarations within interfaces. However, this is unnecessary, because interfaces and their methods are implicitly abstract. You should not use abstract in your interface declarations or in your method declarations within interfaces.

    DB:2.64:Re: What Is Abstract Insterface What Is The Use Of This aa

    If your interface itself is not explicitly declared as
    public, there is a difference - no other interfaces or
    classes can extend/implement the interface unless they
    are in the same package as the interface.But it can do via a sub-interface, in which case all the methods will be visible (as they are public), etc...package mypackage;

    interface NonPublicInterface {
    int x = 1;
    int getY();
    }

    ///////////////////

    package mypackage;

    public interface PublicSubInterface extends NonPublicInterface {
    }

    //////////////////

    package someotherpackage;

    import mypackage.PublicSubInterface;

    public class ExternalImplementation implements PublicSubInterface {
    public int getY() {
    return x;
    }
    }

    //////////////////

    package mypackage;

    import java.lang.reflect.Field;
    import java.lang.reflect.Method;
    import java.lang.reflect.Modifier;

    import someotherpackage.ExternalImplementation;

    public class InterfaceTest {
    public static void main(String[] args)
    throws Exception {

    Class clazz = NonPublicInterface.class;
    System.out.println(clazz.getName()+" : "
    +Modifier.toString(clazz.getModifiers()));

    Method[] methods = clazz.getDeclaredMethods();
    for (int i = 0; i methods.length; i++) {
    System.out.println(methods.getName()+" : "
    +Modifier.toString(methods[i].getModifiers()));
    }

    Field[] fields = clazz.getFields();
    for (int i = 0; i fields.length; i++) {
    System.out.println(fields[i].getName()+" : "
    +Modifier.toString(fields[i].getModifiers()));
    }

    System.out.println("------------");

    ExternalImplementation imp = new ExternalImplementation();
    System.out.println(imp instanceof NonPublicInterface
    ? "imp DOES IMPLEMENT NonPublicInterface"
    : "imp DOES NOT IMPLEMENT NonPublicInterface");

    System.out.println(imp.getClass().getPackage().equals(
    NonPublicInterface.class.getPackage())
    ? "imp's PACKAGE IS THE SAME as that of NonPublicInterface"
    : "imp's PACKAGE IS DIFFERENT to that of NonPublicInterface");
    }
    }

    ...And of course I wouldn't recommend a design anything like that above - its rather contrived.

    The only thing thats really particularly different, is that outside of [i]mypackage you can't declare a reference whose type is mypackage.NonPublicInterface.

  • RELEVANCY SCORE 2.64

    DB:2.64:Why Interfaces? 3f


    Why interfaces have Methods of type public abstract only and Variables of type public, static final only?. Also why no constructors?

    DB:2.64:Why Interfaces? 3f

    I really don't think this general java question should be asked an a mobile subforum...

    Why interfaces have Methods of type public
    abstract only and Variables of type public, static
    final only?. Also why no constructors?Methods: private and protected methods are useless in an interface, since the class using the interface will not be able to use it
    Variables: same thing
    Constructor: An interface has nothing to construct, so therefore there is no constructor.