-2

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.

9
  • 3
    That question has an easy and simple answer: javac compiles your program, but does not strat/execute it. Look in the directory if threre is a new file MyFirstprogram.*class*. Commented Jan 5, 2024 at 19:54
  • 1
    Just to remove all doubt, and echoing other comments, your command line should be C:\Users\username\Documents\test>java MyFirstProgram Commented Jan 5, 2024 at 19:59
  • @g00se iff the call has not been changed for java version "21. ...". They do lot of changes now, but little improvement (if you ask my opinion). Commented Jan 5, 2024 at 20:02
  • It hasn't afaik. It would be very alarming if javac now runs stuff too Commented Jan 5, 2024 at 20:06
  • @g00se I had some issues with java -cp etc.. Doesn't work like I remember it to do, took about an hour of internet research and try&error. Worse are all those improvements on the syntax. Lamda's screwed up eclipse (and I can't deny the feeling this was on purpose.) Commented Jan 5, 2024 at 20:13

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

1 Comment

Executed "java MyFirstProgram.java" and it worked. Thank you for all your support.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.