Forum Stats

  • 3,757,144 Users
  • 2,251,201 Discussions
  • 7,869,743 Comments

Discussions

compiling and running java programs

I have downloaded Java for Java.com. Completed some code in Notepad. I cannot find where to compile the code and test it.

Answers

  • KatAlive
    KatAlive Member Posts: 3 Green Ribbon

    Hi,

    To make it very easy, i suggest you to download IDE like Eclipse or Netbeans, they are very useful, also because they include all Javadocs and suggestions meanwhile you're writing the code.

    Then, if you wanna continue to use notepad :

    1. Save the file as YourFileName.java
    2. open command prompt (cmd) on Windows, if you are Mac OS then open Terminal.
    3. To compile the program, type the following command :
    java YourFileName.java
    

    If you get this error : “javac’ is not recognized as an internal or external command, operable program or batch file“, you need to set the path before compilation; so :

    • Open command prompt (cmd), go to the place where you have installed java on your system and locate the bin directory, copy the complete path and write it in the command like this.
    set path=C:\Program Files\Java\jdk1.8.0_121\bin
    

    When the PATH is ok, try again STEP 3 to compile and then run program with :

    java FirstJavaProgram
    

    That's it.

    Regards,

    Carlo.