By Barry A. Burd

One Java instructor has an interesting policy. He said, “Sometimes when I’m lecturing, I compose a program from scratch on the computer. I do it right in front of my students. If the program compiles and runs correctly on the first try, I expect the students to give me a big round of applause.”

At first, you may think this guy has an enormous ego, but you have to put things in perspective. It’s unusual for a program to compile and run correctly the first time. There’s almost always a typo or another error of some kind.

So these tips deal with the normal, expected errors that you see when you compile and run a program for the first time. Everyone makes these mistakes, even the most seasoned travelers. The key is keeping a cool head. Here’s some general advice:

  • Don’t expect a program that you type to compile the first time.

Be prepared to return to your editor and fix some mistakes.

  • Don’t expect a program that compiles flawlessly to run correctly.

Even with no error markers in Eclipse’s editor, your program might still contain flaws. After Eclipse compiles your program, you still have to run it successfully. That is, your program should finish its run and display the correct output.

You compile and then you run. Getting a program to compile without errors is the easier of the two tasks.

  • Read what’s in the Eclipse editor, not what you assume is in the Eclipse editor.

Don’t assume that you’ve typed words correctly, that you’ve capitalized words correctly, or that you’ve matched curly braces or parentheses correctly. Compare the code you typed with any sample code that you have. Make sure that every detail is in order.

  • Be patient.

Every good programming effort takes a long time to get right. If you don’t understand something right away, be persistent. Stick with it (or put it away for a while and come back to it). There’s nothing you can’t understand if you put in enough time.

  • Don’t become frustrated.

Don’t throw your pie crust. Frustration (not lack of knowledge) is your enemy. If you’re frustrated, you can’t accomplish anything.

  • Don’t think you’re the only person who’s slow to understand.

Be slow and be proud of it.

  • Don’t be timid.

If your code isn’t working and you can’t figure out why it’s not working, ask someone. Post a message in an online forum. And don’t be afraid of anyone’s snide or sarcastic answer.