Márcio Paiva
Márcio Paiva

Reputation: 1003

What is the purpose of Java JDK to Eclipse?

I've just installed Eclipse, after i installed the java JDK. The Getting Started guide (in Eclipse) says i should reference my JDK installation in Window>Preferences>Java>Installed JREs, but that a JRE would also work.

Select the Java > Installed JREs preference page to display the installed Java Runtime Environments. Confirm that a JRE has been detected. By default, the JRE used to run the workbench will be used to build and run Java programs. It should appear with a checkmark in the list of installed JREs. We recommend that you use a Java SDK instead of a JRE. An SDK is designed for development and contains the source code for the Java library, easing debugging.

There was already a JRE set up there (not a JDK), so i did nothing and tried to compile a Hello World (just to see what would happen). To my surprise, it compiled!

I searched a little bit and it looks like this works because Eclipse has a built-in Java Compiler. I tried debugging using the same eclipse set up, and it was also successful.

So, what is the difference between setting a JDK and JRE there? Why is it important to download the JDK, since in my default configuration Eclipse doesn't seem to use it?

Upvotes: 5

Views: 4072

Answers (4)

Miljen Mikic
Miljen Mikic

Reputation: 15241

JDK is equipped with different helpful tools, as DotMasta mentioned. Eclipse's "version" of JDK is called JDT. Apart from range of shipped tools, there are also differences between javac and Eclipse built-in compiler ecj, so check here to see the comparison. One of the most important differences is that javac is strict, i.e. with ecj you can create a class file even in case of errors in code, which is perfectly suitable for testing phase, but not for launch :)

Upvotes: 1

Doszi89
Doszi89

Reputation: 357

JDK contains software development tools which are used to compile and run the Java program.

  • Plenty of classes and methods in standard jdk library
  • Javac java compiler

Diffrences and why you will need this?

JDK includes the JVM, standard class libraries, and several other tools that a developer needs in order to create a Java program. JRE includes the JVM, as the JRE provides some standard libraries and the JVM which can be used to execute a Java program.

You can even look there: http://en.wikipedia.org/wiki/Java_Development_Kit

Upvotes: 0

DotMasta
DotMasta

Reputation: 186

There are a number of tools that come with the JDK that don't come with the JRE - JConsole (http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html) springs to mind. This for example can help you understand & monitor the memory usage of your application and so on. Either way if you head into unfamiliar territory, I highly recommend you follow the Eclipse suggestion and use the JDK!

Upvotes: 2

Francis Upton IV
Francis Upton IV

Reputation: 19443

Probably the main difference is you get the source to all of the Java runtime libraries (with the JDK) which can be a big help. I always use the JDKs for that reason.

Also if you are debugging, this will allow you to meaningfully step into Java runtime libraries.

Upvotes: 5

Related Questions