Sunday, 5 August 2018

Topics to Prepare for Java Interview

Companies looking for Java developers who have experience in following topics
1. Core Java
2. Java 8
3. Multithreading (must)
4. Spring
5. Spring Boot (Micro Services)
6. Hibernate
7. XML
8. Concurrency
9. Algorithms
10. Data structures
11. Design patterns
12. Object-Oriented Design
13. Architecture patterns
14. MVC Design
15. RESTful web services
16. Maven
17. MongoDB
18. Git
19. JUnit & Mockito
20. System Design

Links to refer:
  1. Design patterns
    • Singleton
      • Implement Singleton using Eager Initialisation
      • Implement Singleton using Lazy Initialisation
      • What is the Double-Checked Locking?
      • When Double-Checked Locking fails?
      • How can you fix Double-Checked Locking fail? Ans: use Volatile
    • Factory 
    • Abstract Factory - Factory of Factories
  2. Spring
    • Spring core
    • Spring transactions
    • Spring JDBC
    • Spring MVC
  3. CoreJava & Java8
    • OOPS concepts
      • What is Encapsulation?
      • What is Polymorphism?
    • Streams
    • Lambda expressions
    • Functional interfaces
    • Method references
    • Constructor references
    • Exceptions
      • Difference between Checked and Runtime Exceptions
      • Create your own Exception
      • How can you create your own Checked Exception?
      • How can you create your own Runtime Exception?
      • When will we get CloneNotSupportedException? Is this checked or runtime exception?
      • When will we get NotSerializableException? Is this checked or runtime exception?
      • Difference between throw and throws keywords?
      • Difference between Error and Exception?
        • Errors (Environment specific, cannot be recovered immediately)
          • VirtualMachineErrors such as OutOfMemoryError, StackOverflowError, InternalError, UnknownError.
          • Environment related errors.
          • Errors are always unchecked. 
        • Exceptions (Application specific, caused by application code) 
          • NullPointerException
          • ClassCastException

    • Access Specifiers
      • difference between public, private, protected, default access specifiers.
    • Difference between final, finalize, finally keywords?
    • How to create an Immutable class?
    • How to create a clone of an Object?
    • Serialization
      • What is Marker interface?
      • what is the use of readResolve() method?
      • Difference between Serializable and Externalizable?
    • Enums
      • Can Enum have a constructor? Yes
      • What is the purpose of a constructor in Enums? Ans: Can be used to initialize instance fields. 
      • Enum constructor must be either private or default. you can not declare as public or protected.
      • Can Enum have abstract methods? Yes, in this case, each instance of enum must implement it. 
      • Explain about EnumSet, EnumMap
      • Can Enum extend other class? No, by default extends java.lang.Enum class. 
      • List of enum constants must be separated by commas (,) and terminated by a semi-colon (;).
      • If enum contains fields and methods, these must come after the list of enum constants. 
      • Can a class extend enum? No, Enums are final by default. 
      • Can you instantiate an Enum type? No. Compilation Error - enum types may not be instantiated. 
    • Inheritance
      •  If the superclass method declares an exception, subclass overridden method can declare same, subclass exception or no exception but cannot declare parent exception.
    • Practice Links
  4. Data Structures and Algorithms
    • (all programming questions will be asked from here, must read for any interview)
    • Write Java code for Permutations
    • Write Java code for Combinations
    • Coin change problem (Total number of ways to get the denominations of coins) 
  5. System Design
  6. Multithreading
    • Explain about Volatile and its behavior with an example.
    • Difference between a Volatile variable and normal variable.
    • How JVM handles synchronization internally?

  7. Hibernate
    • what is pessimistic locking?
    • what is optimistic locking?
    • What is lock mode? 
    • Explain about Transactions and Acid properties. 
    • How Distibuted TransactionManager and EntityManager work together?
    • How hibernate implements concurrency control? 
      • Hibernate inherit the isolation guarantees provided by the database management system. for example, Hibernate never locks anything in memory. 
    • What is the isolation level JPA assumes by default? ans: Read Committed isolation level. 
  8. Database
    • How database systems provide isolation among transaction?
      Ans: using locking and some modern database engines implement transaction isolation with multiversion concurrency control (MVCC), which vendors generally consider more scalable. 
  9. JTA
This page will be updated regularly

Wednesday, 6 September 2017

What is Group Id && Artifact Id in a maven project

Artifact is a file, usually a jar. So Artifact Id is the name of the jar.
Each artifact id has a group ID (usually a reversed domain name like

for example, in the below dependencies, you can observer that, all artifacts are belong to same groupId.

Here groupId is org.slf4j & artifacts have different ids.

Thursday, 6 July 2017

Different ways to create an object In Java

Below are the different ways to create an object in java.

1. using new keyword
2. using newInstance() method of class Class
3. using newInstance() method of class Constructor
4. using clone() method
5. using deserialization

Using new keyword:

1. Employee emp = new Employee();

Using newInstance() method of class Class:

1. Employee emp2 = Class.forName("Employee").newInstance();
2. Employee emp3 = Employee.class.newInstance();

Using newInstance() method of class Constructor:

1. Constructor empConstructor = Employee.class.getConstructor(); 
Employee emp4 = empConstructor.newInstance()

Using clone() method:

1. Calling clone() method, actually creates a new object and copies all the contents of old object into it. Creating an object using clone method doesn't invoke any constructor.
2. To use clone() method on an object, we need to implement Cloneable interface and define clone() method in it.

Employee emp5 = (Employee) emp4.clone();

Using deserialization:

1. when ever we serialize or deserialize an object, the JVM creates a separate object for us. JVM doesn't use any constructor to create the object.
2. To deserialize an object we need to implement a Serializable interface in our class.

ObjectInputStream in = new ObjectInputStream(new FileInputStream("data.obj"));
Employee emp6 = (Employee) in.readObject();

You can get the clear explanation in the following link


Wednesday, 5 July 2017

ConcurrentHashMap in Java

ConcurrentHashMap is concrete implementation of ConcurrentMap. Both are from java.util.concurrent package.


1. The functionality is similar to normal HashMap with better concurrency.
2. ConcurrentHashMap is thread safe.
3. It doesn't lock the Map while you are reading from it.
4. It doesn't lock the entire Map when writing to it, it only locks the part of the Map that is being written to, internally.

Difference between HahsMap && ConcurrentHashMap:

Not Thread SafeThread Safe
Allows 1 null KeyWill Not allow NULL Values

Monday, 20 March 2017

Benifits Of Hibernate ORM

The Benifits of ORM (Object Relational Mapping) is as follows.

1. It reduces the development time/cost.
2. It speeds up the development.
3. It provides us with portability. Hibernate supports multiple databases. so there is no need to write database-specific code. This is a useful feature, generally all databases have their own syntax made up of Data Definition Language (DDL) or Data Manipulation Language (DML) statements. If we used JDBC for querying & persisting data, we would need to rewrite a database-specific code as our database is changed. In this regard hibernate gets rid of developer's headache by handling this issue.

How hibernate handles different databases syntaxes?

1. With the help of dialect hibernate achieves this type of functionality. The implementation of dialect class is provided by the database provider to inform hibernate about the syntax of their particular database.

Benifits of Hibernate ORM:

1. Code reusablity.
2. Transaction Management.
3. Efficient Collection/custom classes mapping.
4. The caching mechanism supported by hibernate. 

Saturday, 18 March 2017

Error: Could not find or load mian class org.gradle.wrapper.GradleWrapperMain

When i was trying to build a project for eclipse, i ran the below command gradlew eclipse and i got below error.

I searched in internet and found some solutions and finally the below solution is working for me. I executed below command and this fixed my issue.

'git add -f gradle/wrapper/gradle-wrapper.jar'

There are other solutions but this only worked for me.

GitHub: How to pull changes from online git repository to your local

1. If you are working on some open source project which is hosted on online github repository and you want to get the files modified by other peers. The command to get changes to your local (computer) project folder, you have to execute "git pull" command.
2. Remember, you have to in the project directory of before executing any git commands. 
3. The output of "git pull" looks like below.Here some one added "" to online repository and git pulled that file to my local repository.

GIT: How to add a file to local repostiory

1. If you have created a new file in the project, the file will not be added to Git repository until you explicitly tell the Git.
2. When ever you create a new file, or made changes to a file, Git keeps track of changes to the file.
3. "git status" command lets you know, what are the changes added to the project.
4. The result of "git status" command looks like below. I added a file HelloWorld.txt to my HelloWorld project. 

5. By using "git add" command you can add the file to Git repository. The output of "git add" as follows.

6. After executing "git add", execute "git status", you can see the message, branch is uptodate & changes to be committed, with the list of files to commit.
7. You can commit the changes to repository, by executing "git commit" command.

8. executing "git commit" won't push files to online git repository, it keeps files in your local repository.
9. If you want to push files to your repository on, you have to use "git push" command. If you have not configured username & password, it will ask you to enter, just like below.

10. After push, the output looks like below.

11. Now if you go to your online github repository, you can see new file is added. Here you can see new file "HelloWorld.txt" is added to online repository.