If we have a standalone regular JRE then we can always run java programs but we cant create java programs. I know that when you install JDK, the JRE is included. But just to understand this clearly, is the converse also true internally. If I have a java program, and I just need to make a .class file out of it, then does JRE have any role to play in it; is any component of JRE involved in the compilation process e.g. "import <>.<>.*" statements etc.?
-
Most Java tools, including the compiler, are written in Java, so I would say yes. But the question is rather moot anyway: I've never seen any developer compile code and not running it to test it. – JB Nizet Apr 02 '16 at 20:32
-
Tx JB for being that quick..I understand its moot, but like I said i wanted to theoretically understand, is any component of JRE involved internally – Sheel Pancholi Apr 02 '16 at 20:34
-
Your Java code will inevitably use classes from the standard library (SE). And these classes are in the JRE. Therefore, for your code to be compiled, as in even resolving the implicit imports (java.lang.*), the JRE is needed. That said, it's unless a super-custom compiler is in use. – ernest_k Apr 02 '16 at 20:35
-
1@JBNizet sadly, where I am working now (a very large and very profitable company), there are many Java devs who don't test their code :( They just commit code and wait for the QA team to verify it. And that's only the tip of the ice berg... – Bohemian Apr 02 '16 at 20:52
-
@Bohemian you mean, not even with manual tests, like "I'll run the app and see how it goes"? Man I pity you :( – JB Nizet Apr 02 '16 at 20:54
-
1@jbnizet not even manual testing. It's so sad. I have tried the change the culture, but no one cares. So I work in my own repo on my own project, because no one else there understands anything learned in the last 30 years about software dev. It's like I've stepped into a time warp and gone back to the dark ages of the 1980's (but even then, there was *some* testing - even if for curiosity's sake) – Bohemian Apr 02 '16 at 20:57
-
@Bohemian I couldn't resist to go see your linkedin profile to discover what this great company is. Australia is hopefully too far away from where I live, and I should never have to work for them :-). I've been in that situation once (it was actually worse, I think: I was reprimanded because I dared creating a package and should have put everything in the package I was assigned to). I ran away ASAP. – JB Nizet Apr 02 '16 at 21:01
-
2@JBNizet Here's another gem: An adjacent team (that my area must transact with) had poor uptime of their dev server, so we put in monitoring by hitting their 20 endpoints every 15 minutes. The manager over there came running over angrily asking why we were "performance testing" their dev system as it was causing it to crash. Not joking. Regarding your "package" story, I once did some consulting work for a (profitable, large) company whose production Java project had everything (including resources, test code, everything) in the root folder (no directories whatsoever). – Bohemian Apr 02 '16 at 21:09
2 Answers
The JRE (Java Runtime Environment) consistent of many components, the three most important being:
- JVM (Java Virtual Machine)
- Java Runtime Library
java.exe
(Windows1 executable using above components to run custom Java code)
The JDK (Java Development Kit) consistent of many components, the three most important being:
- JRE (see above)
- Java Compiler
javac.exe
(Windows1 executable for running the compiler)
So, on the to main question:
Is JRE needed to compile a Java program?
Well, no. You just need two things to compile a Java program:
- Java Compiler
- Java Runtime Library
If the compiler itself is not written in Java, then you don't need the JDK or the JRE.
However, most Java compilers are actually written in Java, so they also need a JVM, and if you need both the JVM and the Runtime Library, the best way to get those is to get the JRE, though any JVM will do.
So, do you need the JDK? No. You just need a JRE and a compiler, and there are many good compilers out there, e.g. the Eclipse compiler, which is what Tomcat uses so it doesn't require a full JDK.
1) For non-Windows, a similar java
executable, of course.

- 154,647
- 11
- 152
- 247
When you need to compile, you just need the JDK but when you run the program, it requires the JRE. If the program needs to compile at run time, then it needs both. If you are just compiling a program, then all you need is JDK however if your compiler is made from java, then you need the JRE. This post could help Are both the JRE and the JDK required to run a JAR file?.
-
Tx Yetoo.. the reason why i asked this is because of the way the import statement works during the compile time. If i have an import statement: import java.util (or java.math); I would expect the compilation to go through smoothly as the classloader works only when you run the program. – Sheel Pancholi Apr 02 '16 at 20:47