I don't quite know what you're asking but say the print statement isn't printing what you expected.
Without really knowing I think it's fair to assume the static statements are executed in order. In that case if you move the static assignments to above the static initializer the printing probably will be in better accordance with what you may have expected.
In order to execution of java program first static variable are executed first and static block are executed in that case output was static,1 but why it was giving output static,null ?
Because the description you posted is NOT quite correct.
This is your line of code:
final static String string="static";
That creates a 'constant variable'. See section 4.12.4 'final Variables' in The Java Language Spec.
A variable of primitive type or type
String, that is
finaland initialized with a compile-time constant expression (§15.28), is called a constant variable.
Whether a variable is a constant variable or not may have implications with respect to class initialization (§12.4.1), binary compatibility (§13.1, §13.4.9) and definite assignment (§16).
See that last statement about 'may have implications with respect to class initialization'? Read the section 12.4.1 referred to:
For each class or interface C, there is a unique initialization lock
LC. The mapping from C to
LC is left to the discretion of the Java Virtual Machine implementation. The procedure for initializing C is then as follows:
. . .
6. Otherwise, record the fact that initialization of the
Class object for C is in progress by the current thread, and release
. . .
9. Next, execute either the class variable initializers and static initializers of the class, or the field initializers of the interface, in textual order, as though they were a single block.
. . .
That 'constant variable' is initialized in step #6 of the initialization. Then, as step #9 says, 'the class variable initializers and static initializers' are executed 'in textual order'.
This 'static intializer' line is FIRST in that 'textual order':
At that point the 'string' static (which is a 'constant variable') has been initialized but the 'integer' has not so it is still NULL.
In that above case if we create Object to string using new operator it was giving nullvalue even though 'string' was final and static variable. Can you explain to me ?
final static String string=new String("static");
What I said above DOES explain it to you.
That new line of code is NOT a 'constant variable' so it will be NULL for the same reason the other one was null. Reread what I said above.