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

How Java supports platform independence

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Editor to share with you how Java supports platform independence, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!

Why should Java support platform independence

As we all know, Java is a platform-independent language, so why should Java support platform independence? to sum up, there are the following points

Support the changeable network environment. Today is an era of the Internet, the network connects a variety of computers and devices, such as the network connected to windows PCs, UNIX workstations and so on. In order to ensure that the program can run on any computer on the network without any modification, no matter what kind of computer or platform the computer is, it greatly reduces the work of the system administrator. In particular, the program is deployed through the network environment.

Support networked embedded devices. At present, there are a variety of embedded devices in the workplace, such as printers, scanners, fax machines and so on. They are often connected through the network, and there are embedded devices of one kind or another even in home networks and cars. The platform independence of Java simplifies such system administration tasks. No matter which network administrator it is, it only needs to pay attention to the program itself. In addition, add a new device, which can be immediately accessed by other devices, and can also access other devices. These are all the benefits of platform independence.

Reduce the cost and time for developers to deploy programs.

For developers, Java platform-independent capabilities give the network a homogeneous running environment, so that distributed systems can be built around "network mobile objects". For example, object serialization, RMI, and Jini take advantage of platform independence. Bring object-oriented programming from virtual machines to the network.

How Java supports platform independence

Java supports platform independence from four aspects.

The most important is the Java platform itself. The Java platform acts as a buffer between the Java program and the hardware and operating system. In this way, Java programs only need to deal with the Java platform, regardless of the specific operating system.

The Java language ensures that the range and behavior of basic data types are defined by the language itself. On the other hand, the basic data class is determined by its placeholder width, and the placeholder width is determined by the platform. Different platforms will have different behaviors in compiling the same C++ program. By ensuring the consistency of basic data types across all platforms, the Java language provides strong support for platform independence.

Java class file. Java programs will eventually be compiled into binary class files. Class files can be created on any platform or loaded and run by a Java virtual machine on any platform. Its format is strictly defined and is platform independent.

Scalability. Sun obtains three basic API collections by changing the way of API, which is represented by the different scalability of the Java platform: J2EE, SE, and J2ME.

Factors affecting the independence of Java platform

Deployment of the Java platform. Before running the Java program, you must deploy the Java platform.

Version of the Java platform. Sun offers different API collections, including standard, extended, and so on. In addition, API itself is also facing changes, some API are considered to be out of date, and some API are not even backward compatible, so we need to choose the appropriate Java platform version to support program development.

Local method. When writing a platform-independent Java program, the most important principle is: do not directly or indirectly call local methods that do not belong to Java API. Calling local methods other than Java API makes the program platform relevant. In general, the local approach applies in three cases: to use the features of the underlying host platform that Java API cannot access; to access an old system or to use an existing library, but the system or library is not written by Java; and to speed up program performance, time-sensitive code is implemented locally. So when local methods must be used and multiple platforms are supported, local methods must be migrated to all required platforms. Therefore, the main purpose of writing platform-independent Java programs is to completely prohibit local methods from interacting with hosts through Java API.

Non-standard runtime libraries. One explanation for the so-called platform independence is whether the method you call has been implemented anywhere. As the name implies, the local method is only implemented locally, so there is no guarantee that it is platform-independent. On the other hand, Java API uses local methods to access the host in the implementation of operating systems such as windows and Solaris, which ensures that it is platform independent.

Dependence on virtual machines. Virtual machines can be developed by different developers, but the following two principles must be met: do not rely on finalization to ensure the correctness of the program, because objects in a particular program may be garbage collected at different times; do not rely on the priority of the thread to ensure the correctness of the program. Because some virtual machines can give priority to high-priority threads, some virtual machines cannot guarantee this.

Depending on the user interface, the AWT library provides a basic user interface that maps to local components on each platform, while the Swing library provides users with more advanced components, but is not mapped to local components.

7 steps to achieve platform independence

Select the host and device set on which the program is running (target host)

Select the Java platform version in the target host.

For each target host, select the Java platform implementation (target runtime environment) on which the program will run.

Write programs that call the Java API standard runtime (libraries that do not call local methods, or libraries that specialized developers specifically call local methods)

Write programs that do not depend on the garbage collector's garbage collection time or thread priority

Work hard to design the user interface and work properly on all target hosts

Test in all target runtime environments and all target hosts

The above is all the content of the article "how Java supports platform independence". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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