One o'clock eye
No matter how complex Java procedures, the program has started a number of threads, they are in the Java virtual machine in the process. With all the threads of a JVM, all variables are in the same process, they all use the memory area of the JVM process. When the system following situations, JVM process will be terminated:
-
The program runs to the end of the last normal.
-
Run the program to use System.exit () or Runtime.getRuntime (). Exit () End the program codes.
-
During program execution encounters an uncaught exception or error ended.
-
Platform where the program is forcibly terminated JVM process.
Two combat
A.java
public class A
{
// 定义该类的类变量
public static int a = 6;
}
ATest1.java
public class ATest1
{
public static void main(String[] args)
{
// 创建A类的实例
A a = new A();
// 让a实例的类变量a的值自加
a.a ++;
System.out.println(a.a);
}
}
ATest2.java
public class ATest2
{
public static void main(String[] args)
{
// 创建A类的实例
A b = new A();
// 输出b实例的类变量a的值
System.out.println(b.a);
}
}
Three runs
1 run ATest1
7
2 runs ATest2
6