Exception Handling Interview questions and answers in Java | Part -1 | Code Decode
Вставка
- Опубліковано 13 вер 2020
- 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 : ua-cam.com/users/CodeDecode?...
Linkedin : / codedecodeyoutube
Instagram : / codedecode25
--------------------------------------------------------------------------------------------------------------------------------------
#ExceptionHandlingInterviewQuestionsInJava
#ExceptionHandlingHandlingInterviewQuestionsForExperiencedInJava
#javainterviewquestionsandanswers #codedecode
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();
}
}
Please upload videos on advance exception handling and try with reassures as well. Your videos are great for interview preps. Thanks
Sure will upload soon
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.
Sure, nice topic. We will create videos on that too soon 👍👍
great explanation cleared all the doubt and also gained confidence
thanks
Your explanation is amazing...to the point...understandable...keep making such videos...😊
Thanks a lot Sandhya 🙂👍
Your explanation is really very helpful ❤️
Thank you so much
Thanks 👍👍
Thanks for sharing.
Great content...Upto the point.... Looking for many more to come on the channel 👏
Thanks Rishika for the nice words....
Outstanding work done... Watching all your videos for learning. Expecting more soon.. Good Job
Sure will upload more soon.
Thanks
Thank you for such good videos.
I have watched your other java videos which came out useful for me
Thanks for the nice words 👍
Thank you ma'am, was waiting for this video...
Hope it helps :)
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
Sure Nishi, we will upload them soon 👍🙃
Helps a lot. Thank you @Code Decode
M glad it helps
Hello Mam, You made Java Developer's life easy,, Thank you so much for your dedication towards Java Developer ✌️🙏🏻.. God Bless you 😊
❤❤Thanks a lot 🙂
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
sure in next video i will capture java 8 interview questions
very nice Discuss
this video is very helpful and as you said you need to extend this video to intermediate and advanced level.
Sure will make it soon
Hi Team CodeDecode! hope you are fine. excellent video as usual. Please make a video on try with resources and exception chaining!
Sure Sukun, we will do that soon 👍🙂
Very nice and clear explanation Mam...Its very helpful...Keep it up.
Thanks 👍
very nice and awesone explanation.👌👌👌....keep doing more n more videos like this mam.....hatsoff to u...
Thanks 👍👍
Please make videos on thread interview questions . your explanations are really amazing.👍
Thanks Shamuka 👍. Sure will create a video on multithreading
Such helpful content!!! Appreciate
Thanks for the nice words Manoj
Content is so valuable, Tq 🤗
👍
Could you please tell me in which scenario we will create customized checked exception and in which scenario we will create customized unchecked exception?
Very useful and I like to get some advanced question in exception also
Sure will make part 2 soon
Wonderful video mam 🤩🤩🤩🤩🤩. Mam plz do intermediate exception handling questions
too.
Sure Sneha, we will do that👍👍
Hello, Can we use multi catch block in Java 8 and above also. Thanks in advance
Great content..please upload advanced level exception handling interview questions
Sure Hema 👍👍
Explanation is very good and please upload advanced exception handling questions
Sure 👍
thank you madam, please continue advanced questions on exception handling
Sure Suresh 👍👍
@10.36 - question must prepare , its always ask in interview . Nice video
Yes it is. Nice observation Rahul 👏👏👏👏👏
Very Underrated youtuber. Deserves more subscribers.
Means a lot us 🙏
Great job, thanks!!!!!
You are welcome....
Thanks for all of these videos
You are welcome........
Advanced exception handling will be helpful
Sure
Thanks for such a great video.Request you to also make a intermediate level Exception handling interview video content.
sure we will create video on it soon
You are really doing a great job
Thanks 🙏🙏
Yes,plz create video on try with resource
sure we will create it soon
Superb.Thank uu
Thanks
Please continue this exception handling series
Sure Ayushman 👍👍
thanks for informative video,,
Anytime Parth 🙂👍
good content, thanks !
you're welcome
Firstly thanks for this tutorial. Can you cover the Intermediate and Advance level of questions also. It will be helpful
Sure Sowmya, we will do that👍👍
please provide video link for Intermediate and Advance level of questions
Very useful Pls upload more on that
Sure thanks 😊
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.
Thanks Kalpesh. It means a lot 🙏👍
Hi ,thank you for the useful videos. Can you please do videos on multi threading and web services also
Sure will upload them soon
Nice and easy explanation Thanks ma'am
Thanks 🙂👍
Thank You so much Ma'am..!!
your welcome 👍
thank you very good explaination
You are welcome!
Thank you very much
You are welcome..
Explained very nicely
Thanks 😊👍
Please make exception handling part 2 video with advanced concepts like Exception chaining,try with multiple resources.
Sure Shushma 🙂🙂👍👍
Thanks a lot for all the interview related videos. Appreciate your time and effort.
I am Glad you like them!
Please , upload exception handling advanced and intermdiate level questions with "Exception handling in spring boot applications " . This is mostly asked question in the interviews .
Yes I m planning to upload this soon. Thanks for the topic. 👍
Thanks you so much for this video
Please make Advance questions also
sure ram we will make it soon
@@CodeDecode thanks in advance 😃
Thank you so much
You're welcome
More interview questions of exception handling upload it
Sure
Please make video on intermediate and advance exception handling also.. this was really good🙂
Sure 👍👍
Yes. Really require the intermediate and advanced level video on this.
The way of ur explanation 🙌🙌1st time i will see ur video nd so satisfied..tysm 🙏 please upload multi threading concept 🙏
Sure I will upload a video for multi threading soon 👍👍👍👍
@@CodeDecode tysm☺️🙌
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();
}
Thanks @allancmm for this information. This is very helful !
Please cover the intermediate and advanced also
Please make next set of FAQ on exception.
Ok sure
Hello mam, thank you this video so helpful mam but can you make experience level exception handling questions
Sure. I will soon create advance level interview questions for this topic
Great mam
Thanks
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.
Final is a keyword
Finally is a block
Finalize is a method
Is it correct now?
14.20 timestamp ...checked exception can be propagated using throw
love u madam tq gave much info😍
❤️❤️
Wonderful 🙏😍
Thanks
Please upload interview questions of exception handling, Thank you.
Sure will upload soon 👍
@@CodeDecode waiting for other set questions mam, please upload.
Thank you so much maam
You're Welcome Heena....
Can you please upload video of java best practices
thank you
🙂🙂
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.
a method is also called as a "block" of code
Yes Finalize got deprecated from JDK 9, I read in Java Complete reference 10 book
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..
Thank u so much..
M glad you liked it
Great video, my only feedback is that to say final variable cannot be changed is misleading as final variables can still be mutated
Thanks. Ohh but Except inside constructor, how can we change/ instantiate it's value?
Thank you 3000 😊
🙂👍
Please make video of advanced exception handling like chaining etc..
Sure Suganya. We will upload it in next few days for sure 🙂👍
Superb
Thanks Abirami 🙂👍
Thanks for the vedio it very helpful. Can you please create the same for custom exception?
Sure 👍
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.
That's with try with resources. As said in the video I Will cover that in part 2
Please upload more questions of exception handling.
Sure 👍
❤️ helpful
Thanks Nandini 👍👍
Please upload videos on advance exception handling and try with resources
Sure 👍
thank u
You're welcome nanda ....
Plz do make video for multithreding real time senario based interview question.
I have searched on entire UA-cam but did not get single video which is good.
They have asked like where do you use multithreding in your web project...?
That's very nice topic that you have suggested. I will surely make a video on this.
If possible can you please share what all kind of questions you have faced that you want me to cover.
@@CodeDecode where have u used multithreading in your project is one the question
Thank you ma'am
👍
Can you also create a interview questions on File Handling? Thanks☺
Thank you for the video. Can we handle all the exceptions with the parent class Exception...??
Yes you can but it's not a good practice.
@@CodeDecode Ok. Thank you.
create more video on exception handling,multithreading and collection questions.
sure Priyanka we will create one soon....
😍😭😭❤️😭❤️💞💞😒💞💞💞💞💞💞💞💞💞😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢💋😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢😢@@CodeDecode in in in
Iio iiii you can
@@CodeDecode in in thatioiiii
1. How u have handled expections in u r project?
please give a brief explanation on this mam....asked many times in several interviews...
Will try to put next video on exception handling with spring.
Upload intermediate and advanced level questions... maam.
👏👏👏👏👏👏👏
🙏🙏🙏🙏
your voice is awesome
👍
Can u please upload interview questions on rest Webservices and spring n springboot
Sure. Next spring boot interview questions are lined up
Can you please make a video about advance lavel of exception handling questions
Sure 👍
Waiting for Part-2
Sure will upload soon.
Tq
Welcome
Yes we want advanced level please try a video
Sure will upload that soon
Mentioned in comments.. do a video on it
ua-cam.com/video/RS8oyAJHl2M/v-deo.html
Thanks for the video madam🙏..do we have the 2nd part of the exception handling ??if not...could u plz make a 2nd part of it
We well create second part soon 👍👍
Give more videos on DS and Algorithms
Sure once will complete this will start with data structures