Checked and unchecked exceptions in java

Checked exceptions: Checked exceptions are those exceptions which are checked by compiler at the compile time. These exceptions will force you to either use try-catch or throws keywords. Checked exceptions include all exceptions except RuntimeException, their subclasses, and Error. Examples: SQLException, IOExceptionetc. import java.io.*;   public class Main { public static void main(String[] args) { … Read more

OutOfMemoryError in java

OutOfMemoryError is a subclass of java.lang.VirtualMachineError in java. It is thrown by the Java Virtual Machine (JVM) when an object cannot be allocated due to lack of memory space and also, the garbage collector cannot free some space. OutOfMemoryError will looks like Exception in thread "main" java.lang.OutOfMemoryError: Java heap spaceException in thread "main" java.lang.OutOfMemoryError: Java … Read more

Runtime exceptions in java

RuntimeExceptions are those exceptions which are checked at runtime. RuntimeException is the superclass of all those exceptions that can be thrown during the normal execution of the Java program. These are also called as unchecked exceptions. RuntimeException and their subclasses are known as unchecked exceptions. RuntimeExceptions can be avoided by programmer. Examples – ArithmeticException, ArrayStoreException, … Read more

Exception hierarchy in java

Exception Hierarchy: Throwable is the super class.  Hierarchy Exception Hierarchy Error Throwable Error AssertionError LinkageError BootstrapMethodError ClassCircularityError ClassFormatError UnsupportedClassVersionError ExceptionInInitializerError IncompatibleClassChangeError AbstractMethodError IllegalAccessError InstantiationError NoSuchFieldError NoSuchMethodError NoClassDefFoundError UnsatisfiedLinkError VerifyError ThreadDeath VirtualMachineError InternalError OutOfMemoryError StackOverflowError UnknownError Exception CloneNotSupportedException InterruptedException IOException FileNotFoundException SocketException ConnectException UnknownHostException ReflectiveOperationException ClassNotFoundException IllegalAccessException InstantiationException InvocationTargetException NoSuchFieldException NoSuchMethodException RuntimeException ArithmeticException ArrayStoreException ClassCastException ConcurrentModificationException … Read more

Error and exception in java

Exceptions: Exception in java, represents an exceptional event. It is an event that disrupts the program’s normal flow, during program execution. We can handle exceptions by using try-catch or throws keywords. Exceptions are divided into following two categories:  checked exceptions and unchecked exceptions. e.g. – NullPointerException, ArithmeticException, IOException, SQLException etc. Note: Exceptions generally occur because … Read more

what is an exception?

Exception refers to an exceptional event. Exception is an event that disrupts the normal flow of the program, during program execution. Java interview questions on exception handling what is an exception? How the exceptions are handled in java? What is the difference between error and exception in java? Can we keep other statements in between … Read more

can we declare local inner class as abstract?

Yes, we can declare local inner class as abstract. Example class OuterTest { public void getValue() { int num = 40;   // Abstract Local inner Class abstract class AbstractInnerTest {   abstract void getRemainder();   }   class InnerTest extends AbstractInnerTest { public int divisor; public int remainder;   public void getRemainder() { divisor … Read more

can abstract class be final in java?

No, abstract class can’t be final in Java because abstract classes are used only by extending and if they made final they can’t extended. Example final abstract class DisplayTest {   abstract void display(String str);   }   public class Main extends DisplayTest { public void display(String str) { System.out.println("Hello " + str); }   … Read more