How to Understand the cross-platform nature of a language

Source: Internet
Author: User

English is a common international language, but I do not understand English.

Many people use the "cross-platform language" to write cross-platform programs that are not written, and blindly think that the cross-platform nature of the language is nothing.
This article takes Java as an example to discuss "how to understand the cross-platform nature of the language".

From the perspective of developers or programming languages, the "Platform" refers to the runtime environment of the language. For example, the Java platform is JRE (Java Runtime Environment ). Isn't the platform a Windows or Linux OS? Yes, Windows and Linux are indeed platforms, but this platform is too broad for Java, just as it has never been said that Java platforms are i386 and arm. Simply put, the operating system alone cannot run Java programs. JVM is included in JRE.

If the executable body corresponding to a language can run on other platforms without modification or only a few modifications, the language is cross-platform. Yes, a few modifications are allowed, but this process is generally performed without the programmer's knowledge. Generally, this task is completed by the platform. However, in any case, this is only related to the executable body, rather than the source code.

For a Java program, it must take at least two steps to execute. The first step is to use the Java compiler to compile the source code into bytecode. The second step is, use the Java interpreter to execute bytecode. It can be seen that the Java program is not directly executed as the C program, but has to have an initiator, that is, the so-called JVM (Java Virtual Machine), to load and execute. It can be seen that two important factors for cross-platform Java are:
1. There is a compiler that can generate bytecode compliant with Java specifications;
2. There is an interpreter that can interpret the above bytecode that complies with Java specifications.
In other words, in any operating system, as long as there is a JRE, you can run the Java executable body, regardless of where it comes from, as long as "compliant with Java specifications. Haha, isn't it a bit messy here? Isn't the Java platform a jre? Does JRE change on different operating system platforms? Yes, it is because the above Java tool set varies with the operating system that we have repeatedly stressed that "bytecode compliant with Java specifications". Because a series of tool sets, such as the Java compiler and Java interpreter, depend on the operating system, but their input and output comply with the unified Java specification. If either of the above two conditions is changed, it is likely that Java will not be cross-platform.

In addition to the above two points, there is also a third factor, Java for the platform design library, that is, the so-called jar package, although most of these jar packages are written in Java, however, there are still many unique designs for the platform, such as path representation between different operating systems. From this perspective, the Java bytecode after the platform is transplanted has been changed by the interpreter.

Misunderstanding 1: the Java language is cross-platform, so Java programs are also cross-platform
"Java language" and "Java program" are not the same concept. The Java language is actually just a series of specifications, which provide programmers with Java syntax and Semantic Rules. Java programs are executable bodies based on these specifications. Generally, program requirements are more or less related to the differences between some operating systems. For example, the file systems of windws are multiple, while those of UNIX are single, the platform-related ODBC is used in the Java Database Connection Program. When the program gets to another platform, errors are inevitable. As mentioned above, Java tool sets depend on operating systems, that is, they cannot change the differences between operating systems. This is one of the reasons why JNI (Java Native invoke) exists. When a program uses the features of an operating system and the transplanted operating system does not, although they can be executed by the platform, they still run incorrectly.

Misunderstanding 2: the Java language is cross-platform, so Java programs are cross-Java tool sets.
From the above description, we can see that the cross-platform Java language is essentially because the Java tool set complies with the same set of specifications. Standardization is an abstract concept, which naturally corresponds to an implementation. Currently, there are three common implementations: Sun's official implementation, IBM's implementation, and GNU's implementation. It is very likely that a set of tool sets correspond to a set of implementations, so that different implementations are not universal. Moreover, each set of implementations may add its own features after meeting the specifications, for example, GNU can directly compile Java source code, bytecode, jar package, and other executable objects. Of course, they are the same for the implementation of the source code specification, but it is not guaranteed that these implementations will not be different. Therefore, for a given set of tools, the Java language is cross-platform, and other tool sets are not allowed.

Misunderstanding 3: the Java language is cross-platform, so Java programs are cross-Java application servers.
In a given set of tools, the Java application server is essentially the implementation of javaee specifications as a Java EE container. This can be easily understood by integrating with misunderstanding 2. However, let's just say that misunderstanding 3 should not be at all, because the reasons and results are not at the same level.

Article Source: http://www.diybl.com/course/3_program/java/javajs/20081013/150474.html

How to Understand the cross-platform nature of a language

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.