Posts

Showing posts from October, 2015

Top 20 Java Exception handling interview questions

Image
Last updated: September 2026 — refreshed with interview Q&A and related reading. Recently, I have completed BlockingQueue Tutorial and Exception Tutorial , after completion of Exception tutorial now planning to start specific exception handling interview questions. Although, I have already posted 15 core java written interview question and 20 core java basic interview questions , but in this post, I shall post top 20 only exception related interview questions like specific 20 jsp-servlet interview questions . Well Exception is very popular topic in any java , j2ee interview and definitely you will faced at least 2 questions on this topic. I am going to list top 20 frequently asked questions on exception and mostly started with the words like " Have you used exception in your code "? 1. What is difference between Checked Exception and Unchecked Exception? This question is almost  every interviewer asked, and it seems it is very common interview question like w...

ClassNotFoundException vs NoClassDefFoundError

Image
This is again one of the popular java interview question, like which collections is better to store 10 millions of record between ArrayList and LinkedList , and almost every interviewer ask this question. Although, I have already listed Top 20 core java interview questions  and in this post going to list the key differences between ClassNotFoundException and NoClassDefFoundError both are sub class of java.lang.Throwable. ClassNotFoundException - This exception is thrown when an application tries to load a class through its String name using any of the below methods, and no class definition is found with specified name. forName("class name"); findSystemClass("class name"); loadClass("class name"); The ClassNotFoundException is a checked exception, below is the example to generate the ClassNotFoundException, you can read more about Checked Exception public static void main(String[] args) throws ClassNotFoundException { Class.forName("a...

How to Create Custom Exception in java

Image
In this tutorial, I will show you how to create custom exception. Although I have already posted about Exception in my previous Exception Tutorial post. And we all know Exception is very important and actively used feature in daily programming practice. Sometimes interviewer also asked you about custom exception in java, and ask to write an example of custom exception, so this tutorial is important in both purpose to use or to be in java interview, this question is popular in java interview as like as Why String is immutable in java . Although I have already posted Top 20 Exception Handling interview questions and 15 core java written interview questions How to create custom Exception You can create custom exception by either extending - java.lang.Exception ( Checked Exception ) java.lang.RuntimeException ( Unchecked Exception ) But before creating any custom exception think twice, Is it really required custom exception, are built in exceptions will not helping anymore f...

What is difference between Checked and UnChecked Exception

Image
Very common and popular java interview question, if you are preparing for java,j2ee interview than this question must be in your plates before going for an interview. Although, I have already posted Top 20 Exception Handling interview questions and posting this question in separate post because this is one of the very respected java exception handling interview question. If you are preparing for product based company's interview than, I suggest you to please read  15 core java written test interview questions . Below are the few differences between Checked and Unchecked Exception - The Checked Exception are those exception which are forced by java compiler to catch it or throws it a compile time, whereas Unchecked Exception are bug(s),logical error(s) in your code, so it can be only identified(occur) at Runtime. In java all Exceptions are checked exception, except java.lang.Error or it's sub classes and java.lang.Runtime or it's sub classes. From this image, y...

Error in java example

Image
In java exception is very powerful feature and we have already seen about the Exception in our Exception Tutorial . And in this tutorial, I will try to explain about one of the sub class of Exception called java.lang.Error, and after completion of this tutorial, you will be able to answer what is Error in java? and few examples of Error sub-classes. What is java.lang.Error in java? The java.lang.Error is another sub class of java.lang.Throwable class, which indicates serious problems and application cannot recover from this Error unlike Checked Exceptions . And also a better design of Exception handling is to not handling the Error because handling of error will does not make any sense, so no need to catch or throw  Error or any sub class of Error. The java.lang.Error including it's sub classes also know as UN-checked exception like Runtime Exceptions The common reason of occurring this error in your application is possible that due no space in stack and trying to alloca...

Java Runtime Exception Tutorial

Image
In my previous post we have seen, what is Checked Exception and in this post, I shall try to explain what is Runtime exception and list few runtime exceptions. Runtime exception is also known as un-checked exception, so un-checked exception is also very popular topic in core java interview like How to balance the parenthesis and java program to find missing number . What is Runtime Exception ? The Runtime exceptions are basically a bug in your code. It's developer's fault/mistake, you can easily prevent the run time exception in your code no rocket science is required you just need to do code in a smart way. We will see later in this tutorial "How to prevent the runtime exception" , but before that, I strongly suggest you to must read What is Exception in java The java.lang.RuntimeException is a sub-class of java.lang.Exception class and all the sub-class of java.lang.RuntimeException is treated as runtime exception and application cannot recover from these...

Checked Exception in java

Image
In this tutorial, I shall try to explain What is Checked Exception? and Example using Checked Exception . This topic is also  popular in java interview question for freshers as well as below 5 years of experienced profile like Why String is immutable and What is Serialization in java What is Checked Exception? Checked Exceptions are those exception which are forced by java compiler to catch it or throws it otherwise program will not compile. All exceptions are checked exceptions, except for the sub classes of java.lang.Error and java.lang.Runtime class. You can read more about What is Exception in java and Exception Hierarchy from my previous post. Example of Checked Exception - Trying to reading a file from your hard disk, but somehow file is not in placed, than you will get java.io.FileNotFoundException , That's why compiler forced you to catch the FileNotFoundException or throws it otherwise program will not compile. Code without handling Checked Exception - pub...

Java Exception Tutorial

Image
After completion of BlockingQueue Tutorial and Hibernate Tutorial now starting with very popular topic of core java called Exception. And in this tutorial, I will try to explain what is Exception and What are the different types of Exceptions in java including your own custom exception, and how to use them. What is Exception in java? An exception is an exceptional event, which occurs during the execution of program and interrupt the normal flow of the running program. Like celebrating new year night with dancing on a floor and suddenly audio woofer stopped working. As soon as an error occurs in your method, it' will create an object of Exception class and throwing that exception to the Run-time system. The Run-time system, who will find the appropriate handler(block of code to handle the exception) for the exception from the call stack of the method. The Run-time system will scan all the method in call stack until an appropriate handler is found, once appropriate except...

Java Program to find factorial of a number

Image
We have previously listed core java written interview question s. Sometimes interviewer asked you to write a program to find the factorial value of a given number. So In this post, I am simply creating a program to calculate the factorial of given number using a recursion function, about recursion function we separately post a tutorial. FactorialExample.java package com.javamakeuse.poc; public class FactorialExample { // recursion method to calculate factorial // ex. !5 = 5*4*3*2*1 public static int findFactorial(int num) { if (num < 1) { throw new IllegalArgumentException("Not a valid number"); } else if (num == 1) { return 1; } else { return num * findFactorial(num - 1); } } public static void main(String[] args) { System.out.println("Factorial of given number is - " + findFactorial(5)); } } OUT PUT: Factorial of given number is - 120

Java DelayQueue Tutorial

Image
In our previous tutorial, we have learned What is SynchronousQueue and How to use Synchronous Queue here . In this tutorial, I will try to explain you What is DelayQueue? and How to use DelayQueue with solving producer and consumer problem using java.util.concurrent.DelayQueue . What is DelayQueue? The java.util.concurrent.DelayQueue is an implementation class of BlockingQueue, so before reading the DelayQueue, I strongly suggest you to read about BlockingQueue from any source, we have also posted tutorial on BlockingQueue, so you can follow that tutorial too BlockingQueue Tutorial . The DelayQueue is an un-bounded BlockingQueue for delayed elements unlike ArrayBlockingQueue . You can put element into the queue, but element can be taken from the queue only if the delay has expired for the element. It works on First-In-First-Out data structure. It also does not allow null element. If no delay expired for the elements and trying to accessing through poll() method, it will return...

SynchronousQueue Tutorial

Image
In my previous post, I have posted about LinkedBlockingQueue in java. And in this tutorial, I will try to explain you about SynchronousQueue. After completion of this tutorial, you will be able to answer these questions What is SynchronousQueue? How to use SynchronousQueue and able to solve a producer consumer problem using SynchronousQueue. What is SynchronousQueue? The SynchronousQueue is an implementation of BlockingQueue interface, which extends Queue and Queue extends Collection interface. The SynchronousQueue is totally different implementation of BlockingQueue unlike other implementations of BlockingQueue. The SynchronousQueue was introduced in java 1.5 under java.util.concurrency package, it is a special queue, it has no capacity to hold any element into the queue, even not a single element, calling peek() method will return null, because it has no capacity to hold any element into the queue.  The queue where each insert operation must wait for a corresponding re...

Java PriorityBlockingQueue Tutorial

Image
In this tutorial, we will see What is PriorityBlockingQueue? How to use PriorityBlockingQueue and Example of PriorityBlockingQueue. But before that, I request you to read what is BlockingQueue in java What is PriorityBlockingQueue The PriorityBlockingQueue is an implementation of BlockingQueue interface, which extends Queue and Queue extends Collection interface. That means PriorityBlockingQueue act as Queue(FIFO) and supports all the operations of Collection interface. The PriorityBlockingQueue is an un-bounded Queue and act as PriorityQueue. It act as a PriorityQueue, so the priority ordering rule remained same as java.util.PriorityQueue class. PriorityBlockingQueue is an implementation of BlockingQueue, means it does not allow null element. The PriorityBlockingQueue is un-bounded queue unlike ArrayBlockingQueue , that means you can add as much as element you want to but, but once memory get exhausted it will throws OutOfMemoryError . The priority of the queue is based on nat...

BlockingQueue Tutorial

Image
After completion of Hibernate Tutorial and Hibernate Interview Question , I am started with java 5's one of the excellent feature called BlockingQueue. After java 5, java 7 and java 8 introduced very power full features. You can read more about Java 7 features . In this tutorial, I will explain, what is BlockingQueue and what are the implementations of BlockingQueue. The java.util.concurrent.BlockingQueue is an interface extends Queue interface and Queue extends Collection interface. That means, BlockingQueue act as a Queue and supports all the methods of Collection, Queue is based on FIFO(First-In-First-Out) data structure, which says the element inserted first into the queue will retrieved first from the queue like Car reached first at petrol pump will get fuel first. The BlockingQueue act as a Queue and additionally support  the operations that wait for the queue to become non-empty while retrieving and element from the queue, and same way wait for the space to become ...

LinkedBlockingQueue Tutorial

Image
In this tutorial, I am trying to explain you, What is LinkedBlockingQueue? How to use LinkedBlockingQueue? and solve very popular producer consumer problem with the help of LinkedBlockingQueue. What is LinkedBlockingQueue ? The LinkedBlockingQueue is an implementation of BlockingQueue interface, which extends Queue and Queue extends Collection interface. That means LinkedBlockingQueue act as Queue(FIFO) and supports all the operations of Collection interface. The LinkedBlockingQueue, is an optionally bounded(optional to specify the capacity of the queue, if not specify, than the default capacity would be Integer.MAX_VALUE ) blocking queue based on linked nodes, unlike ArrayBlockingQueue . LinkedBlockingQueue will throws out of memory exception once it's capacity increased and trying to insert element into the queue. The LinkedBlockingQueue works in FIFO(first-in-first-out) data structure, that means, the first element inserted into the queue will be retrieved first from t...

ArrayBlockingQueue Tutorial

Image
I have just completed Hibernate Tutorial and Hibernate Interview topic and now planning to start the ever green topic in java called concurrency in java. Of course concurrency is very huge topic and it will take time to complete. So, I am started with BlockingQueue which was introduced in java 1.5 and become very popular to solve producer consumer problem. In this post, we will solve these questions - What is ArrayBlockingQueue? How to use ArrayBlockingQueue with example? When to use ArrayBlockingQueue? What is ArrayBlockingQueue The ArrayBlockingQueue is an implementation class of BlockingQueue interface, which extends Queue and Queue extends Collection interface. That means ArrayBlockingQueue act as Queue(FIFO) and supports all the operations of Collection interface. It's a fixed size of Queue and backed by an array. Because of it's size is fixed, you cannot add more element than the specified size of the ArrayBlockingQueue and you can specify the size of the queue at...

Hibernate Interview Questions For Experienced

Image
Last updated: September 2026 — refreshed with interview Q&A and related reading. Hibernate is still on demand and very popular ORM framework. In every Java,J2EE interview, you will faced at least 2-3 Hibernate related interview question. So, I thought I have to list popular Hibernate interview questions in my post after completion of Hibernate Tutorial now time has came to list very popular or you can say FAQ Hibernate Questions/answer here. Although I have posted core java specific 20 core java interview question and 10 JSP Servlet interview question So start with most respected Hibernate Interview question, What is difference between load() and get() method of Hibernate This question is just to check your working knowledge on Hibernate and once the interviewer got expected answer from you than start digging into the the deep of Hibernate. The Hibernate load() and get() both methods are used to retrieve the records from the database, I have listed the differences in separate...