\n \npublic class Tech4HumansDebug {\n\n\tstatic int sumMethod1(int num1, int num2) {\n\t\tint sum = 0;\n\t\tsum = num1 + num2;\n\t\treturn sum;\n\t}\n\n\tstatic int sumMethod2(int a, int b) {\n\t\tint sum = 0;\n\t\tfor (int i = 0; i < b; i++) {\n\t\t\ta = a + 1;\n\t\t}\n\t\tsum = a;\n\t\treturn sum;\n\t}\n\n\tpublic static void main(String[] args) {\n \n\t\tint x1 = 2;\n\t\tint y1 = 3;\n\t\t\n\t\tint sum1 = sumMethod1(x1, y1);\n\t\tint sum2 = sumMethod2(5, 4);\n\n\t\tSystem.out.println("sum from method1 = " + sum1);\n\t\tSystem.out.println("sum from method2 = " + sum2);\n\t}\n\n}\n<\/pre><\/div>\n\n\nStep 2 : <\/strong>We have to choose a place in code where we need to start debugging our code and insert a breakpoint. A breakpoint is the line of code from where we need to debug our code and proceed manually. <\/p>\n\n\n\nTo insert a breakpoint right click at the left hand side of program where line numbers are written and click on ‘Toggle Breakpoint’ as shown in below image. A breakpoint will be inserted. Alternatively we can also double click on the line number to insert breakpoint.<\/p>\n\n\n
\n
<\/figure><\/div>\n\n\nStep 3 :<\/strong> Similarly insert breakpoint at line 21 of our code too. There should be 2 circles(breakpoints) inserted at line 6 and 21 as shown below.<\/p>\n\n\n\n
<\/figure><\/div>\n\n\nStep 4 :<\/strong> Now to start debugging the code right click on the code and select ‘Debug as’ and then ‘Java Application’.<\/p>\n\n\n\n
<\/figure><\/div>\n\n\nStep 5 :<\/strong> A new dialog box will appear which will ask to change perspective. Click on ‘Switch’ button. <\/p>\n\n\n\n
<\/figure><\/div>\n\n\nStep 6 :<\/strong> By changing perspective some additional windows will appear on eclipse which will help you debug code easily. The statement with first breakpoint will be highlighted with a green debug pointer. On the tool bar few buttons will be enabled too which were previously disabled. Let us understand one by one.<\/p>\n\n\n\n
<\/figure><\/div>\n\n\nAt the right hand side a new window will appear having 3 tabs ‘Variables’, ‘Breakpoints’, ‘Expressions’. <\/strong><\/p>\n\n\n\n
<\/figure><\/div>\n\n\n\nVariables tab :-<\/strong> This tab shows the current value of the variables in the program. As you progress in the code the change in values of variables is reflected here.<\/li>\n\n\n\nBreakpoints tab :-<\/strong> This tab shows the list of breakpoints inserted in program.<\/li>\n\n\n\nExpressions tab :-<\/strong> While debugging if we want to execute any expression based on the current values of variables then we use Expressions tab.<\/li>\n<\/ul>\n\n\n\nNow let us understand the buttons in the tool bar that are enabled :-<\/strong><\/p>\n\n\n\n
<\/figure><\/div>\n\n\n\nStep Over :-<\/strong> On reaching a breakpoint we need to proceed line by line so that we can analyze changes in code and variables. For this we press Step over button.<\/li>\n\n\n\nStep Into :-<\/strong> While proceeding step by step using ‘Step Over’ if we encounter any function call and press again Step Over on function call then instead of going inside the function the debug pointer will execute function and proceed to next statement after function call. So to get inside the function we press Step Into on reaching the function call.<\/li>\n\n\n\nStep Return :-<\/strong> After reaching inside function if we want to return from body of function to function call then we press Step Return. <\/li>\n\n\n\nSkip all Breakpoints :-<\/strong> Use this button if you want to skip all the breakpoints and continue with normal execution of program.<\/li>\n\n\n\nResume :-<\/strong> When we want to move from one breakpoint to next breakpoint without debugging the code in between them.<\/li>\n\n\n\nTerminate :-<\/strong> If we want to exit debugging and stop program execution.<\/li>\n<\/ul>\n\n\n\nStep 7 :<\/strong> Now press on the Step Over button in the tool bar and you will observe the value of variables being updated in the variables tab. <\/p>\n\n\n\n <\/figure>\n\n\n\nStep 8 :<\/strong> Similarly press Step Over once more to reach the function call.<\/p>\n\n\n