Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the advantages and disadvantages of JAVA portability

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "what are the advantages and disadvantages of JAVA portability". In daily operation, I believe many people have doubts about the advantages and disadvantages of JAVA portability. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "what are the advantages and disadvantages of JAVA portability?" Next, please follow the editor to study!

The powerful portability (portability) of Java technology is mainly manifested in three independent aspects, namely:

Source code portability

CPU portability

Operating system portability

The characteristics of these three portability and their shortcomings are discussed below.

1. JAVA as a programming language: source code portability

As a programming language, JAVA provides one of the simplest and most familiar portability-source code migration. This means that an arbitrary JAVA program, no matter what CPU, operating system, or JAVA compiler it runs on, will produce strange results. This is not a new concept. People can also have different effects when they use C and C++. But there are too many options for programming with C or C++, and it is not strictly defined in many details, such as the value of uninitialized variables, access to freed memory, the tail value of floating-point operations, and so on. So unless you design strictly according to system-independent concepts in the first place, this portability can only be a practical idea, not a practice.

In short, although C and C++ have close grammatical definitions, their symantics definitions are not standard. This semantic inconsistency makes the same program have different results in different system environments. Sometimes unexpected results can occur even if the system is exactly the same and simply because of different compiler settings. JAVA is different. It defines a tight semantic structure so that the compiler does not undertake this work.

In addition, JAVA defines the behavior of the program more strictly than C and C++, such as: it provides automatic memory collection function (GarbageCollection), so that the program can not visit out-of-boundary memory; it provides certain values for uninitialized variables, and so on. Its special functions can reduce the differences between JAVA programs running on different platforms, and make JAVA better platform-independent than C and C++ even without the existence of JAVA virtual machine.

However, these characteristics also have their disadvantages. JAVA envisions running on computers with 32-bit bytes and 8 bits per byte, which makes it impossible for those 8-bit word-long computers and some supercomputers to run JAVA programs effectively. Only those portable C and C++ programs can be run on such a platform.

2. JAVA as a virtual machine: CPU portability

The object code that occurs in most compilers can only run on one kind of CPU (such as Intel's x86 series), and even those compilers that can support multiple CPU cannot produce target code suitable for multiple CPU at the same time. Suppose you need to run the same program on three CPU (such as x86, SPARC, and MIPS), you must compile it three times.

But the JAVA compiler is different. The object code (J-Code) that occurs in the JAVA compiler is for a non-existent CPU-JAVA virtual machine (JAVAVirtualMachine), not an actual CPU. JAVA virtual machine can mask the difference between different CPU, so that J-Code can run on any machine with JAVA virtual machine.

The concept of virtual machines is not unique to JAVA: the University of California proposed the concept of PASCAL virtual machines a few years ago; Perl scripts commonly used in Unix servers also generate machine-independent intermediate code for execution. But what is special about the JAVA virtual machine designed for the use of Internet is that it can generate secure target code that is not threatened by the virus. It is because of Internet's special requirements for security features that JVM can be quickly accepted. Today's mainstream operating systems such as OS/2, MacOS and Windows95/NT have provided support for J-Code once or very soon.

As a virtual CPU, the JAVA virtual machine is independent of the source code (SourceCode). We can generate J-Code not only with JAVA language, but also with Ada95. Ideally, there were J-Code compilers for several types of source code, including Basic, Lisp, and Forth. Once the source code is converted to J-Code, the JAVA virtual machine can execute it regardless of which source code it is generated from. The result is CPU portability.

The advantage of compiling the source program to J-Code is that it can run on a variety of machines, while the drawback is that it is not as fast as native code.

3. 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++ will not run on Unix or Macintosh systems. Why is that? Because programmers use a small amount of WindowsAPI and interrupt calls when writing Windows programs, and the calls to system functions of Windows programs are very different from those of Unix and Macintosh programs, unless the full set of WindowsAPI is transplanted to other operating systems, the recompiled program will not work.

JAVA handles this problem by providing a set of platform-independent library functions (including AWT, UTIL, LANG, and so on). Just as JVM provides a virtual CPU, JAVA library functions provide a virtual GUI environment. The JAVA program only calls the JAVA library function, while the library function calls the operating system function by different virtual machines.

JAVA also uses a "least-commom-denominator" in its OS/GUI library to provide functional calls to a particular operating system, that is, this function takes effect only in specific environments and is neglected in other operating systems. The benefit of this is that an application program with a familiar interface can be generated for an operating system while the program can run under other systems. The defect is that some function calls in the system are highly dependent, so it is difficult to implement in the virtual OS/API of JAVA. In this case, programmers can only write programs that are not portable.

At this point, the study on "what are the advantages and disadvantages of JAVA portability" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report