To run Java code, you need the JDK (Java Development Kit). The JDK includes the compiler (javac), runtime tools, and libraries. If you're a beginner and don't want to deal with setup, you can get started with an online compiler like Replit or OnlineGDB. But once you're ready to build real projects, it's much more convenient to have the JDK and an IDE installed on your local machine.
Local setup flow
1. Install the JDK.
2. Check that it installed correctly in your terminal/CMD with java -version.
3. Use an IDE such as IntelliJ IDEA, Eclipse, or VS Code.
4. Create a .java file and compile/run it.
// Save this file as HelloWorld.java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Compiled and running from terminal!");
}
}
// Terminal commands:
// javac HelloWorld.java
// java HelloWorldjavac HelloWorld.java compiles your Java source code into bytecode. Once it compiles successfully, you'll get a HelloWorld.class file. java HelloWorld then runs that compiled class on the JVM.
Compiled and running from terminal!Real-world use
A local setup becomes essential once you're working on real projects where you need to manage libraries, build tools, files, and folders yourself.