Posts

Showing posts from March, 2015

Java Program Using Comparable Interface

Friends, In our previous post we have seen java.util.Comparator tutorial, Here we are going to show you the implementation example of java.lang.Comparable interface. The Comparable interface is one of the very popular interface in java. It has a single public method public int compareTo(T o) If you are planing to use your object in Collection and may needs to sort the elements of that Collection than you must have to implement java.lang.Comparable or java.util.Comparator interface, here we are going to implement Comparable interface. Although we have listed few key differences between java.lang.Comparable and java.util.Comparator interface . The sorting of element is only possible after the comparison of the elements, that is why Comparable interface has a compareTo(T o) method. The implemented class must have to provide the implementation of compareTo(T o) method, the compareTo method is almost same as equals(Object o) method of java.lang.Object class except that compareTo meth...

30 Core Java Basic Interview Questions for Freshers

Last updated: September 2026 — merged two posts (10 + 20 questions) into one definitive 30-question list, refreshed with related reading. This is the definitive list of core Java interview questions for freshers — 30 questions covering the fundamentals every Java beginner is expected to know. Answers are kept at fresher level: enough to answer confidently, with links to deeper tutorials where it matters. Part 1: Java fundamentals (questions 1–10) 1. What is difference between Java and C++ Here we have listed only few differences. Java does not support pointers whereas C++ Support pointers. Java does not support destructors, it has automatic garbage collector, whereas C++ supports destructors. Java codes run in a JVM(Java Virtual Machine) whereas C++ codes runs on native executable machine. Java does not support operator overloading whereas C++ does. Java provides built in support for Thread whereas C++ does not provide built in support for Thread. 2. What is the difference ...

Spring 4 MVC Hello World Example Using Maven

Image
In our previous post we have already seen Spring 4 MVC Hello World Example , but one of my friend requested to write a post using maven as our previous post was using jar files instead of pom dependency. So here we are going to show you simple Hello World example using maven. Spring Framework is a very popular open source application framework developed using Java language. Spring Framework is nowadays top in the framework list and off course high payee job and yes very easy to learn. Current stable release of Spring is 4.1.4 and we are going to use the same version of Spring. Just follow the below given simple steps and you will complete your Spring+Maven Hello World example, you can download this sample application from the download link at the end of this tutorial. Tools and Technologies we are using here: JDK 7 Spring 4.1.1 Eclipse Kepler 4.3 Maven 3.2 Overview of the Project Structure: Main Objects of this project are: pom.xml web.xml spring4demo-servlet.xml...

Tutorial - Hibernate second level cache annotation example

Image
In our previous post we have seen First Level Cache Example . In this post we are going to show you a very simple and real time example of second level cache using annotation. Second Level Cache: In Hibernate second level cache means Session Factory level cache. Hibernate Session is by default first level cache of persistent data. Sometimes we required to configure a cluster or you can say JVM(Session Factory) level cache. Cache is used to improve the performance of application by reducing your database hit. To configure second level cache, you have to put some additional effort as this is not provided by default. To use second level cache you have to use at least one Cache provider. In our sample application we are going to use one of the popular cache provider called EhCacheProvider . Once you opted the cache provider next you have to use at least one caching strategy, here is the list of Cache Providers and Cache Strategies . How Second level cache works, Hibernate receiv...

Tutorial - Hibernate First Level Cache Example Using Annotations

Image
In our previous post we have seen fetching strategies supported by Hibernate . In this post we are going to show you a very simple and real time example of First Level Cache using annotation. First Level Cache: In Hibernate first level cache means Session level cache, Session is by default first level cache so you can not ignore/disable this cache. Although hibernate provides few methods which can be used to remove/clear cached associated object from the Session. How to Remove/Clear Object from the Session: session.evict(object); session.clear(); Lets implement the First Level Cache, Here is a Country table ER diagram we are going to use this table in our example. Tools and Technologies we are using here: JDK 7 Hibernate 4.3.7 MySql 5.1.10 Eclipse Juno 4.2 Maven 3.2 Overview of the Project Structure: Main Objects of this project are: pom.xml hibernate.cfg.xml annotated pojo database Step 1. Create database script. CREATE DATABASE `hibernate_tutoria...

Hibernate Second Level Cache Providers and Cache Strategies

In our previous post we have seen a example of  Hibernate Data Filter . In this post we are going to list down the few Cache providers and Cache Strategies then we start with example of second level cache in hibernate in our next post. Hibernate Session is a transaction level cache of persistent data. It is also possible to configure a cluster or JVM (Session Factory) level cache. Second level cache is used to reduce the performance of application by reducing the database hit. To configure second level cache we need to use at least one cache provider. There are different types of Cache providers and they can be integrated with Hibernate. Here are few Popular Cache Providers: EHCache (Very Popular) OSCache SwarmCache JBoss Cache Hashtable To configure second level cache in hibernate you need at least one Cache Provider , Once you opted your cache provider then you have to select at least one Cache Strategy . Here are the list of Caching Strategies supported by Hibe...

How to Convert BigInteger to long int in java

In this post we are going to show you, how to convert BigInteger to long, int in java. java.math.BigInteger is a class extends java.lang.Number class sometimes we used to keep the large value in BigInteger, mostly in database we use BigInteger and corresponding to that BigInteger use long in java class. So here we are going to convert BigInteger to long and int. Below BigIntegerTest.java class where we are getting long and int value from the BigInteger. package com.javamakeuse.poc; import java.math.BigInteger; public class BigIntegerTest { public static void main(String[] args) { BigInteger largeValue = new BigInteger("1234567890"); // getting long value from the BigInteger long longValue = largeValue.longValue(); // getting int value from the BigInteger int intValue = largeValue.intValue(); // printing BigInteger System.out.println("BigInteger Value = " + largeValue); System.out.println("long Value of BigInteger = " + longVal...

java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet

Image
While learning Spring Framework most of us getting this exception at least for first time. In this post we are going to show you how to fix this exception, below is the complete stack trace of the exception. java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559) at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:532) at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:514) at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:133) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1136) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1080) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext....

Tutorial - Spring 4 MVC Hello World Step by Step Example

Image
In this post we are going to start our very first Spring MVC off course Hello World implementation example step by step. Spring Framework is a very popular open source application framework developed using Java language. Spring Framework is nowadays top in the framework list and off course high payee job and yes very easy to learn. Current stable release of Spring is 4.1.4 and we are using the same here. If you are a J2EE developer you must have to know Spring Framework, well it has various modules and the best part of spring is modularity. What you need to do is just pick what you need and leave others so definitely light weighted because of  modularity. OK come to the point we are here to start our Spring MVC tutorial and today is our first day first show, so start with Hello World Example you just need to follow the steps and you will complete the Hello World example and of course at last we have download able link from where you can download this Hello World example. ...

What is front controller in Spring MVC

Image
The topic is about front controller in Spring MVC not about the front controller design pattern although front controller in spring is the implementation of front controller design pattern, but here we are not going to dig into the deep of front controller design pattern. We are going to see what is front controller in Spring MVC. Front-Controller: Is a initial level of contract point for handling a request. The front controller provides a centralized entry point for that controls and manages web request handling. By centralizing decision point and controls. The front controller also reduce your java code and business logic by promoting code reuse ability across the requests. The front controller coordinates with dispatcher components. Dispatcher are responsible to view management only, the one who bring the view components to the user is called dispatcher. There are lot of things about the front controller design pattern but we are not going here into the deep, we will see ab...

what is load-on-startup in web.xml

In web application we have web.xml file which is also known as deployment descriptor, In web.xml file we have <load-on-startup> tag inside servlet tag. The <load-on-startup> is an optional tag in web.xml. The Server initializes this servlet when Server starts up. This tag is optional in web.xml file. The tag is define inside servlet tag only. The optional content of this element must be a positive integer indicating the order in which the servlet should be loaded. Priorities start from lower integer, lower integers are loaded before higher integers for example if you pass values as 1,2,3.. in respective servlets. Server will starts initialization of servlet from 1,2,3.. If no value is specified, or if the value specified is not a positive integer, then Server can load the servlet in any order during application startup Below is the example of web.xml with three different servlet with different priority: <?xml version="1.0" encoding="UTF-8"?...