What happens to “System.out.println()” in executable jar?

后端 未结 3 1072
刺人心
刺人心 2020-12-11 15:17

Suppose I\'ve created an executable jar from a code where I have used

System.out.println()

When we run the executable jar, th

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-11 16:11

    I you open it from the console (java -jar YourJar.jar) the text gets printed in your console window.

    If you open it in the explorer (or similar), you won't see the text

    To clarify your second Edit: The bytecode is not omitted, because the compiler cannot know in what context the jar will be executed. The jar can always be called from console, in that case the println has to stay there.

    In fact, many jar Files would be completely useless otherwise. There are plenty of Java programs that interact with the user by console in- and output. It is not neccessary for a java-Program to have a GUI (or to run completely in the background).

提交回复
热议问题