Updated date:

Programming in Java Netbeans - A Step by Step Tutorial for Beginners: Lesson 31

Danson Wachira is a certified Trainer in Computer Science, Information Technology and related studies.

Table of Contents

<< Lesson 30 | Lesson 32 >>

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

Types of programming errors

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.

<< Lesson 30 | Lesson 32 >>

Other related hubs...

Want to make money online?


Ahmed on January 22, 2013:

Thanks for this tutorial, very helpful

Related Articles