Static interface Vs Static nested interface declaration

Hi,
I have observed that static interface declaration is not allowed in Java. However static nested interface declaration is allowed.
I could not understood reason behind this behavior.
e.g.
interface A{
     void AA();
     public static abstract interface Aa{
} ........... this is allowed in Java.
static interface d{
} ...... This is not allowed in Java...
I already know that static mean one for class and interface has only abstract method.
Please let me know if any one know resign behind this.
Thanks .

Why don't you go to a Java forum?

Similar Messages

  • Static final in (Class or Interface)

    Hello Friends ,
    What is the difference in having a public static final variable in an class and having the same kind of
    declarations in an Interface ?
    Does the interface is better or having it in a class ?
    Thanks in Advance,
    -S

    shyamnambiar wrote:
    But I'm not clear . you mean to say its all the same .It does not make any difference ?The only difference that it makes (and that might be an important difference) is what you communicate with your design an intention.
    Constants should usually be placed within their context since that's where they are going to be used, and that's where developers will look. It's more common to place the constants in the class that they are related to. They should not be placed in an empty final class just because you want to group constants. You should also avoid placing constants in an interface just because you then can implement that interface to "get hold of" the constants.
    Kaj

  • Unusual use of interface defining static factory class with getInstance

    This question is prompted by a recent New to Java forum question ask about the differences between Interfaces and Abstract classes. Of course one of the standard things mentioned is that interfaces cannot actually implement a method.
    One of my past clients, one of the 500 group, uses interfaces as class factories. The interface defines a pubic static class with a public static method, getInstance, that is called to generate instances of a class that implements the interface.
    This architecture was very object-oriented, made good use of polymorphism and worked very well. But I haven't seen this architecture used anywhere else and it seemed a little convoluted.
    Here is a 'pseudo' version of the basic interface template and use
    -- interface that defines public static factory class and getInstance method
    public interface abc {
        public static class FactoryClass
            public static abc getInstance ()
                return (abc) FactoryGenerator(new abcImpl(), abc.class);
    -- call of interface factory to create an instance
    abc myABC = abc.Factory.getInstance();1. Each main functional area ('abc' in the above) has its own interface factory
    2. Each main functional area has its own implementation class for that interface
    3. There is one generator (FactoryGenerator) that uses the interface class ('abc.class') to determine which implementation class to instantiate and return. The generator class can be configured at startup to control the actual class to return for any given interface.
    I should mention that the people that designed this entire architecture were not novices. They wrote some very sophisticated multi-threaded code that rarely had problems, was high performance and was easy to extend to add new functionality (interfaces and implementing classes) - pretty much plug-n-play with few, if any, side-effects that affected existing modules.
    Is this a best-practices method of designing factory classes and methods? Please provide any comments about the use of an architecture like this.

    Thanks for the feedback.
    >
    I don't see how 'the generator class can be configured at startup to control the actual class to return for any given interface' can possibly be true given this pseudo-code.
    >
    I can see why that isn't clear just from what is posted.
    The way it was explained to me at the time is that the interface uses standard naming conventions and acts like a template to make it easy to clone for new modules: just change 'abc' to 'def' in three places and write a new 'defImpl' class that extends the interface and the new interface and class can just 'plug in' to the framework.
    The new 'defImpl' class established the baseline functionality that must be supported. This line
    return (abc) FactoryGenerator(new abcImpl(), abc.class);uses the initial version of the new class that was defined, 'abcImpl()', when calling the FactoryGenerator and it acted as a 'minimum version supported'. The generator class could use configuration information, if provided, to provide a newer class version that would extend this default class. Their reasoning was that this allowed the framework to use multiple versions of the class as needed when bugs got fixed or new functionality was introduced.
    So the initial objects would be an interface 'abc' and a class 'abcImpl'. Then the next version (bug fixes or enhancements) would be introduced by creating a new class, perhaps 'abcImpl_version2'. A configuration parameter could be passed giving 'abcImpl' as the base class to expect in the FactoryGenerator call and the generator would actually create an instance of 'abcImpl_version2' or any other class that extended 'abcImpl'.
    It certainly go the job done. You could use multiple versions of the class for different environments as you worked new functionality from DEV, TEST, QA and PRODUCTION environments without changing the basic framework.
    I've never seen any Java 'pattern' that looks like that or any pattern where an interface contained a class. It seemed really convoluted to me and seems like the 'versioning' aspect of it could have been accomplished in a more straightforward manner.
    Thanks for the feedback. If you wouldn't mind expanding a bit on one comment you made then I will mark this ANSWERED and put it to rest.
    >
    I don't mind interfaces containing classes per se when necessary
    >
    I have never seen this except at this one site. Would you relate any info about where you have seen or used this or when it might be necessary?

  • Static MAC for a router interface

    I have a Cisco 851 router that is setup as a VPN device.  I have a managed switch connected to an interface on the 851.  I want to be able to assign a static MAC for the paticular interface so that the connected switch is the only device allowed to connect to that port.  However, the router must still be able to learn and pass traffic from MAC addresses of devices connected to the switch.  Is this possible?

    Interesting, thanks for the report/tip!

  • Do the Interface contains static components like static methods and attribu

    Do the Interface contains static components like static methods and attributes ?

    >
    You have to supply a bit more detail: is that Lotus
    Notes API a Java API?Hmm, It's Java interface to Lotus Notes API
    Does it use JNI? Perhaps it is used somewhere underneath, I do not know for sure, but I think so
    Possibly the Lotus Notes
    implementation keeps a
    reference to those arrays, who knows?
    Maybe, but I'd be really suprised if it did. I derive this thread from Lotus Notes class and provide my own "worker method", overriding Lotus API abstract one, where I reference arrays. Arrays are specific to my program and since they are private fields in thread's class Lotus Notes layer does not have any way of referencing them, nor any reason for this matter
    For starters: if you zero out (set to null) your
    references to those arrays
    in your threads when the threads finish, there might
    surface a useful
    indication that you can blame Lotus Notes for this
    Well, I've become deeply suspect of whether these Notes' threads do really finish :-) My method finishes for sure, but it is just a part of run() method of Lotus Notes thread. Anyway, you can always safely blame Lotus Notes for almost anything :-)

  • Implementing interface with static method?

    Hi,
    I need to implement an interface with a static method. I tried to do it both with the interface method static and non-static, but it don't seam to work! Does it work?
    How can I make a work around?
    Thanks!

    Interfaces are designed to provide a contract that a particular object instance guarantees for it's Clients.
    Since a static method does not relate to any particular object instance there is no contract to define...hence you can't have an interface for static methods...
    What you could do however is return an object via a static method that does provide the implementation of the interface...
    i.e.public class MyClass
        static private String myInterfaceImpl = "<some class>";
        static public MyInterface getInterface ()
             return (MyInterface) MyClass.class.forName (MyClass.myInterfaceImpl).newInstance ();
    }That would return an object that provides the interface. I would presume you need the static method so that you don't have to pass around references to a particular object...this method gets around that...you could also create a single object at start up time and return a reference to that eveytime...
    Also, in a way static methods do define an interface...

  • Nested interface

    Can anybody make any sense of this?
    I cannot do this:
    interface Action {
         void run();
    class SomeAction implements Action {
         public void run() { ? }
    class Controller<A extends Action> {
         public interface Command {
           void doIt(A action);                                      // compile-time error
           void undoIt(A action);                                    // compile-time error
    class SomeController implements Controller<SomeAction>.Command {   // compile-time error
         public void doIt(SomeAction action) { ? }
         public void undoIt(SomeAction action) { ? }
    }But I can do that:
    interface Action {
         void run();
    class SomeAction implements Action {
         public void run() { ? }
    class Controller<A extends Action> {
         public interface Command<A extends Action>  {
           void doIt(A action);
                 void undoIt(A action);
    class SomeController implements Controller.Command<SomeAction> {
           public void doIt(SomeAction action) { ? }
         public void undoIt(SomeAction action) { ? }
    }Why?
    After type erasure the Controller.Command interface boils down to the same thing either way, namely:
    class Controller {
         public interface Command  {
           void doIt(Action action);
                 void undoIt(Action action);
    }I understand that type variables must not appear in static context of a parameterized class and that the first example is rejected for this reason. But, ... is there a really compelling reason?
    It is even worse than in my code snippet. Using the prototype compiler I can refer to the nested interface in the second code sample as
    Controller.Command<SomeAction>
    Controller<SomeAction>.Command<SomeAction>
    Controller<String>.Command<SomeAction>
    Where is the point?

    >
    Looks like a bug to me. Your inner interface in the
    first example is not a static context; therefore the
    type variable should work there.My understanding is that nested interfaces ARE static (ie the one inner interface is shared by all instances of the enclosing class), and therefore the type variable's scope does NOT include the inner interfaces.
    So its not a bug.
    if you are not sure why we're all talking about whether the interfaces are static or not, it is because the draft spec says (section 2.2 near bottom of page 3)
    The scope of a type parameter is all of the declared class, except any static members or initializers, but
    including the type parameter section itself. Therefore, type parameters can appear as parts of their
    own bounds, or as bounds of other type parameters declared in the same section.
    However, whether the inner interfaces should be included under that broad clause, is debatable. (Well I think it's debatable, and despite bringing the issue up previously, no-one has debated the contrary point in this forum)
    The debate could be ended by someone showing how the type system could be broken if an inner interface did reference a type variable of the enclosing class. Any takers?
    In the absence of such proof, it would seem convenient if we didn't have to declare the type parameter in both the enclosing class and the inner interface.
    In summary, what you observe is consistent with (Sun's understanding of) the draft spec. but I believe the spec itself (or Sun's interpretation), is open to discussion.
    Bruce

  • Nested interfaces for constants

    Dear java community,
    I had interface that have big amount of constants of different types:
    public interface ApplicationConrstants {
       String USER_CONSTANT_1 = "userConstant1 value";
       String USER_CONSTANT_2 = "userConstant2 value";
       String USER_CONSTANT_3 = "userConstant3 value";
       String BANK_CONSTANT_1 = "bankConstant1 value";
       String BANK_CONSTANT_2 = "bankConstant2 value";
    }I decided to create nested interfaces in this interface to collect similar constants in groups:
    public interface ApplicationConrstants {
       interface UserConrstants {
          String CONSTANT_1 = "userConstant1 value";
          String CONSTANT_2 = "userConstant2 value";
          String CONSTANT_3 = "userConstant3 value";
       interface BankConrstants {
          String CONSTANT_1 = "bankConstant1 value";
          String CONSTANT_2 = "bankConstant2 value";
    }What do you think about this approach?
    Thanks.

    define constants using:
    public final static type CONSTANT_NAME
    no point creating an interface for them

  • Cann't extend a inner class where as can Implement a nested Interface

    i cann't extend a inner class in some other outer class . Where as i can implement the nested Interface in some other class. Why????
    for example:-
    class ABC
    class Inner
    /* class body */
    interface TempInterface
    /* interfacebody */
    class OuterClass
    class InnerTwo extends ABC.inner //(line 1)Will give error
    class InnerTwo implements ABC.TempInterface //(line 2)Will run fine
    the line 1 is going to give compilation error i.e not in the scope but the line 2 will run fine .
    Both of the things are in the same class but giving 2 other results.
    I am not getting sufficient reasons for it.
    Can any one help me????
    Reagrds
    Arunabh

    As far as the language is concerned, the classonly
    exists in the context of an instance of theenclosing
    class.This still exhibits a class/object confusion to me.
    It should be 'instance only exists ...' or 'instance
    can only exist'. The class only exists in the
    scope of the enclosing class, but this is another
    issue.I'm not following what you're saying. The second sentence sounds like you're disagreeing with me. The last sentence sounds like you're agreeing with me.
    A non-static nested class is an instance member, just like an instance method or instance variable. As such, as far as the language is concerned, that class only exists in the context of an instance of the enlcosing class.It's not just instances of the nested class--its the class definition itself that only exists within the context of an instance of the enclosing class. That's why you have to do anEclosingIntstance.NestedClass and can't do EnclosingClass.NestedClass.

  • Nested interfaces and abstract methods

    Consider the following design:
    interface ZIF_INTERFACE_A.
      methods METHOD_A.
    endinterface.
    interface ZIF_INTERFACE_B.
      interfaces ZIF_INTERFACE_A.
      methods METHOD_B.
    endinterface.
    class CLASS_A_B definition abstract.
    public section.
      interfaces ZIF_INTERFACE_B
        abstract methods METHOD_B.
      interfaces ZIF_INTERFACE_A
        abstract methods METHOD_A.
      methods METHOD_C.
    endclass.
    class CLASS_A_B implementation.
      method METHOD_C.
      endmethod.
    endclass.
    When trying to implement this design, the syntax check is giving me an error:
    The method "METHOD_A" was declared as not ABSTRACT in a previous INTERFACES statement.
    If I implement the design with Java (either using a public nested interface, or using interface inheritance) there is no problem declaring both the methods METHOD_A and METHOD_B as abstract in the CLASS_A_B class.
    So it seems to me this might be a bug in the ABAP Objects implementation. Or perhaps I am missing something else here? Does anyone have any suggestions?

    Hello,
    Nested interfaces
    When you include an IF in another IF both of them will exist on the same level, there is no concept of hierarchy. So when you add interface ZIF_B in the implementing class ZCL_A_B, the interface ZIF_A is also "included" in the relationship with the class ZCL_A_B implicitly.
    Just try to activate the code below & you'll get the error: "Implementation missing for method zif_interface_a~method_a":
    CLASS class_a_b DEFINITION ABSTRACT.
      PUBLIC SECTION.
    *    INTERFACES zif_interface_a
    *      ABSTRACT METHODS method_a.
        INTERFACES zif_interface_b
          ABSTRACT METHODS: method_b.
        METHODS method_c.
    ENDCLASS.                    "CLASS_A_B DEFINITION
    CLASS class_a_b DEFINITION ABSTRACT.
      PUBLIC SECTION.
        INTERFACES zif_interface_b
          ABSTRACT METHODS method_b.
        INTERFACES zif_interface_a
          ABSTRACT METHODS method_a.
        METHODS method_c.
    ENDCLASS.                    "CLASS_A_B DEFINITION
    So when the compiler is trying to compile your code it encounter implementation of ZIF_INTERFACE_B it finds that the "included interface" method ZIF_INTERFACE_Amethod_a is not abstract. So when you declare ZIF_INTERFACE_Amethod_a as "abstract" in the next line the compiler throws this error.
    So you need to define ZIF_INTERFACE_A~method_a as abstract, before defining ZIF_INTERFACE_B. Like this:
    CLASS class_a_b DEFINITION ABSTRACT.
      PUBLIC SECTION.
        INTERFACES zif_interface_a
          ABSTRACT METHODS method_a.
        INTERFACES zif_interface_b
          ABSTRACT METHODS method_b.
        METHODS method_c.
    ENDCLASS.                    "CLASS_A_B DEFINITION
    In this case the compiler treats method_a as abstract while checking ZIF_INTERFACE_B. Hence it doesn't throw any error.
    Hope i'm clear.
    BR,
    Suhas
    PS: Whenever i face any problem while creating local classes, i create a dummy class in the class builder to check

  • Static Vs Non-static methods

    Hello,
    I wonder what should I use. I have got a class which does a lot of counting.. I can put the methods inside the class or make a class Math3D with the static methods that will count it.
    Which is the better way?

    BigDaddyLoveHandles wrote:
    deepak_1your.com wrote:
    Sorry mate... did not get that.By definition a utility class has all static methods. So as soon as you mention "utility class" you've already made a decision. The real question is "should method X be static or non-static"? My default position is to assume no method should be static, and then wait to be convinced.
    Look at utility class java.lang.Math, for example. It has static methods sin(), cos(), sqrt(), etc... An obvious choice for a utility class, right? Then they introduced class StrictMath in 1.3 with exactly the same static method signatures. That's a code smell that one should have written an interface and implemented it in at least two ways, but it's too late for that because the original methods are static.Good post.

  • Bandwith monitoring on physical interface or on tunnel interface ?

    Hi All,
    I would like to ask you a question .i am using solarwind monitoring tool for bandwith monioring.
    I would like to know which interface we should use for monitoring ? Physical interface or tunnel interface .
    I am using GRE tunnel in each of my remote locations.
    and in some locations when i compare my physical interface graph and tunnel interface graph ,there is always hugh difference ,tunnel interface always has high utilization.  but for some sides physical interface and tunnel interface graph are same .
    please do let me know which is the best for monitoing .

    Hi ,
    Genrally it can be posible due bandwidth configuration on tunnel interface but ther is no harm in monitoring both the interface,it is genarlly a benfit only for you as if tunnel goes down it will raise an alarm also for the same.
    For exact monitoring for tunnel interface i would suggest you to check  - VPNTTG (VPN Tunnel Traffic Grapher).
    Advantage of VPNTTG over other SNMP based monitoring softwares is following: Other (commonly used) softwares are working with static OID numbers, i.e. whenever tunnel disconnects and reconnects, it gets assigned a new OID number. This means that the historical data, gathered on the connection, is lost each time. However, VPNTTG works with VPN peers IP address and it stores for each VPN tunnel historical monitoring data into the Database.
    Hope that helps out your query !!
    If helpful do rate the valauble post.
    Regards
    Ganesh.H

  • Static vs Non static

    Hi,
    I was just not clear as to how does the compiler handle Static members.
    As far as fields are concerned if they are declared static, they are created on the HEAP and are shared by all the class instances.
    However, what i want to know is what happenes to the methods. I mean methods are just piece of code so why should a non-static method be instantiated for all the instances?
    So, I presume that static members mean that they are created on the HEAP.
    Am i right here?
    Thanks
    Praveen

    ... not clear as to how does the compiler handles Static members.
    As far as fields are concerned if they are declared
    static, they are created on the HEAP
    Not exactly.
    Methods live in the class definition which lives in Perm Space.
    and are shared by all the class instances.Yes.
    However, what i want to know is what happenes to the
    methods. I mean methods are just piece of codeSee above.
    so why should a non-static method be instantiated for all the instances?'tisn't.
    Methods are not instantiated.
    So, I presume that static members mean
    that they are created on the HEAP.
    Am i right here?No.
    I asked WHAT happens in the background in case of static methods.Why does it matter?
    I mean methods are just piece of code.
    So why this difference, wheather the method is
    static or non-static
    should not make any difference.The magic 'this' keyword can only be used in non-static methods.
    What i want to say is
    there should be some sort of store where the method's
    code is put and called irrespective of whether the
    method is static or non-static
    It is called Perm Space.

  • Static Block vs Static Method

    Hi,
    what is the diff. b/w declaring the variable inside the static block vs static method?
    Why static block is executed first before static method?
    Once the class has been loaded inside the memory the static block will automatically executed by the compiler & it will executed before any static methods. What is the reason behind this why? static block is executed before static method? Please do provide an answer for this..
    Thanks,
    JavaLover

    Um.
    A static method is like a regular method; it only gets called if its...called.
    public class Test
      static
         //this stuff executes after being loaded into memory
      public static void main(string args[])
        //this main method is executed by the VM when you execute "java Test"
        staticMethod(); // this makes the program call staticMethod();
      public static void staticMethod()
        //this code wouldn't be executed if main(string[]) hadn't called it.
    }Hope everything I've said here is correct.

  • Abstract method versus static and non-static methods

    For my own curiosity, what is an abstract method as opposed to static or non-static method?
    Thanks

    >
    Following this logic, is this why the "public static
    void main" 0r "Main" method always has to be used
    before can application can be run: because it belongs
    to the class (class file)?
    Yes! Obviously, when Java starts up, there are no instances around, so the initial method has to be a static (i.e. class) one. The name main comes from Java's close association with C.
    RObin

Maybe you are looking for

  • Guide to External Jobs on 10g with dbms_scheduler e.g. scripts,batch files

    GUIDE TO RUNNING EXTERNAL JOBS ON 10g WITH DBMS_SCHEDULER NOTE: Users using 11g should use the new method of specifying a credential which eliminates many of the issues mentioned in this note. This guide covers several common questions and problems e

  • New Harddrive changed library paths

    I had a new 160 HD installed in my G4 1book a month ago. When my original HD failed, the tech was able to recover my data (which included the folders pictures->iPhoto Library and it's contents. I use iPhoto to view and organize my photos, but I use P

  • Cannot move or copy Projects or Events to external drive

    Short version: I have a project that I have been working on for a few months. Now that it's burned off to DVD, I want to store the whole thing on an External (Seagate) drive, in case I want to come back to it later. (For now, it's just sucking up spa

  • Servlet Filter not working in Oracel9iAS(9.2.0.3)

    Hi, May i know what cause the servlet filter not workinng in Oracle9iAS? Is there any library files missing? I have tried deploy the war file in Tomcat but is working fine but when i try to deploy in Oracle9iAS, the application seems like can't call

  • Downloading from the Cloud?

    This should be simple and probably is!! (Me thicko!!)  I've recently done a lot of composing work using Garage Band on my iPhone while on holiday.  It is supposed to feed it to the Cloud.  iCloud management says that the files are there but they are