Skip to main content

Posts

Core Java Interview Questions and Answers

Core Java Interview Questions and Answers Hi guys, I am attempting to put as many of Core Java interview questions and answers as possible in this post. You can bookmark this post as the no. of questions here will increase over time as I keep updating them. Q.1 How is Java platform independent? Ans: Before going into the detail,first you have to understand what is the mean of platform? Platform consists of the computer hardware(mainly architecture of the microprocessor) and OS. Platform=hardware+Operating System Anything that is platform independent can run on any operating system and hardware. Java is platform indepedent so java can run on any operating system and hardware. Now question is how it is platform independent? This is because of the magic of Byte Code which is OS indepedent. When java compiler compile any code then it generate the byte code not the machine native code(unlike C compiler).Now this byte code need a interpreter to execute on a machine.This interp
Recent posts

Exception – Handle or Declare Rule

Exception – Handle or Declare Rule Java – Exceptions An exception (or exceptional event) is a problem that arises during the execution of a program. When an Exception occurs the normal flow of the program is disrupted  and the program/Application terminates abnormally, which is not recommended, therefore, these exceptions are to be handled. Advantage of Exception Handling The core advantage of exception handling is  to maintain the normal flow of the application . Exception normally disrupts the normal flow of the application that is why we use exception handling. Let’s take a scenario: statement  1 ; statement  2 ; statement  3 ; statement  4 ; statement  5 ; //exception occurs statement  6 ; statement  7 ; statement  8 ; statement  9 ; statement  10 ; Suppose there are 10 statements in your program and there occurs an exception at statement 5, rest of the code will not be executed i.e. statement 6 to 10 will not run. If we perform exception handling,

Exception Hierarchy

Exception Hierarchy What is an Exception An exception is a problem that occurs during the execution of a program and disrupts the normal flow of  the program . Exception Hierarchy All the  checked  exceptions and unchecked exceptions are subclasses of Exception class and the Exception class is subclass of Throwable class as  shown  below. Types of Exceptions There are two types of exceptions in java 1. Checked exceptions 2. Unchecked exceptions 1) Checked Exceptions:  are the exceptions that are checked at compile time. If some code within a method throws a checked exception,  then the method must either handle the exception(using  try-catch  block) or it must specify the exception using  throws  keyword. Else, the code will not compile. 2) Unchecked   Exceptions:  are the exceptions that are not checked at compiled time, so it is not forced by the compiler to either handle or specify the exception. It is up to the programmers to be civilized, and specify or ca