Home > database >  Nothing happens when I run javac on command prompt
Nothing happens when I run javac on command prompt

Time:10-06

On Command Prompt I see the following

C:\Users\lek-h\Downloads\OOP>javac Example.java

C:\Users\lek-h\Downloads\OOP>

(i.e., no response from Command Prompt)

Java file

Under the following C:\Users\lek-h\Downloads\OOP\Example.java I have

class Example {
    // A Java program begins with a call to main().
    public static void main(String args[]) {
        System.out.println("Java drives the Web.");
    }
}

I have jdk 17 installed and set as path in system.

Under my system variables, I have System variable JAVA_HOME with value C:\Program Files\Java\jdk-17 System variable JAVA_PATH with value C:\Program Files\Java\jdk-17

Under user variables I have Variable Path with one value being %JAVA_HOME%\bin

CodePudding user response:

You need to run two commands for the java file compilation.

  1. javac <filename.java>
  2. java

Run these commands on your command prompt:-

1) javac Example.java
2) java Example

Run these commands and check the output.

CodePudding user response:

You can directly run the program using the java command.

java Example.java
  •  Tags:  
  • java
  • Related