Platform-agnostic in-depth Java virtual machines

Source: Internet
Author: User

Platform agnostic:

The Java architecture supports platform-agnostic:

①java Platform

The Java Platform acts as a buffering role between the runtime Java program and its hardware and operating systems, and the Java program is compiled into a binary program that runs in a Java virtual machine, and assumes that the Java API's class file is available at run time, and then the virtual machine runs the program. Those APIs give the program the ability to access the underlying computer resources. No matter where the Java program is deployed, it only needs to interact with the Java platform without worrying about the underlying hardware and operating system. As a result, he is able to run on any computer that has a Java platform.

②java language

The domain and behavior of the basic data types of the Java language are defined by the language itself, in languages such as C or C + +, where the value of the base integer type int is determined by its placeholder width, and its placeholder width is determined by the target platform, in general, C or C + + The placeholder width of int is determined by the compiler based on the word length of the target platform, which means that the same C + + program for different platform variants may behave differently at run time, simply because the base data types are different on different platforms. While the int in Java is a signed integer represented by a 32-bit twos complement, float always follows the floating-point standard 32-bit floating-point number. This is consistent within the Java Virtual machine and in the class file, and the Java language itself provides strong support for the platform-agnostic nature of Java programs by ensuring that the data types are essentially consistent across all platforms.

③java class file

The class file defines a binary format that is specific to a Java virtual machine, which can be created on any platform or loaded and run by any platform's Java virtual machine. Its format includes multi-byte high-level storage conventions, all of which are strictly defined and are independent of the platform in which the Java virtual machines reside.

④ Scalability

The Java platform can be implemented on a wide variety of different types of computers (from embedded devices to large hosts). Each platform provides a subset of the API for a specific target area. Finally, Sun's changed API definition approach has three base API collections that show the different scalability of the Java platform:

Enterprise Edition (Java EE)

Standard Edition (J2SE)

Mini Version (J2ME)

One of the most important principles to follow when writing a platform-independent Java program is to not invoke local methods that are not part of the Java API directly or indirectly, and calling the Java API with unexpected local methods will make the program platform relevant.

Platform-Independent Seven steps:

The approach that can be taken to ensure optimal portability of the program:

① Select a collection of hosts and devices to be run by your program (your "Destination host")

② Select the Java platform version that you think is good enough for the target host and write and run the program on that version of the Java platform.

③ for each target host, select the Java platform implementation (your "Target runtime environment") that some programs will run

④ writes the program so that it accesses the computer only through the standard runtime of the Java API (do not call local methods, or libraries that are proprietary to the developer calling local methods)

⑤ writes the program so that it does not depend on the correctness of the garbage collector's timely finalization, nor does it depend on the priority of the thread.

⑥ strives to design a user interface so that it works properly on all of your target hosts.

⑦ test program on all target runtime environments and all target host hosts

Platform-agnostic in-depth Java virtual machines

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.