Step 2: Compiling the Java Program
Open Command Prompt (CMD) in the Folder
Command Prompt (CMD) is a tool that helps us tell the computer what to do.
Instead of typing cd <path>
, you can open CMD directly inside the folder by following these steps:
- Open your FirstProgram folder.
- Click on the address bar at the top (where you see the folder’s path).
- Type cmd and press Enter.
- A black window (CMD) will open.
Compile the Java Program
Java programs cannot run directly. First, we need to convert the code into a language the computer understands (this process is called compiling).
- In CMD, type:
javac MyFirstProgram.java
2. Press Enter.
- If there are mistakes in your code, CMD will show errors. You must fix them and compile again.
- If there are no mistakes, CMD will not show anything, and a new file named MyFirstProgram.class will be created in the folder.
What is the correct command to compile the Java program MyFirstProgram.java
in Command Prompt (CMD)?
class MyFirstProgram {
public static void main(String args[]) {
System.out.println("Hello, Java!");
}
}