Java Notes
Install a JDK to write and run Java programs. The JDK compiles your code, and the JVM is the part that runs the compiled program.
To start Java, install the JDK. Think of it as the complete Java package for a learner or developer. It lets you write a program, turn it into a runnable form, and run it.
The JVM is the runner inside Java. After your program is compiled, the JVM reads it and runs it on your computer. JRE is an older term that you may see in tutorials; it means the part of Java needed to run programs.
One program, three names
Suppose you write a file named Hello.java.
- You use the JDK command
javacto check and compile the file. - Java creates
Hello.class, the compiled version of your program. - You use the JDK command
javato start it. - The JVM reads
Hello.classand runs themainmethod.
So the short answer is: JDK helps you make a Java program; JVM runs the finished program.
See the relationship
| Name | Simple meaning | What you do with it |
|---|---|---|
| JDK | Complete Java kit for developers | Install it to write, compile, and run code. |
| JVM | Java program runner | It runs the compiled .class file. |
| JRE | Java runtime environment | Older name for the JVM plus Java's built-in libraries. |
| Java libraries | Ready-made Java code | Your program uses classes such as String and System. |
You do not need separate JDK and JRE downloads for this course. Install one supported JDK; it contains the compiler, the runner, and the libraries.
Check whether Java is installed
Before writing a Java file on your computer, check whether Java is already available.
On Windows, press the Windows key, type Command Prompt or PowerShell, and open it. A terminal is simply a window where you type a command and the computer shows a result. You do not need to open your project folder for this check.
First type the command below, then press Enter. Type the second command on the next line and press Enter again.
What result should you see?
If Java is set up correctly, each command prints version information. The exact number can differ, for example java 21 or javac 21. The important point is that both commands show a version.
java --versionchecks whether your computer can run Java programs.javac --versionchecks whether your computer can compile the Java code you write.
For this course, both commands are needed. A program may run with only java, but you cannot turn your own .java file into a runnable program without javac.
If a command does not work
If the terminal says something like java is not recognized or javac is not recognized, Java is not installed correctly or Windows cannot find it yet.
- Install a JDK, not only a JRE.
- Close the terminal and open a new one after installation.
- Run the same two commands again.
If java --version works but javac --version does not, a JDK compiler is missing from the PATH. Reinstalling a JDK and choosing the option to add Java to PATH normally fixes this. Do not worry about PATH details yet; first confirm whether both commands work.
Your first compile-and-run cycle
Create a file named VersionCheck.java, paste this code, and run it in the live editor first. When you use a terminal later, save the same code in a file with exactly the same name as the public class.
Try it in WoHoCode
Edit the program, then run it here.
Run this example to see its output.
In a terminal, move to the folder where VersionCheck.java was saved and run:
javac VersionCheck.java— Java checks your code and createsVersionCheck.class.java VersionCheck— Java starts the JVM, which runs the class.
Notice the difference: the first command uses the file name including .java. The second command uses only the class name, without .java or .class.
What the JVM does while your program runs
You do not need to memorise its internal parts yet. In simple terms, the JVM:
- finds the compiled program;
- checks that the program is safe enough to run;
- gives your program memory for variables and objects;
- runs the statements inside
main; - clears unused memory when it is no longer needed.
This is why the same compiled Java program can run on Windows, Linux, or macOS when each system has a compatible JVM.
Fix common setup messages
| What you see | What it means | First thing to do |
|---|---|---|
javac is not recognized | Windows cannot find the Java compiler. | Install a JDK, then add its bin folder to PATH. |
Could not find or load main class | Java cannot find the compiled class. | Open the terminal in the folder containing the .class file and check the class name. |
class VersionCheck is public... | File name and public class name do not match. | Save the code as VersionCheck.java. |
Different java and javac versions | Your runner and compiler come from different installs. | Check both version commands and use the intended JDK. |
Remember this
- Install the JDK when you want to learn or develop Java.
javacconverts.javasource code into.classcompiled code.javastarts the JVM, which runs the compiled class.- JRE is a runtime term you may see in old tutorials; a modern JDK already gives you what you need.
Continue the lesson path