Java Development Workflow – Write, Compile & Run Your First Program
Before diving deep into Core Java concepts, it’s essential to understand the Java workflow — how a Java program is written, compiled, and executed.
This guide walks you through each step using simple examples and command-line instructions.
Step 1: Write Your First Java Program
Create a Java file with the .java extension. The file name should match the class name.
Example: HelloWorld.java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}
Explanation:
| Part | Description |
|---|---|
public class HelloWorld | Declares a class named HelloWorld |
public static void main(String[] args) | Entry point of the program |
System.out.println("Hello, Java!"); | Prints text to the console |
Every Java program must have a main method to run.
Step 2: Compile Your Program
Compile your source code (.java) into bytecode (.class) using the Java compiler:
Command Line:
javac HelloWorld.java
- On success, this generates
HelloWorld.class. - If there are syntax errors, the compiler will display them with line numbers.
IDE (Eclipse / IntelliJ):
- Click Run or Build; the IDE compiles your program automatically.
Step 3: Run Your Program
Execute the compiled bytecode using the JVM:
Command Line:
java HelloWorld
Output:
Hello, Java!
IDE:
- Eclipse: Right-click → Run As → Java Application
- IntelliJ: Click the green Run button
The JVM reads the bytecode and converts it into machine code for your system.
Step 4: Debug and Iterate
Java development is iterative:
Write → Compile → Run → Fix Errors → Re-runCommon Issues & Fixes:
| Issue | Fix |
|---|---|
| Syntax Errors | Check semicolons, brackets, and case sensitivity |
| Class Name Mismatch | File name must match the public class name |
| PATH/JDK Not Set | Add JDK bin folder to your system PATH |
| Cannot Find Symbol | Verify variable/method names |
Optional: Using Build Tools for Larger Projects
For advanced workflows or bigger projects, you can use Maven or Gradle to:
- Automate compilation and execution
- Manage dependencies
- Simplify project structure
Workflow Visualization
1️⃣ Write Java Source Code (.java)
↓
2️⃣ Compile (javac) → Bytecode (.class)
↓
3️⃣ Run (java) → JVM executes bytecode
↓
4️⃣ Output & Debug → Improve Code
Concepts Learned
- Java source code →
.javafile - Compilation → converts source code → bytecode (
.class) - Execution → JVM converts bytecode → machine code
- Main method → program entry point
- Iterative development → write → compile → run → debug
Summary Table
| Step | Action |
|---|---|
| Write Code | Create .java file with main class |
| Compile | Use javac to generate .class bytecode |
| Run | Execute with java command via JVM |
| Debug | Fix errors and iterate |
| Optional | Use Maven/Gradle for larger projects |
