 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you how you can handle array index out of bounds exception in Java. Before starting, you can subscribe my YouTube channel by clicking on the link which is available at bottom right corner of this video. You can download my app TechMS that is available on Google Play. You can connect with me by following these details which are available in front of you. Now, coming on to the topic. To understand the concept, I have implemented this code in front of you. Here, name of classes test which is containing main method. Inside main method, an array is initialized which is having five elements. Then I variable is declared. Inside try block, a message, system.out.println, array contains. So this instruction will display array contains message on console. While this code will be executing, then this loop will print values of AO5 on console. Right now, this loop is repeating five times from zero to four. If any exception occurs in this try block control will be transferred to catch block and catch block is handling array index out of bound exception. And here a message array index out of bound is written in system.out.println. After try and catch block, this general statement println end of program is written. If exception is available, then also this end of program will print. If exception is not available, then also it will display. If exception is available, then this code will be terminated and control will be transferred to catch. If there is no exception, then control from try will be transferred to directly this system.out.println end of program. So right now, loop is repeating five times. So no exception will be generated. So we can check this by executing this code. You can see that array contains one, two, three, four, five. These five values are printed properly and then end of program is displayed. Now, this time loop is repeating 15 times, sorry, 10 times and size of array is five. It means we are trying to access values which are out of bound of this array. So again, I am executing this code. You can see the output one, two, three, four, five has been displayed properly. But when this code is trying to access sixth location, which is not available, which is not the part of this array. So then an exception has generated and control is transferred to catch log. So catch has displayed array index out of bound. After catch execution control has been transferred to the statements which are available just after the catch log. That's why end of program message has been printed. So friends, I hope with the help of this code, you have understood the use of exception handling. If any error message available in the code, then also it is handled with try and catch and that piece of code is terminated. But remaining code is executed properly. Here in this example, this single statement is treated as remaining code. You can write many many instructions after the catch block and those all instructions will be executed properly. If we have not implemented try and catch, then this end of program will not be printed because we have not handled the exception. So you can see that if I remove this try and catch block. And if I execute the code right now, you can see that an exception conditions condition has occurred here, which is showing an error message. And end of program is not displayed. Only five elements are displayed when we are trying to access sixth location exception has generated. And it is handled by the JVM. So friends, if you want to handle exceptions using try and catch, you can do so. So that a piece of code is terminated and remaining code is executed properly. I hope you have understood the concept well. If you want to watch more programming related videos, you can subscribe my YouTube channel. Thank you for watching this video.