Difference between revisions of "Netbeans/C2/Netbeans-Debugger/English-timed"
From Script | Spoken-Tutorial
Sandhya.np14 (Talk | contribs) |
|||
Line 1: | Line 1: | ||
{| Border=1 | {| Border=1 | ||
− | |||
|| '''Time''' | || '''Time''' | ||
|| '''Narration''' | || '''Narration''' | ||
Line 78: | Line 77: | ||
|- | |- | ||
|01:20 | |01:20 | ||
− | |I have already created a Java Application- | + | |I have already created a Java Application- '''sampleDebug''', in my IDE, for this demonstration. |
|- | |- | ||
|01:27 | |01:27 | ||
− | |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:35 | |01:35 | ||
− | |Then it prints "Hello World!" and the value of 'a'. | + | |Then it prints "'''Hello World!'''" and the value of '''a'''. |
|- | |- | ||
|01:40 | |01:40 | ||
− | |It also creates a '''class''' object | + | |It also creates a '''class''' object '''SampleClass''' which has a 'value' integer, as a '''private''' integer value. |
|- | |- | ||
|01:52 | |01:52 | ||
− | |Then, it computes the value of 'b' | + | |Then, it computes the value of '''b''' |
|- | |- | ||
|01:55 | |01:55 | ||
− | | and calls a '''function''' to compute the value of 'c', | + | | and calls a '''function''' to compute the value of '''c''', |
|- | |- | ||
| 02:00 | | 02:00 | ||
− | |and prints the values of 'b' and 'c'. | + | |and prints the values of '''b''' and '''c'''. |
|- | |- | ||
Line 114: | Line 113: | ||
|- | |- | ||
| 02:13 | | 02:13 | ||
− | |I will set it at this line which prints "Hello World!". | + | |I will set it at this line which prints "'''Hello World!'''". |
|- | |- | ||
Line 134: | Line 133: | ||
|- | |- | ||
|02:41 | |02:41 | ||
− | |So far, 'a's value has been set. | + | |So far, '''a'''s value has been set. |
|- | |- | ||
Line 154: | Line 153: | ||
|- | |- | ||
| 03:07 | | 03:07 | ||
− | |So far, only the variable 'a' has been initialized. | + | |So far, only the variable '''a''' has been initialized. |
|- | |- | ||
Line 190: | Line 189: | ||
|- | |- | ||
| 04:06 | | 04:06 | ||
− | |So far, 'aSample' has not been created. So, it says it does not know the value. | + | |So far, '''aSample''' has not been created. So, it says it does not know the value. |
|- | |- | ||
Line 206: | Line 205: | ||
|- | |- | ||
| 04:25 | | 04:25 | ||
− | |What if I wanted to know what 'a-4' is. | + | |What if I wanted to know what '''a-4''' is. |
|- | |- | ||
Line 218: | Line 217: | ||
|- | |- | ||
| 04:41 | | 04:41 | ||
− | |Here, I will enter the expression 'a-4'. | + | |Here, I will enter the expression '''a-4'''. |
|- | |- | ||
Line 234: | Line 233: | ||
|- | |- | ||
| 05:06 | | 05:06 | ||
− | |That should execute only that 1 single line of the code to print | + | |That should execute only that 1 single line of the code to print “'''Hello World'''”. |
|- | |- | ||
Line 306: | Line 305: | ||
|- | |- | ||
| 07:05 | | 07:05 | ||
− | |You can see that it has computed the value of 'b' as 20. | + | |You can see that it has computed the value of '''b''' as 20. |
|- | |- | ||
| 07:10 | | 07:10 | ||
− | |And inside the '''Variable''' window, it has set 'b' to be 20. | + | |And inside the '''Variable''' window, it has set '''b''' to be 20. |
|- | |- | ||
Line 334: | Line 333: | ||
|- | |- | ||
| 07:47 | | 07:47 | ||
− | |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. |
|- | |- | ||
Line 358: | Line 357: | ||
|- | |- | ||
| 08:27 | | 08:27 | ||
− | |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. |
|- | |- | ||
Line 378: | Line 377: | ||
|- | |- | ||
| 08:59 | | 08:59 | ||
− | |Or, have ''' | + | |Or, have '''filters''' to decide on which methods you would want to step in. |
|- | |- | ||
Line 466: | Line 465: | ||
|- | |- | ||
| 10:49 | | 10:49 | ||
− | |For more details, contact: | + | |For more details, contact:'''contact@spoken-tutorial.org''' |
− | '''contact@spoken-tutorial.org''' | + | |
|- | |- | ||
Line 479: | Line 477: | ||
|- | |- | ||
| 11:05 | | 11:05 | ||
− | |More information on this mission is available at: | + | |More information on this mission is available at:'''spoken-tutorial.org/NMEICT-Intro'''. |
− | '''spoken-tutorial.org/NMEICT-Intro'''. | + | |
|- | |- |
Revision as of 12:11, 5 January 2017
Time | Narration |
00:01 | Hello everyone. |
00:02 | 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:17 | * 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 sample debug 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. |