DEV Community

Vidya
Vidya

Posted on

Debugging

Debugging
Debugging is the process of finding, analyzing, and fixing errors (bugs) in a program so that it works correctly.

--> A bug is any mistake in the code that causes:
* Wrong output
* Program crash
* Unexpected behavior

    Debugging = Detecting + Fixing mistakes in code
Enter fullscreen mode Exit fullscreen mode

Why Do We Use Debugging?

1. Fix Errors

Programs often have mistakes (syntax, runtime, logical). Debugging helps correct them.

2. Improve Program Performance

It helps optimize code and remove unnecessary parts.

3. Understand Code Behavior

Debugging lets you see how data changes step-by-step.

4. Prevent Crashes

Fixing bugs avoids application failure.

5. Ensure Correct Output

Helps verify that the program gives expected results.

Example of Debugging

int a = 10;
int b = 5;

int result = a - b;   // mistake
System.out.println("Sum is: " + result);


Enter fullscreen mode Exit fullscreen mode

What’s the Issue?
We want sum, but used - (subtraction)

Output will be:
        Sum is: 5   ❌ (wrong)

Enter fullscreen mode Exit fullscreen mode

Debugging Process
1. Check the output
2. Compare with expected result (10 + 5 = 15)
3.Find the mistake (- instead of +)
4.Fix the code

Top comments (0)