Introduction: How to Code a Program in Java

Picture of How to Code a Program in Java

By: Matthew D. Perry

Step 1: Read Over What You Need to Do

No matter what you're going to code, your program has to have a point. Whether or not it's a simple output of "Hello World!" or a fully functioning calculator or something even more complex, your program has to do something, and the first step is to figure out in basic parts, what exactly you need to do.

Example: You want a simple "Hello World" statement to be printed out.

Step 2: Psuedocode

For your code, you have figured out what you need the code to do, now it's a matter of translating into your programming language of choice. If your code requires user input, for instance, you would need a scanner. Use any resource you can to use you know what you need. Suggestions include google, your notes, or anything else.

EX: To output "Hello World", you need to use a printline statement.

Step 3: Choose a Compiler

Picture of Choose a Compiler

To execute any sort of code, you must first choose a program dedicated to running the code. These are known as compilers, and each has its own benefits and downsides.

EX: I use DrJava for mine.

Step 4: Type Your Code

Most compilers start off with a "main" category, which is where the program will be written. You use what you have learned in step 2 to put it all together. You name your program in the main code line, and after the bracket, write what you have.

Ex:

public static main HelloWorld {

System.out.println("Hello World!")

}

Step 5: Debugging

Some times, your code will run perfectly. Most times, your code will have several errors. This can be annoying, but you have to go through each error, figure out the problem with it, and rewrite your lines to fix what went wrong.

Ex: public static main HelloWorld {
System.out.println("Hello World!") }

Will deliver an error, since java statements are supposed to end in semicolons.

Step 6: And You're Done!

Picture of And You're Done!

Your code has compiled correctly, and the output is exactly as what you wanted.

Ex: "Hello World!" displays.

Comments

About This Instructable

1,412views

12favorites

License:

More by mperry17:How to code a program in Java
Add instructable to: