Tuesday, 31 December 2024

JDK v/s JRE

 

📌 To summarize:

PurposeYou NeedTools Included
Just run Java codeJREJVM, Libraries
Write + run codeJDKJRE + Compiler + Tools


✅ 1. Can you run Java code with only JRE?

Yes, if you already have compiled .class or .jar files.

📦 Example:
If someone gives you Hello.class or Hello.jar, and you have JRE, you can run it like this:

bash
java Hello # runs Hello.class java -jar Hello.jar # runs Hello.jar

JRE includes java (to run programs)

JRE does NOT include javac, which is used to compile .java files


❌ 2. Can you compile Java code or create JAR files with only JRE?

No, because JRE does not have the compiler or packaging tools.

You cannot do:

bash
javac Hello.java # ❌ Not available in JRE jar cf Hello.jar *.class # ❌ Not available in JRE

Those tools come only with JDK.


📦 Summary

ActionJRE ✅ / ❌JDK ✅ / ❌
Run .class file (java)
Run .jar file
Compile .java file
Create .jar file

🔧 What You Need:

Use CaseYou Need
Just run an existing .jar or .class app✅ JRE is enough
Write Java code, compile, and package as JAR✅ JDK is required

✅ Conclusion:

🔹 You need JDK if you're developing Java apps
🔹 You only need JRE if you're just running precompiled Java apps (like Minecraft, Jenkins, etc.)


No comments:

Post a Comment