Interfaces and methods of Object class

JSL 2.0 states the following
If an interface has no direct superinterfaces, then the interface implicitly
declares a public abstract member method m with signature s, return type r,
and throws clause t corresponding to each public instance method m with
signature s, return type r, and throws clause t declared in Object, unless a
method with the same signature, same return type, and a compatible throws
clause is explicitly declared by the interface.
But the following codes produces empty output
package test;
import java.lang.reflect.Method;
public class TestIterface {
    public static void main(String [] args){
        Method [] methods=Y.class.getMethods();
        for(int i=0, n=methods.length;i<n;i++)
            System.out.println(methods);
interface Y{
What are the reasons of such behaviour?

then the interface implicitly declares a public abstract member method
"Implicit" means that it's implied that the interface declares those methods; unlike java.lang.Object, there is no interface from which all other interfaces descend. All interfaces at the "top" of the inheritance hierarchy are implied to expose at least the same methods as Object.
Hope this helps...

Similar Messages

  • How do interfaces have methods of Object class

    Hi All,
    Please consider the following code snippet.
    public interface EmployeeService
        public void createEmployee(Employee emp);
        public Employee findEmployee(String empId);
    public class EmployeeServiceImpl implements EmployeeService
        public void createEmployee(Employee emp) { ................. }
        public Employee findEmployee(String empId) { ................. }
    }The above is a simple example where I have an employee object with two service methods to create and find an employee.
    Now the consider the following
    EmployeeService empService = new EmployeeServiceImpl();
    Employee emp = empService.findEmployee("1").So the above code helps me in finding an employee.
    Now, we know that you can only call those methods that are defined in the interface.
    My question is, if I use the empService you would be able to access the methods of the Object class (equals, hashCode, wait etc.)
    How does this happen? In the Jave API we know all class by default override the Object class, so how does it work with interfaces?
    Thanks in advance for the reply

    [JLS 6.4.4 The Members of an Interface Type|http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.4.4] says:
    If an interface has no direct superinterfaces, then the interface implicitly declares a public abstract member method m with signature s, return type r, and throws clause t corresponding to each public instance method m with signature s, return type r, and throws clause t declared in Object, unless a method with the same signature, same return type, and a compatible throws clause is explicitly declared by the interface. It is a compile-time error if the interface explicitly declares such a method m in the case where m is declared to be final in Object.
    So, in short, those methods exist in interfaces because the JLS says they do.

  • Track public classes, interfaces and methods by ID

    Hi All,
    I'm wondering whether there is a tool to assign a unique ID to classes, interfaces and methods (eg. within Javadoc) and track these IDs.
    The reason I'd need such a feature is that I'd like to do requirements tracking in an easy but complete way. I have a document containing functional specifications (with IDs) and on the other side there is the source code; where the javadoc of the public methods and classes is my software specification. What I now want to do is make a link between the IDs in the functional spec to the IDs in the sofware spec (ie. the source code).
    Does anybody know of such a tool (commercial or not)?
    Thanks,
    Daniel

    I'm a bit confused as to whether or not I understand you correctly. Please tell me if the following pseudocode is somewhat like the solution you are looking for:
    class MethodFunctionality {
       private Class methodClass;
       private String methodSignature;
       private List methodFunctions;
        *   Returns true if the method is used for the specified
        *   requirement, false otherwise.
       public boolean fulfills(int requirementId) {
          if methodFunctions.contains(requirementId)
             return true;
          else
             return false;
       public String getMethodSignature() {
          return this.methodSingature;
       public Class getMethodClass() {
          return this.methodClass;
        *   Returns an array with IDs of each functional
        *   requirement covered by the method.
       public int[] getCoverage() {
          return this.methodFunctions;
    class ClassFunctionality {
       private Map methodDetails;
       private List classFunctions;
       public MethodFunctionality getMethodDetails(String methodSignature) {
          return (MethodFunctionality) this.methodDetails.get(methodSignature);
        *   Returns true if the class is used for the specified
        *   requirement, false otherwise.
       public boolean fulfills(int requirementId) {
          if classFunctions.contains(requirementId)
             return true;
          else
             return false;
        *   Returns an array with IDs of each functional
        *   requirement covered by the class.
       public int[] getCoverage() {
          return this.classFunctions;
    }Mapping classes and methods to functionality like this would both allow you to query each class and method for all the functional requirements they claim to cover and would allow you to collect all classes and methods involved for a particular functional requirement.

  • Deprecated interfaces and methods

    We have a weblogic time service that utilize a lot of
    deprecated interfaces and methods such as
    ScheduledTriggerDef, TimeServicesDef etc. Although the time
    service runs in the WLS 7, it is a big concern to me
    that it uses so many deprecated interfaces or methods.
    I am just wondering how I can replace them with non-deprecated ones

    Mark,
    I have a question about the API.
    From the documentation and the API docs it is not clear how to schedule
    a callback to be called just once ASAP.
    We use the deprecated Timer service to execute long running operations
    on the Weblogic thread pool and want the operation to execute only once
    and start as soon as there is a thread available.
    It is not clear what will happen in case a task is scheduled to be
    executed only once and the time for that execution has passed ( 5 ms ago).
    I'd appreciate the clarification.
    Thanks,
    Dejan
    Mark Griffith wrote:
    It will run because it is only deprecated. You should at some point
    "rewrite", but the rewrite is not that big of a deal. There maybe some
    slight differences in timers, since we moved to jmx interfacs, but the
    scemantics should be very very close.
    Attached is an example that will run in the 8.1 sample environment.
    cd to $WLS_HOME
    (On my box it is /bea/wls81/weblogic81/)
    cd samples/domains/examples/
    setExamplesEnv.sh
    cd ../../server/examples/src/examples
    ../examples/src/examples 201$ pwd
    C:/bea/wls81/weblogic81/samples/server/examples/src/examples
    cp jmxTimerEar.zip .
    jar xvf jmxTimerEar.zip
    cd jmxTimerEar
    ant
    And it should build for you.
    Cheers
    mbg
    "Eric Sundberg" <[email protected]> wrote in message
    news:[email protected]..
    We have a weblogic time service that utilize a lot of
    deprecated interfaces and methods such as
    ScheduledTriggerDef, TimeServicesDef etc. Although the time
    service runs in the WLS 7, it is a big concern to me
    that it uses so many deprecated interfaces or methods.
    I am just wondering how I can replace them with non-deprecated ones

  • Native method in object class........

    I would like to know that which method of object class is a native method..........

    flounder wrote:
    The natives are getting restless.
    What they do with him when he arrives, I don't know.This reminds me of one of my favorite entries in Ambrose Bierce's [Devil's Dictionary|http://en.wikipedia.org/wiki/Devil%27s_dictionary]
    h3. Aborigines
    Persons of little worth found cumbering the soil of a newly discovered country. They soon cease to cumber; they fertilize.

  • Interfaces and methods with complex object

    In all the examples I have, the methods of an interface use only basic java datatypes (int, Character, ..)
    I want to pass a Vector that represents a list of objects from one of my own classes to an interface method.
    class Myclass ...
    private String p1;
    private int p2;
    myInterfaceMethod(..., Vector list, ...)
    // list is a vector of Myclass objects
    How do I know about Myclass when implementing the interface and how do I access p1 and p2 ?

    You can use any kind of "complex" object in your interface methods, all of them are objects at last.
    The other question seems to be a misunderstanding of interface implementation. When u "implement" an interface in a class, all that JVM does is to check that you actualy have one method (with code inside its body) for each method you defined previously in the interface.
    Think of an interface as a contract signed by a class. It's forced to implement each method definied in you interface. So, as the method is defined inside the class, you can access any data member of the class without doing anything "special". Do u catch it?

  • Java interfaces and containers in different classes

    Hi in trying to create an interface in Java that will be the basis for other classes to populate areas on in in certain panels.
    So for example I have a default size for a screen and some default buttons that should appear on it. These are all setup in a class called ScriptyUI. Within ScriptyUI I want to set up several rows where each row will be populated with the container of a different class. So for instance another class called NetworkAreaUI will create all the buttons and boxes needed for the NetworkUI class along with the actionListeners for each of the buttons. I therefore want to add this into one of the rows of the ScriptyUI class.
    Each time I try and call the networkAreaUI class from within the ScriptyUI class I get an error stating that a container is expected and not a window.
    Any Ideas?
    I have placed everything within the ScriptyUI class and it works, however this class soon becomes so large it is quite unmanageble.
    What I am also trying is something similar to these code snippets:
    I want to add this.............:
    public class NetworkAreaUI extends JFrame implements Runnable, ActionListener
        private JPanel networkPanel;
        private JTextField netPath;
        private JButton remove;
        private JButton add;
        private JLabel netDrives;
        private JComboBox driveList;
        private int driveCount = 0;
        private Thread adds;
        private Thread lists;
        private Thread removes;
        protected NetworkDrive myNetworkDrive;
    public NetworkAreaUI()
            Container cp = getContentPane();
            cp.setLayout(new BorderLayout());
            networkPanel = new JPanel();
            networkPanel.setLayout(new GridLayout(3,4));
            netDrives = new JLabel("Type Network Drive Location");
            networkPanel.add(netDrives);
            remove = new JButton("Remove");
            networkPanel.add(remove);
            netPath = new JTextField("\\\\Server\\Share\\Name",20);
            networkPanel.add(netPath);
            add = new JButton("add");
            networkPanel.add(add);
            driveList = new JComboBox();
            networkPanel.add(driveList);
            networkPanel.setVisible(false);
            cp.add(networkPanel);
            //Adds action listeners
            //Adds MenuSelection to the menu's
            remove.addActionListener(this);
            add.addActionListener(this);
            driveList.addActionListener(this);(then there is code for the action listeners )........into this.....
    public class ScriptyUI extends JFrame// implements ActionListener, Runnable
        private final int FRAME_WIDTH = 600;
        private final int FRAME_HEIGHT = 540;
        private JPanel rows;
        private JPanel row1;
        private JPanel row2;
        private JPanel row3;
        private JPanel row4;
        private JPanel button;
        private JPanel outputArea;
        private JTextArea message;
        private JPanel selection;
        private JButton vbs;
        private JButton bat;
       /* private JPanel networkPanel;
        private JTextField netPath;
        private JButton remove;
        private JButton add;
        private JLabel netDrives;
        private JComboBox driveList;
        private int driveCount = 0;
        private JMenuBar menu;
        private JMenu fileMenu;
        private JMenu helpMenu;
        private JMenuItem restartMenu;
        private JMenuItem quitMenu;
        private JMenuItem show;
        protected NetworkDrive myNetworkDrive;
        protected NetworkAreaUI myNetGui;
        private JButton back;
        private JButton next;
        private JTextArea output;
        private JScrollPane jsp;
        private JButton save;
        private JFileChooser fc;
        private String fileType;
        // private Thread thread;
    /*   private Thread adds;
        private Thread lists;
        private Thread removes;
        private Thread nextOne;
        private Thread saveIt;*/
      //  private Thread;
        public ScriptyUI(String title)
            super(title);
            myNetworkDrive = new NetworkDrive();
            myNetworkDrive.reset();
         //   myNetGui = new NetworkAreaUI();
            setUpGui();
    public void setUpGui()
            setSize(FRAME_WIDTH,FRAME_HEIGHT);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            Container cp = getContentPane();
            cp.setLayout(new BorderLayout());
            //Setup Menu Bar
            menu = new JMenuBar();
            setJMenuBar(menu);
            fileMenu = new JMenu("File");
            helpMenu = new JMenu("Help");
            restartMenu = new JMenuItem("Start Over");
            quitMenu = new JMenuItem("Quit game");
            show = new JMenuItem("Show Drives");
            //Construct Menu Bar
            menu.add(fileMenu);
            menu.add(helpMenu);
            fileMenu.add(restartMenu);
            fileMenu.add(quitMenu);
            fileMenu.add(show);
            rows = new JPanel();
            rows.setLayout(new GridLayout(6,1));
            //Create Message area and populate with Text.
            row1 = new JPanel();
            message = new JTextArea("Select which format you " +
                    "would like the Script to be in. Visual Basic" +
                    "Script or Batch Script", 3, 30);
            row1.add(message);
            rows.add(row1);
            //setup the selection screen
            row2 = new JPanel();
            selection = new JPanel();
            selection.setLayout(new BorderLayout());
            //sets the buttons on the selection screen
            vbs = new JButton("Visual Basic Scripts");
            selection.add(vbs, BorderLayout.NORTH);
            bat = new JButton("Batch Scripts");
            selection.add(bat, BorderLayout.SOUTH);
            row2.add(selection, BorderLayout.CENTER);
            rows.add(row2);
            row3 = new JPanel();
            myNetGui = new NetworkAreaUI();
            row3.add(myNetGui);
            rows.add(row3);
    cp.add(rows, BorderLayout.CENTER);Any help or guidance will be greatly appreciated,

    Encephalopathic wrote:
    good
    Thanks :)
    Are you sure that you want to use a Container and not a JPanel or JComponent? This is Swing after all.Hi i set up the method as below which seemed to work:
    public Container setup()
            networkPanel = new JPanel();
            networkPanel.setLayout(new GridLayout(5,2));
            netDrives = new JLabel("Type Network Drive Location:");
            networkPanel.add(netDrives);
            typeName = new JLabel("Type Drive Letter:");
            networkPanel.add(typeName);
            netPath = new JTextField("\\\\Server\\Share\\Name",20);
            networkPanel.add(netPath);
            nameDrive = new JTextField("X",1);
            networkPanel.add(nameDrive);
            add = new JButton("add");
            networkPanel.add(add);
            remove = new JButton("Remove");
            networkPanel.add(remove);
            driveList = new JComboBox();
            networkPanel.add(driveList);
            driveNames = new JComboBox();
            networkPanel.add(driveNames);
            //Adds action listeners
            //Adds MenuSelection to the menu's
            remove.addActionListener(this);
            add.addActionListener(this);
            driveList.addActionListener(this);
            //return the content panel
            return networkPanel;
    }it is set up in the header to return container
    public Container setup()
    .but i actually return networkPanel which is setup as a JPanel.
    So have now changed it to read:
    public JPanel setup()
    .I think that should be a little better? is it?
    Thanks for the heads up.
    Ian

  • Adding data members and methods to generated classes that will not produce

    I want to use XMLBeans XMLObject for a project, but for the classes generated by XMLBeans, I want to add some additional data members and methods to handle program state that I do not want to have written out to an XML document.
    I have been using .NET's system.xml.XmlParser class, and it provides this sort of capability.
    In looking at the code produced by XMLObject, it looks possible.
    Question: Does anyone have any thoughts on the best way to accomplish what I want to do? Is there a good design pattern to follow?
    Question: Are there any gotchas in doing this? The only immediate one I can think of is that everytime the .java files are regenerated by XMLObject, I will have to reinsert my data members and methods.

    Hi Chuck,
    Setting the dispaly Field property should in no way affect your validation execution.
    The valiadtion if is working fine on the field value when it is not a display field it should do so when a display field as well.
    Besides if you are working on MDM main table all the main table fields are display fields.even if you do not set the property.As main table fields are always visible in MDM Data manager.
    Which version of MDM you are currently working on.
    As I have tried on the SP06 version on MDM and the  Null  validation runs fine on Display fields as well.
    Check your MDM version and also your MDM clients as well as MDM server be on the same version.
    What I am finding confusing here is that initially you wish to keep the material number as Blank for the approver to enter the material number which will be send through a mail.
    But the validation is checking for the material field to be balnk then how are you poulating the same field with Material number in the later stage.As it will fail the validation here.As per teh vlaidation it should remain blank as soon as someone enters a value it will throw an error.
    Or in either which wise you need to mainatin 2 valiadtion steps before and after the Approver for blank and filled field check.
    Just check your process flow correctly and the order of it in case that is causing the records to fail.
    Hope It Helped
    Thanks & Regards
    Simona Pinto

  • Passing variables and methods between two class files

    I created two simple programs to see what I can learn about how separate class files work together.
    There are two files, Alpha.java and Beta.java. Both are located in the same folder.
    Here�s Alpha.java:
    ********* Alpha.java *********
    public class Alpha {
    public int alphaInt;
    public void alphaMethod() {
    System.out.println("This is Alpha's alphaMethod.");
    ******** End Alpha **********
    Here�s Beta.java
    ******** Beta.java ***********
    public class Beta {
    public static void main() {
    Alpha a = new Alpha();
    a.alphaInt = 10;
    System.out.println(The value of alphaInt is " + a.alphaInt);
    a.alphaMethod();
    ******** End Beta ***********
    Alpha compiles fine. Beta does not compile and I get this error:
    �Exception in thread �main� java.lang.NoSuchMethodError: main�
    My first problem to solve is to get Beta to compile. After that I should be able to run it from the command line and get something like this as output:
    �The value of alphaInt is 10�
    �This is Alpha�s alphaMethod.�
    Would some kind people please help me with this?
    TIA,
    Logan

    That was easy, and it confirms what I thought should happen. Now for the real question:
    Alpha and Beta are servlets in a package called abClasses. Alpha starts out like this:
    package abClasses;
    import javax.servlet.*;
    import javax.servlet.jsp.*;
    import java.util.*;
    import javax.servlet.http.*;
    import java.sql.*;
    public class Alpha extends HttpServlet {
    Beta is the same, except for the name of course.
    Alpha creates a Connection variable, and Beta is going to use it. But when I try to compile Alpha I get an error that says this:
    cannot resolve symbol
    symbol: class Alpha
    location: abClasses.Beta
    Alpha a = new Alpha();
    Any suggestions on why what we did in the simple Alpha and Beta programs won't work in the Alpha and Beta servlets?
    You are appreciated,
    Logan

  • Is Method.invoke (Object,Class[]) efficient

    hi
    How efficient is the method invoke compared to explicit method calling?
    thanks

    I cna't give any solid numbers either, but when I've used it I've noticed it to be much slower than directly invoking the method. Ballpark I'd guess 5 times as much overhead, but don't hold me to that. Of course, if the work your method does is large compared to method invocation overhead, then it shouldn't really matter.

  • Pls help me on finding info abt classes and methods....

    hi.. I'm new to java .. but i know the very basics of it.. so that i could write a couple of simple programs.. I've been working wit .NET all these days and MSDN library helps me a gr8 deal.. it gives explanation for every class and methods of the class, even explaining the parameters passed into the methods.. I'm currently workin wit J2ME for developing MIDlets... As i know the basics programming isnt very bad.. but where can i find the explanation for the classes used in micro edition or the methods that belong to the classes...
    Is there any facility like MSDN library for java where i can find the whole information...?????
    Pls help with....
    Thanks for ur patience...

    * Goto [http://java.sun.com/j2me/docs/|http://java.sun.com/j2me/docs/]
    * Click on link "MIDP 2.0 Specification (JSR 118)"
    * Under Specification, Click on Download
    * Hit Accept License Agreement
    * Download ZIP file (not the pdf version)
    * Unzip file and view files
    * Enter folder "midpng-javadoc-final"
    * Open Overview.html
    * Find link "JavaDoc API Documentation".
    [Ref.|http://www.java-tips.org/java-me-tips/midp/where-is-j2me-api-javadoc.html]

  • String equal method Vs Object equal method.

    hello, Can anybody explain me difference between equal method in String class and equal method in Object class. We have equal method in object classes. and object class is the super class of all classes, so why we need equal method in String class.

    RGEO wrote:
    hello, Can anybody explain me difference between equal method in String class and equal method in Object class. We have equal method in object classes. and object class is the super class of all classes, so why we need equal method in String class.Because "equal" means different things for different objects. For a String, "equal" would mean that both Strings being compared have the exact same characters, in the same sequence. For an Integer, "equals" would mean that both objects have the same integer value.

  • Table name for list of methods for given class

    Hi Experts,
      Is there any table where I can get list of methods in the class?
    Req: Input parameter: Class Name
            Output: List of all methods in it
    Note: As we know, we will have different program names and method names for Classes and Methods. I am okay if I can find table which contains method programs for given class program name.
    Regards,
    Naveen Inuganti

    Hi,
    Check table TMDIR.
    Thanks,
    Venkatesh

  • HashCode function in Object class.

    Hi! to all!
    I have got a confusion about hashCode function of Object class, which returns an integer.
    What is the real purpose of introducing this method in Object class.
    Please comment.

    hashCode() method of the object is intorduced for the benefit of collections like HashTables. Typically
    hashCode method should return distinct integers for distinct objects which are decided distinct based on
    equals method of the object. Though this is not mandatory , if distinct objects have distinct
    hashCodes, it will improve the performance of HashTables.A good distribution of hash codes will indeed help in the performance of a HashMap or Hashtable. However, by definition, hashcodes are not necessarily distinct for objects that are distinct based on equals. Two objects for which "equals" is true should have the same hashcode, but two objects which have the same hashcode don't have to have "equals" be true. There is a limited number of hashcodes (the range of int), but an unlimited number of objects. So, some objects will necessarily have the same hashcode. The pigeonhole principle describes this situation:
    http://en.wikipedia.org/wiki/Pigeonhole_principle

  • Issue regarding object class RKAUFTRAG,

    Hi friends,
    My issue is regarding object class RKAUFTRAG,
    while passing this object class to function module 'CHANGEDOCUMENT_READ' it is extracting records only for changes, but i want both for creation and deletion too. this function module is working fine for other object classes like for ANLA and ALLOCATION.
    My requirement is whatever created(KO01) or changes(KO02) made for internal order master data. sh. come throgh object class RKAUFTRAG, but except changes i am not getting for creation and deletion.
    creation is reflecting in object class ANLA.
    in SWEC and SWED, this object class is configured for all.

    So how can the constructor of Foo call superimplicitly if the Object class
    does not contain any constructor.Even if you don't specify one, there will alwaysbe
    at least a no-args c'tor.But if you do specify a ctor with args, the
    compiler will not insert a no-arg ctor for you.That why I said there is "at least" a no-args (or more args) c'tor [in any class].

Maybe you are looking for

  • History - Incoming Sales Orders!

    hello, i load data from 2LIS_11_VAITM into BI. Now, i should historicize the changes of "Incoming Sales Orders" per month/year in my DSO "Incoming Sales Orders". I use BI 7.0 The rules in my start-Routine of Transformation 1. If a new Position(record

  • Lightroom 5 - Organizing Your Images | Getting Started with Adobe Photoshop Lightroom 5 | Adobe TV

    Learn how to organize your images in Lightroom using the Folder panel so that finding, moving and editing your images is a breeze. http://adobe.ly/12t0KCm

  • Horizontal scroll bar for each page of the ADF page???

    Hi Everyone, I have developed one ADF page which is working very fine. The width and height of the page is more by which it is showing vertical scroll bar and horzontal scroll bar at the end(bottom) of the page. But the requirement is that the horzon

  • Content Managed Image Gallery

    I am looking to see if there is an image gallery available out there that I can use in DreamWeaver that will allow my client to upload images, add categories and captions and the likes. I know nothing of dynamic development so I guess I am looking fo

  • Windows 2003 Subordinate CA

    Hello, We have a root CA and subordinate CA in our domain. Both are Windows 2003 physical servers. We use computer certificates on each client to authenticate them against the wireless ntwk. How do i check if my subordinate CA is issuing certs to all