1.2. Create your First Java Program

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:

  1. Open your FirstProgram folder.
  2. Click on the address bar at the top (where you see the folder’s path).
  3. Type cmd and press Enter.
  4. A black window (CMD) will open.

Java programs cannot run directly. First, we need to convert the code into a language the computer understands (this process is called compiling).

  1. 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!");
    }
}

Pages: 1 2 3