Introduction to Java Architecture

Source: Internet
Author: User
Tags object serialization

The core of Java technology is the Java Virtual machine--all Java programs run on it, requiring Java virtual machines, Java APIs, and Java,class file mates to run Java programs Why using Java's infrastructure of smart devices and computers connected by a network creates a new environment for software that creates new challenges and opportunities for software developers. Java can be a great way to help software developers face challenges and seize them. Because Java is designed for the network. Java's ability to adapt to the network environment is determined by its architecture, which ensures that secure, robust, platform-independent programs are spread over the network and run on many different computers and devices. Network challenges and opportunities platform independence: One of the challenges that software developers face is the growing network-centric hardware environment, which includes devices that are increasingly widespread. The general network has many different devices, different hardware systems, different operating environments for different purposes. Java solves this problem by creating platform-independent programs. A platform-independent program written in Java is easier to write, manage, and maintain than a program compiled with a specific system and operating environment, and is less expensive to secure: Java Architecture guarantees program robustness, and some harmful code does not appear in Java code, such as memory leaks. Java inherently prevents a lot of bugs from appearing, so it also brings another benefit that is unrelated to the network: Improving Programmer Productivity Network mobility: moving objects--It also passes code and State on 2 of networks, Java implements the promise of object movement-- Through its object serialization API and RMI (remote invocation method), the object has created a new model in network-based sports distributed system programming, effectively bringing the advantages of object-oriented programming to the network Architecture Java architecture consists of four independent but related technologies:
    • Java programming language
    • Java.class file format
    • Java application Programming Interface (API)
    • Java Virtual machine
The four relationships are as follows: When you write and run a Java program, you experience these four techniques, writing the source code in the Java programming language, Compile it into a java.class file, and then run the class file in the Java Virtual machine to access system resources (such as I/O) by invoking the methods in the class (which implements the Java API) when the program is written. When the program runs, it implements the Java API method by calling the class file to satisfy the Java API call Java Virtual Machine Java is the core of the network-oriented Java virtual machine, it supports all aspects of Java-oriented architecture three pillars: platform-Independent, Security and network mobility. The primary task of a Java virtual machine is to load a class file and execute its bytecode. 1. Different execution engines in different Java virtual machines:
    • In the virtual machine implemented by software, the simplest execution engine is a one-time interpretation of bytecode;
    • The other engine is faster, but also consumes memory, called "Instant Compiler", in this case, the first executed bytecode will be compiled cost of machine code, the compiled local machine will be cached, when the method is called later can be reused;
    • The third engine is an adaptive optimizer, in which the virtual machine interprets the bytecode at the beginning, but monitors the activity of the running program and logs the most frequently used code snippets.
When the Java virtual machine is implemented by the software on the host operating system, the Java program interacts with the host by calling the local method (native). 2. There are two methods in Java: Java method and Local method
    • Java methods are written in the Java language, compiled into bytecode files, stored in the. class file.
    • Native methods are written by other languages (such as c,c++, or assembly language) and compiled into processor-related machine code
The difference: The local method is saved in the dynamic link library, and the format is proprietary to each platform. Java methods are platform-independent, when a running Java program calls a local method, the virtual machine loads the dynamic library containing the local method and invokes the method's local method: Using the local method may also relate the program to a specific Java platform implementation. A local method interface--java local interface--enables local methods to run on any one of the Java platform implementations of a particular host system if you want to guarantee the platform independence of the program, you can only access the underlying system resources through the Java API Class Loader architecture There are multiple class loaders in the Java Virtual machine, so the class loader block in the structure diagram actually represents a subsystem that may contain multiple class loaders, and the architecture of the class loader is an aspect of the Java virtual machine that plays an important role in security and network mobility. Two loaders:
    • Startup class loader is part of the Java Virtual Machine implementation
For example, if a Java virtual machine is implemented as a C program on an existing operating system, the startup class loader is a part of this C program, and the startup class loader typically uses some default way to load classes from the local disk, including the Java API class (the boot loader is also known as the original class loader, System class loader or default class loader)
    • Java applications can install user-defined class loaders at run time, which is a custom way to load classes
For example: Downloading a class file from the network, although the Startup class loader is the essential part of the virtual machine implementation, and the user-defined class loader is not, but the user-defined class loader can be written in Java, can be compiled into a class file, can be loaded by the virtual machine, It is also possible to instantiate every class as if it were loaded, and the Java virtual machine monitors the class to see if it is loaded by the class loader or by the user class loader, and when the loaded class references another class, The virtual machine loads the referenced class using the class loader that loads the first class for example: If the virtual machine uses a particular class loader to mount the volcano class, it will use this class loader to load all classes used by the Volcano class. If the same volcano uses a class called lava, say, perhaps a method that calls the lava class, the virtual machine will load lava using the same class loader that loads volcano, so that The lava class, returned by this class loader, establishes a connection to the Volcano class dynamically  java.class file Java.class files make Java more adaptable to the network in terms of platform independence and network mobility. The main task in terms of platform independence is to provide a binary form of service for Java programs that is independent of the underlying host, Java.class files are the main tasks that can be run on any Java Virtual machine hardware platform and operating system binaries on the network mobility: first, the. class file is designed to be compact, helping to deliver quickly on-line, and secondly, because Java programs are dynamically connected and dynamically extensible,. class files can be Download when needed to minimize end-user latency  java the Apijava API is a collection of runtime libraries that provide a set of standard methods for accessing host system resources. When writing Java programs, you can assume that Java APIs are available on any Java virtual machine that can run the program. class file, All loaded class files (including from the application and from Java API) and all loaded dynamic libraries (including local methods) together make up the entire program running on a Java virtual machine. The Java API's class file is inherently closely related to the host platform, and the internal design of the Java API is also related to platform-agnostic, such as: the Java API's user graphical interface library-the AWT (Abstract Windows Toolkit, Abstract window Toolbox) and swing are designed to enable user-designed interfaces to run on all platforms. Because of the considerable differences in the appearance of the user interface on different platforms, it is difficult to create a platform-independent user interface. The AWT Class library architecture does not enforce JThe AVA API makes a schema for the Java program user interface on all platforms. On the contrary, the AWT Class library architecture encourages the adaptation of the underlying platform to the appropriate style. The Swing class library even provides a more flexible way to allow programmers to choose their own style of appearance. And because of the considerable differences between platform and platform font size, buttons, and other user interface controls, both AWT and swing include the layout manager of the run-time anchored form or dialog member, and the layout manager takes a slightly different approach to locating the dialog box control on different platforms. In addition to this, the internal system architecture of the Java API has contributed to the development of Java program Platform independence as a design purpose Java API in the Java security Model: by enforcing Security Manager and access controller established security environment, In this security environment, potentially dangerous code can be run  java programming language Java technology is very suitable for the network, but the Java programming language is quite generic. Using the Java language Program, you can take advantage of many of the following software technologies:
    • Object-oriented
    • multithreading
    • structured error handling
    • garbage collection
    • dynamic connections
    • dynamic extensions
One of the most compelling reasons for using the Java language is that he can improve the efficiency of developers, and its main disadvantage is that it is slower to execute. Java is an object-oriented language. One of the promises of object-oriented technology is to increase the reuse rate of code and improve the efficiency of developers. Unlike C + +, there is no way to access memory directly in Java by using the cast pointer type or by doing pointer operations. When you use objects in Java, you need to strictly obey the type rules. Another way to avoid unintentional destruction of memory is through automatic garbage collection. Like Java and C + +, there is a new operator that allows you to allocate memory for new objects in the heap. However, unlike C + +, Java does not have a delete operator corresponding to new, and C + + programmers often use Delete to clean up objects that are no longer needed in the program, while Java only needs to stop using an object for a period of time. The garbage collector automatically reclaims the memory occupied by this object. The third way that Java protects memory integrity at run time is array bounds checking. Array operations in C + + are actually pointer operations, which can lead to potential memory conflicts. In Java, arrays are well-developed objects, and Java checks array boundaries every time an array is used, and Java never allows array operations to go out of bounds, causing memory conflicts The last example of Java to ensure program robustness is the check of object references, each time it is used, Java will ensure that these references are not null values. In C + +, using a null pointer usually causes the program to crash. In Java, using an empty reference causes an exception to be thrown. The use of the Java language improves productivity, resulting in shorter development cycles and lower development costs. If you take advantage of the potential platform independence of Java programs, the cost of further reducing the cost of the   java architecture and other technologies (such as C + +) may be slower to execute than in,java programs, This is one of the main costs of Java in object-oriented network features. The first Java virtual Machine was born in 1995, it can execute bytecode on an interpreter, this is a relatively simple technology, performance is not high. Soon, its compiler was born. Compared with the interpreter, it greatly improves the performance of Java. With the recent development of virtual machine technology, even though it is not possible to say that the flaws in the speed of Java have completely disappeared, there have been significant improvements. Advanced technologies such as adaptive optimization enable Java programs to run at speeds comparable to locally compiled C programs. One of the difficulties faced by Java developers is that even if a particular Java Virtual machine can provide quite good performance, in general, Developers cannot choose which Java Virtual machine their program will run Java is a very flexible tool that provides many ways to solve potential performance problems, for example: if you need to provide just a single executable file, you can:
    • A virtual machine comes with the program
    • Implement the time-critical part of the program as a local method
    • Compile the entire program into a single executable file, just like C and C + +
The ability to compile Java programs into separate executable programs can improve performance, but this is often at the expense of Java's dynamic scalability, however, when developing not a single application but a distributed system, especially when code and objects need to move between virtual machines, Performance management becomes very difficult although the speed of the program is a worrying thing when using Java, there are many ways to compensate for this. By using a variety of techniques for developing, publishing, and executing Java programs, most of the time, you can achieve the satisfaction of the end user, as long as you can successfully solve the speed problem, you can use the Java language and realize its benefits-to improve the efficiency of developers, for the end user to enhance the robustness of the program. Difficulty two: The defect garbage collector on memory management and thread scheduling can make many programs more robust, which is also a valuable security measure in the network. But the garbage collector also adds some uncertainty to the performance of the program, and you can't confirm what the garbage collector started collecting garbage, can't confirm whether the garbage collector started collecting garbage, and can't confirm how long the garbage collection will last. Difficulty three: To achieve platform independence, there is a minimum common denominator problem this is the inherent difficulty in any API that attempts to provide cross-platform functionality, and the least common denominator problem not only afflicts the designers of platform-agnostic APIs, And it also affects the developer of the program that uses this API. Four: When the Java.class file is tied to the Java programming language and the Java Natural Dynamic Connection feature, there is a price to pay because the Java program is polymorphic, and the reference from one class to another is symbolized. The Java.class file contains not only symbolic references to other class fields and member methods, but also symbolic references to his own fields and member methods. It is fairly easy to decompile the Java.class file into a Java source file, but it is quite difficult to reverse-compile the statically connected binary executable, not just because the symbolic information (the original class, field, method, and local variable name) is missing, but also because the static connection library is usually highly optimized. The more optimized the static connection binary file, the smaller the initial source code will be. Conclusion Java can greatly improve the programmer's efficiency, enhance the program ear robustness, compared with the old program design techniques (such as C and C + +), with the performance of the past, Provides a tool for emerging network-centric computing

Introduction to Java Architecture

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.