About 163,000 results
Open links in new tab
  1. Static Block in Java - Stack Overflow

    May 31, 2010 · yes, static block is used for initialize the code and it will load at the time JVM start for execution. static block is used in previous versions of java but in latest version it doesn't work.

  2. java - Static Initialization Blocks - Stack Overflow

    java static initialization static-block initialization-block edited Nov 25, 2017 at 11:17 Andrew 49.8k 15 99 145

  3. java - What is the difference between a static and a non-static ...

    The static initializer is actually invoked later, when the class is initialized, after it has been loaded and linked. That happens when you instantiate an object of a class or access a static variable or method …

  4. Necessity of static block in Java - Stack Overflow

    Dec 21, 2012 · I found that in Java, there is a feature called static block, which includes code that is executed when a class is first loaded (I don't understand what 'loaded' means, does it mean …

  5. java - When is the static block of a class executed? - Stack Overflow

    Feb 3, 2012 · The static code is executed when your class (StaticClass I guess) is referenced. Thus, it should be executed if you create a new instance of StaticClass or if you call one of its static methods.

  6. java - In what order do static blocks and initialization blocks execute ...

    Oct 24, 2013 · With the newer version of Java (1.7 and above), the JVM will throw a runtime exception as it does not find a main method in the class even though you have a static block.

  7. java - What is an initialization block? - Stack Overflow

    Oct 21, 2010 · We can put code in a constructor or a method or an initialization block. What is the use of initialization block? Is it necessary that every java program must have it?

  8. Static block vs. initializer block in Java? - Stack Overflow

    Sep 23, 2012 · The non-static initializer block on the other hand is created on object construction only, will have access to instance variables and methods, and (as per the important correction suggested …

  9. java - What is the purpose/advantage of a static {} block ... - Stack ...

    Sep 7, 2012 · It seems like the static blocks simply contain regular lines of code which could belong in any regular static method, so what is the advantage to having it run automatically at initialization …

  10. unit testing - Mocking Static Blocks in Java - Stack Overflow

    Nov 16, 2015 · My motto for Java is "just because Java has static blocks, it doesn't mean that you should be using them." Jokes aside, there are a lot of tricks in Java that make testing a nightmare. …