Avatar ·

What is the difference between JDK and JRE in Java? Explain for a beginner

Hello everyone! I just started learning Java and got confused with the terms. When I was downloading the development environment, I saw that you can download JDK or JRE. I thought they were the same thing, but then I noticed that JDK has the javac compiler, while JRE does not. I wrote a simple "Hello, World!" program: ```java public class Hello { public static void main(String[] args) { System.out.println("Hello, World!"); } } ``` When I tried to compile it using the command `javac Hello.java`, I got an error "javac is not recognized as an internal or external command". It turned out that I only had JRE installed. I had to install JDK. Now I have two questions: 1. Why is JRE needed at all if you can't compile code without JDK? 2. Why can't they be combined into one package?