WISDOMBYDATA
  • BLOG
    • Blog Guide
    • Blog History
  • EXCEL
    • Functions & Formulas
    • VBA & Macros
    • VLOOKUP
    • Pivot Tables
    • Conditional Formatting
    • Tricks & Shortcuts
  • BI
    • SAP BOBJ/BW
    • Tableau
  • SQL
  • ABOUT
    • About WBD
    • About Me

Running a JAVA Program from Command Prompt

12/2/2013

0 Comments

 

1. Install Java

If you dont have Java installed on your system click here to download Java from the Oracle website. Without Java, command Promt will not execute our program. So please proceed to step 2 after installing and configuring Java to your system.

2. Write your Java command in Notepad

In this example I will be creating a Java Class called knowledge along with a simple program that when executed in "Command Prompt" will display the phrase "Knowledge is Power".
Picture
After writing the code above, the notepad file must be saved on the primary hard drive (e.g. C drive) and within another folder. I have named this folder "project".
​
Note1] In order for command prompt to recognize this file you must save it as a Java file. to do so the name of the file must end with ".java". As such I will be naming this file "knowledge.java".
Note2] You will need to keep the notepad document open while executing commands in Command Prompt.

3. Execute the JAVA program from Command Prompt

First we must go to the project directory using in the commands in the screenshot below:
Picture
Next step is to compile our program. The purpose of compiling is to turn our program into a class file because the computer cannot read any ".java" files. In order to compile a java file we must use a command called "javac"which stands for Java Compiler.
Picture
After executing the Javac command as depicted in the screenshot above, we must use the DIR command in order to verify that the correct execution of this command. As you could observe in my screenshot the "knowledge.class" line which did not exist before the compilation has now been added and this is indicative that the compilation has been successful. Moreover, if we go to the our C drive and look under the project folder an additional file called "knowledge.class" has been created there.
Picture
We are know at the final step of successfully executing our java program. This step is as simple as typing "java" followed by name of our class. I.e. "java knowledge".
Picture
Command promt has successfuly executed our program. "Knowledge is Power!"
0 Comments



Leave a Reply.

    Categories

    All
    BI
    EXCEL
    MISC
    SQL

    Archives

    June 2020
    May 2020
    April 2020
    March 2020
    February 2020
    December 2019
    November 2019
    October 2019
    September 2019
    August 2019
    July 2019
    June 2019
    May 2019
    April 2019
    March 2019
    February 2019
    January 2019
    December 2018
    November 2018
    October 2018
    September 2018
    August 2018
    July 2018
    June 2018
    May 2018
    April 2018
    March 2018
    September 2017
    August 2017
    July 2017
    June 2017
    May 2017
    April 2017
    March 2017
    February 2017
    January 2017
    December 2016
    November 2016
    October 2016
    September 2016
    August 2016
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    May 2015
    April 2015
    March 2015
    February 2015
    January 2015
    December 2014
    November 2014
    October 2014
    September 2014
    August 2014
    April 2014
    March 2014
    February 2014
    January 2014
    December 2013
    November 2013

Picture
  • BLOG
    • Blog Guide
    • Blog History
  • EXCEL
    • Functions & Formulas
    • VBA & Macros
    • VLOOKUP
    • Pivot Tables
    • Conditional Formatting
    • Tricks & Shortcuts
  • BI
    • SAP BOBJ/BW
    • Tableau
  • SQL
  • ABOUT
    • About WBD
    • About Me