Java-based cross-platform performance. Differences between JDK and JRE

Source: Internet
Author: User

 

I have been working on report development (outsourcing project of the insurance system). The main content is data processing. As for Java, I have forgotten about it. what did you say about the previous job? It's not good or not, but I lost my interest in the job. I hope I can go back to Java Development. I hope I can find my previous daily active learning experience, and I will not talk nonsense about myself here. I will start to review today and work hard to become a dark horse. next we will start to review the basics of Java:

Java features: one compilation and running everywhere

Java cross-platform:

Because the compiled code of a Java program is not a code that can be directly run by the hardware system, it is an "intermediate code"-bytecode. Different Java virtual machines (JVM) are installed on different hardware platforms. The JVM then translates bytecode into codes that can be executed on the corresponding hardware platform. Therefore, Java programmers do not need to consider what the hardware platform is. Therefore, Java can be used across platforms.
Because it has a Virtual Machine (JVM), Java programs are not directly run on a computer, but on virtual machines. Each system platform has its own Virtual Machine (JVM ), therefore, Java can be used across platforms.
Java code runs on a Java VM (JVM) instead of a CPU.
Java first compiles the Java file into a binary byte code class file, and the JVM will explain and execute the class file.
Because Java runs on the JVM, its code can run on the JVM of different platforms without modification (unix jvm is used in UNIX, linux JVM on Linux and Windows JVM on Windows)
If you use Windows to transplant to Unix, you only need to compile the Java file on the Unix JVM into a class file, and then run it with JVM.
Java Virtual Machine (JVM)
The reason why Java can be cross-platform is that Java virtual machines can be cross-platform.

Differences between JDK and JRE:

JDK is the Java Development Kit. In short, JDK is an SDK for developers. It provides the Java development environment and runtime environment. The SDK is a software development kit. It generally refers to a software development kit, which can include function libraries and compiled programs.

JRE is the Java runtime enviroment, which refers to the Java Runtime Environment and is intended for Java program users rather than developers.

If JDK is installed, there will be two sets of JRE on your computer, one in the \ JRE and the other in the c: \ Program Files \ Java \ jre1.5.0 _ 15 directory, this later set is less server-side Java virtual machine than the previous one, but simply copy the previous server-side Java virtual machine. When installing JDK, you can choose whether to install the JRE in the c: \ Program Files \ Java directory. If you only install JRE instead of JDK, only a unique set of JRE will be installed in the c: \ Program Files \ Java directory.

The status of JRE is just like that of a PC. The Win32 application we write requires the operating system to help us run it. Similarly, the Java program we write must also run JRE. So after installing JDK, if two sets of JRE are installed in two different locations on the hard disk, you can imagine that your computer has two virtual Java PCs, all have the function of running Java programs. So we can say that if your computer has installed JRE, you can run the Java application correctly.

1. Why does Sun need JDK to install two identical JRE?

This is because JDK has a lot of Java-compiled development tools (such as javac.exe‑jar.exe), and they are all placed in \ Lib \ tools. jar. As shown in the following example, change tools.jarto tools1.jarand run javac.exe. the following result is displayed: exception in thread "Main" Java. lang. noclassdeffounderror: COM/Sun/tools/javac/Main. You can input javac.exe and Java-CP c: \ JDK \ Lib \ tools. jar
Com. Sun. Tools. javac. Main is the same and will get the same result. From this we can prove that javac.exe is just a wrapper, and the purpose is to prevent developers from entering too long fingers. In addition, we can find that the programs in the \ lib directory are very small, not greater than 2 9 K. Here we can draw a conclusion. That is, JDK tools are almost written in Java, so they are also Java applications. Therefore, to use the tools attached to JDK to develop Java programs, you must also attach a set of JRE, therefore, the JRE located in the c: \ Program Files \ Java directory is used to run general Java programs.

2. If two or more JRE are installed on a computer, who will decide?

This major task falls on java.exe. The job of java.exe is to find the appropriate JRE to run the Java program. Java.exe searches for jre in the following order: whether JRE is in its own directory; whether JRE is in its parent directory; and query the registry: [HKEY_LOCAL_MACHINE \ SOFTWARE \ javasoft \ Java Runtime Environment] The running result of java.exe has a great relationship with which JRE is executed on your computer.

 

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.