The concept of software portability is how easy it is to move software from one environment to another. In order to obtain high portability, common programming language and running support environment are often used in the design process. Try not to use a language that is highly relevant to the underlying system. Java portability is described below.
One, Java as a virtual operating system (OS) and graphical user interface (GUI): Operating system portability
Even after recompilation, most Windows programs written in C and C + + cannot run on UNIX or Macintosh systems. What is this for? Because programmers use a large number of WINDOWSAPI and interrupt calls when writing Windows programs, the Windows program's call to System functionality differs greatly from UNIX and Macintosh programs, so unless the full set of WINDOWSAPI is ported to another operating system, Otherwise, the recompiled program still cannot run. Java employs a method that provides a set of platform-agnostic library functions (including AWT, UTIL, Lang, and so on) to solve this problem. Just as the JVM provides a virtual CPU, Java library functions provide a virtual GUI environment. Java programs only make calls to Java library functions, while library functions call the functions of the operating system by different virtual machines. Java also uses a "rare name" (Least-commom-denominator) in its Os/gui library to provide functional calls to a particular operating system, meaning that the feature is only valid under certain circumstances and is ignored under other operating systems. The advantage of this is that an application that has a familiar interface can be generated for an operating system while the program can run under other systems. The disadvantage is that some function calls in the system have a strong dependency and are therefore difficult to implement in Java virtual Os/api. In this case, the programmer can only write a non-portable program.
? Java Early advanced learning sharing, common learning is the most sensible choice, like words can my Learning Group 64 residence 46 clothes 3 Ling 9, or add Data group 69 like 64 land 0 Bar 3 (enter the Group notes platform name)
Second, Java as a programming language: Source code portability
As a programming language, Java offers one of the simplest and most familiar portability – source code porting. This means that any Java program, regardless of the CPU, operating system, or Java compiler it runs on, will produce the same result. People using C, C + + can also produce the same effect. But with C or C + + programming people can have too many choices, and in many details it is not strictly defined, such as: The value of uninitialized variables, the access to freed memory, the tail value of floating-point arithmetic and so on. So unless you start by strictly following the concept of system-independent design, this portability can only be a theoretical assumption and not to form a practice. In summary, although C and C + + have strict syntax definitions, their semantic (symantics) definitions are not standard. This semantic disunity makes the same program produce different results in different system environments. Sometimes even if the system is exactly the same and only because the compiler's settings are different, it can produce unexpected results. and Java is different. It defines a strict semantic structure, and makes the compiler not take on this aspect of the work. In addition, Java defines the behavior of the program more rigorously than C and C + +, such as: it provides a memory auto-reclaim function (garbagecollection), which makes the program inaccessible to out-of-bounds memory, provides deterministic values for uninitialized variables, and so on. These features reduce the difference between Java programs running on different platforms, and make Java more platform agnostic than C and C + + without the existence of a Java virtual machine. However, these features also have a negative side to it. Java is supposed to run on a computer with 32-bit bytes and 8 bits per byte, which makes it impossible for those 8-bit word-length computers and some giant machines to run Java programs efficiently. Only those portable C and C + + programs can be run on such a platform.
Third, Java as a virtual machine: CPU portability
Most compiler-generated target code can only run on one CPU (such as Intel's x86 series), even those that support multiple CPUs can not produce target code that is suitable for multiple CPUs at the same time. If you need to run the same program on three CPUs (such as x86, SPARC, and MIPS), you must compile three times. But the Java compiler is different. The Java compiler produces target code (J-CODE) for a Cpu–java virtual machine (javavirtualmachine) that does not exist. Instead of a real cpu.java virtual function that masks the difference between different CPUs, the J-code can run on any machine that has a Java virtual machine. The concept of virtual machines is not unique to Java: The University of California introduced the concept of Pascal virtual machines a few years ago; Perl scripts that are widely used in UNIX servers are also used to generate machine-independent intermediate code for execution. But the special thing about a Java virtual machine designed for Internet applications is that it can produce a secure target code that is not virus-protected. It is because of the special requirements of security features of the Internet that the JVM can be quickly accepted by people. Today's mainstream operating systems, such as OS/2, MacOS, and windows95/nt, have been or are quickly providing support for J-code. As a virtual Cpu,java virtual machine is independent of the source code (sourcecode). Not only can we generate J-code in the Java language, we can also use ADA95 to generate them. In fact, there are j-code compilers for a number of provenance codes, including Basic, Lisp, and forth. Once the source code is converted to J-code, the Java Virtual machine is able to execute without distinguishing which provenance code it was generated from. The result of this is CPU portability. The advantage of compiling the source program into J-code is that it can run on a variety of machines, and the disadvantage is that it runs faster than native code.
In short, Java's portability features make it a broad application prospect on the Internet. At the same time, its own anti-virus capability also makes it a place in applications that require high reliability.
Question/interaction please leave a message, can directly in the bottom right "write a message can"
? If you feel good, please click "Subscribe" to update the new content every day!
? Your love and attention is my greatest power support!!!
Three aspects of the source of Java portability