When it comes to the Java Virtual Machine (JVM), most people’s first impression may be “difficult”, but when we step into the “JVM world”, we find that the problem is not as complicated as we imagined. The only thing we really have to fear is fear itself. This article, the first in a series on the JVM, will take you through some of the confusion you may have when you first started learning about the JVM. For example: What is the JVM? Why learn the JVM? How to learn the JVM effectively? With these questions in mind, let’s step into the world of the JVM.
What is a JVM?
Introduction to JVM: JVM is short for Java Virtual Machine, The Chinese translation for Java Virtual Machine, is a specification for computing devices, it is a fictional computer, by simulating various computer functions on the actual computer to achieve. Simply put, the JVM is used to parse and run Java programs.
A very important feature of Java, “platform independence,” is implemented using the JVM. The Java language simply needs to generate object code (bytecode) that runs on the Jvm to run unmodified on multiple platforms, because the Jvm itself shields platform-specific information, enabling Java to “compile once, run anywhere.”
Why learn the JVM?
There are several reasons to learn about the JVM:
1. Program tuning
Different applications (business scenarios) require different Jvm configurations, such as different garbage collectors, and memory configurations and ratios for the new generation and the old generation, which can have a huge impact on how the application performs. The default configuration of the Jvm only ensures that your program will “run,” and wanting to “run well” or even “run better” is one of the most important factors in learning about the Jvm.
2. Check the running problems of the program
Some programs may be used in online will encounter all sorts of problems, and these problems are often fatal, such as memory, a deadlock caused by application runs slowly, etc., and these problems in the development and small amounts of concurrent test phase is easy to be ignored, so study well the Jvm to at the time of key, Help you clean up the “stubborn disease” in the system.
3. Mastered the fundamentals and principles of program execution
That is, many people say: not only to “know”, but also “know why”.
4. Avoid code mistakes
For example, avoid overloading calls with variable-length arguments (a more detailed example will be provided in a later article).
5. Deal with interviews
I have to say that’s part of what a lot of people learn, and it’s also a positive driver, if you understand the catfish effect.
6. Master the general mechanism of other languages
Another power of the JVM is that it can run not only Java programs, but also Scala, Clojure, Groovy, and the popular Kotlin. Learning the JVM allows you to understand the general mechanics of these languages and even share their ecosystems.
How to learn the JVM effectively?
Now that you’ve seen the benefits of learning the JVM, how do you learn it effectively? Someone might see the words “JVM” or “Java virtual machine” and be confused about what it is, let alone how to learn it. This section is to teach you how to effectively learn the JVM, the JVM to do a knowledge point division. You can say that to master the following points is to master the entire JVM.
JVM knowledge points, divided into the following:
1. Composition of JVM
The JVM is made up of five parts: the heap, the virtual machine stack, the local method stack, the program counter, and the method area. Later articles will explain the specific uses of each part.
2, a variety of garbage collection algorithms
The Jvm has a lot of garbage collection algorithm, advantages and disadvantages of different algorithm also each are not identical, such as: remove algorithm and replication algorithm, marking clear algorithm can produce a variety of space debris, copy the memory is divided into two pieces, although performance is very good but can be used at a time, and waste the memory space, that have a relatively perfect algorithm? There must be an answer, but for reasons of space, this article will explain it in detail later.
3. Multiple garbage collectors
There are many garbage collectors for the Jvm, such as Serial, the earliest version of the collector. Serial, the oldest collector, is a new generation collector that uses a copy algorithm. It is a single-thread collector that must suspend all other worker threads while garbage is collected. Until The Serial collector collection is complete (” Stop The World “). The CMS (Concurrent Mark Sweep) collector is a collector whose goal is to obtain the shortest collection pause time; There are also more advanced G1 (garbage-first) collector.
Learning these collectors, on the one hand, is to configure the appropriate collectors for their own programs, on the other hand, each collector Settings are not the same parameters, after learning the configuration of these collectors, you can set the optimal running matching parameters for the program.
4. JVM analysis tools
The Jvm analysis tool is used to check the defects of the program operation, find out the problems of the program, so as to ensure the stable operation of the program, Jvm analyzer is divided into: Command-line tools (officially called experimental tools, but no doubt stable), and view analysis tools, the former is certainly better than the latter, but the latter is built on the former, each of which will be covered in more detail later in this series.
5. Java class loading mechanism
The Java class loading mechanism, which describes how Java classes are loaded and run in the Jvm, is very helpful in understanding how Java works, and that’s one of the interesting things about learning Java, is that you can see the whole process of Java running, completely transparent, giving you a sense of “control.” This is what the Java language naturally supports, so you’ll find the Java language interesting.
6. JVM optimizations are commonly used
One of the biggest benefits of learning about the Jvm is that it makes your applications run more efficiently using these common configurations of the Jvm, so learning about this is essential.
Four,
This article gives you an overview of the Jvm as a whole, the benefits it can bring, and how it can be learned, which are the biggest barriers to learning the Jvm in the first place. Starting well is half the battle. Congratulations on learning an indispensable skill in Java. If you think this article is good, please share it with your friends.
This article is the first in a series of Jvm articles. Follow the author’s public account for more exciting articles: