Загрузка страницы

Exception Handling Interview questions and answers in Java |Java Interview Questions and Answers|

In this video we have covered all important Exception Handling Interview questions in Java

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 : https://youtube.com/playlist?list=PLyHJZXNdCXscoyL5XEZoHHZ86_6h3GWE1

Advance Java Interview Questions and Answers : https://youtube.com/playlist?list=PLyHJZXNdCXsexOO1VQ4vs-BM2-8CKrixd

Java 8 Interview Questions and Answers : https://youtube.com/playlist?list=PLyHJZXNdCXsdeusn4OM33415DCMQ6sUKy

Hibernate Interview Questions and Answers : https://youtube.com/playlist?list=PLyHJZXNdCXsdC-p2186C6NO4FpadnCC_q

Spring Boot Interview Questions and Answers : https://youtube.com/playlist?list=PLyHJZXNdCXsexOO1VQ4vs-BM2-8CKrixd

Angular Playlist : https://www.youtube.com/watch?v=CAl7RQSdq2Q&list=PLyHJZXNdCXsfxRtDwtGkDD_lLfTWc1g0i

GIT : https://youtube.com/playlist?list=PLyHJZXNdCXscpl6pxOnL2lRWJlzvzjyZE

-------------------------------------------------------------------------------------------------------------------------------------
Subscriber and Follow Code Decode

Subscriber Code Decode : https://www.youtube.com/c/CodeDecode?sub_confirmation=1

Linkedin : https://www.linkedin.com/in/codedecodeyoutube/

Instagram : https://www.instagram.com/codedecode25/

--------------------------------------------------------------------------------------------------------------------------------------

#ExceptionHandlingInterviewQuestionsInJava
#ExceptionHandlingHandlingInterviewQuestionsForExperiencedInJava
#javainterviewquestionsandanswers #codedecode

Видео Exception Handling Interview questions and answers in Java |Java Interview Questions and Answers| канала Code Decode
Показать
Комментарии отсутствуют
Введите заголовок:

Введите адрес ссылки:

Введите адрес видео с YouTube:

Зарегистрируйтесь или войдите с
Информация о видео
14 сентября 2020 г. 15:39:30
00:23:15
Другие видео канала
Java collections framework interview questions | [MOST ASKED COLLECTIONS INTERVIEW QUESTION]Java collections framework interview questions | [MOST ASKED COLLECTIONS INTERVIEW QUESTION]Java Interview Questions & Answers | Multithreading Interview Questions and Answers in Java (Demo)Java Interview Questions & Answers | Multithreading Interview Questions and Answers in Java (Demo)Global Exception Handling Spring Boot with Controller advice | Exception Handling in Spring BootGlobal Exception Handling Spring Boot with Controller advice | Exception Handling in Spring BootAccenture Core Java Interview | Accenture Interview Experience | Java interview questions and ansAccenture Core Java Interview | Accenture Interview Experience | Java interview questions and ansJava is pass/call by value or pass/call by reference [MOST IMP. JAVA INTERVIEW QUESTION]Java is pass/call by value or pass/call by reference [MOST IMP. JAVA INTERVIEW QUESTION]Java 8 new features || Java 8 Interview Questions and Answers ( Live Demo with Examples )Java 8 new features || Java 8 Interview Questions and Answers ( Live Demo with Examples )Exception Handling In Java | Exception Handling In Java With Examples | Java Tutorial | EdurekaException Handling In Java | Exception Handling In Java With Examples | Java Tutorial | EdurekaJava Exception Handling Interview Questions and AnswersJava Exception Handling Interview Questions and AnswersJava Design Pattern Interview Questions [ MOST ASKED DESIGN PATTERN INTERVIEW QUESTIONS ]Java Design Pattern Interview Questions [ MOST ASKED DESIGN PATTERN INTERVIEW QUESTIONS ]Equals and Hashcode Contract in Java [Important Java Interview Question]Equals and Hashcode Contract in Java [Important Java Interview Question]Hibernate Interview Questions and Answers in Java PART -1[ MOST ASKED HIBERNATE INTERVIEW QUESTION ]Hibernate Interview Questions and Answers in Java PART -1[ MOST ASKED HIBERNATE INTERVIEW QUESTION ]How HashMap works internally || Popular java interview question on collection (HashMap)How HashMap works internally || Popular java interview question on collection (HashMap)Java Interview Questions and Answers | Java Tutorial | Java Online Training | EdurekaJava Interview Questions and Answers | Java Tutorial | Java Online Training | EdurekaGarbage Collection in java || Garbage collection interview questions (With Live Demo)Garbage Collection in java || Garbage collection interview questions (With Live Demo)Comparable and Comparator Implementation in Java with Example [Interview Question]Comparable and Comparator Implementation in Java with Example [Interview Question]Polymorphism in Java - Concept | Compile time and Runtime | Overloading and OverridingPolymorphism in Java - Concept | Compile time and Runtime | Overloading and OverridingJava Multithreading Interview QuestionsJava Multithreading Interview Questions10.1 Exception Handling in Java Theory10.1 Exception Handling in Java TheoryTop 65 SQL Interview Questions and Answers | SQL Interview Preparation | SQL Training | EdurekaTop 65 SQL Interview Questions and Answers | SQL Interview Preparation | SQL Training | Edureka
Яндекс.Метрика