The magic of Java: bytecode-general Linux technology-Linux programming and kernel information. The following is a detailed description. Java solves the above two problems-the key to security and portability is that the output of the Java compiler is not executable code, but bytecode ). Bytecode is a set of highly optimized instruction sets designed for execution in the Java runtime system. The Java runtime system is called the Java Virtual Machine (JavaVirtual Machine, JVM ). In its standard format, JVM is a bytecode interpreter. This may be a bit surprising, because the compilation results of languages such as C ++ are executable code. In fact, for performance considerations, many modern languages are designed to be compiled rather than interpreted. However, it is through the JVM to run Java programs to help solve the main problem of downloading programs on the Internet. This is why Java outputs bytecode.
Translating a Java program into bytecode makes it easier to run programs in a large environment. The reason is very direct: you only need to implement Java virtual machines on various platforms. In a given system, any Java program can run on the system as long as the system running package exists. Remember: Although Java virtual machines on different platforms have different details, they all explain the same Java bytecode. If a Java program is compiled as a local code, the corresponding version of the program is required for each CPU type connected to the Internet. This is certainly not a feasible solution. Therefore, interpreting bytecode is the easiest way to write truly portable programs.
The explanation of Java program also helps its security. Because every Java program runs under the control of the Java virtual machine, the Java Virtual Machine can contain this program and prevent it from generating side effects outside the system. As you will see, some restrictions specific to the Java language enhance its security.
The speed of the interpreted program is usually slower than that of the same program compiled into executable code. But for Java, the difference between the two is not big. Byte Code can make the Java runtime system program run much faster than you think.
Although Java is designed as an interpreted program, technically, Java does not prevent dynamic compilation of bytecode into local code. SUN provides a bytecode compiler-JIT (Just In Time) In the Java 2 release ). JIT is part of a Java virtual machine. It compiles bytecode into executable code in real time as needed. It cannot compile the entire Java sequence into executable code at one time, Because Java needs to execute various checks, which are executed only at runtime. It is important to remember this because JIT only compiles the Code required for its running. However, this instant compilation and execution method still greatly improves the performance. Even after the bytecode is dynamically compiled, the portability and security of the Java program can be ensured, because the runtime system (the system executes the compilation) can still control the runtime environment of the Java program. Whether Java programs are interpreted as bytecode in the traditional way or dynamically compiled as executable code, their functions are the same.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.