Using the IntelliJ debugger with step into and step over

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this video is going to be the first in a series of videos where we take a look at the tools available to us with intellij for debugging our application so the debugging tools provide us with the capability to run our program step by step and to look at the different local variables and method calls as they're made by the application with a good sense of control so if we quickly take a look at the code we'll be running we have a class called player which has a name and age which are string and integers we instantiate 11 different players of different ages and then add them to a list called squad we use this method call to understand the total age of all the players within that squad and then we perform a calculation to work out the average age within that squad and then at the end we print that average age so i'm just going to run the application so we can see what the result is we can see that it's 26 so we're able to run the debugger by selecting this bug icon at the top right of your screen within intellij alternatively wherever you see this sort of green play button on the left hand side you can select it and then hit the debug choice now the difference between running the application normally and running it through the debugger is that the debugger will pause at a certain point known as a breakpoint where we can then begin running the application manually ourselves line by line to understand what our application is actually doing so the first point i'm going to do is add a break point and a break point can be added by selecting to the left of the line where we would like our application to pause and this will automatically add a breakpoint which is a red circle and a red line so the application has paused where we're defining this integer called accumulative age of squad and that is defined by passing in the squad itself to this method called calculate player list total age [Music] so if you want to take a look at how this calculate player list total age method actually works we can use the step into method or use the shortcut of f7 so this step into method will dive straight into that method call and it looks like a downward pointing blue arrow within this debugger console at the bottom of the screen [Music] so by selecting the step into method we've now actually come to this calculate player list total age method and the very first line so the first line is just a system out print line where we're printing the size of the squad to the console and then next we can see that there's a stream where each player is mapped to an integer which is obtained by using their getage method and then the sum of all these values are returned from that method call so you can skip over this line for the system out print line and go straight to this stream by using the step over within the debugger console and the step over is a blue pointed arrow down to the bottom right that we can see here so by using the step over we've executed this line of code above the system out print line and we can see that within the console and now we're able to dive into this stream which is actually calculating the total wage for that squad so once more we can use the step into method to step into either of these calls so we can step into the stream to understand how the stream works and we can see the implementation of the stream and then if we want to return back to that stream we can use the step out button within the debugger console once more we can step into the further methods within this method such as the map to int so i'm going to highlight over map to int and i'm going to hit step into and then we can see the implementation code for map to int and equally we can step over these lines of code to see more about the mapped in method or we can step out of it completely and return back to the calculate player list total age and lastly we can step into this player.getage method so we can understand how this getage method works so i've highlighted it once more and now i can click step into i'm just going to step out of this method and by hitting the step over method we'll now complete this method and return the integer from this line of code back to our main method call so we've returned back to the main method call where we've defined this accumulated age of squad and by stepping over this method once more we will be able to see the actual value assigned to the accumulative age of squad so quite conveniently on the bottom right here as different objects are created by our application and as different local variables are defined they will appear here in this variable section underneath so we've defined 11 different players and we can dive into them a little bit more so we can see that the name is jordan and 27 player 6 is calvin who's 25 player 10 is harry who's 27 and we can also see that this accumulated age of squad is 286. [Music] the current line that we're executing which is line 26 is called squad size and that will be equal to the size of our list which is called squad so if i step over this method we can now see in the bottom right we have a variable called squad size which is equal to 11. [Music] the next step we have is defining the average age and the average age is computed by using this divide two numbers method and by passing in the cumulative age of the squad and the squad size so if we want to understand how the divide two numbers method works we can simply step into it and we can see the numerator divided by the denominator is the implementation for this method once more if i step over we should be able to return the double value from the divide two numbers method back to our main method and once more if i step over again that average age should now be computed below and we can see that it's defined as 26. so if we were running this application and we wanted to understand how has that age of 26 actually come about we can see that the accumulated age of the squad is 286 the size of the squad is 11 and this divide two numbers method will divide 286 by 11 to return 26. [Music] so to complete this application i'm just going to step over from this last method and that's the end of this main application and we can see that the number 26 is once again printed to our console
Info
Channel: Aneesh Mistry
Views: 4,045
Rating: undefined out of 5
Keywords: Software Engineering, Software Development, IntelliJ, Java, Debugger, Aneesh Mistry Tutorial, Aneesh Tutorial, Aneesh Mistry, Java 8, Software Tutorial, Software Engineer, Mockito Tutorial, Junit Tutorial, Backend Engineer, How to test software, Test Automation, testing software, beginner software engineer, learn to code, learning to code, step by step tutorial, Step into, step over, IntelliJ Tutorial, JetBrains, Debugging, Debug, Software review
Id: JnTfQCjq9xM
Channel Id: undefined
Length: 7min 55sec (475 seconds)
Published: Mon Jul 05 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.