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.
Saturday, 19 September 2015
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
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.
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.
e.g.
SELECT * FROM Employee WHERE EmployeeId=3
will print details of employee with id = 3.
1) WHERE clause can be used with SELECT, UPDATE and DELETE statements and clauses but HAVING clause can only be used with SELECT statements.
e.g.
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
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.
Subscribe to:
Posts (Atom)