Subscribe to The Way I See It        RSS Feed

Compiling Programs With Command Prompt

Icon 1 Comments
New guys, this is for you. Many of you have asked, "What is the best way to learn how to program?" To put it simply, notepad and command prompt. Though coding in notepad isn't particularly difficult as long as you go slow and check your code along the way, getting your computer to compile the code without an IDE can be a pain if you don't know what you are doing. I'm here to fix that. Before we begin, I would like to note that I am using Windows 7

Step One: Setting the PATH
The first thing we need to do is get your computer to recognize the javac.exe file inside your JDK folder. This is the interpreter that will compile your code! The easiest way to do this is change your Command Prompt PATH to begin inside this folder which allows the computer to automatically recognize the files within.

  • Open My Computer
  • Click on the tab located on the top labeled "System Properties"
  • Now click on the tab in the left panel labeled "Advance System Settings"
  • Click on the button labeled "Environmental Variables"
  • Scroll down in the bottom pane until you find a variable named "Path"
  • Double click it
  • Now we change the address to that of the bin folder located in your JDK directory. Append this to the end of the current PATH after the last semicolon: "C:\Program Files\Java\jdk1.6.0_18\bin;" note, you may have a different version than me or have it stored in a different location,so the path might be slightly different The process is the same nonetheless.
  • "Ok" out of those three windows and open your command prompt.

Step Two: Compiling
good deal, now that's done. We're good to go. In my C: directory, I have a folder named "javaFiles" that holds my, well, .java files. Inside this folder is a sub folder named "Exercise18_19" that holds a .java file by the same name. I am going to compile this, but feel free to create your own folder and place a working java file into it.

  • "cd" to the directory where the .java file is
    cd "c:\javaFile\Exercise18_19 //we are inside the folder now

  • use javac on the .java file

  • run the compiled program
    java Exercise18_19

congrats, you've complied and run your program via command prompt. If it didn't work for you, make sure to repeat step one to verify that your PATH is correct. Check out the pics attached if you are a visual learner :bigsmile: The Steps are in LARGE RED LETTERS Happy Coding!

Attached image(s)

  • Attached Image
  • Attached Image

1 Comments On This Entry

Page 1 of 1


24 August 2010 - 08:28 PM
ignore that little error in the command prompt window btw. It means that I already have a class file in that folder (because I have complied it once already). I did it again for your benefit
Page 1 of 1

Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

January 2022

23242526 27 2829

Recent Entries

Recent Comments

Search My Blog

0 user(s) viewing

0 Guests
0 member(s)
0 anonymous member(s)