Home > Java > javaTutorial > body text

How Java uses local environments

PHPz
Release: 2023-05-09 15:10:23
forward
1319 people have browsed it

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);     }
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!