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

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.