1. I believe the three types of errors you can run into with a Java program consist of:
1. Syntax Errors
2. Semantic Errors
3. Logic and Runtime Errors
A syntax error is an error that violates the coding rules for the Java language (or
any language for that matter). I believe the most common syntax error, and
speaking from personal experience, is forgetting the end bracket to a statement.
Other common syntax errors include forgetting a semicolon. Forgetting a
semicolon at the end of a statement could potentially cause multiple errors. The
best place to start correcting these errors is with the first one detected in the list, as
it will probably clear other errors out. A great way to combat this problem is to
have a methodology in how you write your code. One habit I've gotten into, is after
I type out a starting bracket for a statement or method, I immediately hit enter a
few times then put the end bracket in. Once I do that I will move my cursor back
up between the brackets and start typing out the logic of that statement.
A semantic error in simple terms changes the meaning of the code to the compiler,
confusing it. I think the most ubiquitous source of these errors (for me) is
inadvertently messing up the names of variables. I tend to follow a specific naming
schema, so all my variables are usually upper-case first word, upperclass second
word, etc. For instance, SalesTax, or EmployeeFirstName, would be my variables.
With that said, I have ran into error issues because I might type a variable
incorrectly like salesTax and it produces an error. I believe only way to prevent
errors (if possible) is to follow a strict naming rubric and maintain attention to
detail as you pound out your code.
The last error is a logic and/or runtime error. These errors result from poor
program design; where the program will successfully compile but still tends to run
improperly. A good example is poor error control and detection. For instance,
suppose I created a program to calculate an employee's monthly paycheck, by
deducting certain taxes from inputting hours and wages. So, let’s say I accidently
inputted for "hours worked" -30 or 1825 hours. Clearly, these inputs are both
impractical, so they will potentially have a problem with some of the other
calculations that will be made once the user enters that information into the
program. The best way to prevent these errors is to slow down and think out your
program thoroughly. Asking a lot of "what ifs" is a great thing to do with every
step in the logic control process. What if I typed in "A" or "dog" for my hours.
Most likely entries like this would not happen but another aspect of other than just
an appropriate range of numbers to be mindful of.