Order of execution of static { }  statements question

Hi,
I have a question about the order of execution of static statements. Let's imagine the following Class B inheriting of Class A:
public class A {
    static {  // My static code for A };
public class B extends A {
    static { // My static code for B; };
}I know that static statements are executed when classes are loaded, but does Java guarantee an order of execution of static statements between inherited classed (like for constructors) or is it 'random' in that it depends which class is loaded first?
Thanks,
J.

Jrm,
My advise with this and all such questions is "Suck it and see"...
Have compiler, will travail ;-)
Cheers. Keith.
PS:
package forums;
import java.util.List;
import java.util.ArrayList;
public class InitBlocksTesterpator
  private List<String> list = new ArrayList<String>() {
      add("This hack uses an anonymous inner-class to populate the list.");
      add("It causes serialization problems");
C:\\Java\\home\\src\\forums\\InitBlocksTesterpator.java:8: warning: [serial] serializable class <anonymous forums.InitBlocksTesterpator$1> has no definition of serialVersionUID
  private List<String> list = new ArrayList<String>() {
                                                      ^
1 warning
  static {
    System.out.println("this is a static initialiser block above the main method.");
    System.out.println("this is a instance initialiser block above the main method.");
  public static void main(String[] args) {
    // static { System.out.println("this is a static initialiser block inside the main method."); } // won't compile
    { // this is hardly ever used. just use a method FFS!
      int n = 0; // n is lexically scoped... i.e. it only exists in this code block
      System.out.println("this is a code block inside the main method.");
    new InitBlocksTesterpator().moreBeer();
    System.out.println("this is a instance initialiser block below the main method.");
  static {
    System.out.println("this is a static initialiser block below the main method.");
  public void moreBeer() {
      System.out.println("this is a code block in the moreBeer instance method.");
    // static { System.out.println("this is a static initialiser block in an instance method"); } // won't compile
    System.out.println(list);
}... just to save you some time ...

Similar Messages

  • Statechart Module: What is the order of execution for a parent state and its substates?

    Hello,
    This page describes the order of execution of transitions and actions for one level of nesting. What about compound states? Do the static reactions of the parent state execute before the transitions of the sub-states?

    Hello, 
    I'm not incredibly familiar with the Statechart module, but I will look into it for you on our internal database. In the mean time, there are some examples that may answer some of your questions here:
    https://decibel.ni.com/content/docs/DOC-8716
    and here:
    http://www.ni.com/white-paper/7425/en
    -N
    National Instruments
    Applications Engineer

  • WHERE clause order ox execution question

    I dont understand order of execution of a WHERE clause, using a complex database
    I want to write a SELECT statement with the following condition
    ... WHERE ( branch = 'main' ) AND ( type = 1 ) OR ( charge -1 AND charge = 2 )
    My question is
    <1> Can yoyu use parenthesis inside of a WHERE clause
    <2> How would you write such a clause as above if you can not use parenthesis
    Thanks

    Just to echo what everyone else is saying, of course parentheses are syntactically valid and can make a difference to the logic. In you example though,
    WHERE ( branch = 'main' ) AND ( type = 1 ) OR ( charge {noformat}<{noformat}> -1 AND charge <= 2 )is the same thing as
    WHERE ( branch = 'main' AND type = 1 ) OR ( charge {noformat}<{noformat}> -1 AND charge <= 2 )and even
    WHERE branch = 'main' AND type = 1 OR charge {noformat}<{noformat}> -1 AND charge <= 2because AND takes precedence over OR. You can think of it as a "stronger" operator.
    However I would not use the last version because it's ambiguous to anyone reading it, and code like that can easily hide bugs. I would also not use the first version because all those redundant brackets are just confusing, making it almost as hard to read (and therefore prone to bugs) as the last version.
    btw I've changed your example because I know this forum can swallow *{noformat}<{noformat}>* (I've used {noformat} tags to preserve it).
    I'm not sure if any of this affects order of execution (and if it does, your Oracle version will make a difference).

  • SQL Statement order of execution within batch

    Hi all, 
    Can someone please explain the purpose of the GO command in SSMS. MSDN states it is used to signal the end of a batch of statements. I am trying understand the reasons you need this e.g. variable scope?, statement order of execution?
    In particular, I'm concerned with the order of exuction...for example, with the following two statements:
    use AdventureWorks2012;
    select * from [Sales].[SalesOrderHeader];
    Is there any risk that SQL server will attempt to execute the second statement before completing the first?
    Thanks inadvance.

    Sorry Shriven - I somehow initially missed this part of your answer....ignore my original reply. Thanks.
    --It will always execute in order
    SELECT GETDATE() AS CURRENT_DATETIME INTO #TEMP3  
    WAITFOR DELAY '00:00:10';-- 10 Seconds Delay
    SELECT GETDATE()
    WAITFOR DELAY '00:00:15';-- 15 Seconds Delay
    SELECT * FROM #TEMP3 

  • The order of execution (of PL/SQL function calls) changes...why??

    select e.EMPID empid,
    e.name name,
    aatest.SETVALUES(2) z,
    aatest.TEST1() b,
    aatest.TEST2() x,
    aatest.TEST3() y
    from emp e
    where e.empid = 101
    order by e.name;
    when I execute this select statement...the order of function calls is as follows:
    setvalues 1st (call no:1)
    test1 (call no:2)
    test2 (call no:3)
    test3 (call no:4)
    Now...I introduce a join between the two tacles as mentioned in the query
    select e.EMPID empid,
    e.name name,
    e2.deptno deptid,
    aatest.SETVALUES(2) z,
    aatest.TEST1() b,
    aatest.TEST2() x,
    aatest.TEST3() y
    from emp e, emp2 e2
    where e.empid = e2.empid
    order by e.name;
    The order of execution of function calls changes to
    (I observed this using DBMS_OUTPUT.PUT_LINE)
    test3 (call no:1)
    setvalues 1st (call no:2)
    test1 (call no:3)
    test2 (call no:4) (the first and last calls swap!)
    i.e: it calls the last function in the select statement at the beginning
    instead of calling it at the last. Is it the normal behaviour? or whats going on
    here?
    Can somebody explain me, please....
    Details:
    the following four functions are defined in a package called 'aatest' and compiled.
    aatest.SETVALUES(2)
    aatest.TEST1()
    aatest.TEST2()
    aatest.TEST3()
    the Tables EMP and EMP2 are two tables defined in the same schema.

    Your "thinking" is wrong here. You can not use the column order to model your program flow. As SQL is set/tupel based, there is no given sequence of the execution order. Otoh you want to have a specific order in wich your functions must be executed otherwise the result will be wrong (or undefined). Thus here you need a procedural approach. This can be done by using PL/SQL for example.
    You would code your functions in that way, that they are working correctly independent from the place where they are called ie if function1 needs the setvalues function, this function must be called inside the function1 then.
    Are you sure you need all these functions in this procedural approach inside the sql-statement? This is mostly not needed and can be accomplished by using pure SQL. If not, may be your design is broken.

  • Tracking the order of execution of sql scripts in SQL*Plus

    In our production environment we sometimes have to run some .sql scripts in a particular order. Since the order of execution is important , i have created another .sql file caller caller.sql(shown at the bottom) which will call all the scripts in the right order.
    i thought of putting a exec DBMS_LOCK.SLEEP (5); after the end of every execution of the script so that i can see the
    'Ending script1'message .
    The spooling within the caller script(execute_stack.log) has become meaningless because each script has a spool <filename.log> and spool off within it. These spool logs (for every script) is important for tracking purposes as each script belongs to a different development team and i have to send them the spooled log file after the execution.
    I don't want to see the entire scripts running by in my screen. Since these scripts have their own spooling, i can later check the logs if the scripts where executed properly.
    So i need two things.
    1.I just need to see the following and nothing else in the screen.
    Ending script1
    Ending script2
    Ending script3
    .2. I need to log the order of execution. ie. the execute_stack.log should look like the above.Since there is a spool off within each script, this wouldn't be possible.Right?
    Ending script1
    Ending script2
    Ending script3
    .The caller.sql script which calls all the scripts in the right order
    alter session set nls_date_format = 'DD-MON-YYYY hh24:MI:SS';
    set serveroutput on
    set echo on;
    set feedback on;
    spool execute_stack.log
    @script1.sql
    exec dbms_output.put_line ('Ending script1');
    dbms_output.put_line(chr(10)||chr(10)||'.'||chr(10)||'.'||chr(10));
    exec DBMS_LOCK.SLEEP (5);
    @script2.sql
    exec dbms_output.put_line ('Ending script2');
    dbms_output.put_line(chr(10)||chr(10)||'.'||chr(10)||'.'||chr(10));
    exec DBMS_LOCK.SLEEP (5);
    @script3.sql
    exec dbms_output.put_line ('Ending script3');
    dbms_output.put_line(chr(10)||chr(10)||'.'||chr(10)||'.'||chr(10));
    exec DBMS_LOCK.SLEEP (5);
    @script4.sql
    dbms_output.put_line(chr(10)||chr(10)||'.'||chr(10)||'.'||chr(10));
    exec dbms_output.put_line ('Ending script3');
    commit;
    spool off;Is this a professional way of tracking the execution of .sql scripts?

    Pete_Sg1 wrote:
    Is this a professional way of tracking the execution of .sql scripts?No. There is very little professional about using .sql scripts on a production system - when stored procedures are safer, more robust, easier managed and controlled and secure.. and where a log table can be used to properly log the runtimes (and other stats) of each processing step.
    Let's just take a look at the number of moving parts you need to schedule and run a .sql script. A cron job needs to be configured with the proper environment setting. It needs to run a shell script. That shell script needs to load SQL*Plus. SQL*Plus needs to connect to the database (starting a dedicated server process most likely). SQL*Plus then needs to read a .sql file, parse these commands and either execute these locally (SQL*Plus commands) or remotely (PL/SQL and SQL commands).
    How can this be considered professional when the very same can be achieved with a
    - stored procedure
    - using DBMS_JOB to schedule the procedure for execution
    There are so many things that can go wrong with the first method. And so few things that could go wrong with the last one. No contest as to which method is not only better, but also professional.
    PS. See that you use Windows to run these scripts. It is even worse as it introduces another hardware and software layer making the scenario even more insecure & unsafe with more moving parts that can go wrong or simply fail.

  • Order of execution DML sentences

    Hi,
    I have put this text on a post in the JDeveloper forum, but maybe it is convenient to put it here, because I don't know if JHeadStart classes, can help in some way to solve the problem.
    We are interested in the same subject. We came from a Oracle Forms environment, where the default and logical behavior is delete/update/insert.
    In the ADF Model (using JHeadStart, at least), it seems that the execution order is a bit random (it is not the order I choose in the screen, for example), or maybe we have not understood, which is the order it applies.
    So, the questions are:
    1) There is an established order? Which is it?
    2) As klee have been asking, there is any way to change the default order?
    As ADF BC is promoted as an easy way to do Java applications for Form Developers, it seems strange that the execution order in forms hasn't been respected.
    Carles Biosca
    BBR Ingeniería de Servicios

    Carles,
    The DML sentences order is determined by the sequence in which ADF BC receives the changes, which is the following in case of multi-row changes:
    1. updates
    2. inserts
    3. deletes
    We have to stick to this sequence for the following reasons:
    - The multi-row update is perforemed as part of the standard JSF lifecycle phase "Model Update"
    - multi-row insert is JHeadstart-specific and performed after the Model Update phase
    - multi-row delete is JHeadstart specific and performed after multi-row insert. The reason we do the deletes last is to handle the case where the transaction fails: to be able to redisplay the rows that the user attempted to delete, we must do a middle-tier "rollback to savepoint", and this save point is set after the multi-row insert, otherwise we cannot redisplay the new rows entered by the user.
    Steven Davelaar,
    JHeadstart Team.

  • Order of execution of VPD policies

    Hi,
    I have a table on which I have defined two policies (one for column masking and one for row filtering).
    From whatever testing I have done, it seems the policy functions get executed in the order in which the policies were created.
    Does oracle guarantee any order of execution of policies defined on the same table?
    Thanks!
    Edited by: kedruwsky on Sep 26, 2008 7:43 AM

    Sounds more like a question for the Database General forum (General Database Discussions
    I'm guessing that there's no guarantee on the order of execution, just like having multiple triggers on tables.

  • Order of execution of used DCs(doModifyView) in a Main DC

    Hello all,
    I am working in an application  using webdynprojava.
    The Application  has a main DC and this main DC uses four seperate DCs as used DCs.
    We have code written in doModifyView in all the  respective DCs(views). And all those are executing in specific order.
    My question is,
    what decides the order of execution of used DCs(doModifyView).
    If any one has any knowledge on the above querry please provide your suggestions
    Thanks
    Uvendu Bala

    Hi Uvendu,
    From what you mentioned, you are using 4 DCs as Used DCs in a the main DC.
    Say you have view1 in used DC1,view2 in used DC2,view3 in used DC3 and view4 in used DC4.
    If during the application execution view4 appears before others then the wdDoModifyView of view4 is called first.
    The wdDoModifyView is called just before the view is displayed in the browser. Hence, the order of execution of the wdDoModifyView will depend on the order the views are being displayed to the end user.
    If say, you just calling a method in the component controller in DC1 means that the wdDoModifyView of view1 will not be called.
    Regards,
    Kartikaye
    P.S :- Please grant points for correct or helpful posts.

  • Order of execution of Callable objects in an ExecutorService

    what determines the order of execution of Callable objects in an ExecutorService ?
    here is my test code:
        ExecutorService exe = Executors.newCachedThreadPool();
        Set<Callable<String>> tasks = new HashSet<Callable<String>>();
        for (int i = 0; i < 10; i++) {
          Worker worker = new Worker(i);
          tasks.add(worker);
        List<Future<String>> results = exe.invokeAll(tasks);
        for(int i = 0; i < results.size(); i++) {
          Future f = (Future) results.get(i);
          String s = (String) f.get();
          System.out.println("__" + s);
    public class Worker implements Callable<String> {
      private int seqNumb = -111;
      public Worker(int i) {
        this.seqNumb = i;
      public String call() {
        double d = Math.random();
        int i = (int) (d * 10000);
        Thread.sleep(i);
        return (Integer.toString(i) + "___" + seqNumb);
    }i ran this code within NetBeans on one XP machine. and ran it from the command line on a different XP machine.
    the sequence is always:
    *6*
    *9*
    *4*
    *3*
    *8*
    *1*
    *0*
    *5*
    *2*
    *7*
    the sequence should be random because of the random wait???
    the sequence looks random. why does "6" come before "9"? why is "7" last?
    yet, the sequence is always the same.
    i can't understand the order of execution of the Callable objects.
    note:
    what i'm trying to do is implement my own version of the ExecutorService interface.
    so, its important to understand the above question?
    Edited by: kogose on Feb 9, 2009 6:53 PM

    jtahlborn wrote:
    ejp wrote:
    2. The order of execution is defined by the queue associated with the ExecutorService. Normally it is a FIFO, but one can imagine using a PriorityQueue, given some kind of priority implementation in the submitted tasks.just to be clear for others who may be reading this, the order of submission is controlled by the queue implementation (where submission is the movement of a Callable from a queue to a thread). once the Callables are passed to threads, their actual order of execution is undefined (where execution is the invocation of the "call" method).And not only that, but even if we knew that the order of execution were call1, call2, call3, that still doesn't tell us anything, since there's no synchronization here, and hence any thread can be swapped out at any time. Call1 could be entered, but then swapped out before it gets to print anything, etc.
    Bottom line: When you're dealing with multiple threads, unless you use synchronization, wait, notify(All), or higher level java.util.concurrent constructs, you have no ability to control or predict what executes when.

  • Order of execution in triggers

    Hi
    On a table t1 i've written 4 triggers.
    (1) before update {stmt level}
    (2) before update for each row
    (3) after update {stmt level}
    (4) after update for each row
    Could you please hint me
    If i fire the update statement on table t1 in which order they execute
    Regards
    josh

    Following is the order of execution:
    (1) before update {stmt level}
    (2) before update for each row
    (4) after update for each row
    (3) after update {stmt level}
    And its pretty simple to test it yourself,
    SQL> drop table t purge;
    Table dropped.
    SQL>
    SQL> set serveroutput on
    SQL>
    SQL> create table t(t1 number);
    Table created.
    SQL>
    SQL>
    SQL> CREATE OR REPLACE TRIGGER TEST.BEF_UPD_STMT BEFORE
      2  UPDATE OF T1 ON TEST.T BEGIN
      3    dbms_output.put_line('Before UPDATE - STATEMENT level');
      4  END;
      5  /
    Trigger created.
    SQL>
    SQL> CREATE OR REPLACE TRIGGER TEST.AFT_UPD_STMT AFTER
      2  UPDATE OF T1 ON TEST.T BEGIN
      3      dbms_output.put_line('After UPDATE - STATEMENT level');
      4  END;
      5  /
    Trigger created.
    SQL>
    SQL> CREATE OR REPLACE TRIGGER TEST.BEF_UPD_ROW BEFORE
      2  UPDATE OF T1 ON TEST.T FOR EACH ROW BEGIN
      3      dbms_output.put_line('Before UPDATE - ROW level');
      4  END;
      5  /
    Trigger created.
    SQL>
    SQL> CREATE OR REPLACE TRIGGER TEST.AFT_UPD_ROW AFTER
      2  UPDATE OF T1 ON TEST.T FOR EACH ROW BEGIN
      3      dbms_output.put_line(' After UPDATE - ROW level');
      4  END;
      5  /
    Trigger created.
    SQL>
    SQL> insert into t values (1);
    1 row created.
    SQL> insert into t values (2);
    1 row created.
    SQL> insert into t values (3);
    1 row created.
    SQL>
    SQL> commit;
    Commit complete.
    SQL>
    SQL> update t set t1 = t1 + 2;
    Before UPDATE - STATEMENT level
    Before UPDATE - ROW level
    After UPDATE - ROW level
    Before UPDATE - ROW level
    After UPDATE - ROW level
    Before UPDATE - ROW level
    After UPDATE - ROW level
    After UPDATE - STATEMENT level
    3 rows updated.
    SQL>

  • IPhone 5s wireless connectivity issues, cannot upload files/state to iCloud, and supposedly needing to do so in order to get my files/state onto a new iPhone 6 Plus

    I am trying to get my files from my old iPhone 5s onto my new iPhone 6 Plus. I am currently and have been using iCloud to backup my files/state. However, I believe the antenna on the iPhone 5s went kaput a few months ago, because the Wi-Fi and Bluetooth, both, do not work at all, meaning, I have tried all solutions including, resetting network settings, restarting the phone, etc. This is problematic because, as far as I know the iPhone 5s needs to be connected to Wi-Fi or Bluetooth to a Wi-Fi Hotspot in order to ask the internet, in order to upload current information/state to iCloud. Herein lies my problem.
    I have used iCloud already, to download my current files/state to my iPhone 6, with a caveat, these are only the files/state from before the antenna supposedly went kaput. That means, that all of my files/state since that time, while still being on my iPhone 5s, is not uploaded to iCloud, which then means I do not have it on my iPhone 6 which was updated to the most current files/state that was available at the time.
    What do I do?
    I have iTunes installed on a Windows 7 and Windows 8.1 Computer, and I have made a backup on there. However, I have to admit, I find iTunes very counter-intuitive and very difficult to use/understand. And I'm mostly referring to the syncing/backing-up features. I know you have to have safe guards to protect software usage, but with this high-minded philosophy of minimalism, couldn't it be as easy as drag and drop? Even software syncing? USB syncing with iCloud, etc?

    Thank you for the information. I checked out the section and read it through. From what I can gather, you can start your new iPhone from an itunes backup (Set Up Iphone > Restore from iTunes Backup), but, in my situation I need to add the Files/State from the old iPhone backup to the new iPhone that was started from scratch and has it's own unique Files/State, without subtracting from either. The problem is, that I don't want to subtract anything, and from what I understand about Syncing, if I am Syncing a new iPhone that's been started up, edited, has it's own suite of apps, etc. to an old backup of a previous iPhone, I am going to lose everything new I've done, as it will sync with the previous Files/State.

  • Order of execution for various Nodes in HANA Views

    Hello Folks,
    I have created some analytic and calculation views. I would like to know order of execution of various nodes inside them such as Logical Join, Data Foundation, Semantics for Analytic views.

    And to find out how to use planviz:
    Show me the timelines, baby! by Lars himself
    Ravi

  • Can anyone explain this to me, please. It's a static section question.

    Can anyone explain this to me, please. It's a static section question.
    I came across the following style of programming recently and I would like to know what the Static section is actually doing in the class. Thx.
    Here is the code.
    public class ClassA {
         private static Hashtable ClassAList = new Hashtable();
         private ClassB cB;
         private Vector goodLink;
         private Hashtable classCList;
         static
              ClassA cA = new ClassA();
              ClassAList.put("whatever", cA);
         public static ClassA getClassA()
              return (ClassA) ClassAList.get("whatever");

    hi,
    The static section shall be loaded before it's constructor is called. (i.e at the time of loading the class). Therefore making it available for any other objects to call.
    hope this clarifies ur question
    prasanna

  • How to reverse service order which is in released state

    Hi,
    Please guide me how can we reverse a service order which is in released state.
    Is it possible to reverse a service order with released state?
    Please guide it is very urgent.
    Thanks and Regards
    Edited by: MPVash Vash on Dec 5, 2008 10:04 AM
    Edited by: MPVash Vash on Dec 5, 2008 10:06 AM

    Hi,
    a delivery suspension due to non-payment can just be released via an incoming payment.
    You could also manually do this be setting the end date of the suspension, but I would not advise that. As I currently do not have system to check I'm not sure whether you could use ISM_SALES_ORDER_CHANGE, but you can try via the where-used list of structure JKSI_SUSPEND which needs to be used in this case.
    Tim

Maybe you are looking for