Thursday, 31 December 2015

7 Difference between REST and SOAP WebService in Java Interview

Difference between REST and SOAP in Java
What is the difference between REST and SOAP Web-service is a very popular question from Java J2EE interviews. I have myself asked this question a number of times. Here I am listing out some of the key differences between REST and SOAP purely from interview perspective i.e. I am only mentioning key points, not going into details. Unless you are doing exclusive work in REST or SOAP Web service, interviewer will not go into deep and if you have done the work already, you probably don't need this list. Anyway, let's see some key difference between REST and SOAP web service in Java.

6 Difference between wait() and sleep() method in Java

Though both wait() and sleep() method are used to pause the running thread, here are some important difference between them:

1) The wait() method must be called from the synchronized context (can be a synchronized block or method) but sleep() method can be called from within our with-out synchronized block.

Sunday, 8 November 2015

15 Advanced Core Java Interview Questions for Experienced Developers

In this article, I am going to share some advanced core Java interview questions for experienced programmers i.e. someone who has 2 to 5 years of experience in Java programming, mostly in core Java but JEE work is also fine. I have found that once you become senior and your experience grows, you no longer see questions like String vs StringBuilder or Vector vs ArrayList, instead many companies ask about class loaders, Garbage collectors, concurrency and about JVM. I have started collection some core Java questions for my preparation and today I am going to share some with you, I don't have their answer, So, I am looking forward to you guys to answer them, of course only if you know.

Saturday, 31 October 2015

How to sort an ArrayList on Increasing and Decreasing Order

In this Java tutorial, I will teach you how to sort an ArrayList on both increasing and decreasing order of elements. Though, we will use ArrayList of Integers on examples, you can practically sort any list by using this technique. Only requirement is that your object should implement Comparable interface otherwise you need to pass Comparator implementation to sort objects stored inside list. The sort() method is defined inside java.util.Collections class. It is overloaded to accept a Comparator. The version which doesn't take any argument sort the given list on default order e.g. increasing order for integers. This is defined by their compareTo() method which comes from Comparable interface. The version which takes Comparator, uses that to sort the list, as we have done to sort the list in reverse or decreasing order.

Saturday, 26 September 2015

How to Convert String to Date in Java in yyyy-MM-dd format

 In this tutorial, I will show you how to convert String to Date in Java which is in yyyy-mm-dd format. We will use DateFormat and SimpleDateFormat class from java.util.text package for this conversion.

Here are the steps :
1) Create a DateFormat with format String as "yyyy-MM-dd" (remember, small "m" is for minutes, and capital "M" is for month)
2) Call the parse() method with given String, this will return a java.util.Date object

Saturday, 19 September 2015

Singleton Design Pattern using Double Checked Locking Idiom

Singleton design pattern using Double checked locking pattern
In my last interview, I was asked to write code to implement Singleton design pattern using "Double checked locking" idiom, which I thought to share with you all. In Singleton design pattern, only instance of class is created during application lifetime and that's shared between all its clients. One of the challenge with Singleton pattern is to ensure that only instance of class is created without compromising performance.

How to convert String to int and Integer in Java? An Example

There are two main way to convert a String to int primitive and Integer class in Java :

1) Integer.parseInt(), which takes a String and return an int primitive

2) Integer.valueOf() ,which accept a String and return an Integer object

Sunday, 6 September 2015

Difference between Vector and ArrayList in Java

One of the classic question from from Java interviews is, "what is difference between Vector and ArrayList?" You might have seen this in on your own interviews as well. Though both are implementation of List interface from JDK 1.4 onward, the key difference between them is Vector is not a thread-safe and synchronized Collection but ArrayList is not synchronized. Which means if multiple threads tries to add and remove elements from Vector, it will still be Ok, but ArrayList's structure may be destroyed. If you remember this key factor then you can automatically derive several other differences between Vector and ArrayList las shown below.

Sunday, 23 August 2015

Difference between Comparator and Comparable in Java

Here are main difference between Comparator and Comparable in Java :

1) Comparable is used to define natural order of object in Java e.g. numeric order for numbers, lexicographic order for String etc, and Comparator is used to define custom order which in addition of default ordering provided by Comparable e.g. default ordering for an Employee class could be by name or id, but you can provide additional Comparator to compare them by salary, age and branch.

Monday, 3 August 2015

What are the difference between Having and Where Clause?

Here are some useful difference between WHERE and HAVING clause in SQL :

1) WHERE clause can be used with SELECT, UPDATE and DELETE statements and  clauses but HAVING clause can only be used with SELECT statements.


SELECT * FROM Employee WHERE EmployeeId=3

will print details of employee with id = 3.

Friday, 3 July 2015

10 Spring Framework Interview Questions for Experienced Java Programmers

Spring framework is very popular in Java world for doing application development. It provides dependency injection and inversion of control and also provides several API like JdbcTemplate, JmsTemplate to make developer's work easier while working with JDK core libraries.

Sunday, 28 June 2015

Java Interview Questions for 3 to 4 Years Experienced Programmers

Java Interview Questions for 3 Years Experienced Programmers

Here is the list of some useful Java interview questions for experienced Java programmers having experience in range of 2 to 5 years. As an experienced developer you are expected to learn about OOP concepts, Java basics,  Java Collection framework, Multi-threading and Concurrency utilities introduced in Java 5 and 6, Debugging Java application, Algorithm and Data structure, Some questions on design patterns, JVM and Garbage collection and couple of puzzles. Actually its mix of everything you do in your day to day work.