Introduction to JAVA virtual machine

In 1991, Sun MicroSystems (acquired by Oracle in 2010) wanted to develop new technologies that could control smart appliances (microwave oven TV) or allow smart appliances to communicate with each other. Called Green Project

The difficulty of this project is that the target is home appliances. There are many restrictions as follows

1. Less memory for embedded systems: So programs must consume as little memory as possible

2. Cross-platform: we don't want a program to be compiled after each device is compiled to execute. We want to compile once and run everywhere

3. Security: The process of transferring programs between devices must be ensured that the device will not be damaged even if it is maliciously modified

4. Multi-thread support

Translator

Initially, the team planned to use C ++, but C ++ could not meet the cross-platform requirements. For example, Hello.exe that you compiled in the Linux system cannot be directly executed by Window

So although C ++ was very popular at the time, it was eliminated first because it did not meet the requirements

Interpreter

The interpreter allows your high-level language to execute every line without going through the compiler. For example, Python and Ruby, which are often heard, use the interpreter.

So as long as each device has a translator for my programming language, it can be cross-platform.

But the well-known interpreter is very slow, very slow, and very slow because he only executes one line every time he runs a line. Some compilers do not optimize it.

Is there a way to cross-platform and fast?


Compiler + interpreter

The Java bytecode is stored in Hello.class. Of course, we will have another chapter to introduce the format of this bytecode. Now you can think of it as the machine language bytecode in C

The bytecode is compiled, compressed, and optimized so that it runs much faster, and then throws the bytecode to the JVM specific to each platform. He will do the same processing with different hardware and operating systems result

This is how JAVA achieves cross-platform, but when this method came up at the time, the language was not called Java, but Oak.

Follow-up to the Green Project

After the invention of Oak, I originally wanted to use this language for TVs, telephones and other home appliances. But the final conclusion is that this language is too strong and will give the TV users too much authority. At that time, the demand for smart home appliances was not high at all. Dead belly

In 1994, the Green Project team discovered that the central idea of ​​the popular world wide web is very close to their initial idea of ​​home appliances. Data was passed between devices, so they renamed their newly invented language. He wrote a small World Wide Web browser for Java, HotJava, which announced the programming language that has changed the software ecosystem for 30 years at SunWorld in 1995

The more important name is James Gosling. He said that the father of Java is a member of the Green Project.

After the advent of JAVA, everyone found that the style of Java is very similar to C ++, but it is an object-oriented language. However, Java does not have the cumbersome pointer in C ++. It is changed to reference and the multiple inheritance is removed. Features running everywhere

In 1998, JDK1.2 was launched and renamed as Java 2 Platform. Not only that, but also quite ambitious to push three versions.


  • J2SE Standard Edition Offensive Desktop
  • J2EE Enterprise Edition Offensive Server
  • J2ME mini version offensive set-top box mobile phone and PDA
  • What a vision, basically the goal is to succeed in one direction
  • It is conceivable that the most successful is that J2EE rides on the Internet and all the features are in line with the server requirements of the Internet of Things
  • Cross-platform security fast and easy to use (object-oriented)


The number of developers has expanded rapidly. Some giants that support the C language have expressed their interest. Among them, IBM is among them the overlord quickly launched the web server WebSphere and then launched a giant cannon IDE-Eclipse plus its own strong hardware directly one-stop product Line (hardware + software + server) IBM's troika at that time was exactly like Google's troika (MapReduce, BigTable, GFS) ten years ago, with direct revenue skyrocketing

Later, a lot of strangers who want to occupy the server are more famous. Ruby on rails and PHP are basically not a big threat to Java.

In 2006, Hadoop was born, and the bottom layer also used Java to complete map / reduce. Since then, the rise of massive data computing has also helped Java.

Android came to the surface in 2008, and Google's strong support made Java once again reach an unprecedented peak

The introduction of the JVM in 2020 that every programmer must understand makes everyone aware of the unknown field of Java's underlying layer, lowering the threshold of Java's 30 years of learning and unveiling the mystery of the JVM for many years.

Why is the JAVA virtual machine called the JAVA virtual machine
I read a lot of books about virtual machines, and almost no one answered this question. I think it is very helpful to understand the answer to this question first.

First of all, we must first know what a virtual machine is. As the name implies, a virtual machine is not a physical machine. He uses software to simulate (implement) a fully functional hardware. The thing that simulates hardware is called a virtual machine. A virtual machine can execute programs like a physical machine.

Using the example of daily life, even if you buy a Window computer, you often hear that someone uses a virtual machine to install the operating system of Linux. After installation, you can execute Linux program instructions in the virtual machine as if you were using Linux. You do n’t need to use it at all. What is the actual underlying hardware

Shop the stems a little bit obviously. Seeing the above paragraph, you probably know what to take in the next paragraph! This concept is basically the same as our cross-platform, so JAVA also uses the same concept as the virtual machine. No matter what hardware and operating system your underlying layer is, as long as you have a Java virtual machine, you can execute java bytecode in the Java virtual machine. No matter what the actual underlying hardware is

So you write java, you compile java not to make your program run on a specific Linux or a Window, you are to make your program run on the JVM

It turns out that virtual machines are so convenient

But in order to achieve this, writing a JVM that executes everywhere must have very strict specifications so that each JVM on a different machine can get the same bytecode and run the same result.

Three concepts of JAVA virtual machine
Specification implementation and runtime examples

Specification:
Everyone who writes Java programs no longer needs to consider on which machine or operating system they only need to write the JVM. To achieve this goal, there are many strict requirements that must comply with the Java Virtual Machine Specification released by Oracle. All is to implement the JVM The rules that people must abide by As long as you follow the rules, anyone can implement their own virtual machine

Implementation:
There are norms and there are implementations. The most famous ones are the following two dear friends

Oracle HotSpot JVM

IBM's JVM

(You can see who implemented your virtual machine by typing java -version on your terminal)

Runtime instance:
There is a runtime instance when it is implemented. When you execute java Hello, an instance of a JVM is created in the memory and then the Hello file is loaded.

Note that each runtime instance will only run one java application, so if you enter java Hello five times in the terminal, five runtime instances will be generated to run five programs.

JVM architecture
The following figure is all the main components that make up a JVM

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations