Can think so, each class has a method named Initialize (), which implies that it has to be invoked before it is used, and unfortunately, to do so, the user has to remember to invoke this method, and the designers of the Java class Library can use a special method called constructors, To ensure that each object can be initialized. If the class has a constructor, then Java will automatically call that constructor when the object is created and the user is not able to get it, so the initialization is guaranteed.
I do not know the difference between the original author's description and the translator's understanding, combined with the whole chapter, I did not find two key words "" and "". At the very least, the original author and the translator did not really explain what the JVM did when it was initialized, or did not understand the JVM's initialization insider, or why do you think there is a "Initialize ()" approach that doesn't actually exist?
Where are the "and" methods? These two methods are real and you can not find the way, perhaps it is so that some of the masters have to make a halo. Plus the JDK implementation of some bugs, if not in-depth understanding, really let people touch the North.
Now that the scientific system has a strange phenomenon, then the vast system was initially based on the assumption that 1 is correct, deriving 2, and then continuing to deduce 10000000000. Unfortunately, too many people do not care about the 2-100000000000 system is based on the assumption that 1 is correct. I am not going to use the assumption that "I can think like this" and I have to prove that the "and" methods are truly real:
package debug;
public class MyTest{
static int i = 100/0;
public static void main(String[] args){
Ssytem.out.println("Hello,World!");
}
}
To perform a look, this is the output of jdk1.5:
java.lang.ExceptionInInitializerError
Caused by: java.lang.ArithmeticException: / by zero
at debug.MyTest.(Test.java:3)
Exception in thread "main"
Note that, as with the exception generated by other method invocations, the exception is set to Debug. MyTest's.
Look again:
package debug;
public class Test {
Test(){
int i = 100 / 0;
}
public static void main(String[] args) {
new Test();
}
}
jdk1.5 Input:
Exception in thread ' main ' java.lang.ArithmeticException:/by zero
At Debug.test. (test.java:4)
At Debug. Test.main (Test.java:7)
Instead of locating the exception in the test () construct method, the JVM is in Debug. Test..
When we see these two methods, we'll discuss the two "built-in initialization methods" in detail (I don't like sporogenous some non-standard terminology, but I really don't know how to address them in a canonical way).
The built-in initialization method is a unique method for the JVM to initialize internally, rather than a method that is invoked by the programmer, and in fact the syntax "<>" is not even compiled in the source program. This means that initialization is controlled by the JVM rather than by the programmer.