Exception Handling Interview questions and answers in Java | Part -1 | Code Decode
In this video of code decode we have covered all important Exception Handling Interview questions in Java for freshers and experienced
Udemy Course of Code Decode on Microservice k8s AWS CICD link:
openinapp.co/udemycourse
Course Description Video :
yt.openinapp.co/dmjvd
Exception Handling part 2 : • Exception handling Int...
Q) What is an exception?
The exception is an abnormal condition that occurs during the execution of a program and disrupts the normal flow of the program. If not handled properly it can cause the program to terminate abruptly.
Q) How do we handle exceptions in Java
Try
Encloses set of statements which can throw exception hence are required to be monitored.
Catch
When exception occur, this block catches that exception and work accordingly to handle it or to throw it as required.
Finally
This block gets executed always regardless of exception occurrence. Hence clean up is done here.
Q) Difference between Exception VS Error
Exception
We can recover from exception using try catch block or using throw
Compiler will have knowledge about checked Exceptions hence Compiler will force you to use try-catch blocks
Exceptions are related to application
Exceptions include both checked as well as unchecked type.
Exceptions in java are of type java.lang.Exception.
Error
Recovering from Error is not possible
Compiler will not have any knowledge about unchecked exceptions and Errors
Errors are related to environment where application is running
All errors in java are unchecked type
Errors in java are of type java.lang.Error.
Q) Can we write only try block without catch and finally blocks?
No. either catch or finally is must.
if no then what error will come?
Answer : compile time error saying “insert finally to complete try statement” like this:
Q) Can we write any other statements between try catch or finally block?
No. Try must be followed directly by either catch or finally.
Q) Does remaining statements in try block executes after exception occurs.
No. if exception occurs at a particular point in try block then all statements after that statement where exception is occurred will not be execute and the flow goes directly to either catch block if there is any or else program terminates. Hence we need finally block to do all clean up like closing files or removing locks.
Q) What Is the Difference Between Throw and Throws Keywords in Exception Handling in java?.
Throw
Java throw keyword is used to explicitly throw an exception.
Checked exception cannot be propagated using throw only.
Throw is used within the method.
You cannot throw multiple exceptions.
Throws
Java throws keyword is used to
declare an exception.
Checked exception can be propagated with throws.
Throws is used with the method signature.
You can declare multiple exceptions.
Q) What Happens When an Exception Is Thrown by the Main Method?
When an exception is thrown by main() method, Java Runtime terminates the program and prints the exception message and the stack trace in-system console.
Q) What do you understand by unreachable catch block error.
This error comes when you keep super classes first and sub classes later. Like here We kept Exception which is parent of NullPointer Exception first.
Hence the order of catch blocks must be from most specific to most general ones.
-------------------------------------------------------------------------------------------------------------------------------------
Code Decode Playlists
Most Asked Core Java Interview Questions and Answers : • Core Java frequently a...
Advance Java Interview Questions and Answers : • Advance Java Interview...
Java 8 Interview Questions and Answers : • Java 8 Interview Quest...
Hibernate Interview Questions and Answers : • Hibernate Interview Qu...
Spring Boot Interview Questions and Answers : • Advance Java Interview...
Angular Playlist : • Angular Course Introdu...
GIT : • GIT
-------------------------------------------------------------------------------------------------------------------------------------
Subscriber and Follow Code Decode
Subscriber Code Decode : kzread.info?...
Linkedin : / codedecodeyoutube
Instagram : / codedecode25
--------------------------------------------------------------------------------------------------------------------------------------
#ExceptionHandlingInterviewQuestionsInJava
#ExceptionHandlingHandlingInterviewQuestionsForExperiencedInJava
#javainterviewquestionsandanswers #codedecode
Пікірлер: 268
Java 7 and beyond, try with resources allows to skip writing the catch as well as finally and closes all the resources being used in try-block itself. Any object that implements java.lang.AutoCloseable, which includes all objects which implement java.io.Closeable, can be used as a resource. See this code example static String readFirstLineFromFile(String path) throws IOException { try (BufferedReader br = new BufferedReader(new FileReader(path))) { return br.readLine(); } }
Great content...Upto the point.... Looking for many more to come on the channel 👏
@CodeDecode
3 жыл бұрын
Thanks Rishika for the nice words....
Your explanation is amazing...to the point...understandable...keep making such videos...😊
@CodeDecode
2 жыл бұрын
Thanks a lot Sandhya 🙂👍
great explanation cleared all the doubt and also gained confidence
@CodeDecode
8 ай бұрын
thanks
Thanks for sharing.
Thank you ma'am, was waiting for this video...
@CodeDecode
3 жыл бұрын
Hope it helps :)
Your explanation is really very helpful ❤️ Thank you so much
@CodeDecode
3 жыл бұрын
Thanks 👍👍
Outstanding work done... Watching all your videos for learning. Expecting more soon.. Good Job
@CodeDecode
3 жыл бұрын
Sure will upload more soon.
@CodeDecode
3 жыл бұрын
Thanks
Many thanks for making such wonderful videos and this really help people to Crack an interview. Please make videos on exception handing with real time scenarios along with garbage collector.
@CodeDecode
2 жыл бұрын
Sure, nice topic. We will create videos on that too soon 👍👍
Hello Mam, You made Java Developer's life easy,, Thank you so much for your dedication towards Java Developer ✌️🙏🏻.. God Bless you 😊
@CodeDecode
Жыл бұрын
❤❤Thanks a lot 🙂
Please upload videos on advance exception handling and try with reassures as well. Your videos are great for interview preps. Thanks
@CodeDecode
3 жыл бұрын
Sure will upload soon
very nice Discuss
Helps a lot. Thank you @Code Decode
@CodeDecode
3 жыл бұрын
M glad it helps
Very Underrated youtuber. Deserves more subscribers.
@CodeDecode
6 ай бұрын
Means a lot us 🙏
Thank you for such good videos. I have watched your other java videos which came out useful for me
@CodeDecode
3 жыл бұрын
Thanks for the nice words 👍
Great content...They r really helpful...Concept is very clear...U r sharing ur knowledge with us...It is appreciable madam...Thanks alot ...pls upload advanced exception handling interview questions
@CodeDecode
3 жыл бұрын
Sure Nishi, we will upload them soon 👍🙃
@10.36 - question must prepare , its always ask in interview . Nice video
@CodeDecode
2 жыл бұрын
Yes it is. Nice observation Rahul 👏👏👏👏👏
Such helpful content!!! Appreciate
@CodeDecode
2 жыл бұрын
Thanks for the nice words Manoj
Finalize is not a block it is a method of Object class.and another info I found it's depricated from Java 9.correct me if I wrong. Great Video thanks.
@ig_haxie
Жыл бұрын
a method is also called as a "block" of code
@divsreviews2860
Жыл бұрын
Yes Finalize got deprecated from JDK 9, I read in Java Complete reference 10 book
@Foodmoods_s
9 ай бұрын
That method is "Finalized" which is used before the garbage collection, "Finally" is a keyword and a block also which will always execute except when we use the system.exit or in jvm crash abruptly..in these two situations "finally" block will not executed..
very nice and awesone explanation.👌👌👌....keep doing more n more videos like this mam.....hatsoff to u...
@CodeDecode
3 жыл бұрын
Thanks 👍👍
Very nice and clear explanation Mam...Its very helpful...Keep it up.
@CodeDecode
3 жыл бұрын
Thanks 👍
Thanks for all of these videos
@CodeDecode
3 жыл бұрын
You are welcome........
Advanced exception handling will be helpful
@CodeDecode
3 жыл бұрын
Sure
Content is so valuable, Tq 🤗
@CodeDecode
3 жыл бұрын
👍
Wonderful video mam 🤩🤩🤩🤩🤩. Mam plz do intermediate exception handling questions too.
@CodeDecode
2 жыл бұрын
Sure Sneha, we will do that👍👍
Please continue this exception handling series
@CodeDecode
Жыл бұрын
Sure Ayushman 👍👍
Hi Team CodeDecode! hope you are fine. excellent video as usual. Please make a video on try with resources and exception chaining!
@CodeDecode
2 жыл бұрын
Sure Sukun, we will do that soon 👍🙂
this video is very helpful and as you said you need to extend this video to intermediate and advanced level.
@CodeDecode
3 жыл бұрын
Sure will make it soon
Thanks a lot for all the interview related videos. Appreciate your time and effort.
@CodeDecode
3 жыл бұрын
I am Glad you like them!
Please make videos on thread interview questions . your explanations are really amazing.👍
@CodeDecode
3 жыл бұрын
Thanks Shamuka 👍. Sure will create a video on multithreading
You are really doing a great job
@CodeDecode
3 жыл бұрын
Thanks 🙏🙏
Very useful and I like to get some advanced question in exception also
@CodeDecode
3 жыл бұрын
Sure will make part 2 soon
Superb.Thank uu
@CodeDecode
2 жыл бұрын
Thanks
Great job, thanks!!!!!
@CodeDecode
3 жыл бұрын
You are welcome....
Hi, your interview questions are very good and helpful, I want you to make an video on Generics concept and also on Java 8 feature interview questions
@CodeDecode
3 жыл бұрын
sure in next video i will capture java 8 interview questions
good content, thanks !
@CodeDecode
Жыл бұрын
you're welcome
All the interview questions are very helpful. Please cover the Intermediate and Advance level of questions also. I have watched all your videos. Your efforts are highly appreciate.
@CodeDecode
3 жыл бұрын
Thanks Kalpesh. It means a lot 🙏👍
Yes,plz create video on try with resource
@CodeDecode
Жыл бұрын
sure we will create it soon
thanks for informative video,,
@CodeDecode
2 жыл бұрын
Anytime Parth 🙂👍
Explanation is very good and please upload advanced exception handling questions
@CodeDecode
3 жыл бұрын
Sure 👍
Thank You so much Ma'am..!!
@CodeDecode
3 жыл бұрын
your welcome 👍
Thank you very much
@CodeDecode
3 жыл бұрын
You are welcome..
love u madam tq gave much info😍
@CodeDecode
11 ай бұрын
❤️❤️
thank you madam, please continue advanced questions on exception handling
@CodeDecode
3 жыл бұрын
Sure Suresh 👍👍
Great content..please upload advanced level exception handling interview questions
@CodeDecode
2 жыл бұрын
Sure Hema 👍👍
Very useful Pls upload more on that
@CodeDecode
3 жыл бұрын
Sure thanks 😊
Explained very nicely
@CodeDecode
2 жыл бұрын
Thanks 😊👍
Nice and easy explanation Thanks ma'am
@CodeDecode
2 жыл бұрын
Thanks 🙂👍
Thanks for such a great video.Request you to also make a intermediate level Exception handling interview video content.
@CodeDecode
2 жыл бұрын
sure we will create video on it soon
Since Java 8, it's possible to use try whitout expliciting using catch. When creating object from classes that implement AutoCloseable: try (FileReader fr = new FileReader(path); BufferedReader br = new BufferedReader(fr)) { return br.readLine(); }
@anushrutimohanty6113
6 ай бұрын
Thanks @allancmm for this information. This is very helful !
thank you very good explaination
@CodeDecode
2 жыл бұрын
You are welcome!
Thank you so much
@CodeDecode
2 жыл бұрын
You're welcome
Firstly thanks for this tutorial. Can you cover the Intermediate and Advance level of questions also. It will be helpful
@CodeDecode
2 жыл бұрын
Sure Sowmya, we will do that👍👍
@nehaladva256
2 жыл бұрын
please provide video link for Intermediate and Advance level of questions
Great mam
@CodeDecode
11 ай бұрын
Thanks
More interview questions of exception handling upload it
@CodeDecode
3 жыл бұрын
Sure
Thank you so much maam
@CodeDecode
2 жыл бұрын
You're Welcome Heena....
at the end ,you mentioned finally is key word , and finalize is a block , which is wrong statements, Except this you explained nicely, Awesome explanation. pls try to cover all topics for interview perspective.
@dileepnb01
2 жыл бұрын
Final is a keyword Finally is a block Finalize is a method Is it correct now?
@vishalkadam7728
Жыл бұрын
14.20 timestamp ...checked exception can be propagated using throw
Could you please tell me in which scenario we will create customized checked exception and in which scenario we will create customized unchecked exception?
Wonderful 🙏😍
@CodeDecode
2 жыл бұрын
Thanks
Please make exception handling part 2 video with advanced concepts like Exception chaining,try with multiple resources.
@CodeDecode
3 жыл бұрын
Sure Shushma 🙂🙂👍👍
your voice is awesome
@CodeDecode
Жыл бұрын
👍
Thanks you so much for this video Please make Advance questions also
@CodeDecode
2 жыл бұрын
sure ram we will make it soon
@rampatil1261
2 жыл бұрын
@@CodeDecode thanks in advance 😃
Thank you 3000 😊
@CodeDecode
3 жыл бұрын
🙂👍
thank you
@CodeDecode
2 жыл бұрын
🙂🙂
Please make video on intermediate and advance exception handling also.. this was really good🙂
@CodeDecode
3 жыл бұрын
Sure 👍👍
@kshitizkamaljain8233
3 жыл бұрын
Yes. Really require the intermediate and advanced level video on this.
Please make video of advanced exception handling like chaining etc..
@CodeDecode
2 жыл бұрын
Sure Suganya. We will upload it in next few days for sure 🙂👍
The way of ur explanation 🙌🙌1st time i will see ur video nd so satisfied..tysm 🙏 please upload multi threading concept 🙏
@CodeDecode
3 жыл бұрын
Sure I will upload a video for multi threading soon 👍👍👍👍
@ankitanayak6485
3 жыл бұрын
@@CodeDecode tysm☺️🙌
Hello, Can we use multi catch block in Java 8 and above also. Thanks in advance
Thank u so much..
@CodeDecode
3 жыл бұрын
M glad you liked it
Please , upload exception handling advanced and intermdiate level questions with "Exception handling in spring boot applications " . This is mostly asked question in the interviews .
@CodeDecode
3 жыл бұрын
Yes I m planning to upload this soon. Thanks for the topic. 👍
Please cover the intermediate and advanced also
Waiting for Part-2
@CodeDecode
3 жыл бұрын
Sure will upload soon.
create more video on exception handling,multithreading and collection questions.
@CodeDecode
3 жыл бұрын
sure Priyanka we will create one soon....
@sonalibajpai8323
3 жыл бұрын
😍😭😭❤️😭❤️💞💞😒💞💞💞💞💞💞💞💞💞😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢💋😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢@@CodeDecode in in in
@sonalibajpai8323
3 жыл бұрын
Iio iiii you can
@sonalibajpai8323
3 жыл бұрын
@@CodeDecode in in thatioiiii
Please make next set of FAQ on exception.
@CodeDecode
3 жыл бұрын
Ok sure
thank u
@CodeDecode
2 жыл бұрын
You're welcome nanda ....
Superb
@CodeDecode
2 жыл бұрын
Thanks Abirami 🙂👍
Can you also create a interview questions on File Handling? Thanks☺
Please upload interview questions of exception handling, Thank you.
@CodeDecode
3 жыл бұрын
Sure will upload soon 👍
@GauravKawatrakir
3 жыл бұрын
@@CodeDecode waiting for other set questions mam, please upload.
Hi ,thank you for the useful videos. Can you please do videos on multi threading and web services also
@CodeDecode
3 жыл бұрын
Sure will upload them soon
Great video, my only feedback is that to say final variable cannot be changed is misleading as final variables can still be mutated
@CodeDecode
3 жыл бұрын
Thanks. Ohh but Except inside constructor, how can we change/ instantiate it's value?
❤️ helpful
@CodeDecode
3 жыл бұрын
Thanks Nandini 👍👍
Thank you ma'am
@CodeDecode
3 жыл бұрын
👍
Can you please upload video of java best practices
Hello mam, thank you this video so helpful mam but can you make experience level exception handling questions
@CodeDecode
3 жыл бұрын
Sure. I will soon create advance level interview questions for this topic
Upload intermediate and advanced level questions... maam.
Please upload more questions of exception handling.
@CodeDecode
3 жыл бұрын
Sure 👍
Plz do make video for multithreding real time senario based interview question. I have searched on entire KZread but did not get single video which is good. They have asked like where do you use multithreding in your web project...?
@CodeDecode
3 жыл бұрын
That's very nice topic that you have suggested. I will surely make a video on this.
@CodeDecode
3 жыл бұрын
If possible can you please share what all kind of questions you have faced that you want me to cover.
@yoshitamahajan353
3 жыл бұрын
@@CodeDecode where have u used multithreading in your project is one the question
Please upload videos on advance exception handling and try with resources
@CodeDecode
3 жыл бұрын
Sure 👍
👏👏👏👏👏👏👏
@CodeDecode
3 жыл бұрын
🙏🙏🙏🙏
Really helpful video mam but please be slow thnak you
@CodeDecode
2 жыл бұрын
Sure Gautam thanks for inputs 🙂🙂👍👍
Tq
@CodeDecode
4 ай бұрын
Welcome
1. How u have handled expections in u r project? please give a brief explanation on this mam....asked many times in several interviews...
@CodeDecode
3 жыл бұрын
Will try to put next video on exception handling with spring.
Thank you for the video. Can we handle all the exceptions with the parent class Exception...??
@CodeDecode
3 жыл бұрын
Yes you can but it's not a good practice.
@josephkumar8259
3 жыл бұрын
@@CodeDecode Ok. Thank you.
Thanks for the vedio it very helpful. Can you please create the same for custom exception?
@CodeDecode
3 жыл бұрын
Sure 👍
Yes we want advanced level please try a video
@CodeDecode
3 жыл бұрын
Sure will upload that soon
Mentioned in comments.. do a video on it
@CodeDecode
2 жыл бұрын
kzread.info/dash/bejne/hIds0dt6eqvSYrA.html
Please add interview questions for 3+ year experience
@CodeDecode
2 жыл бұрын
sure we will upload it soon
Mam plz do intermediate exception handling questions
@CodeDecode
3 жыл бұрын
Sure Aakash 👍👍
I think from java 1.7 onwards we can provide only try block also. Or may be it is possible when we are using try with resource . Can you please confirm that by looking into it once.
@CodeDecode
3 жыл бұрын
That's with try with resources. As said in the video I Will cover that in part 2
excellent content. But can you please create videos for experienced people with more advanced concepts?
@CodeDecode
Жыл бұрын
Sure it's already uploaded on channel Jayalaxmi. You need link or you can surf channel??
@jayalaxmirn9820
Жыл бұрын
@@CodeDecode Can you please send me the link?