Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: which one more powerful in java ?

  1. #1
    Contributing Member
    Join Date
    Sep 2006
    Answers
    962

    which one more powerful in java ?

    Which concept (Interface or Inheritance) is more powerful in java?

    -------------
    suresh


  2. #2
    Expert Member
    Join Date
    Oct 2005
    Answers
    383

    Re: which one more powerful in java ?

    hi
    I think both are equally imp in java!Still i think may be inheritance simply coz it allows code reusability.interfaces used for multiple inheriance only,so i think
    inheritance is powerful.
    bye

    :)
    NEVER SAY DIE.

  3. #3
    Junior Member
    Join Date
    Mar 2007
    Answers
    1

    Re: which one more powerful in java ?

    Interface no doubt!


  4. #4
    Junior Member
    Join Date
    Mar 2007
    Answers
    5

    Re: which one more powerful in java ?

    'both are imporatant no doubt abt it...i am going to explain it clearly tomorrow..becaoz...there is need to refer abt it clearly'


  5. #5
    Junior Member
    Join Date
    Mar 2007
    Answers
    3

    Re: which one more powerful in java ?

    Both the concepts are having its own important,But compare to Inheritance Interface having more powerful....


  6. #6
    Junior Member
    Join Date
    Feb 2007
    Answers
    23

    Re: which one more powerful in java ?

    Inheritence is a time tested, 'globally' accepted feature. So inheritence is a very, very powerfule feature.

    Interfaces are powerful only because inheritence is powerful.

    Interfaces combine two very important notions in programming.

    Inheritence + abstraction = interface

    The abstractness part allows us to 'program to interfaces' and is used in atleast a couple of design patterns (I know only two p[atterns ). This provides a common interface making the code extensible and maintanable at the same time.

    And you know what inheritence brings to the package.

    I still can't decide which is more powerful


  7. #7
    Junior Member
    Join Date
    Apr 2007
    Answers
    1

    Re: which one more powerful in java ?

    Inheritance -->enforces reusability in the design phase (closed to traffic at runtime JRE ).

    Interface --> enforces and defines an open standard for any future framework to be build upon. (open to traffic at runtime JRE )


  8. #8

    Re: which one more powerful in java ?

    Both are equally important in java..


  9. #9
    Contributing Member
    Join Date
    Feb 2007
    Answers
    47

    Re: which one more powerful in java ?

    As the famous GoF book says:

    Prefer interfaces over inheritance.

    Use interfaces as a design-time resource when you are planning your system. Inheritance should be used almos always to reuse code. If your system is designed based on interfaces, it will be easier to maintain and to evolve. Of course this is not a fixed rule, but it works most of the time.

    --------------
    Neelima


  10. #10
    Contributing Member
    Join Date
    Nov 2007
    Answers
    46

    Re: which one more powerful in java ?

    encapsulation,polymophism and interfaces.
    another main concepts:
    reusability.
    portability.


  11. #11
    Junior Member
    Join Date
    Nov 2008
    Answers
    2

    Re: which one more powerful in java ?

    can we read a xml file through the core java application?if possible provide one example also?


  12. #12
    Junior Member
    Join Date
    Nov 2008
    Answers
    1

    Re: which one more powerful in java ?

    Quote Originally Posted by psuresh1982 View Post
    Which concept (Interface or Inheritance) is more powerful in java?

    -------------
    suresh
    Interface. Because Multiple inheritance are not allowed in jave


  13. #13
    Junior Member
    Join Date
    Nov 2007
    Answers
    1

    Re: which one more powerful in java ?

    Inheritance is the major force behind any object oriented language.

    First inheritance concept comes in picture then any other thing(like interface) which need to be inherited.

    So powerful in Inheritence offcourse!!!


  14. #14
    Junior Member
    Join Date
    Dec 2008
    Answers
    1

    Re: which one more powerful in java ?

    interface has to be implemented("extends" in other case), sort of inheritence. So the question is absurd.


  15. #15
    Junior Member
    Join Date
    May 2007
    Answers
    7

    Re: which one more powerful in java ?

    interface is useful


  16. #16
    Junior Member
    Join Date
    Jan 2009
    Answers
    4

    Re: which one more powerful in java ?

    inheritance is not useful to inherit from many classes..ie multiple inheritance..
    in that situation only inteface came..so interface can do more than inheritance..so interface is best..It all depends ,where u r using it..


  17. #17
    Junior Member
    Join Date
    Jan 2009
    Answers
    1

    Re: which one more powerful in java ?

    One benefit of using interfaces is that they simulate multiple inheritance. All classes in Java must have exactly one base class; multiple inheritance of classes is not allowed. However, a Java class/interface may implement/extend any number of interfaces.
    you know u cannot achieve multiple inheritence widot interfaces.,this is one of the limitations of the Java language.so according 2 me interfaces r more powerful,but we can also say dat both r relatively connected 2 each other....k nw cya if u gt ny rite option den do inform us.gud day.


  18. #18

    Re: which one more powerful in java ?

    my point of view inheritance is more pwerful because interface are given to implement multilevel or hirechical inheritance,which is not supported by java classes


  19. #19
    Junior Member
    Join Date
    Mar 2009
    Answers
    6

    Re: which one more powerful in java ?

    Well guys

    Without inheritance,interface has least meaningful existence but when both exist Interface is lovely to play with. [ To my understanding the question lays the scenario that both exist,only then we can compare and speak about the power between the two ]

    So my vote goes to interface

    By
    Venky


  20. #20
    Junior Member
    Join Date
    Apr 2009
    Answers
    3

    Re: which one more powerful in java ?

    Quote Originally Posted by hemanthreddy42 View Post
    can we read a xml file through the core java application?if possible provide one example also?
    We can read XML files using DOM Model -- as follows:
    <?xml version="1.0"?>
    <company>
    <employee>
    <firstname>Tom</firstname>
    <lastname>Cruise</lastname>
    </employee>
    <employee>
    <firstname>Paul</firstname>
    <lastname>Enderson</lastname>
    </employee>
    <employee>
    <firstname>George</firstname>
    <lastname>Bush</lastname>
    </employee>
    </company>

    import java.io.File;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;

    public class XMLReader {

    public static void main(String argv[]) {

    try {
    File file = new File("c:\\MyXMLFile.xml");
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.parse(file);//This can take a string variable also
    doc.getDocumentElement().normalize();
    System.out.println("Root element " + doc.getDocumentElement().getNodeName());
    NodeList nodeLst = doc.getElementsByTagName("employee");
    System.out.println("Information of all employees");

    for (int s = 0; s < nodeLst.getLength(); s++) {

    Node fstNode = nodeLst.item(s);

    if (fstNode.getNodeType() == Node.ELEMENT_NODE) {

    Element fstElmnt = (Element) fstNode;
    NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("firstname");
    Element fstNmElmnt = (Element) fstNmElmntLst.item(0);
    NodeList fstNm = fstNmElmnt.getChildNodes();
    System.out.println("First Name : " + ((Node) fstNm.item(0)).getNodeValue());
    NodeList lstNmElmntLst = fstElmnt.getElementsByTagName("lastname");
    Element lstNmElmnt = (Element) lstNmElmntLst.item(0);
    NodeList lstNm = lstNmElmnt.getChildNodes();
    System.out.println("Last Name : " + ((Node) lstNm.item(0)).getNodeValue());
    }

    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }

    Do try this code just by sending the string [thats the contents of the XML-file].


  21.  Sponsored Ads
    Ad


     
Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact