Forgive me for my lack of Java-lingo. In fact I'd like to find a book someday that will teach me all of the definitions of words that are mentioned for Java classes and objects, as well as processes, etc.

If the title isn't at all clear, what I mean is "what happens first when an object is created?"

Is the order Static, Transient then Constructor?

For example, consider the following code--

 * To change this template, choose Tools | Templates
 * and open the template in the editor.

package chapter_21_multimedia_practice;

public class NewClass {
     Much more performance-friendly to have static calls before any pre-initialization.*/
    static { System.out.println("Running..."); /*what if I did deserializaton here?*/}
    /*Field variables here...*/
    public static void main(String args[]){
        System.out.println("I think I got it to work!");

--from the example, you can probably tell that I was fooling around with NetBeans and somehow opened a file that had an anonymous static block so I tested it out and realized that it worked. I never saw something like it before so I was curious.

From there I tried creating an object of this class and realized that before the constructor was called, the static block ran. Also the compiler had an easier time compiling when the static call was closer to the head of the class, which is why I made the above assumption.

My question now is... what is the order of processes executed during the instantiation of a new object?

8 Years
Discussion Span
Last Post by sciwizeh

Create two small classes and have one class call new on another class (that contains all the things you want to see) and run through the instantiation in a debugger.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.