Danson Wachira is a certified Trainer in Computer Science, Information Technology and related studies.
Lesson 31: Types of programming errors
As a beginner programmer in Java, you’ll encounter a number of errors in programming. The good thing about most compilers is that they will underline most of the design errors within the code window to alert you about them.
Making programming errors is common but as you become more used and experienced in writing codes you shall learn how to detect, isolate and correct errors which are likely to be present in the program.
Most errors will occur because of minor omissions like forgetting to match braces, improper commenting, wrong method declaration, missing a semicolon at the end of a statement, missing quotes in strings etc. Most of these errors are design errors but in general, we have the following types of errors in programming:
Types of programming errors
- Design or Syntax errors
These are errors that occur due to violation of rules of the programming language. The good thing about Syntax errors is that most compilers can detect and isolate these errors. Java NetBeans underlines these type of errors in wavy red lines. If Syntax errors are not corrected then the program cannot run.
- Semantic errors
Semantic errors occur when a programmer obeys the syntax rules of the programming language but use statements that are out of context. For example, a programmer may define a variable and later try to use it when it is out of scope.
- Run-time errors
In most cases, run-time errors will not stop a program to run but it will produce erroneous result. For example, you may have wanted to generate a range of random numbers and multiply each generated number by a constant value. In such a case, if the loop is not correctly set then you many have a run-time error. Generally it is a difficult task to isolate run-time errors.
Java Programming Syntax Errors and Logical Errors
- Logical errors
As the name suggest, logical errors usually results from poor understanding of the program specification and inaccurate translation of the program algorithm. For example, the following code will cause a logical error since variable i will never be less or equal to zero.
for(int i = 1; i<=0; i++)
- Latent errors
One of the difficult errors to correct in programming is the latent error. This type of error may occur when certain types of operations are executed in the program but not in all cases. Take for example the following statement:
The above statement will generate a latent error if and only if when p and q are equal such that we’ll be dividing a number by zero. These types of errors are best detected by using all possible combinations of test data.
- System errors
System errors are usually beyond the control of a programmer because they are usually caused by a hardware failure. For example, hard disk may fail to respond when writing into a file, graphic display drivers may fail or program may be accessing a memory location which is not available.
The best way to approach error handling in any programming language is to be familiar with many types of errors and develop various tricks of detecting, isolating and correcting those errors. While some errors such as syntax errors are easy to detect and correct other types such as logical and latent errors are tricky and difficult to trace and correct.
Sometimes error handling in programming may entirely depend on the experience and wit of the programmer. In the next lesson, we shall specifically look at error handling in Java programming language.
Other related hubs...
- Programming In Java NetBeans - A Step By Step Tutorial For Beginners: Lesson 4
In Lesson 3, we learnt how to write a Java program in the Java code window and how to Run a Java program. In this lesson, we shall learn how to work with variables in Java and how to manipulate computer memory using variables.
- Programming In Java NetBeans - A Step By Step Tutorial For Beginners: Lesson 18
Array lists in Java are dynamic structures for store of values, that means values can be added or be removed from the list. We do not even need to declare the size of the list but values can be accessed by their index positions.
- Programming In Java NetBeans - A Step By Step Tutorial For Beginners: Lesson 1
Java is increasingly becoming the world’s programming language of choice. This tutorial will take you on step by step lessons covering specialized topics on Java programming that are aimed at providing the fundamental skills needed for beginner...
- Programming In Java NetBeans - A Step By Step Tutorial For Beginners: Lesson 2
In this lesson you will learn how to create your first Java project and how to interpret the NetBeans code editor window.
Want to make money online?
Ahmed on January 22, 2013:
Thanks for this tutorial, very helpful