Java interfaces allow us to specify limited ways in which otherwise

can anyone explain "Java interfaces allow us to specify limited ways in which otherwise dissimilar classes, from completely different parts of inheritance hierarchy, resemble one another." please?
many thanks.

An interface defines a contract which an implementing class must fulfill. As long as the implementing class is written properly, then it provides a specific, advertised behavior. There are no restrictions as to which classes may implement a given interface (in the sense that there are inheritance restrictions, such as single-inheritance, no inheritance loops, and the like). Therefore, any two arbitrary classes may implement the same interface, and therefore provide the same behavior.
For example, the Iterator interface provides the ability to loop over a collection of objects in a well-defined way. Any class which implements Iterator would be manipulable in the same way, and could therefore be said to resemble each other.

Similar Messages

  • Why fields cannot be "blank finals" in java interfaces?

    Friends,
    Interfaces limit or disallow the usage of "blank finals" - the same implies the feature that fields are implicitly static and final.
    But why is this restriction - why "blank finals" are disallowed in interfaces?
    Thanks,
    Sundar

    To be precise - when interfaces allow classes which
    implement them to provide definition for the methods
    in it in their own way, why does it not allow the
    same for it's fields?Which methods must be present is part of the contract--the behavior.
    Fields are just an internal implementation detail. No class should ever be required to provide any field--and in fact Java (wisely) doesn't allow you to require a class to provide a field.
    The static final fields that interfaces allow are different from implementation-specifc, instance-specific fields because they're associated with the type as a whole--not with any particular implementation of the type, and not with any instance--and because they're "constant" (i.e. final).
    Again, it would make no sense to say, "All implementations must provide this field, with some value that they determine."
    As detailed below, when class X and Y are allowed to
    provide different implementations for "display()",
    they are forced to use the variable iYou can't (and shouldn't try to) force implementations to use any particular variable.

  • Q: Declaratively Implement a Java Interface, How?

    Hi Again,
    I want to be able to Declaratively Implement 'Response' in a JavaFX (very impressive stuff if I can do this!). Follow the example code below :)
    Java Interface:
    public interface Response {
       public String doResponse(String input);
    }The JavaFX Class:
    public class MyResponse extends Response {
      override public-init var doResponse: function (input:String):String; //doesn't work!
    }JavaFX Declarative Implementation (the goal):
    var responder:MyResponse {
        doResponse:  function (input:String):String {
            return "JavaFX Rocks!"
    }So the above should allow whoever is creating "MyResponse" to implement the doResponse functionality of the class.
    Alternatively, I can just have to do the following.....
    public class MyResponse extends Response {
      public-init var doResponseImpl:function (input:String):String;
      public override function doResponse(input:String):String{
          return doResponseImpl(input);
    }Either way works... but the alternative is not so nearly as clean :)
    Thanks in advance...

    I don't see a way to do this. You want to transform a function to a variable. Even if that's a variable holding a function, these are incompatible.
    But you can just override the function in the class instantiation:
    var responder = Response {
        override function doResponse(input: String): String {
            return "JavaFX Rocks!"
    }

  • Error Message: A main Java class needs to be specified to run the program.

    Hi,
    I am adding a program object to cms using java program, and trying to run it. I am getting an error message like
    Error Message: A main Java class needs to be specified to run the program.
    Could you please help me on this., please find the pasted program object pasted below
    public class MoveReports   {
    public void run(IEnterpriseSession enterpriseSession, IInfoStore infoStore,
                   String[] args) throws SDKException {
        int objectSize = ;
        String cms = "";
         String username = "";
         String password = "";
         String auth = "";
        try {
              ISessionMgr sm = CrystalEnterprise.getSessionMgr();
             enterpriseSession = sm.logon(username, password, cms, auth);
             IInfoStore oInfoStore=(IInfoStore)enterpriseSession.getService("", "InfoStore");
                 IInfoObjects iObjects = null;
                   iObjects = oInfoStore.query("Select * from CI_INFOOBJECTS where SI_PARENTID = 44104 AND SI_PROGID LIKE '%CrystalEnterprise.Excel%'");
                   // Getting total number of reports
                   objectSize = iObjects.size();
                   if(objectSize > 0)
                        for (int count = 0; count < objectSize; count++)
                             IInfoObject obj = (IInfoObject) iObjects.get(count);
                             // Specify the Destination parent Id to move the reports
                             obj.setParentID(44102);
                        oInfoStore.commit(iObjects);
                        System.out.println("Reports Moved Successfully");
                   else
                        System.out.println("Reports Not Available");
             catch (SDKException e) {
                 e.printStackTrace();
                 System.out.println("Error : " + e.getMessage());
    Thanks&Regards
    Damodar
    Edited by: Damodaram B on Nov 2, 2009 1:29 PM

    There's couple of things at issue here - you've not specified the proper interface (IProgramBase or IProgramBaseEx), and the program job server can't find the class in question (a deployment issue).
    You may want to open a support ticket with SAP.
    Sincerely,
    Ted Ueda

  • How to allow only the specified users/groups to open my pdf files...

    Hi there,
    I'm looking for resources/documents describing how to allow only the specified users/groups to open my pdf files by the Java API...
    I've found a sample code creating a policy in the following document.
    http://livedocs.adobe.com/livecycle/es/sdkHelp/programmer/sdkHelp/wwhelp/wwhimpl/js/html/w whelp.htm?context=sdkHelp&topic=learn_lc_sdk_invokeremoting
    ( API Quick Starts (Code Examples) > Rights Management Service API Quick Starts > Quick Start: Creating a new policy using the Java API )
    But the sample code doesn't set recepients( users/groups ) who can open the pdf file.
    How can I make it ?
    Any samples ? or Does anybody can tell me which Java classes/methods I should use ??
    Policy#addPolicyEntry(PolicyEntry policyEntry) ??
    PolicyEntry#setPrincipal(Principal principal) ??
    or none of them ?
    Any hints are appreciated !
    Thanks.

    I'm not exactly sure what you are tying to do here, but typical approach when issuing one PDF par user/groups scenario goes like:
    1. Create policy for specific purpose and add principal (user/group)
    2. Apply policy on server side
    3. Deliver the file (via email etc...)
    If you are looking for sample codes, try quick start.
    http://livedocs.adobe.com/livecycle/8.2/programLC/programmer/help/wwhelp/wwhimpl/js/html/w whelp.htm?&accessible=true
    If you go "API Quick Start/Rights Management Service API Quick Starts", you might find something useful. I think you need "Creating Policies" or "Modifying Policies" for step 1 above, and "Applying Policies to PDF Documents" for step 2.
    Hope this helps.

  • Does java api allow access the ethernet card directly

    i m working on cluster computing. i like to code in java. i need to send object from one single machine to other machines in a university computer lab. i would like to send the objects very efficiently and fastly. i used java.net and also java.nio. but i think it would be fast more if i could directly access the ethernet card- read from and write to the network interface card directly.

    does java api allow access the ethernet card directlyNo.

  • Java interfaces as c++ controls?

    in my c++ program (windows), i need to use java interfaces (i.e. JFrame or JButton). i want to use c++ interface as container and java interface as its components (controls), is this possible? if yes, what is right tech to do that?
    thx

    Have a look at JNI (Java Native Interface). This is a way to link c++ and Java code.

  • Contract-first : WSDL vs Java interface

    Hello,
    I am starting to work with web Service.
    Many blogs and articles suggest to write WebServices contract from a WSDL.
    I am a java Programmer. I totally agree with the contract-first and the data-driven communication concept.
    Here is my question: why use WSDL when you can convert any Java Interface and Bean into a WebServices?
    If a tool gives you the possibility to move from xml to java (and vice-versa), why not stay with a java interface?
    What are the pitfalls of using this technique (other than being too easy to change the contract)?

    The main reason why you would want to write WSDL first is to be able to create a more verbose XML schema. For instance, if you take a raw Java interface or class and convert from Java to WSDL/XSD everything ends up being optional because the converters have no idea what is supposed to be required versus what isn't as well as field length restrictions etc. Some of the newer tools may allow you to do this with annotations but I haven't really looked into this.
    Writing the XML schema first allows you to offload more work on the XML parser at run time because it can do the schema validation for you instead of you having to manually perform this. This also allows someone writing their own client to consume the WSDL and be able to generate a client that will do more work than one based off of Java classes (e.g. someone creating a .NET client can let the XML parser do some heavy lifting during the marshalling process before ever sending the request to your web service).

  • (262119469) Q WSC-15 Is the .ctrl file just a java interface?

    Q<WSC-15> Is the .ctrl file just a java interface?
    A<WSC-15> Yes. Any control that you generate in Workshop is really an interface definition
    for the methods that the enterprise component understands. You can then use those
    methods in the interface directly in your .jws code. The actual object that implements
    that interface and acts as a broker to the enterprise resource is generated during
    the compilation of the web service. This helps keep your web service code very simple.

    I don't see a way to do this. You want to transform a function to a variable. Even if that's a variable holding a function, these are incompatible.
    But you can just override the function in the class instantiation:
    var responder = Response {
        override function doResponse(input: String): String {
            return "JavaFX Rocks!"
    }

  • Running a Java program automatically at a specified time

    How to run a Java appln automatically at a specified time?

    Java Application, or method within a running Java application?
    To run Java you would have to use the OS native tools.
    Windows Scheduled Tasks
    Newbie: Intro to cron.
    To execute a block of code within a running Java VM, you want to look at Timer.

  • Java.sql.SQLDataException: ORA-01878: specified field not found in datetime

    I am getting the exception mentioned in the subject field. Here is the query
    select * from tabel_abc where from_tz(cast(LAST_RECEIVED_TIME + timeout_duration/86400 as timestamp),'UTC') <systimestamp at time zone 'UTC';
    This is happening only for the during the daylight saving, because the date operation is returning the incorrect time value.
    timeout_duration holds the value in terms of number of seconds.
    Please suggest how to resolve the issue.
    Caused by: java.sql.SQLDataException: ORA-01878: specified field not found in
    datetime or interval
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:457)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:405)
    at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:889)
    at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:476)
    at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:204)
    at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:540)
    at
    oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:217)
    at
    oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.ja
    va:1079)
    at
    oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1
    293)
    at
    oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1
    419)
    at
    oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedState
    ment.java:3752)
    at
    oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatemen
    t.java:3806)
    at
    oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedS
    tatementWrapper.java:1667)
    at
    weblogic.jdbc.wrapper.PreparedStatement.executeQuery(PreparedStatement.java:13
    5)
    at

    >
    When I run the following expression on this value I get the ORA-01878 error:
    (EXTRACT(DAY FROM ((ETD_ZULU - 4/24) - SYSTIMESTAMP)))
    >
    That isn't the same as the snippet you first posted
    This works
    select EXTRACT(DAY FROM ((ETD_ZULU - 4/24) - SYSTIMESTAMP)) from
    (select cast (systimestamp as timestamp(6)) etd_zulu from dual)The first snippet you posted was
    >
    select * from tabel_abc where from_tz(cast(LAST_RECEIVED_TIME + timeout_duration/86400 as timestamp),'UTC') <systimestamp at time zone 'UTC';
    >
    And it includes time zone. All of the web references I have found indicate the problem is either a missing timezone or a timezone mismatch.
    I can't reproduce the problem with the last snippet you used. Are you certain that ETD_ZULE is timestamp and does not include timezone?
    Do you have a complete query that fails? If so, try to narrow the query down to one record that is causing the problem. If you have to you can use brute force approach. Assume that 60 records should be produced. Add
    WHERE ROWNUM < 30to the query. If it runs clean the problem is in the second half so use '< 40', and keep testing until you know which record. Then examine the contents of the field for that record.
    Without some code to try to reproduce the problem there isn't much other help to offer.

  • Second posting - spent hours on this - yesterday and today - I have downloaded the FlashPlayer upgrade (now 10 times), in Security - no pop-ups are checked, the "allow Java" and "allow other other plug-ins" are both checked.  I have re-booted after the Fl

    Repeat message - I have downloaded the FlashPlayer upgrade (now 10 times), in Security - no pop-ups are checked, the "allow Java" and "allow other other plug-ins" are both checked.  I have re-booted after the Flash-Player upgrades - still "pop=ups blocked"

    Hello,
    Please provide the following information:
    Your operating system & version
    Your web browser(s) & version
    Your Flash Player version
    Explain your problem in step-by-step detail if possible
    A direct link to a page that demonstrates the problem
    If you get error messages, please quote them exactly, or provide a screenshot: http://forums.adobe.com/thread/1070933
    Thank you.
    Maria

  • Java Interface Question.

    There are classes in the Java SDK, such as the Interface:
    org.w3c.dom.Document
    that have factory methods in them that carry out actual operations.
    But how can this be possible, because when I program an interface:
    public interface test {
    public void setString(String s);
    It will only compile thus, with no implementation on the method signatures?
    How do Java interfaces with factory methods to this?
    org.w3c.dom.Node is another one. Where does the functionality/method implementation
    come from?

    public interface MyInterface {
         public void method1();
    class MyImplementation implements MyInterface {
         public void method1(){
    public class MyFactory {
         public static MyInterface createMyInterface(){
              return new MyImplementation();
    public class Test{
               public static void main(String args[]){
                      MyInterface x=MyFactory.createMyInterface();
                      x..method1();
    }Now can you understand this? Assume all These classes are separate classes. This is not a problem with inner classes. Before make a reply, try to understand it or post a reply as saying it is not clear rather than posting this kind of post.

  • Are Java Interfaces 'free'?

    From a performance point of view, are Java interfaces free?
    That is, if I have:
    class Foo
    public void bar() { ... // some code }
    }and I change it to:
    interface Foo
    public void bar();
    class FooImpl implements Foo
    public void bar() { ... // some code }
    }And I call one or other of the Foos like
    Foo foo // A parameter, field or local variable.
    foo.bar();Does calling foo through an interface add any overhead that calling it direct in the first example not? As I understand it, all methods are 'virtual' in Java, so it should perform the same in either case.
    Thanks for any of your thoughts.
    Rupert

    rupertlssmith wrote:
    YoungWinston wrote:
    The Second Rule of Program Optimization (for experts only!): Don't do it yet.&#148;
    - Michael A. Jackson
    Basically, don't worry about it. Worry about writing clear, correct, object-oriented code.
    Wierdly enough, in the long run, that is more likely to help than anything else you can do, should (and if) you ever need to worry about optimization in the future.
    WinstonThanks for the advice. I can write good clear OO code. I am now at the future and worrying about optimization, so have made it past the second rule!Then you exactly know where your bottleneck is from the profiler you've used. Did it tell you that your interfaces are the bottleneck? If so, why do you even bother to ask here?

  • Java interface with Crystal Reports

    Post Author: [email protected]
    CA Forum: JAVA
    Hello everyone,I need to build a Java interface for JSP to interact with crystal reports.Could anyone recommend any book or forward me the url's where I can find the related material with examples. Eagerly Waiting for reply!Thanks,Prathima.

    Post Author: MJ@BOBJ
    CA Forum: JAVA
    The latest version of the Java Report Component (JRC) is available from the Diamond website.  This download is actually a plugin for Eclipse but you can still use the JRC runtime jars to use the SDK APIs in your JSP page.  You will also find lots of resources such as samples, videos, and forums to help you get started.  You can also refer to the DevLibrary for more information.

Maybe you are looking for