For many people, how computers do what they do is an incredible mystery.  This how-to guide is an attempt to put you on the path to understanding how programs work by helping you create a program.

For this guide to be effective you need to be running a version of Windows.  This is because most of the instruction will only work on Windows  You do need to be able to download and install programs, but we'll cover what program later in these instructions.

Step 1: Make a File

1. Navigate to your My Documents folder in a file explorer.  
2. In that window right-click hover over new and click on "Text Document" this will create a file name "New Text Document" with the name highlighted, so you can rename it.  
3. Click away from the document it because we will rename it later.

Step 2: Write the Framework of Your Progam

1. Open your newly created text document.  
2. Inside your file type "class MyFirstProgram {" 
Do not forget the curly brace because this tells the computer where the meat of your program is.  
3. Press enter twice to create to new lines and then type "}" this tells the computer that everything that makes up this program has been entered. 
4. At this point your program should look like the attached picture for this step.

Understanding The Code:
At this point we can actually generate the program. The only problem is it won't do anything. In fact if you tried to run the program an error message will appear that says "Error: Main method not found in class MyFirstProgram, please define method as: " and then shows a specific line of code. We will be writing in that line of code in the next step since it is an important part of the program to understand.

We are using a specific programming language called Java, and as with most languages Java has a very specific way of organizing and expressing itself this organization is called the code's syntax and must be followed or the program cannot be generated by the compiler. What we did was set up the basic framework of this program.

Every Java program is composed of Classes and Methods. Classes are more commonly known as Objects and provide us with a way to organize our code. Classes store information and instructions, our program is going to be a single class with a single instruction, or method. An easy way to think of it is that classes are an entire keyboard where the methods are the individual keys on the keyboard. Right now our program is just a empty class (A keyboard with no keys). We know this, and more importantly the compiler knows this because the first word we typed says "class".

After reading the word class Java's syntax dictates that we need to state the programs name (a label on the key), in this instance we will name our program "MyFirstProgram". We will name it this because it is descriptive of what our program is: our first one!  An important thing to note is that most programming languages will not allow spaces the names of things. This is because the use of empty space withing code helps the compiler understand what is going on.

The compiler, reading in the name of our class, expect us to show some way of denoting what part of our file constitutes the class itself to do this we use curly braces ("{" "}") to denote where it starts ("{") and where it ends ("}"). Since our file does do this when we pass it through the compiler, the compiler will produce a program, but since our class has no methods to use (keys to press) an error will be produced.

Step 3: Setup the "main" Method

1. On the second line of your program press Tab and type "public static void main(String[] args) {". 
2. Press enter twice, then tab again and type "}". 
3. Your program should now look like the picture.

Understanding the Code:
What we just wrote is the "main" instruction, or method, of our program. The "main" method of a class is quite literally the main instruction of a program. When a class contains a "main" method it allows a program to be executed. This is because when a java program is run it the first thing a computer looks for is a method named "main" and follows out all the instructions within that method. Since there are no instructions within main right now, running the program will cause nothing to happen.

In front of the main method's name are three words. These words describe specific attributes of the method. The first word describes who can use the method, and since this is the main method it must be available for everyone to use so it says "public."

The next word is optional and describes when the method can be used. The specific details of word requires a deeper knowledge to fully understand so it the author will leave it up to the reader to investigate thing more on their own to gain this understanding.

The last word described what sort of object the method produces. In this case we do not want to produce anything so we state "void" so the computer knows not to be expecting anything at the end of the instruction.

Next to main we have a left parenthesis some code and a left parenthesis followed by the curly braces. The curly braces again describe where this part of the program starts and ends. The code inside the parentheses denotes the inputs of the method or what the method expects to receive from whomever using it. In this case it expects to receive an array (denoted by "[]") of Strings to run, or, in other words, it expects to receive a list of words. They are usable by the method under the name "args" which is shorthand for "arguments". When the main method is called by a computer it puts all the words that are after it into that list and hands them over to the program.

We don't need any arguments for this program so don't worry about it, but still keep the input argument in there because your computer will get confused if it isn't.

Step 4: Write Your Instruction

1. On the empty line in the middle of the program press tab twice and type "System.out.println("Hello, World!");"

Understanding the Code:

This instruction will cause the sentence "Hello, World!" to appear where we will be executing the program from.

This part of any program is where we're telling the computer to do something. The heart of programming lies in being able to do this.  Write this line of code and you've essentially done it. "System.out" is the first part of this instruction we need to understand.  System is a class readily available at any time anywhere. Appending ".out" to System allows gives us access to a class contained in System that gives us access to the computer's output. Calling the "println" method from out will write (or print) the text passed to the method to the available output. In our case this will be the command line.

Step 5: Save Your Program

1. In your text editor click on "File" then select "Save As..."
2. In the dialogue window that appears next there is a drop down selector labeled with "Save as type:" it should currently have "Text Documents (*.txt)" click on the selector and select "All Files". 
3. By "File name:" change the name of the file to "MyFirstProgram.java".
4. Click Save.

Step 6: Install the Java JDK

1. Go to http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html click on the agree radio button.
2. Click on the download for Windows x86 .
3. Once the download is finished open the file and follow the setup.  All the default options will work.

This step installs the Java JDK, or Java Developer's Kit, which gives us access to the Java compiler and the command that allows us to run Java programs.

Step 7: Copy the Path to the Java Tools

1. Open up your window file explorer and navigate to your computer's main directory (where you find your CDs and USB sticks).
2. Double click on "Local Disk" which typical has a "(C:)" following it. 
3. Double click "Program Files"
4. Highlight any fold and press the "j" key. 
5. This should take you to you a folder named "Java" open it. 
        If you cannot find the "Java" folder go back to "Local Disk" and open "Program Files (x86)".  If you still can't find it repeat Step 6.
6. You will be presented with two folder options open the folder starting with "jdk" in lowercase. 
7. Open the folder titles "bin".
8. Click on the file path, but not on any part of the path.
9. This should highlight path like in the picture.
10. Press "crtl" and "c" at the same time this will copy that path (the path tells the computer where that directory is).

Step 8: Open the Command Prompt

1. Navigate to your My Documents directory in you file explorer.
2. Create a new folder (right click hover over "New" and click on "Folder")
3. Name it "MyFirstProgramFolder" (as soon as the folder is made type out the name).  
4. Drag your "MyFirstProgram" file to the folder.  Do not enter the folder. 
5. While holding shift right click on "MyFirstProgramFolder" and select "Open command window here...".  Like in the picture.
6. The command prompt should now be open like in the second picture.

Step 9: Compile the Program

1. Once in the command prompt type ' " '
2. Right click in the window and select "Paste".  
3. The path you copied from step 7 should appear.  If not, just repeat step 7 without closing the command prompt and try again.
4. With the path pasted type ' " '
5. Type "\javac MyFirstProgram.java".
6. The command prompt cursor should go to the next line and look similar to the picture.

What's Going On

You just compiled your program.  This means that your computer now has access to a file with instructions it can understand.

Step 10: Run Your Program

1. Without closing the command prompt press on the up arrow key.  
2. This should bring up the compile command you just executed.  
3. Press delete just the Java tools directory remains (with the quotes).  
4. Type "\java MyFirstProgram" to run your program.

The result this time should be similar to the previous step, but this time a line of text should be printed out saying "Hello, world!"  Just like the picture.

For an extra challenge change the message that is printed by editing your MyFirstProgram.java file and repeating the last two steps to run your modified program.
<p>this is what i keep getting please help</p><p>MyFirstProgram.java:3: error: package system does not exist</p><p> system.out.PrintIn(&quot;Hello, World!&quot;);</p><p> ^</p><p>1 error</p>
<p>the ^ is pointing at the &quot;.&quot; between system and out</p>
<p>this might be a visual issue because i can see it pointing at the s</p>
<p>Alex,</p><p> In Java, some of the syntax is case sensitive. Instead of what you have typed, &quot;system.out.Println(&quot;Hello, World!&quot;);&quot; type this, &quot;System.out.println(&quot;Hello, World!&quot;);&quot;.</p><p>You will notice that the 'S' in system is capitalized and the 'p' in println is lower case. These changes should help your code run successfully. Just an FYI... println means &quot;print line&quot; which means that each time you run the code it will print the words on a new line. You could also write &quot;System.out.print&quot; and the text would be written on the same line each time. Lastly, the little caret (^) is pointer showing you where your error is. It is pointing to the first s in &quot;system&quot; because it is not capitalized. Hope this helps. Have fun coding. :) </p><p>-- Brian</p>
<p>Hey TracyT46, it seems like the &quot;MyFirstProgram.java&quot; file is not present in the directory that you are in.</p>
<p>what am I doing wrong?</p><p>C:\Users\tthompson\Documents\MyFirstProgramFolder&gt;&quot;C:\Program Files (x86)\Java\jdk1.7.0_79\bin&quot;\javac MyFirstProgram.java</p><p>javac: file not found: MyFirstProgram.java</p><p>Usage: javac &lt;options&gt; &lt;source files&gt;</p><p>use -help for a list of possible options</p><p>C:\Users\tthompson\Documents\MyFirstProgramFolder&gt;&quot;C:\Program Files (x86)\Java\jdk1.7.0_79\bin&quot;\javac MyFirstProgram.java</p><p>javac: file not found: MyFirstProgram.java</p><p>Usage: javac &lt;options&gt; &lt;source files&gt;</p><p>use -help for a list of possible options</p><p>C:\Users\tthompson\Documents\MyFirstProgramFolder&gt;</p>
<p>this website is flop</p>
<p>i did that before, im famous programer i made game and any kind website so i preffer to use eclipse IDE:;//</p>
<p>good job</p>
<p>Yay I made it!</p>
well i just figured out the backslash button on my keyboard doesnt work. lol.
<p>Mine just opened up the file in notepad++?</p>
<p>is there any virus in the program ?</p>
do I need to download some kinda special progrum to type in?
<p>I personally Like To Use Notepad ++ But It All Depends On What You Prefer :)</p>
<p>Look at Step 6. ; )</p>
<p>I keep getting i dont have permission, even though i am a administrator </p>
<p>k nvm thx!</p>
<p>Um How Did U Enter The Cmd In The File?</p><p>:/</p>
<p>please will anyone tell me?????</p>
<p>At step 9 it says that it can't find the entered path please help me</p>
<p>same here . did you get any solution?</p>
<p>I am trying to make my first program . But I can't understand the 8 th step . and I can't go forward</p>
<p>Once I get to step 6 and click on the link, I'm lost. Can someone please explain what to do? I have Windows 8.1, if that helps. When I get to the website, should I get 'Java SE Development Kit 7u79' or 'Java SE Development Kit 7u80'? ( I might be completely off and need to get a different program )</p>
<p>My local disk seems to be called &quot;<strong>S3A8666D003</strong>&quot;</p>
<p>You Can Rename It. Just Right Click it, then Click Rename.</p>
<p>i have a 64x Verson Of Windows 10</p>
<p>Me too.</p>
<p>me too.</p>
<p>me too. You need to do the same things just download jdk for 64x</p><p>no problems</p>
<p>I got a hard time dealing with this but you need to work hard to make a success.I kept rechecking my program and the finally...</p>
<p>when im at step 7.....eventhough i press the shift n right-click...there was no &quot;</p><p>Open command window here&quot; option...what should i do?</p>
<p>well what version of windows OR mac do you have?</p>
<p>\Documents\MyFirstProgramFolder&gt;&quot;C:\Program Files (x86)\Java\jdk1.7.0_79\bin&quot;\Javac MyFirstProgram.Java</p><p>error: Class names, 'MyFirstProgram.Java', are only accepted if annotation processing is explicitly requested</p><p>1 error</p><p>Kept getting this same error no matter how many times i retried it? Any suggestions? </p>
<p>I'm new to coding and I've followed the steps, done every right (as far as I can tell) but when I get to running the program, the command window keeps telling me '/java is not recognized as an internal or external command, operable program or batch file'</p><p>What does this mean?</p>
<p>great i made it thanks for you valuable guidance. </p>
<p>Great 'ible!</p>

About This Instructable




More by sniget:How to Make Your First Java Program 
Add instructable to: