• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using Command Prompt In relation to Java  RSS feed

 
Mohamed Said
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys i just have a Question in relation to java, What Output do you expect when you use command prompt to compile java programs? Like HelloWorld.java when compiling  are you expecting "Hello World" on the cmd sscreenshot
 
Liutauras Vilda
Sheriff
Posts: 4928
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. Compilation process produces *.class file/-s which can be executed using 'java' command along with an executable Java class name - google for its exact use.
 
Mohamed Said
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liutauras Vilda wrote:No. Compilation process produces *.class file/-s which can be executed using 'java' command along with an executable Java class name - google for its exact use.


No output in that sense
What is this "Compilation process produces *.class file/-s which can be executed using 'java' command along with an executable Java class name - google for its exact use."
 
Liutauras Vilda
Sheriff
Posts: 4928
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamed Said wrote:What Output do you expect when you use command prompt to compile java programs?

No output expected.

Liutauras Vilda wrote:Compilation process produces *.class file/-s which can be executed using 'java' command along with an executable Java class name

In order to see some possible output you need to execute your  class after you got it compiled.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several steps involved in writing a program in Java.

First, you use a text editor (or a more sophisticated tool called an IDE - Integrated Development Environment) to create Java source files, such as HelloWorld.java.

Then, before you can run the program it needs to be translated to executable code. That is what the compiler does. You use the compiler to translate the source file HelloWorld.java into a class file, HelloWorld.class, that contains the code that can be run. In the command prompt, you compile the source code with a command like: javac HelloWorld.java. The result will be a file named HelloWorld.class. Note that the compiler does not run the program, so you will not see output from the program such as a "Hello World" message at this step.

Finally, you can run the program by using a command like: java HelloWorld. When you do that, you will ofcourse see the output of the program.

This is explained in more detail in Oracle's Java tutorials: About the Java Technology and Hello World.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!