Right way to debug code using pen and paper

Anyone who is starting to code, the most difficult thing they face is to understand others code. If the code has 2-3 nested loops then even an experienced persons face a lot of problem.

Understanding someone else’s code or code present on internet is very frustrating and takes a lot of time. So my advice is to use pen and paper if you are not able to understand code mentally.

There are many inbuilt debug tools present in IDEs such as Eclipse, Netbeans etc, but using them will cripple your mind and you will never develop the ability to debug code mentally. You should use these debug tools to understand Enterprise level codes.

The correct way to debug code for beginners is to use pen and paper, then only they will be able to do it mentally after some time. Let us see the right way to debug code.

Consider the below code have 2 nested loops to debug :-

public class Tech4Humans {

	public static void main(String[] args) {

		// side size of triangle
		int size = 5;

		for (int i = 0; i < size; i++) {
			for (int j = 0; j <= i; j++) {
				System.out.print("* ");
			}
			System.out.println();
		}

	}

}

Output

* 
* * 
* * * 
* * * * 
* * * * *
 

Let us see how to debug code using pen and paper :

Understand the debugging in above image carefully.

After this you should try to debug yourself some other similar programs such as :-

If you are familiar with Eclipse IDE then you can also debug code in Eclipse – Debugging in Eclipse.

0

Ankit

Ankit is a computer adventurer who loves to explore different things related to technology. He has been associated with technology and coding from past 10 years.

View all posts by Ankit →

Leave a Reply

Your email address will not be published. Required fields are marked *