javacmdprintingjavacprintln

Java println string not showing up in CMD


I am trying to execute the simple java application in CMD using javac but the outputs of System.out.println is not coming out. Let me show you my code in my MyFirstProgram java file.

public class MyFirstProgram {
   public static void main(String[] args){
      int number =10;
      System.out.println(number);
      System.out.println("Hello, World!");
      System.out.println("Strange");
   }
}

Also showing you the results when I executed javac in CMD. I tried not only string but also integer variable in println but still doesn't show up anything. However, if the compile error log comes up when there is a source logic error so I don't think it's an source issue.

[ CMD Result ]

C:\Users\username\Documents\test>javac MyFirstProgram.java

{blank}

Let me share you my java jdk version for reference. I believe there is an issue in the jdk version or maybe my PC settings. Can anyone help me out on this issue? Thanks in advance.

C:\Users\username\Documents\test>java -version
java version "21.0.1" 2023-10-17 LTS
Java(TM) SE Runtime Environment (build 21.0.1+12-LTS-29)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.1+12-LTS-29, mixed mode, sharing)

Thank you.


Solution

  • javac is used to compile the java file not executing it if you looked at same folder you will find your compiled java file

    you can run it using java command and see output