What is the difference between JDK and JRE?

What is the difference between JDK and JRE?
What are their roles and when should I use one or the other?


JRE : Java Runtime Environment. It is basically the Java Virtual Machine where your Java programs run on. It also includes browser plugins for Applet execution.

JDK : It's the full featured Software Development Kit for Java, including JRE , and the compilers and tools (like JavaDoc, and Java Debugger) to create and compile programs.

Usually, when you only care about running Java programs on your browser or computer you will only install JRE . It's all you need. On the other hand, if you are planning to do some Java programming, you will also need JDK .

Sometimes, even though you are not planning to do any Java Development on a computer, you still need the JDK installed. For example, if you are deploying a WebApp with JSP , you are technically just running Java Programs inside the application server. Why would you need JDK then? Because application server will convert JSP into Servlets and use JDK to compile the servlets. I am sure there might be more examples.


Pablo is very right. This is just additional information:

"The JRE " is, as the name implies, an environment. It's basically a bunch of directories with Java-related files, to wit:

  • /bin with executable programs like java and (for Windows) javaw , which are essentially the program that is the Java virtual machine;
  • /lib with a large number of supporting files: Some jar s, configuration files, property files, fonts, sounds, icons... all the "trimmings" of Java. Most important are rt.jar and a possibly a few of its siblings, which contain the "java API," ie the Java library code.
  • Somewhere, possibly squirreled away by the installer to some directory specified by the operating system, are some .DLL s (for Windows) or .so 's (Unix/Linux) with supporting, often system-specific native binary code.
  • The JDK is also a set of directories. It looks a lot like the JRE but it contains a directory (called JRE ) with a complete JRE, and it has a number of development tools, most importantly the Java compiler javac in its bin directory.


    在这里输入图像描述

    JDK is a superset of JRE, and contains everything that is in JRE, plus tools such as the compilers and debuggers necessary for developing applets and applications. JRE provides the libraries, the Java Virtual Machine (JVM), and other components to run applets and applications written in the Java programming language.

    链接地址: http://www.djcxy.com/p/12548.html

    上一篇: 如何清除或清空StringBuilder?

    下一篇: JDK和JRE有什么区别?