Interface class Initialization

A class or interface type T will be initialized immediately before the first occurrence of any one of the following:
1..T is a class and an instance of T is created.
2..T is a class and a static method declared by T is invoked.
3..A static field declared by T is assigned.
4..A static field declared by T is used and the field is not a constant variable (?4.12.4).
5..T is a top-level class, and an assert statement (?14.10) lexically nested within T is executed.
Above is from JLS.
public class Demo {
     static int y;
     int x=instanceMethod();
     int instanceMethod()
          System.out.println("instance method");
          return 5;
     public static void main(String[] args)
          Demo.y=15;
          Demo.staticMethod();
     static void staticMethod()
          System.out.println("static method");
}In this case the output is static method
This contradicts points 2 and 3, since in this program static method is invoked and a static field is assigned , yet instanceMethod is not called, i.e not initialized

Initialization of a class consists of executing its static initializers and the initializers for static fields (class variables) declared in the class. Initialization of an interface consists of executing the initializers for fields (constants) declared there.
Your class has no static initializer nor class variable initializer...
Therefore I wouldn't say your example illustrates the statement you mentioned.

Similar Messages

  • How do  I use a variable from an Interface class?

    Right now I have three classes. First class is called Game and it extends my second class call Parent and also implements my third class call Source. Source is an interface class. I have a variable that I want to use in my Source class named Checker. Now, How do I go among using that variable from my Game class? What should the code look like?
    ex.
    public class Game extends Parent implements Source
    need help badly....

    ok, what I forgot to tell you guys is that my variable
    in my interface class is a boolean type(true or
    false). It is set to true now. But I want it to change
    to false when a user triggers a button in the Game
    class. How do I do this? You don't because you can't. If you have a varaible declared in an interface it must be static and final. It cannot, therefore, be changed. Better head back to the drawing board.

  • How do i hide a column in table interface class

    Hi,
    I need to hide a column in Abap table interface class. When i tried to hide from web item properties it didn't work so i am thinking to hide first column in the table interface class
    Thanks,
    mala

    In the WebApplication Designer start Tools -> View Definition -> Based on a Query. Choose your query, change layout to your requirements and save the view. Now just use the view in your webtemplate.
    Pls assign points if answer is useful
    <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/u/37289">vitaliy</a>

  • Understanding the use of interface class?

    Hello,
    This question referes to java servlets, but the questions is about java design.
    My wrox java server pages text, includes an example where some user data is posted to servlet.
    To process the data posted and store this, they created a interface class and another class AdminManager which implements the interface.
    In the servlet they create an object from the interface class, and call the AdminManager methods through the interface object.
    In the book this was the only example which used a interface. And I wondered if this design approach was often used, or should an interface normally be used if several classes would implement the interface.
    Thanks

    It depends. You might want to create an interface even if you only have a single implementation of that interface in mind, because you want to make it easy to create more implemenations later.
    Also keep in mind that not all implementations of an interface are strictly for production use. For example, you might want to define an interface, define an implementation of that interface for production use, but then also define a "mock" version of that interface for testing, prototyping, etc.
    Generally I feel that if you have a sufficiently complex set of types and relationships between those types, it makes a lot of sense to express those relationships purely as interfaces, on a high level. Then provide implemenations as a separate step in the programming process.

  • Bean problem: No interface classes found

    Hi ;
    I try to create a adapter . according to tutorial "How To Create Modules for the J2EE Adapter Engine"
    https://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/f013e82c-e56e-2910-c3ae-c602a67b918e&overridelayout=true
    Although I did all steps in it , I copied sda files and extract them  then I imported them to the project but I get this error in Netweaver Studio "Bean problem: No interface classes found" while creating ejb file.
    the document says you must close and reopen project when you come accross this error but it doesnt work?
    Is there any one solve this error?
    ps: I use NWDS 7.0.19 , I copied aii_af_lib.sda, aii_af_svc.sda and aii_af_cpa_svc.sda files from PI 7.01

    Hi Tuncer!
    Did you download and "import" these JAR files into your NWDS Build Path  - classpath variables:
    com.sap.aii.af.lib.mod.jar     <bin>/ext/com.sap.aii.af.lib/lib
    sap.comtcloggingjavaimpl.jar     <bin>/system
    com.sap.aii.af.svc_api.jar     <bin>/services/com.sap.aii.af.svc/lib
    com.sap.aii.af.cpa.svc_api.jar     <bin>/services/com.sap.aii.af.cpa.svc/lib
    com.sap.aii.af.ms.ifc_api.jar     <bin>/interfaces/com.sap.aii.af.ms.ifc/lib
    <bin> stands for: /usr/sap/<SID>/<instance-id>/j2ee/cluster/bin in a PI 7.1 system.
    Windows -> Preferences -> Build Path -> Classpath Variables -> New ...
    Choose a name of your choice and then select the JAR files mentioned above.
    This should resolve your problem.
    Regards,
    Volker

  • RE: Hide a column in web report using table interface class

    Hi,
    I want to hide first column in web template using table interface class. Following is the code i used in CAPTION_CELL and CHARACTERISTIC_CELL. Is this correct?
    method CAPTION_CELL.
    *First column
    if i_x = 1.
    add comment tag
    move '<!-- ' to C_CELL_CONTENT.
    endif.
    endmethod.
    method CHARACTERISTIC_CELL
    First column
    if i_x = 1.
    save start-time column
    move I_CHAVL_EXT to L_STARTTIME.
    add comment tag
    move '<!-- ' to C_CELL_CONTENT.
    endif.
    endmethod.
    When i execute the web template it is still displaying the first column. Do i have to code in any other method?
    Thank you,
    Mala Venkatesh

    Hi , the implementation should look like...
    method CAPTION_CELL .
    *CALL METHOD SUPER->CAPTION_CELL
    EXPORTING
    I_X =
    I_Y =
    I_IS_EMPTY =
    I_IOBJNM_ROW =
    I_ATTRINM_ROW =
    I_TEXT_ROW =
    I_IOBJNM_COLUMN =
    I_ATTRINM_COLUMN =
    I_TEXT_COLUMN =
    I_IS_REPETITION =
    I_COLSPAN =
    I_ROWSPAN =
    CHANGING
    C_CELL_ID =
    C_CELL_CONTENT =
    C_CELL_STYLE =
    C_CELL_TD_EXTEND =
    First column
    if i_x = 1.
    add comment tag
    move '<!-- ' to C_CELL_CONTENT.
    endif.
    Second column
    if i_x = 2.
    close comment tag
    concatenate '--> '
    C_CELL_CONTENT
    into C_CELL_CONTENT.
    endif.
    endmethod.
    method CHARACTERISTIC_CELL .
    *CALL METHOD SUPER->CHARACTERISTIC_CELL
    EXPORTING
    I_X =
    I_Y =
    I_IOBJNM =
    I_AXIS =
    I_CHAVL_EXT =
    I_CHAVL =
    I_NODE_IOBJNM =
    I_TEXT =
    I_HRY_ACTIVE =
    I_DRILLSTATE =
    I_DISPLAY_LEVEL =
    I_USE_TEXT =
    I_IS_SUM =
    I_IS_REPETITION =
    I_FIRST_CELL = RS_C_FALSE
    I_LAST_CELL = RS_C_FALSE
    I_CELLSPAN =
    I_CELLSPAN_ORT =
    CHANGING
    C_CELL_ID =
    C_CELL_CONTENT =
    C_CELL_STYLE =
    C_CELL_TD_EXTEND =
    First column
    if i_x = 1.
    save document-item number
    move I_CHAVL_EXT to l_docitem.
    add comment tag
    move '<!-- ' to C_CELL_CONTENT.
    endif.
    Second column
    if i_x = 2.
    close comment tag
    concatenate '--> '
    C_CELL_CONTENT
    l_docitem
    into C_CELL_CONTENT
    separated by space.
    endif.
    endmethod.
    Activate the methods/class and add this in the Web Template!
    for example:
    <param name="MODIFY_CLASS" value="ZHCOLAPP">
    ZHCOLAPP is the table interface class in this case.
    Best,
    Michael

  • Syntax error on keyword "void"; "interface", "class" expected

    When migrating my application for Visual-Age to Web-Sphere 5.1
    The following error occurred:
    Syntax error on keyword "void"; "interface", "class" expected
    for the code:
    * ejbLoad method comment
    * @exception javax.ejb.EJBException The exception description.
    public void ejbLoad() throws javax.ejb.EJBException{
         _initLinks();
    }Thanking you in an advance

    I had missed a closing breacket '}'

  • Default Table Interface Class - 0TPL_BAP_MASTER

    Hi there
    We are trying to determine which table interface class is used on the default 0TPL_BAP_MASTER web template.
    We have created our own web template, but one of the pieces of functionality delivered with the standard template is the sort (ascending/descending) functionality which is included as arrows on the table column headings. We would very much like to use this on our custom template, and believe it to be implemented in the table interface class, but are not sure what that class is.
    Anybody know the name of the class?
    Cheers,
    Andrew

    Hi Deepu,
         How are you?
    I got a error about 0TPL_BAP_MASTER, when we are exicuting webtemplates in my portal. Can you please tell me what may be the error and how to overcome with this error.
    Thanks,
    Surendra.

  • Abstract Classes & Interface Classes

    Dear members of the Sun Community
    My studies are progressing and just 1 period ago we started doing Object-Orinted Programming in Java and I must say I'm quite fond of it. It's become quite clear that OOP is an important aspect of Programming and just can't be missed. We've learned about Inheritance, Polymorfism, Mutators, Inspectors, Uses-Relationships and everything else however now I've come to the point where I got a problem:
    Up until now we have been using normal classes to work with in which you could create objects and in your main program create objects from that class however. We've just learned about Abstract and Interface classes. As far as I'm concerned I'm quite confused with both of them.
    If I am not mistaken (please correct me if I'm wrong) Abstract classes are classes from which you cannot create an object but is only used to make a subclass inherit everything from this superclass.
    I am not quite sure what Interface classes are as they just plain confuse me. Would anyone be so kind to maybe explain what all of this is ?
    Thanks a whole bunch
    Herazio

    Funny enough that already solved the question !
    Thank you so much for the quick reply ^^
    Herazio

  • Who can tell the difference of the abstract interface class?

    someone ask me that he had a abstarct interface class, such as :
    public abstract interface Book{
    I was comfused, who can tell me why use it?

    http://java.sun.com/docs/books/tutorial/java/interpack/interfaceDef.html
    Scroll down to the bottom.
    Drake

  • Interface classes

    can somebody tell me why interface classes are useful.. right now i'm just not convinced, because, like an abstract class, interfaces only contain method headers that are to be used in derived classes. Why write another class to store the method headers when you still need to code the header again except this time there's code? Instead, can't u just write that same method in another class without implementing an interface in the first place, isn't that less coding?
    I'm just confused about abstract and interface classes, and don't know when to use them.
    Can someone explain the concepts...

    Firstly interfaces. Look at the Java event model. If a programmer wants to register interest in someone pressing a JButton, he registers his interest with the button through the method JButton.addActionListener(ActionListener l). The parameter here is of type ActionListener which is an interface. This achieves two things. Firstly the programmer can make his whole class implement ActionListener and fill in the method. Alternatively he could make it using an anonymous inner class. Secondly, it is an issue of security - within the JButton whatever object is sent to the addActionListener method, the JButton can only "see" the ActionListener part of it - ie. the JButton can only call the actionPerformed() method.
    Let us look at another use of Interfaces - the java Collection API. Apache have various implementations of such interfaces as Map, Set, List that differ in some way from HashMap, HashSet, Hashtable, ArrayList that Java provides. Usually the difference is performance-related, such as a Map that is used for fast-lookups in a multi-threaded environment but assumes that writes are done seldomly (org.apache.commons.collections.FastHashMap being a case in point). Suppose you have written your code everywhere thus.
    public void someMethod() {
      HashMap m = new HashMap();
      callMethod( m );
    private void callMethod(HashMap m) {
      //do something here
    }And then when you come to profile your application, you find that it is too slow and would be benefitted by using FastHashMap - you will have to go through every single place you have written HashMap in your code and change it. However, if you had originally done...
    public void someMethod() {
      Map m = new HashMap();
      callMethod( m );
    private void callMethod(Map m) {
      //do something here
    }You won't - you will only need to change where the HashMap was Constructed. Going a bit further, had you used a Factory object to return you the new Map implementation, then wouldn't have to look through the code at all - you could merely go straight to the factory Object where all Construction is done and change it there.
    A further use of interfaces is to define an API for vendors to implement. One example of this is JDBC. The interfaces (as with the Collections API) provide a contract of behaviour.
    Abstract class are slightly different - suppose you were coding an application for a Company - you might have classes representing Employee, Manager, Customer etc etc. These will have some properties that are shared (ie. all will have contact telephone numbers, not all will have salary, or bonus etc. So you might have the hierarchy
    Person (abstract : attributes address, telephone, email)
       |
       |--> Employee (attributes salary, employeeNumber)
       |          |
       |          |--> Manager (attributes bonusPayment, staff[])
       |
       |--> Customer (attributes accountNumber)You would make the Person class abstract as it makes no sense to be able to instantiate a Person, only concrete sub-classes. Its subclasses can inherit its attributes (if you so wish) and also functionality (you could define a public void sendEmail(String message) on Person to be inherited by its subclasses), again if you so wish.
    I hope this helps.

  • Interface class

    what is interface class and what is the use of interface class.
    Why should we define the interface class in our program.
    Give me any example.
    Thanx.

    what is interface class and what is the use of
    interface class.
    Why should we define the interface class in our
    program.
    Give me any example.
    I'm glad you asked. See this thread for an excellent example of the Interface class:
    http://forum.java.sun.com/thread.jspa?threadID=730816

  • JDK class initialization...

    Hi,
    I believe that class level member variables are not guarenteed to be initialized anymore by the JDK starting from jdk1.4 due an optimization that tries to reuse the instances.
    So for example, if I defined a class level String variable, and was creating a number of instances of this class, it could be that some of the valus of this variable would be "dirty", i.e they would contain the previous values leftover from the last instance. So it was the developer's responsibility to make sure to explicitly initalize all class level variables.
    Can anyone confirm this behaviour? Is this still the case?
    Thanks

    Hi,
    I believe that class level member variables are not
    guarenteed to be initialized anymore by the JDK
    starting from jdk1.4 due an optimization that tries to
    reuse the instances.Initialization is very closely described in the spec.
    Refer to these sections to get started:
    12.4 Initialization of Classes and Interfaces
    12.4.1 When Initialization Occurs
    12.4.2 Detailed Initialization Procedure
    http://java.sun.com/docs/books/jls/second_edition/html/execution.doc.html#44411
    So for example, if I defined a class level String
    variable, and was creating a number of instances of
    this class, it could be that some of the valus of this
    variable would be "dirty", i.e they would contain the
    previous values leftover from the last instance. So
    it was the developer's responsibility to make sure to
    explicitly initalize all class level variables.That would sound like a bug to me. Can you post
    a code example that demonstrates this?

  • EJB deployment problem --New remote interface class files are not loaded

    Hi, I face a problem while deploying an ear file in oc4j. I basically get some problems like the method in the remote interface is not implemented in the EJB class. But the implementation is actually available in the EJB class.
    We get this problem when we actually change the signature of the EJB remote methods. The new methods are not referenced by oc4j. Only the old version of remote interface is referenced by oc4j. But the latest version of EJB class is taken. I am using 9.0.3 version of the oc4j. Could you pls help me regarding this problem ?
    Regards
    Solomon

    I have found the solution :-)
    You must add to the ejbCreate() method of the bean class throws javax.ejb.CreateException

  • Interface/class hierarchy and serialization?

    Hi,
    I have an interface, base class that implements this interface and subclasses derived from base class that also implement this interface.
    I also have a method with this interface as an argument. My question is: how to do serialization of this argument in this method without using instanceof operator? Should interface extend Serializable and/or each class/subclass implement Serializable? Is it sufficient to just have common interface extend Serializable without classes/subclasses implementing it?
    thanks,
    sale

    How should I serialize for example if the argument in the method is subclass XYZ? Do I need to use instanceof operator?

Maybe you are looking for

  • Acrobat crashed when try to a print the PDF opened through browser

    Hi, I have Acobat pro and reader installed on my machine. I have set the properties - Open pdf in browser. So, all the PDFs are opening in browser uses Acrobat not the reader. And this is way I want. It was woking fine on Windows XP. After Windows 7

  • Some apps give just sound and no view

    I just installed my apple tv, with the ipad i am able to look and hear ie. youtube and videos (synced to my ipad)on my television. However some apps give only sound and no view. Why is this, and is this going to Be supported by apple? Or should i con

  • The problem of connect and resource role

    Hi, As we know, that while crating a new user, we can assign connect and resource so that the user can access the system tablespace. The problem that i got is instead of assigning the connect and resource role, i have assigned each and every privileg

  • Problem Installing a Plug-In

    I am trying to install a plug-in, but keep getting the following error message: "Sorry; there is a space in your home directory path.  MacOS makes it difficult to do that by accident.  Contact your administrator for information on how to fix this." I

  • Corporate Phone book - LDAP

    Hi! I downloaded the newest firmware (6.1.3(a)) to SPA9x2 phones. I found a new feature, the SPA9x2 phones can connect to a LDAP database and search in that. I think, with this feature I can use an Active Directory integrated corporate phone book. I