Difference between revisions of "Netbeans/C2/Netbeans-Debugger/English-timed"
From Script | Spoken-Tutorial
PoojaMoolya (Talk | contribs) |
Sandhya.np14 (Talk | contribs) |
||
(9 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{| Border=1 | {| Border=1 | ||
− | + | || '''Time''' | |
− | || Time | + | || '''Narration''' |
− | + | ||
− | || Narration | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
− | | 00 | + | |00:01 |
− | | Welcome to the tutorial on '''Netbeans Debugger. ''' | + | |Hello everyone.Welcome to the tutorial on '''Netbeans Debugger.''' |
|- | |- | ||
− | |00 | + | |00:06 |
|If this is the first time you are using '''Netbeans''', please view the earlier tutorials on the '''Spoken Tutorial''' website. | |If this is the first time you are using '''Netbeans''', please view the earlier tutorials on the '''Spoken Tutorial''' website. | ||
|- | |- | ||
− | |00 | + | |00:14 |
− | |For this demonstration, I am using the Linux Operating System Ubuntu | + | |For this demonstration, I am using the '''Linux Operating System Ubuntu''' version '''12.04''' |
|- | |- | ||
− | | 00 | + | | 00:21 |
− | |and Netbeans IDE | + | |and '''Netbeans IDE''' version '''7.1.1'''. |
|- | |- | ||
− | |00 | + | |00:26 |
− | |We all know that | + | |We all know that debugging programs can be a rather painstaking task. |
|- | |- | ||
− | | 00 | + | | 00:31 |
− | |Hence, knowing a | + | |Hence, knowing a debugging tool and being familiar with its features can help you save valuable time. |
|- | |- | ||
− | | 00 | + | | 00:39 |
− | |This powerful | + | |This powerful debugging tool is very useful, |
|- | |- | ||
− | |00 | + | |00:42 |
|especially when you have to code or test large programs. | |especially when you have to code or test large programs. | ||
|- | |- | ||
− | | 00 | + | | 00:46 |
− | |In this tutorial we will learn some of the features that the '''Netbeans Debugger''' provides. | + | |In this tutorial, we will learn some of the features that the '''Netbeans Debugger''' provides. |
|- | |- | ||
− | | 00 | + | | 00:53 |
− | | This tutorial will acquaint you with | + | | This tutorial will acquaint you with- |
|- | |- | ||
− | |00 | + | |00:55 |
− | |the | + | | the debugging window |
− | + | ||
|- | |- | ||
− | |00 | + | |00:58 |
− | |configuring | + | | configuring '''breakpoint'''s |
|- | |- | ||
− | + | |01:00 | |
− | |01 | + | | evaluating expressions or setting watches |
− | + | ||
− | |evaluating expressions or setting watches | + | |
− | + | ||
− | + | ||
|- | |- | ||
− | + | |01:04 | |
− | |01 | + | | options for tracing the execution of your program and |
− | |options for tracing the execution of your program | + | |
− | + | ||
|- | |- | ||
− | + | | 01:07 | |
− | | 01 | + | | options to '''configure''' the '''debugger''' itself. |
− | + | ||
− | | | + | |
− | + | ||
|- | |- | ||
− | + | |01:12 | |
− | |01 | + | |Now, Let's get started and '''debug''' this sample '''code'''. |
− | + | ||
− | |Now Let's get started and '''debug''' this sample code. | + | |
|- | |- | ||
− | + | |01:17 | |
− | |01 | + | |I will switch to the '''Netbeans IDE'''. |
− | + | ||
− | |I will switch to the Netbeans IDE | + | |
− | + | ||
|- | |- | ||
+ | |01:20 | ||
+ | |I have already created a Java Application- '''sampleDebug''', in my IDE, for this demonstration. | ||
− | |||
− | |||
− | |||
|- | |- | ||
− | + | |01:27 | |
− | |01 | + | |This is a small program that initializes three integer values '''a''', '''b''', and '''c'''. |
− | + | ||
− | |This is a small program that initializes three integer values a, b, and c. | + | |
− | + | ||
|- | |- | ||
− | |01 | + | |01:35 |
− | |Then it prints | + | |Then it prints "'''Hello World!'''" and the value of '''a'''. |
|- | |- | ||
− | + | |01:40 | |
− | |01 | + | |It also creates a '''class''' object '''SampleClass''' which has a 'value' integer, as a '''private''' integer value. |
− | + | ||
− | |It also creates a class | + | |
|- | |- | ||
− | + | |01:52 | |
− | |01 | + | |Then, it computes the value of '''b''' |
− | + | ||
− | |Then, it computes the value of | + | |
|- | |- | ||
− | + | |01:55 | |
− | |01 | + | | and calls a '''function''' to compute the value of '''c''', |
− | + | ||
− | | and calls a function to compute the value of c, | + | |
− | + | ||
|- | |- | ||
− | + | | 02:00 | |
− | | 02 | + | |and prints the values of '''b''' and '''c'''. |
− | + | ||
− | |and prints the values of 'b' and 'c'. | + | |
− | + | ||
|- | |- | ||
− | + | | 02:05 | |
− | | 02 | + | |To start with the debugging, let us first set the '''break-point'''. |
− | + | ||
− | |To start with the | + | |
|- | |- | ||
− | | 02 | + | | 02:09 |
− | |To set a | + | |To set a '''break point''', click on the line number. |
|- | |- | ||
− | | 02 | + | | 02:13 |
− | |I will set at this line which prints ''' Hello World!''' | + | |I will set it at this line which prints "'''Hello World!'''". |
− | + | ||
− | + | ||
|- | |- | ||
− | | 02 | + | | 02:18 |
− | |Notice that the line at which a | + | |Notice that the line at which a '''break-point''' is set, changes it's colour to pink and is marked by a small square against its line number. |
|- | |- | ||
− | | 02 | + | | 02:28 |
− | |When you run the program in the '''debugging''' mode, | + | |When you '''run''' the program in the '''debugging''' mode, |
|- | |- | ||
− | | 02 | + | | 02:31 |
− | |by clicking on the ''' Debug Project''' button in the toolbar, | + | |by clicking on the '''Debug Project''' button in the toolbar, |
|- | |- | ||
− | |02 | + | |02:35 |
− | | the execution of the program stops at the line at which the breakpoint is located. | + | | the execution of the program stops at the line at which the '''breakpoint''' is located. |
|- | |- | ||
− | |02 | + | |02:41 |
− | |So far, 'a's value has been set. | + | |So far, '''a'''s value has been set. |
|- | |- | ||
− | |02 | + | |02:45 |
| Hover on it to check it's value. | | Hover on it to check it's value. | ||
− | |||
|- | |- | ||
− | |02 | + | |02:49 |
|It indicates that it's value is 10. | |It indicates that it's value is 10. | ||
− | |||
|- | |- | ||
− | | 02 | + | | 02:52 |
− | |You can see that there are some additional windows below the workspace. | + | |You can see that there are some additional windows below the '''workspace'''. |
|- | |- | ||
− | | 02 | + | | 02:59 |
− | |There is a 'Variables' window that shows a list of variables and their values. | + | |There is a ''''Variables'''' window that shows a list of variables and their values. |
− | + | ||
|- | |- | ||
− | + | | 03:07 | |
− | | 03 | + | |So far, only the variable '''a''' has been initialized. |
− | + | ||
− | |So far, only the variable 'a' has been initialized. | + | |
− | + | ||
|- | |- | ||
− | + | |03:11 | |
− | |03 | + | |We can also look at the '''Output''' window with the '''sampleDebug''' output. |
− | + | ||
− | |We can also look at the 'Output' window with the | + | |
− | + | ||
− | + | ||
|- | |- | ||
− | + | |03:17 | |
− | |03 | + | |
− | + | ||
|There is no output yet. | |There is no output yet. | ||
+ | |- | ||
+ | | 03:19 | ||
+ | |There is also a '''Debugger Console''' that says that the program hit a breakpoint on line 29 and has stopped there. | ||
|- | |- | ||
− | + | | 03:28 | |
− | | 03 | + | |There is also a '''Breakpoints''' window that tells you that a breakpoint has been set on line number 29. |
− | + | ||
− | |There is also a | + | |
− | + | ||
|- | |- | ||
− | + | | 03:36 | |
− | | 03 | + | |Before proceeding, let us see how to add a '''watch'''. |
− | + | ||
− | | | + | |
− | + | ||
|- | |- | ||
− | + | | 03:40 | |
− | | 03 | + | |For example, let us say, I want to watch on the integer value ''''aSample''''. |
− | + | ||
− | | | + | |
− | + | ||
|- | |- | ||
− | + | | 03:48 | |
− | | 03 | + | |In the 'Variables' window, below the '''workspace''', I will double-click on the '''Enter new Watch''' option and enter the name of the variable "aSample.value". |
− | + | ||
− | | | + | |
− | + | ||
|- | |- | ||
− | + | | 04:02 | |
− | | | + | |Click on '''OK.''' |
− | + | ||
− | | | + | |
− | + | ||
|- | |- | ||
− | + | | 04:06 | |
− | | 04 | + | |So far, '''aSample''' has not been created. So, it says it does not know the value. |
− | | | + | |
− | + | ||
− | + | ||
|- | |- | ||
− | | 04 | + | | 04:12 |
− | | | + | |Once it executes the line, we'll know what the variable contains. |
− | + | ||
|- | |- | ||
− | + | | 04:16 | |
− | | 04 | + | |In a similar way, you can also watch and evaluate expressions. |
− | | | + | |
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
− | + | | 04:21 | |
− | | 04 | + | | Here, I'm checking for b=a+10. |
− | + | ||
− | | | + | |
− | + | ||
|- | |- | ||
− | + | | 04:25 | |
− | | 04 | + | |What if I wanted to know what '''a-4''' is. |
− | + | ||
− | | | + | |
− | + | ||
|- | |- | ||
− | + | | 04:29 | |
− | | 04 | + | |So, let me go to the '''Debug''' menu in the menu bar and select '''Evaluate expression''' option. |
− | + | ||
− | | | + | |
|- | |- | ||
− | | 04 | + | | 04:37 |
− | + | |The ''''Evaluate Code'''' window appears in the workspace. | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | |The ''' 'Evaluate Code' ''' window appears in the workspace. | + | |
|- | |- | ||
− | | 04 | + | | 04:41 |
− | |Here I will enter the expression | + | |Here, I will enter the expression '''a-4'''. |
|- | |- | ||
− | | 04 | + | | 04:45 |
− | |Click on the '''Evaluate Expression | + | |Click on the '''Evaluate Expression''' button here and in the '''Variable''' window, it says (a-4)'s value is 6. |
|- | |- | ||
− | + | | 04:56 | |
− | | 04 | + | |
− | + | ||
|Let us now proceed and execute this single line of code. | |Let us now proceed and execute this single line of code. | ||
|- | |- | ||
− | + | | 05:00 | |
− | | 05 | + | |
− | + | ||
|To do that, choose the '''Step-Over''' button from the toolbar. | |To do that, choose the '''Step-Over''' button from the toolbar. | ||
− | |||
|- | |- | ||
− | + | | 05:06 | |
− | | 05 | + | |That should execute only that 1 single line of the code to print “'''Hello World'''”. |
− | + | ||
− | |That should execute only that 1 single line of the code to print ''' | + | |
|- | |- | ||
− | + | | 05:12 | |
− | | 05 | + | |
− | + | ||
| To see the output, go to the output window and choose the '''sampleDebug''' output window | | To see the output, go to the output window and choose the '''sampleDebug''' output window | ||
− | |||
|- | |- | ||
− | + | | 05:17 | |
− | | 05 | + | | that says, "Hello World! 'a' is 10". |
− | + | ||
− | | | + | |
− | + | ||
|- | |- | ||
− | + | | 05:22 | |
− | | 05 | + | |
− | + | ||
|The program has now stopped at the line to create a '''SampleClass''' object. | |The program has now stopped at the line to create a '''SampleClass''' object. | ||
|- | |- | ||
− | + | | 05:28 | |
− | | 05 | + | |Now, I want to go into the '''constructor''' of the ''' SampleClass.''' |
− | + | ||
− | |Now, I want to go into the constructor of the ''' SampleClass.''' | + | |
|- | |- | ||
− | | 05 | + | | 05:32 |
− | |To that I can choose the ''' Step Into''' option from the toolbar. | + | |To do that, I can choose the ''' Step Into''' option from the toolbar. |
− | + | ||
|- | |- | ||
− | + | | 05:41 | |
− | | 05 | + | |Then I can choose the '''Step Over''' and see that the value came inside the '''constructor call''' is now set to 10. |
− | + | ||
− | |Then I can choose ''' Step Over''' and see that the value came inside the constructor call is now set to 10. | + | |
|- | |- | ||
− | + | | 05:51 | |
− | | 05 | + | | You can also check that by hovering over the variable. |
− | + | ||
− | | You can also check that by hovering | + | |
|- | |- | ||
− | + | | 05:55 | |
− | | 05 | + | |When I '''Step Over''' again, we can see that '''this.variable''' is also set to 10. |
− | + | ||
− | |When I Step Over again, we can see that '''this.variable''' is also set to 10. | + | |
− | + | ||
|- | |- | ||
− | + | | 06:03 | |
− | | 06 | + | |To get out of this function, I can either choose '''Continue, Step Over''' or '''Step Out.''' |
− | + | ||
− | |To get out of this function I can either choose '''Continue, Step Over or Step Out.''' | + | |
− | + | ||
|- | |- | ||
− | + | | 06:11 | |
− | | 06 | + | |
− | + | ||
|Let me choose '''Step-Out''' to come out of the method. | |Let me choose '''Step-Out''' to come out of the method. | ||
|- | |- | ||
− | + | | 06:14 | |
− | | 06 | + | |And, now I'm back to where the '''function call''' was made. |
− | + | ||
− | |And now I'm back to where the function call was made. | + | |
|- | |- | ||
− | + | | 06:19 | |
− | | 06 | + | |When I say '''Step-Over''' again, you will notice that '''aSample.value''' is now set to 10. |
− | + | ||
− | |When I say '''Step-Over''' again, you will notice that '''aSample.value''' is now set | + | |
|- | |- | ||
− | | 06 | + | | 06:27 |
|This is what we were watching for. | |This is what we were watching for. | ||
|- | |- | ||
− | + | | 06:30 | |
− | | 06 | + | | Apart from '''Breakpoint'''s and '''Step Over'''s, you can also stop the execution of the program at the line of the cursor. |
− | + | ||
− | | Apart from | + | |
|- | |- | ||
− | | 06 | + | | 06:38 |
|For example, let me go into the function here and set the cursor to be on this line which says d=b-5; . | |For example, let me go into the function here and set the cursor to be on this line which says d=b-5; . | ||
− | |||
|- | |- | ||
− | + | | 06:49 | |
− | | 06 | + | |Now, from the toolbar, choose the '''Run To Cursor''' option. |
− | + | ||
− | |Now from the toolbar, choose the '''Run To Cursor''' option. | + | |
|- | |- | ||
− | + | | 06:54 | |
− | | 06 | + | |
− | + | ||
|You will notice that the execution of the program gets into the function and stops at the line where the cursor is located. | |You will notice that the execution of the program gets into the function and stops at the line where the cursor is located. | ||
|- | |- | ||
− | + | | 07:05 | |
− | | 07 | + | |You can see that it has computed the value of '''b''' as 20. |
− | + | ||
− | |You can see that it has computed the value of b | + | |
|- | |- | ||
− | + | | 07:10 | |
− | | 07 | + | |And inside the '''Variable''' window, it has set '''b''' to be 20. |
− | + | ||
− | |And inside the | + | |
|- | |- | ||
− | + | | 07:14 | |
− | | 07 | + | |Now, I can choose '''Step Over''' again and 'd's value also gets initialized and becomes 15. |
− | + | ||
− | |Now, I can choose '''Step Over''' again and d's value also gets initialized and becomes 15. | + | |
|- | |- | ||
− | + | | 07:23 | |
− | | 07 | + | |
− | + | ||
|Now, I can either choose to return or completely finish the execution of the program. | |Now, I can either choose to return or completely finish the execution of the program. | ||
|- | |- | ||
− | + | | 07:29 | |
− | | 07 | + | |Let me choose '''Step Out''' and come back to the '''function call'''. |
− | + | ||
− | |Let me choose '''Step Out''' and come back to the function call. | + | |
− | + | ||
− | + | ||
|- | |- | ||
− | + | | 07:36 | |
− | | 07 | + | |
− | + | ||
|When you hover on the '''getC() '''function, you'll notice that the function has returned a value of 15. | |When you hover on the '''getC() '''function, you'll notice that the function has returned a value of 15. | ||
|- | |- | ||
− | + | | 07:43 | |
− | | 07 | + | |
− | + | ||
| The variable 'c' has not yet been assigned that value. | | The variable 'c' has not yet been assigned that value. | ||
|- | |- | ||
− | + | | 07:47 | |
− | | 07 | + | |So, when we '''Step Over''' and execute that line, '''c''' will get a value of 15. |
− | + | ||
− | |So, when we '''Step Over''' and execute that line, 'c' will get a value of 15. | + | |
− | + | ||
− | + | ||
|- | |- | ||
− | + | | 07:55 | |
− | | 07 | + | |We can now check it in the '''Variable''' window or hover on the variable to check it's value. |
− | + | ||
− | |We can now check it in the | + | |
|- | |- | ||
− | + | | 08:03 | |
− | | 08 | + | |Now, if you want to stop the debugging session, you can choose the '''Finish Debugger Session''' option from the toolbar. |
− | + | ||
− | |Now if you want to stop the | + | |
|- | |- | ||
− | + | | 08:12 | |
− | | 08 | + | |If you want to continue the execution to the next breakpoint, you can choose the '''Continue''' option. |
− | + | ||
− | |If you want to continue the execution to the next breakpoint you can choose the '''Continue''' option. | + | |
|- | |- | ||
− | + | | 08:19 | |
− | | 08 | + | |Once you finish, you can choose the '''Continue option''' to complete the execution of the remaining program. |
− | + | ||
− | |Once you finish, you can | + | |
|- | |- | ||
− | + | | 08:25 | |
− | | 08 | + | |
− | + | ||
|Let me choose '''Continue''' here. | |Let me choose '''Continue''' here. | ||
|- | |- | ||
− | + | | 08:27 | |
− | | 08 | + | |In the '''Output''' window, it shows me the output as: '''b''' is 20 and '''c''' is 15. |
− | + | ||
− | |In the Output window, it shows me the output as: ''' b '''is 20 and '''c''' is 15. | + | |
|- | |- | ||
− | + | | 08:34 | |
− | | 08 | + | |Now, this was a quick overview of the options of debugging on '''netbeans. ''' |
− | + | ||
− | |Now, this was a quick overview of the options of | + | |
− | + | ||
|- | |- | ||
− | + | | 08:39 | |
− | | 08 | + | |If you want any advanced feature settings, you can |
− | + | ||
− | |If you want any advanced feature settings, you can | + | |
− | + | ||
− | + | ||
|- | |- | ||
− | + | | 08:42 | |
− | | 08 | + | |go to '''Tools''' menu, click on '''Options'''. Go to the '''Miscellaneous''' option, click on the '''Java Debugger''' tab. |
− | + | ||
− | | | + | |
− | + | ||
− | + | ||
|- | |- | ||
+ | | 08:53 | ||
+ | |Here, you can change settings for multi-threaded program breakpoint options. | ||
− | |||
− | |||
− | |||
|- | |- | ||
− | + | | 08:59 | |
− | | 08 | + | |Or, have '''filters''' to decide on which methods you would want to step in. |
− | + | ||
− | |Or have filters to decide on which methods you would want to step in. | + | |
|- | |- | ||
− | | 09 | + | | 09:07 |
− | |Now to the assignment. | + | |Now, to the assignment.. |
|- | |- | ||
− | | 09 | + | | 09:09 |
|As an assignment, take any of your programs, excellent if it has already errors. | |As an assignment, take any of your programs, excellent if it has already errors. | ||
|- | |- | ||
− | | 09 | + | | 09:16 |
− | |If not, introduce some errors with the logic or algorithm. | + | |If not, introduce some errors with the '''logic''' or '''algorithm'''. |
|- | |- | ||
− | | 09 | + | | 09:20 |
− | |Set | + | |Set '''breakpoint'''s in the code. Usually, you would set a '''break''' at the calling point of a '''function''' which you suspect has the '''error'''. |
|- | |- | ||
− | + | | 09:29 | |
− | | 09 | + | |Use '''Step Into''' to go into the function. |
− | + | ||
− | |Use '''Step | + | |
|- | |- | ||
− | + | | 09:32 | |
− | | 09 | + | |Use '''Step Over'''s to '''execute''' the lines and make sure to inspect the values of variables in the '''Variable''' window. |
− | + | ||
− | |Use '''Step | + | |
− | + | ||
|- | |- | ||
− | + | | 09:41 | |
− | | 09 | + | |Add some '''watch'''es to help you identify and correct the '''error'''. |
− | + | ||
− | |Add some | + | |
− | + | ||
|- | |- | ||
− | + | | 09:45 | |
− | | 09 | + | |Step Out of the method. |
− | + | ||
− | |Step | + | |
|- | |- | ||
− | + | | 09:48 | |
− | | 09 | + | |
− | + | ||
|Continue till you reach the next breakpoint. | |Continue till you reach the next breakpoint. | ||
|- | |- | ||
+ | | 09:51 | ||
+ | |And finally, finish the '''debugger''' session and '''run''' your application. | ||
− | |||
− | |||
− | |||
|- | |- | ||
− | + | | 09:57 | |
− | | 09 | + | |In this tutorial, we became familiar with the '''Netbeans Debugger. ''' |
− | + | ||
− | |In this tutorial, we became familiar with the ''' | + | |
|- | |- | ||
− | + | | 10:02 | |
− | | 10 | + | |We saw how to set '''breakpoint'''s and '''watch'''es. |
− | + | ||
− | |We saw how to set | + | |
|- | |- | ||
− | + | | 10:06 | |
− | | 10 | + | |Add expressions which we want to evaluate while the code is running. |
− | + | ||
− | |Add expressions which we want to evaluate | + | |
|- | |- | ||
− | + | | 10:11 | |
− | | 10 | + | |Trace the execution of a program with '''Step-Into, Step-Over, Step-Out''' and '''Run-to-Cursor''' options. |
− | + | ||
− | |Trace execution of a program with '''Step-Into, Step-Over, Step-Out and Run-to-Cursor''' options. | + | |
|- | |- | ||
− | + | | 10:19 | |
− | | 10 | + | |Also, saw how to configure the '''debugger''' for advanced debugging. |
− | + | ||
− | |Also saw how to configure the '''debugger''' for advanced | + | |
|- | |- | ||
− | + | |10:24 | |
− | |10 | + | |Hope this tutorial saves you a lot of time in your testing and debugging tasks. |
− | + | ||
− | |Hope this tutorial saves you a lot of time in your testing and | + | |
− | + | ||
|- | |- | ||
− | + | |10:30 | |
− | |10 | + | |Watch the video available at the '''link''' shown on the screen. |
− | + | ||
− | |Watch the video available at the link shown on the screen. | + | |
|- | |- | ||
− | + | | 10:33 | |
− | | 10 | + | |
− | + | ||
|It summarizes the Spoken Tutorial project. | |It summarizes the Spoken Tutorial project. | ||
|- | |- | ||
− | + | |10:36 | |
− | |10 | + | |If you do not have good bandwidth, you can download and watch it. |
− | + | ||
− | |If you do not have good bandwidth, you can download and watch it | + | |
|- | |- | ||
− | + | | 10:41 | |
− | | 10 | + | |The Spoken Tutorial project team: * conducts workshops using Spoken Tutorials. |
− | + | ||
− | |The Spoken Tutorial project team | + | |
− | + | ||
|- | |- | ||
− | + | | 10:46 | |
− | | 10 | + | | Gives certificates to those who pass an online test. |
− | + | ||
− | |Gives certificates to those who pass an online test. | + | |
− | + | ||
|- | |- | ||
− | + | | 10:49 | |
− | | 10 | + | |For more details, contact:'''contact@spoken-tutorial.org''' |
− | + | ||
− | |For more details contact contact@spoken-tutorial.org | + | |
− | + | ||
|- | |- | ||
− | + | | 10:55 | |
− | | 10 | + | |'''Spoken Tutorial''' project is a part of the '''Talk to a Teacher''' project. |
− | + | ||
− | |Spoken Tutorial | + | |
|- | |- | ||
− | + | | 10:59 | |
− | | 10 | + | | It is Supported by the National Mission on education through ICT, MHRD, Government of India. |
− | + | ||
− | | It is Supported by the National Mission on education through ICT, MHRD, Government of India | + | |
|- | |- | ||
− | + | | 11:05 | |
− | | 11 | + | |More information on this mission is available at:'''spoken-tutorial.org/NMEICT-Intro'''. |
− | + | ||
− | |More information on this mission is available at spoken-tutorial.org/NMEICT-Intro | + | |
|- | |- | ||
− | + | | 11:14 | |
− | | 11 | + | |This tutorial has been contributed by '''IT for Change'''. |
− | + | ||
− | |This tutorial has been contributed by | + | |
− | + | ||
|- | |- | ||
− | + | | 11:18 | |
− | | 11 | + | |
− | + | ||
|Thank you for joining us. | |Thank you for joining us. |
Latest revision as of 20:06, 10 September 2018
Time | Narration |
00:01 | Hello everyone.Welcome to the tutorial on Netbeans Debugger. |
00:06 | If this is the first time you are using Netbeans, please view the earlier tutorials on the Spoken Tutorial website. |
00:14 | For this demonstration, I am using the Linux Operating System Ubuntu version 12.04 |
00:21 | and Netbeans IDE version 7.1.1. |
00:26 | We all know that debugging programs can be a rather painstaking task. |
00:31 | Hence, knowing a debugging tool and being familiar with its features can help you save valuable time. |
00:39 | This powerful debugging tool is very useful, |
00:42 | especially when you have to code or test large programs. |
00:46 | In this tutorial, we will learn some of the features that the Netbeans Debugger provides. |
00:53 | This tutorial will acquaint you with- |
00:55 | the debugging window |
00:58 | configuring breakpoints |
01:00 | evaluating expressions or setting watches |
01:04 | options for tracing the execution of your program and |
01:07 | options to configure the debugger itself. |
01:12 | Now, Let's get started and debug this sample code. |
01:17 | I will switch to the Netbeans IDE. |
01:20 | I have already created a Java Application- sampleDebug, in my IDE, for this demonstration. |
01:27 | This is a small program that initializes three integer values a, b, and c. |
01:35 | Then it prints "Hello World!" and the value of a. |
01:40 | It also creates a class object SampleClass which has a 'value' integer, as a private integer value. |
01:52 | Then, it computes the value of b |
01:55 | and calls a function to compute the value of c, |
02:00 | and prints the values of b and c. |
02:05 | To start with the debugging, let us first set the break-point. |
02:09 | To set a break point, click on the line number. |
02:13 | I will set it at this line which prints "Hello World!". |
02:18 | Notice that the line at which a break-point is set, changes it's colour to pink and is marked by a small square against its line number. |
02:28 | When you run the program in the debugging mode, |
02:31 | by clicking on the Debug Project button in the toolbar, |
02:35 | the execution of the program stops at the line at which the breakpoint is located. |
02:41 | So far, as value has been set. |
02:45 | Hover on it to check it's value. |
02:49 | It indicates that it's value is 10. |
02:52 | You can see that there are some additional windows below the workspace. |
02:59 | There is a 'Variables' window that shows a list of variables and their values. |
03:07 | So far, only the variable a has been initialized. |
03:11 | We can also look at the Output window with the sampleDebug output. |
03:17 | There is no output yet. |
03:19 | There is also a Debugger Console that says that the program hit a breakpoint on line 29 and has stopped there. |
03:28 | There is also a Breakpoints window that tells you that a breakpoint has been set on line number 29. |
03:36 | Before proceeding, let us see how to add a watch. |
03:40 | For example, let us say, I want to watch on the integer value 'aSample'. |
03:48 | In the 'Variables' window, below the workspace, I will double-click on the Enter new Watch option and enter the name of the variable "aSample.value". |
04:02 | Click on OK. |
04:06 | So far, aSample has not been created. So, it says it does not know the value. |
04:12 | Once it executes the line, we'll know what the variable contains. |
04:16 | In a similar way, you can also watch and evaluate expressions. |
04:21 | Here, I'm checking for b=a+10. |
04:25 | What if I wanted to know what a-4 is. |
04:29 | So, let me go to the Debug menu in the menu bar and select Evaluate expression option. |
04:37 | The 'Evaluate Code' window appears in the workspace. |
04:41 | Here, I will enter the expression a-4. |
04:45 | Click on the Evaluate Expression button here and in the Variable window, it says (a-4)'s value is 6. |
04:56 | Let us now proceed and execute this single line of code. |
05:00 | To do that, choose the Step-Over button from the toolbar. |
05:06 | That should execute only that 1 single line of the code to print “Hello World”. |
05:12 | To see the output, go to the output window and choose the sampleDebug output window |
05:17 | that says, "Hello World! 'a' is 10". |
05:22 | The program has now stopped at the line to create a SampleClass object. |
05:28 | Now, I want to go into the constructor of the SampleClass. |
05:32 | To do that, I can choose the Step Into option from the toolbar. |
05:41 | Then I can choose the Step Over and see that the value came inside the constructor call is now set to 10. |
05:51 | You can also check that by hovering over the variable. |
05:55 | When I Step Over again, we can see that this.variable is also set to 10. |
06:03 | To get out of this function, I can either choose Continue, Step Over or Step Out. |
06:11 | Let me choose Step-Out to come out of the method. |
06:14 | And, now I'm back to where the function call was made. |
06:19 | When I say Step-Over again, you will notice that aSample.value is now set to 10. |
06:27 | This is what we were watching for. |
06:30 | Apart from Breakpoints and Step Overs, you can also stop the execution of the program at the line of the cursor. |
06:38 | For example, let me go into the function here and set the cursor to be on this line which says d=b-5; . |
06:49 | Now, from the toolbar, choose the Run To Cursor option. |
06:54 | You will notice that the execution of the program gets into the function and stops at the line where the cursor is located. |
07:05 | You can see that it has computed the value of b as 20. |
07:10 | And inside the Variable window, it has set b to be 20. |
07:14 | Now, I can choose Step Over again and 'd's value also gets initialized and becomes 15. |
07:23 | Now, I can either choose to return or completely finish the execution of the program. |
07:29 | Let me choose Step Out and come back to the function call. |
07:36 | When you hover on the getC() function, you'll notice that the function has returned a value of 15. |
07:43 | The variable 'c' has not yet been assigned that value. |
07:47 | So, when we Step Over and execute that line, c will get a value of 15. |
07:55 | We can now check it in the Variable window or hover on the variable to check it's value. |
08:03 | Now, if you want to stop the debugging session, you can choose the Finish Debugger Session option from the toolbar. |
08:12 | If you want to continue the execution to the next breakpoint, you can choose the Continue option. |
08:19 | Once you finish, you can choose the Continue option to complete the execution of the remaining program. |
08:25 | Let me choose Continue here. |
08:27 | In the Output window, it shows me the output as: b is 20 and c is 15. |
08:34 | Now, this was a quick overview of the options of debugging on netbeans. |
08:39 | If you want any advanced feature settings, you can |
08:42 | go to Tools menu, click on Options. Go to the Miscellaneous option, click on the Java Debugger tab. |
08:53 | Here, you can change settings for multi-threaded program breakpoint options. |
08:59 | Or, have filters to decide on which methods you would want to step in. |
09:07 | Now, to the assignment.. |
09:09 | As an assignment, take any of your programs, excellent if it has already errors. |
09:16 | If not, introduce some errors with the logic or algorithm. |
09:20 | Set breakpoints in the code. Usually, you would set a break at the calling point of a function which you suspect has the error. |
09:29 | Use Step Into to go into the function. |
09:32 | Use Step Overs to execute the lines and make sure to inspect the values of variables in the Variable window. |
09:41 | Add some watches to help you identify and correct the error. |
09:45 | Step Out of the method. |
09:48 | Continue till you reach the next breakpoint. |
09:51 | And finally, finish the debugger session and run your application. |
09:57 | In this tutorial, we became familiar with the Netbeans Debugger. |
10:02 | We saw how to set breakpoints and watches. |
10:06 | Add expressions which we want to evaluate while the code is running. |
10:11 | Trace the execution of a program with Step-Into, Step-Over, Step-Out and Run-to-Cursor options. |
10:19 | Also, saw how to configure the debugger for advanced debugging. |
10:24 | Hope this tutorial saves you a lot of time in your testing and debugging tasks. |
10:30 | Watch the video available at the link shown on the screen. |
10:33 | It summarizes the Spoken Tutorial project. |
10:36 | If you do not have good bandwidth, you can download and watch it. |
10:41 | The Spoken Tutorial project team: * conducts workshops using Spoken Tutorials. |
10:46 | Gives certificates to those who pass an online test. |
10:49 | For more details, contact:contact@spoken-tutorial.org |
10:55 | Spoken Tutorial project is a part of the Talk to a Teacher project. |
10:59 | It is Supported by the National Mission on education through ICT, MHRD, Government of India. |
11:05 | More information on this mission is available at:spoken-tutorial.org/NMEICT-Intro. |
11:14 | This tutorial has been contributed by IT for Change. |
11:18 | Thank you for joining us. |