Programmingerrors can happen to anyone. Amongst the countless errors a programmer canencounter there a few that are deemed common.
The easiest error to make, is toeither use a variable that is undeclared or to have too many variables definedthat end up not being used at all in the program. Sometimes the undeclaredvariable dilemma is really just a spelling or capitalization error, so it isvery important to always double check when declaring and using variablesthroughout a program. Anothercommon error is integer overflow. Integer overflow occurs when a number is toolarge to be contained within the selected variable type. All numeric data type variableshave a limit to the length a number can be and each variable is designed toaccommodate data within a certain range. The most commonly used number variabletypes are integer and double.
Typically Java will not alert a programmer to anoverflow problem, so it is best to use the appropriate variable every time anumeric data type is selected. Round-offerrors and mistakes within mathematical operations are also common mistakes forprogrammers. Round-off errors can occur when using an approximation data type,like integer, instead of a more specific mathematical data type for a number inwhich significant figures are needed like float or double. It is also importantto declare what type of mathematical variable will be needed for a problemcorrectly. If an answer requires a decimal or something other than a wholenumber answer that has been truncated, integer is not the best variable typefor the situation.
When dealing with numbers it is always important todetermine the best numeric data type for the problem at hand. Thebiggest mistake new programmers make when coding, is multiple instances ofinput within a block of code. For instance, say that a user needs to enter afew lines of data after being prompted.
Instead of initializing the Scannerjust once and having multiple lines of print to obtain data from a user, therewill be multiple instances of the Scanner class called as well as multiplelines of print to obtain data from a user. This is redundant, the Scanner onlyneeds to be initialized once and then multiple lines of data can be obtainedfrom the users. Overallthere are a lot of common errors and pitfalls that a new programmer can make,however it is ok to make mistakes. It is expected that when starting out tomake mistakes. Mistakes help programmers grow, it shows where improvements canbe made.