Home  >  Article  >  Java  >  How Java uses local environments

How Java uses local environments

PHPz
PHPzforward
2023-05-09 15:10:231359browse

Use the local environment

The parameters passed when calling the method and the temporary variables created during the call are saved in the stack (Stack), which is faster. Other variables, such as static variables, instance variables, etc., are created in the Heap and are slower.

The following is a test case

//   private static int a = 0;     public static void main(String[] args) {                int a = 0;                long start = System.currentTimeMillis();                for (int i = 0; i < 1000000; i++) {             a = a + 1;             System.out.println(i);         }         System.out.println(System.currentTimeMillis() - start);     }

The running results are obvious. It takes 15677ms to use static variables and 13509ms to use local variables. It can be seen that the access speed of local variables is higher than that of class member variables.

The above is the detailed content of How Java uses local environments. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete