Java 9 : Collections factory methods

As of Java 8, there's  no simple or single statement way of creating collections with a small number of elements. In scenarios like unit tests where a Set of Strings are to be created as mock data,  it is needed to create a new Set and start repeatedly adding the elements which is highly verbose. Java… Continue reading Java 9 : Collections factory methods

Different ways of String formatting in Java : Benchmarking

Java programmers use mostly the following three ways for formatting or building a string. String concatenation using + operator Using String.format Using StringBuilder Functionally all these 3 ways will produce the same result but the question is "are all the 3 ways have the same time and space performance?". I wrote small code snippet to… Continue reading Different ways of String formatting in Java : Benchmarking

JUnit Practices 1 : Let the Tests Talk

Each variant of the assertion in JUnit has a distinct purpose, used in a right context the assertions yield useful information on test failures. It is possible to construct tests with an assertion that is intend for a different purpose and make it work as expected; when we do so we may possibly loosing the… Continue reading JUnit Practices 1 : Let the Tests Talk

Handling unused imports in Eclipse

The following three ways can be used to fix the unused imports in Eclipse If you have a file or two with unused imports, open the file that has unused imports and use ctrl+shift+O, this automatically organizes the imports; removes unused and adds any missing imports Avoid unused imports by enabling the organize imports option… Continue reading Handling unused imports in Eclipse