View RSS Feed

Java Basic

Basic Java programming tutorials for learning Java fundamentals.

  1. Static initialize

    by , 01-08-2012 at 11:50 AM
    All the code blocks that do not have a function name and are declared as static are executed before the constructor is called. They are usually used to initialize static fields as shown in below code.

    Java Code: This is an example of static initialize
    public class StaticInitilaizer {
    public static final int A = 5;
    public static final int B;
    //Static initializer block, which is executed only once when the class is loaded.
    static {
    if(A == 5)
    B = 10;
    B = 5;

    Updated 01-14-2012 at 07:37 PM by Java Basic