Friday, 29 June 2018

How to install OpenSSL in Windows?

For those who does not know what is OpenSSL, then I would like to say that OpenSSL is a robust, commercial-grade, and full-featured toolkit for the Transport Layer Security (TLS) and Secure Sockets Layer (SSL) protocols. It is also a general-purpose cryptography library.

OpenSSL is licensed under an Apache-style license, which basically means that you are free to get and use it for commercial and non-commercial purposes subject to some simple license conditions.

This open source cryptography library that implements the Transport Layer Security (TLS) and Secure Sockets Layer (SSL) protocols is designed to “secure communications over computer networks against eavesdropping”, but it has been ridden with bugs which may be unavoidable.

Official OpenSSL website offers Linux sources only.

Linux distributions routinely come loaded with OpenSSL but this is not the case for Windows.

Here is how you can set up OpenSSL on Windows -

1. Go to the Website to Download the binaries for Windows by clicking "Download"
Download OpenSSL

2. Download the installer as per the Windows version-


3. Once you download the installer from the website, install it by doing Right Click on the file and Select as "Run as Administrator"


4. Then follow the below screenshot to install OpenSSL in windows.









5. Once you install OpenSSL you can verify by going to Command Prompt and type command "openssl". If it is installed then you will get below screen -


Thursday, 21 June 2018

How to remove all unused imports from Java File in Eclipse?

While writing any program in Eclipse IDE, we have seen many a times Eclipse shows an unwanted warning "The import xxx.xxx is never used" for unused imports.

Though the unused imports does not create any harm, it's just unnecessary increase in length and size of Java file.

In this blog post we will see how to remove these unused imports from Java file in Eclipse IDE.

1. First, Go to line of unused import, press CTRL + 1, this will show a drop down menu to fix this error and we can select "Remove unused import". This option will remove that particular unused import statement from Java File.

2.Second, as the above option is not efficient in case of removing multiple unused imports from Java file. In case of removing multiple or all unused import statements from Java file, we can select "Organize imports" from the drop down menu.

This option can be found by -
(a) Press CTRL + 1 and select "Organize imports"
(b) Right Click on Java File -> Click Source -> Organize Imports

3. Third, to remove all unused imports from Java file, we can use CTRL + SHIFT + O, which is a shortcut for "Organize imports"

One advantage of using Organize imports or CTRL + SHIFT + O is that it imports all packages which are required by code.

How HashSet works internally in Java?

As we all know that a Set is a well-defined collection of distinct objects. Each member of a set is called Element of Set. Set contains unique elements.

In Java, Set interface implements classes like HashSet, LinkedHashSet, TreeSet to achieve the uniqueness.

In this post, we will see how HashSet works internally in Java.

HashSet internally uses HashMap to store its object. Whenever we create a HashSet object, one HashMap object associated with it is also created. This HashMap object is used to store the elements we enter in the HashSet. The elements we add into HashSet is store as Keys of the HashMap and the Values associated to those keys will be constant.

Lets look into the HashSet class -


Here we can see constructor of HashSet class is internally creating HashMap object. There are four public constructors available in HashSet class, all the constructors creates HashMap objects internally.


Whenever we add an element to HashSet using add() method, it actually calls put() method on internally created HashMap object with element we have specified as a Key and constant PRESENT as its Value.


And whenever we remove an element from HashSet using remove() method, it actually call remove() method on internally created HashMap object.


So we can say HashSet maintains its uniqueness internally through HashMap.