Deep understanding of the Java cross-platform principle

Source: Internet
Author: User

The topic of this article is a summary of the cross-platform principles that characterize the Java language.

Before that, let's understand why the computer language is not cross-platform.

Two levels of hardware-level system level across platforms

First, the hardware level.

The computer can only recognize binary numbers that consist of "0" and "1".

So casually to the computer a group of 0101 binary number computer can recognize it?

Of course not!

Taking people as an example

A person can recognize a sound.

A scene like this: There are 3 people sitting in the room, Chinese, Koreans and Americans, respectively.

Now you need to greet them separately.

What do you do, go ahead and yell at everyone?

If you don't, people will think you're scolding him.

So then we need to separate.

Chinese say: Hello

The Koreans say, "Ah, Ernie.

The American said: Hello

So that people can know is to say hello, rather than scold him.

Because they can only accept the language of a particular greeting.

Back to the computer!

Each computer is pre-programmed with a set of instructions that it can recognize to be stored in a computer called an instruction set. The set of instructions that each company sets out from the factory may be different, so specific programs need to be written for specific computers.

Just like the above, 3 different computers may need to write 3 sets of programs.

The same thing needs to be done 3 times, if there are several computers may have more times, hemp is not troublesome? I feel it.

Can the hardware level cross the platform?

The answer is yes, the best examples are AMD and Intel.

Since the problem above is due to the different sets of instructions created by various computer vendors, the unification of the instruction set can solve the cross-platform problem on the hardware level.

So AMD and Intel now uniformly support the x86 instruction set (64-bit called x64). This only requires writing programs for a specific set of instructions. This solves the hardware-level cross-platform.

In fact, hardware-level cross-platform is not what we should worry about, only the operating system is directly running on the hardware.

We are writing applications, applications are running on the operating system, so the system-level cross-platform is what we focus on.

Hardware-level cross-platform has been resolved, how the system level out of the cross-platform problem?

We take Windows, Linux, and Mac as an example

Windows Linux and Macs can control AMD and Intel CPUs through the X86 instruction set

So what's the problem with the app that we're writing running on these 3 systems?

Here we use the C language to illustrate the following

There is a phrase called "write once, compile everywhere", that is, C language, such as compiled language.

This means that you only need to write a C-language source file and then compile it on a different operating system once to use it.

If you just compile it, it's easy.

Can this idea be realized?

Theoretically, yes.

Why is it theoretically?

If you are programming using the API interfaces provided in the C standard library, "write once, compile everywhere" is completely achievable.

But the C standard library implementation of the interface is too little, not enough!

In this way, each operating system manufacturer has expanded its own system class library.

For example, under Windows MFC (Microsoft Basic Class Library) you write programs under Windows to invoke the interface under MFC, compile and run is no problem. But it will compile under Linux, because the compiler cannot find an interface for MFC. That code doesn't work on Linux.

This results in the problem of cross-platform of computer language. In essence, it is not the language that cannot cross the platform, but the system libraries that are used in the language writing process.

Can't the C language boast the platform? Can study the next QT

Next, let's talk about how Java solves this problem and implements cross-platform.

We can see the Java writing process:

Start by writing a Java source file, using a Java compiler to generate a bytecode file with the suffix. class, which is not associated with a particular operating system, and is then interpreted by the JVM for execution.

So Java is also called interpreted language.

Java's cross-platform focus is on the JVM, because the. class bytecode file does not need to be interpreted for specific operating system related needs.

Then you can execute the Java program as long as you can explain the execution of the. class file.

So once Sun company developed different JVMs on different operating systems to explain the execution of Java programs. This enables the Java cross-platform.

Thus the Java language is cross-platform, but the JVM is not cross-platform.

Is it just that Java is a cross-platform?

PHP, Python, Ruby, Perl and so on are all smiling and not words.

In-depth understanding of Java cross-platform principles

Related Article

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.