Eclipse Debugging Techniques And Tricks:Step Over,Step Into and Step Return

Eclipse Debugging Techniques And Tricks:Step Over,Step Into and Step Return

Articles , , , , , , , , 6 Comments

hi in this session we are going to discuss controlling of the program execution during debugging which includes the use of step over step into and step return features so let's go to eclipse open a sample program for debugging called debug person dot java if you have a look at debug person it is a sample program with the main method and the main method has full lines of code line number 11 shows a list of person objects that his personal list is retrieved from a utility class called data you read and here a method called get person data of data utility is called now once that list object of persons is retrieved it is printed at line number 12 similarly at line number 13 a person map which contains integer object as keys and person objects as values that person map is retrieved from data into classes another method called get person map and in the next line that is line number 14 the particular map object is printed so overall what we can see it's a pretty simple main method where one list object is retrieved from an util class that is printed and another map object is retrieved from another util class and that is printed in the next line let's have a brief look into the into this methods like get person data and get person map one by one so let's first go to get person data in the data you tilt glass so inside get person data method as we can see over here in line number 27 a person object is created with a constructor or person object and we're three parameter is passed and similarly multiple person objects are created at say line number 28 30 31 32 etc and finally a person list I mean a list object of persons is created at line number 35 and all this person objects which are created earlier on are added to this person list and finally this list is returned so gate person data is a method which creates different person objects and adds those person objects inside a list and finally it returns that particular list now similarly another method get' person map let's have a look into it so get person map we have a look at line number 46 here also a new person object is created using new person Steve forty us etc so in line number 46 and line number 47 we can see two new person objects are created and at line number 48 a map hash map is created with its type key type as integer and value type as person now this map object is populated with this two person objects created at line number 46 and 47 and key as one and two are inserted inside that person map object and finally the map is returned so gay person map is a simple method which creates two person objects populates a map with integer keys and those person objects as values and finally returns the person map to have a further clarity just have a brief look at the person object the constructor itself because person object is used in both methods get person map and get person data so let's go to the person object now person object is a simple puja class where we have a name age and country as the field and one public constructor where these three parameters are assigned so that's it now if I want to debug let me close other programs if I want to debug this particular program certain certain utilities certain features of debugging can be used and I want to show the use of those utilities now let me first put breakpoint at certain lines say at line number 12 and maybe at line number 40 now let's run this program in debug mode so what we can do is right-click debug as java application now as we can see over here is that the first breakpoint at line of a 12 is hit and the programming is paused at line number 12 which means the first line number 11 is a already executed and person list objects should be populated so in the variables view we can see yes we have a person list object and if I select person list it shows the elements inside person list now how to control the flow of the program from here earlier we learned the use of resume and terminate now we need to use the I mean we need to understand the use of this free button step into step over and step return now I would start with step over because this is the simpler one among this three so what step over does first let me explain I mean let me mention step over has a shortcut key of f6 so you can use that shortcut key as well now what step over does is suppose you have a program like we have here and a particular brick point is hit now if you press step over then what would happen the particular line where the program is paused that line would get executed and the program would pause at the next line so here if I press step over this particular line with system dot out dot println would get executed means that the console would show this person list and the program would be pausing at the next line that is line number thirteen so let me press step over once as you can see what has happened this particular system dot out dot println with person list has got executed and the program is pausing at line number 30 so this is the use of step over now let me explain what is the use of step into and once I explain step into I can explain step return as well because step into and step return are related to each other as you can see over here step into has the shortcut of f5 so you can use a five as well instead of pressing this button using your mouse now if we focus at line number 13 can see that here data util dot get person map is going to be executed now if I want to go inside data util dot get person map during debugging I can press step into in that case the debugging control would shift into this particular method now we can do one thing we can directly go to get person map so let me control click on this particular method and we can place some some breakpoints over here as well and if we press f8 from the main program the corner the power flowed stop over here but if you don't want to place any new breakpoints and we want to still go inside this gate person map and pause over there then step into method becomes handy so if I press step into now the program flowed start executing and it would move into this particular method and pause over there so let me press step into once as you can see over here we are inside this get person map method and the program has pause here and we can execute the lines one by one using the old mayor step over as well another thing we can do if we want to go back to where we where that is if we want to go back to debug person dot Java in that case we can use step return if you have a look at the top step return is right now enabled now if we press step return it would go back earlier as you would have noticed it was disabled because we were not inside a particular method from where we could have returned so right now is enabled and if we click the control would go back to the program which invoked this method so let me press step return now the method has been executed and the control has come back now what we can do over here we can you move to the next line using step over and as you can see the step return is disabled here okay so let's do step over once again and let's click step over once again and see what is the final output so that's it so we can finish the session using resume so in this session what we have learned is the usage of this three basic buttons like step in to step over and step returned this three are very important whenever we do any sort of divine

6 thoughts on “Eclipse Debugging Techniques And Tricks:Step Over,Step Into and Step Return

Leave a Reply

Your email address will not be published. Required fields are marked *