views:

828

answers:

7

To tell the truth, I am quite confused on all these terms (JDK/JRE/Java SDK). I am not sure what each one does.

When I first started doing simple java examples in eclipse, I am pretty sure I only had the JRE, which I believed was the default java installer regular users use to be able to run java programs/applets on their system.

However, now in class we are using Google Appengine, and this requires the JDK which I am guessing is the same as Java SDK. After wasting some time finding out that installing the JDK meant I also had to add java/bin to the environment variables to get javac -version to work in the command prompt I find that only the JDK has javac...

How were my early java programs working without having installed the JDK and therefore not having javac? And really the main question... What is the difference between the JRE and JDK, and when do you use each one?

Thank you :)

+11  A: 

JRE = Java Runtime Environment - what you need to run programs/software that require Java or use libraries written in Java. For example, OpenOffice requires the Java Runtime Environment

JDK/Java SDK = Java Development Kit/Java Software Development Kit - what you need to write programs that require Java or use libraries written in Java. For example, if you were to write your own word-processing tool in Java.

java comes with the JRE because it launches the VM (virtual machine). It can take in class files which are files that have been compiled using the JDK.

The JDK comes with javac because that's what you need to compile your .java files into .class files that can then run on the JRE.

Vivin Paliath
You sure that the JRE comes with javac?
mlaverd
Haha, that was me typing through my android phone. I'll fix the typo!
Vivin Paliath
I wish I could vote 2 answers as the best answers. Between you and Chris you guys explained it perfectly for me. Thanks!
Javed Ahamed
+7  A: 

Eclipse has its own built-in compiler (called ecj), which is probably the reason you could get away with not having the JDK installed to use it. It does not use javac.

Google App Engine uses the javac that comes with the JDK.

Chris Jester-Young
A: 

There's no way you used the JRE to compile Java programs. javac, the Java compiler, only comes with the JDK.

  • You may write Java programs with whatever text editor, you don't need anything special to do this.
  • You need the JRE to run Java programs. The JRE includes the Java Virtual Machine, needed to run already compiled Java programs.
  • You need the JDK to compile Java programs. So if you are a Java developer, you may want to only install the JDK since it comes with the tools needed to compile, in addition to the Java Virtual Machine.
Cesar
Actually, that's correct, as long as you don't take eclipse into account. But this the original question mentioned eclipse, it's wrong. See Chris Jester-Young's answer. (Though I have to admit that I worked several years with eclipse without realizing that it doesn't use javac)
Brian Schimmel
I wasn't aware of that either.
Cesar
+2  A: 

What is the difference between the JRE and JDK and when do you use each one?

JRE: Java Runtime Environment. It is used to run Java programs only. As Chris Jester -Young mentioned, Eclipse had a built in compiler. That's why you just needed JRE ( to run eclipse )

If you ship a Java program, the only thing the client need to have is this runtime environment

JDK: Java Develpment Kit, this also includes a JRE inside, but additionally have other tools for program development such as the java compiler javac among many others.

If you want to create java program you should use this.

OscarRyz
A: 

'Sometimes you can develop with jre'

No. Never.

You develop with the Java Development Kit. You run with the Java Runtime Environment or Engine or whatever it's called.

EJP
A: 

'Sometimes you can develop with jre'

No. Never.

Are you sure there aren't support for this in tools.jar? Like others have pointed out, Eclipse works without jdk, and so does some webcontainers that need to produce bytecode from jsp's. I think these programs just contains logic for utilizing parsing and compilation code in tools.jar, and that they do not actually implement full java compilers themselves.

deleted
I'm 100% sure there *is* support for this in tools.jar, but as tools.jar isn't part of the JRE the question is pointless and irrelevant. Eclipse comes with its own JDK, and the webcontainers ditto, or else they require a JDK installed.
EJP
A: 

When You make jar file,then add rt.jar(which is present in jdk>jre>rt).It jre to any System.

Sharad Sinha