Cross-platform Java IT Band of Brothers Grammar Java language

What is the platform

Java is cross-platform programming language, so first of all we need to know what the platform is, we usually put the overall CPU and operating system called platform.

CPU we all know, is the brains of the computer, both responsible for thinking operation, is also responsible for various parts of the computer command control. CPU type is very large, the current mainstream CPU we are using the Inter and AMD company produces a variety of CPU. The CPU set using the same or a different instruction set, the instruction set is used to calculate the CPU controls the computer system and a set of instructions. Instruction set is divided into RISC and complex instruction set, each CPU has its own specific set of instructions. Develop applications, we must first know what the program is running on the CPU, that is, to know the instruction set used by the CPU.

The operating system is software that acts as the interactions between users and computers, different operating systems support different CPU, strictly speaking different operating systems support different CPU instruction set. Such as the early Windows and Linux support complex instruction set Inter and AMD, but does not support PowerPC RISC set used, and the use of the earlier MAC computer (Apple Computer) is a PowerPC processor, so it can not MAC under the direct installation of Windows, and macOS can not be installed over Inter and AMD platforms. Currently all major operating systems (Windows, Linux, MAC, etc.) are supported instruction set Inter and AMD.

And because now mainstream operating systems support mainstream CPU, it is sometimes also called the operating system platform. In fact, I want to know what the cross-platform Java in the end, need only provide the platform version when downloading Java on Java's official website www.oracle.com Java in the end you can know what cross-platform. We will explain how to download later in the book is in Java, and what is the reason can be judged cross-platform Java by the above method.


The principle of cross-platform Java

From the above explanation we understand what is in the platform, and now tell you about cross-platform Java principle, we first look at a C language source code into the executable program related to the picture process (Figure 2.2).

bff853bf3d724bed846795cece896af4.png

FIG 2 C language source code into an executable program from a process


If you have had C language development experience, 2 will look very easy. We know that using standard C development program, the executable file using a different compiler is run on the corresponding platform, such as Windows can use VC to compile C source code files can be compiled to run under Windows ; executable files can use GCC compiler, the next generation of Linux can run on Linux, but there is a problem is to use the C compiler VC program can be run on Linux it? The answer is definitely no, if you want to get the program under Windows platform running under the Linux platform, you need to use the compiler under Linux platform again, the compiler source code to generate an executable file to run. Because the executable file of C language compiler is not cross-platform, using a specific compiler to compile C program can only be run on the corresponding platform, where you can also say that the compiler is associated with the platform, and also compiled file platform-dependent. We say that language is cross-platform executable file compiled cross-platform, rather than source code cross-platform (if source code is cross-platform, any language is a cross-platform language).

Let's Java language is how to solve cross-platform executable by 2.3 point of view.

967c47258d004596bbdbbbd54f03f8d9.png

FIG 3 Java language source code into an executable program from a process


We can be found through 3, between Java source code for each platform and more than a compiler and a bytecode file, and then each platform through interpreter to explain the implementation of the byte code file. Then the middle of the compiler and bytecode files in the end what is it? The original, in order to do cross-platform Java language, the Java source code by a compiler through, compiled into bytecode files a platform-independent, and each platform in the appropriate interpreter can be loaded, interpret and execute the byte code files (each platform interpreter interpret the same bytecode file will produce different results, but running the same machine instructions, Windows and Linux machine instructions is different, but the result is the same Java program run is no difference), that is written in one platform applications without modification can also run on other platforms, but requires that the platform must have the corresponding version of the interpreter can.

Usually using the Java language source code files with .java suffix, using a Java compiler tools provided by the javac generated source code is compiled byte code file to .class suffix, using the tools provided by Java java run to run word bytecode files.


Guess you like

Origin blog.51cto.com/14311187/2409843