1.2-java Tour: Write once, run anywhere

Source: Internet
Author: User

Features and benefits of Java

• Simplicity: The pure version of C + + syntax. There are no header files, pointer operations, structs, unions, operator overloads, virtual base classes, and so on. Because the grammar is based on C, it is completely effortless to learn.

· Object-oriented: Object-oriented is a programming technique that focuses on the interface between data (that is, objects) and objects.

· Portability: This is an important advantage of Java. Java code or bytecode, binary code can be ported across platforms, without the need for a specific operating system and hardware environment.


Java itself is network-oriented, only in the network environment in order to show his advantage,

For example: Now I have a network environment, to let my notebook and mobile phone interaction, the notebook environment is Windows issued a mobile phone timing recording Java code, the phone only a simple Linux kernel operating system, still can execute this code perfectly.

· "Write once, run anywhere": "Write once, run anywhere"Java is designed with a focus on porting and cross-platform.

For example: The int of Java is always 32 bits. Unlike C + +, which may be 16, 32, may be based on compiler vendor-specified changes. In this case, the transplant of the program will be very troublesome.

• High performance:JIT (JUST in time) instant compilation. Compile some "hot" bytecode into the cost of the machine code and cache the results and recall them when needed.


In this way, the execution efficiency of Java programs is greatly improved, and some code even receives the efficiency of C + +. As the technology grows, it may one day surpass the efficiency of compiling code.

• Distributed:Java is designed for the distributed environment of the Internet because he is able to handle the TCP/IP protocol.


In fact, accessing a network resource through a URL is as simple as accessing a local file. Java also supports remote method calls (Rmi,remote methods invocation) to enable programs to invoke methods over the network.

• Dynamic: It is the reflection mechanism that adds some code to the running program when needed. Dynamic is a very important feature when you need to add some code to a running program.


The dynamic nature of Java is an extension of its object-oriented design approach. It allows the program to dynamically load the classes needed to run the process, which is not possible with the C + + language for object-oriented programming.

· Multithreading: multi-threaded use can lead to better interactive response and real-time behavior. The simplicity of multithreading is one of the main reasons why Java has become a mainstream server-side development language.

• Security:Java is suitable for network/distributed environments, in order to achieve this goal, put a lot of effort in security, so that Java can build anti-virus, anti-tamper system.

• Robustness: Java is a robust language that absorbs the advantages of the C + + language, but removes the parts that affect the robustness of the program (such as pointers, memory applications and releases, etc.).


Java programs cannot cause a computer crash. The Java system carefully detects every access to memory, confirms that it is legitimate, and does not cause any problems.


However, even Java programs may have errors. If something unexpected happens, the program does not crash, but discards the exception. Through the exception handling mechanism, the program will find such exceptions and deal with them.

Running mechanisms for Java applications

High-level programming language types for computers: compiled, interpreted

The Java language is a combination of two types;

Use the editor to write Java source program source file name: main class name. Java

compile the source program into bytecode using the compiler (JAVAC) bytecode file name: source file name. class

Use the virtual machine (interpreter, Java) to interpret the execution:

Operating Procedures: loading, code validation, interpreting

JVM (JAVA VIRTUAL machine)

A JVM is a specification that can be implemented using software or hardware, a virtual computer that executes bytecodes bytecode. He also defines the instruction set, register set, structure stack, garbage collection heap, memory area.

The JVM is responsible for running the Java bytecode interpretation and running the side interpretation, so that the speed will be affected.

Java provides another way to explain how to run the JIT (just in time), can be explained at once , and then run the machine code on a particular platform, the advanced JIT can only analyze hotspot code, and the code to the local machine code, and the results are cached. The next time it is called directly from memory, this greatly improves the efficiency of executing Java code.

This enables cross-platform, portable functionality.

A JVM is a computer that is emulated by software or hardware on a single computer; it resembles a small, efficient CPU.

The Byte-code code is a platform-independent machine instruction for a virtual machine.

The Java byte code runs in two ways:

Way Interpreter (explanation)

Just-in-time (Instant Compilation): There is a code generator that converts the byte code into the machine code of the machine, which can then be executed at a higher speed.

Different operating systems have different virtual machines.
The Java virtual machine mechanism masks the difference between the underlying operating platform, enabling "one-time compilation, running Anywhere".

Java Runtime Environment JRE (Java Runtime Environment)

Java Runtime Environment (JRE)

Contains: Java virtual machines, library functions, required files for running Java applications and applets

Java 2 SDK (development Kit)

includes: a superset of the JRE, containing files for program development such as compilers and debuggers

Three key features of the Java Runtime Environment:

Loading code: Completed by class loader;

Checksum code: completed by bytecode verifier;

Execution code: completed by runtime interpreter.

JDK and JRE:

The SDK, or JDK, is a superset of the JRE, with the addition of a compiler and other development tools based on the JRE.


The JRE is the Java Runtime environment, including the JVM and some other Java core APIs, and any computer that has a JRE installed can run Java programs.

Summarize:

If you just want to run a Java program, you need the JRE. The JRE is usually very small and contains the JVM.

If you are developing a Java program, you will need to install the JDK.




This article is from the "12931675" blog, please be sure to keep this source http://12941675.blog.51cto.com/12931675/1928592

1.2-java Tour: Write once, run anywhere

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.