 welcome back friends I hope everyone is doing great and in this video this is the second part like we have already shared one of first part of java interview question and answers so this is especially for experienced people like what kind of questions they will encounter and these questions that I am going to share you right now will be definitely you will encounter in almost all your interview questions almost all interview processes so let us start first question this is not the second part first question what will happen if an exception is thrown from the finally block so what will happen so if an exception is thrown from the finally block like if at all we are not handling from that the program will exit or is the exception propagates out and up and will be handled at the higher level finally block will not be computed beyond the point where the exception is thrown if the finally block was executing during the handling of an earlier exception then the first exception is lost this is one important point you need to know like if at all there is try catch and finally in the try block there suppose there was one exception that got raised saying suppose a exception goes raised and in the finally block when you were executing some when you were closing something b exception got raised so now when you throw an exception like when the exception gets traversed the a exception will be suppressed here and the b exception will traverse back so that is one important point that needs to be noted down here next question is what is it better to use hibernate or any jrm or m then jdbc for database interaction in various java application like why it is you know easy or why it is better to use hibernate or any or m in that perspective over jdbc so what the benefit that we get using hibernate so hibernate is or any other or m or m framework pro is object oriented view of the database by mapping the various classes to the database tables this this helps in thinking in terms of object oriented language then in rdbms terms and hence increases productivity so basically here we just need to concentrate on the our own logic and not on the right not on writing the coding part just we need to take care of the correct mapping and everything will work fine so like irrespective of the db that we are using any or m framework will generate is respective db queries and will execute that is the best fit that we get of over m framework next question is what is the purpose of intern method in string class this is one of the important interview question like especially for the people of two to four years of experience range so like most of the time this is this question is asked for them so java string intern method is used for getting the string from the memory if it is already present this method ensures that all the same string shares the same memory for example create a string hello 10 times using intern method would ensure that there will be only one instance of hello in the memory and all the 10 references point to the same instance so basically this is the answer for this so and this is one of the important question as well next question is can we declare constructor as private if yes where you can use it in your application or project so yes we can declare constructor as private especially like whenever i face this interview currently at that time what the scenario that strikes the mind is singleton so in singleton we have private constructor and using the get instant static method we initialize that constructor so coming to a scenario where i have used construct that is we were asked to create a service and that service was was to be a singleton class so in that scenario we have used a private constructor can you make a constructor final one of the tricky interview question i would say this is for any experience like private definitely we can do can we do a final like firstly what is final we need to understand it so final basically we cannot subclass it we cannot override final methods final constants we cannot change so constructor coming to construct it so overriding thing comes into picture when we are extending the class so even if we are extending a class constructor doesn't get inherited so even if you write final that is of no use so java will not allow us to write a final so that we cannot have a final keyword in with constructor like final and constructor cannot go hand in hand it is a compile time exception itself like modifier final is not allowed will be the exception that will be throwing by the idea next question what is the use of transient keyword this is one of the important question i would say again and one of the important keyword as well because using transient keyword we will restrict few variables from getting from taking part from serialization so if at all you want to restrict some what i what i can say variables not to take part in the serialization thing so we need to use transient keyword with that variable so like basically there are scenarios like where we where it is unethical to serialize some specific data like if you take in a healthcare industry ph there is something about personal health information data that you cannot serialize in that scenario so what all things like we can use this transient keyword and we can stop those values from getting serialized next question is what will happen if you call return statement or system.exe can try your cache block will finally block execute or one more interview tricky interview question or like i used to get confused a lot of time in the yesterday so basically when you do system.exe finally block won't get executed and if you are returning a statement if you are retaining something from the try block then finally block will definitely get executed so in java the finally block will execute even if you put return statement in try block or cache block but finally block won't return if you call system.exe from try or cache block so that is the answer next question is why is thread drop stop deprecated this is important question again i would say like to know whether you understand things or how deep you understand trending multi-threading this question will be asked yes this is a deprecated method but why because it is inherent inherently unsafe stopping a thread cost is causes it to unlock all the monitors that it has locked if any of the object previously protected by this monitors where in the inconsistent state other threads may now view this objects in an inconsistent state such as objects are said to be damaged such objects are said to be damaged and when threads operate and on damaged objects arbitrary behavior can result this viewer may be it will be stable and difficult to detect thread death exception kills thread silently the user has no warning that what program may be corrected so that is the issue with thread dot stop method coming to the next question what is the difference between class dot for name and class dot for name dot new instance method so let us take one example and explain this so basically when we do if we see the example i've taken a demo class there is a constructor there is a main method and inside the main method first one is class dot for name of demo which returns a class of time and then again class dot new instance we are typecasting it to demo class so this is the explanation is here here is like class dot for name returns the class object associated with the class or interface with the given string name then calling class dot like new instance creates a new instance of the class represented by the class object this is this class is instant instantiated as if we as if we are getting new keyword and we are creating an object that is the same thing that happens here one more important question that is what is the different bit plane heap and stack this is one of the important interview questions for irrespective of your experience so here are few lists that i could find it out so heap is used to store objects like objects created anyway in the class inside method or any in any block of code so those are stored in heap only exception is that string literals which are stored mainly in the perm gem area until like java 7 they used to get stored there so stack space is used to store local variables methods frames and concepts heap space in java is much bigger than stacks obviously heap space is shared by thread differences but each thread has its own own stack space again and any local variables created in the thread are not visible to other threads we can resize heap space using the command hyphen capital xms and hyphen xmx to specify the start and maximum heap memory in java similarly we can use hyphen access to specify stack size of individual threads in jvm order like in there is no order that gets maintained in the heap but stack follows leave for like last in first out order that is why when we can use recursion in java like in java like in federal heap gets filled we get a heap out of memory error exception when stack gets filled we get stack overflow exception or error sorry coming to the next question this is the last question so this is the last question i hope you like this video so please do like provide your feedback there are a few other questions that we'll be sharing as part of the other video so as this the video is getting long so you are immediately going to watch and be just