What is a singleton pattern? Singleton pattern is used in cases where we want to ensure that only a single instance of the class exists in the application. It is one of the most popular patterns. With lot of views around the web calling it a code smell. In this post I will not be … Continue reading Singleton Pattern – Implementation in Java
Variable arguments to a function in any language gives us a flexibility while calling the function. The number of arguments to a function are not fixed, and a number of calls can be made to the same function which would otherwise have been impossible without method overloading. Consider the following example: You have to write … Continue reading Variable Arguments in Java
As a developer, it is extremely important to understand how memory management in java works. It can help avoid creating difficult to trace problems. This blog post would give a simplistic view of memory management in java. With respect to memory management of Java applications, you need to understand two terms, the stack and the heap. The memory … Continue reading How memory works in Java?
String literals and String Objects String s1 = "abc"; String s2 = "abc"; Both string s1 and s2 refer to the same string object and value residing in the string literal pool. String A = new String("abc"); String B = new String("abc"); The two strings A & B are two different string objects, because we … Continue reading Java Strings
Static Initialization Typically static initialization block is used to initialize static variables of a class. The block is called at the time of class initialization. It is called only once. You can initialize static variables inline. If more complicated logic is required for initialization, a static initialization block can be used. The static initialization blocks … Continue reading Java Static Initialization vs. Instance Initialization – When to use which?
We have a Solr cloud installation on AWS EC2 instances. We use the SolrJ Client from our Java application. Till date we used to have a Solr Cloud installation on our local machine in order to test the code against. As the team started growing, we realized that we should have a way to access … Continue reading Accessing Solr Cloud on AWS from SolrJ
Interfaces are a key feature of object oriented programming. An interface provides a set of methods that an implementing class must provide. One can assign instances of the class to variables of the interface type. As of Java8, an interface can contain default methods that an implementing class can inherit or override. Default methods (also … Continue reading Interfaces in Java8
Immutability means something that cannot be changed. In java an immutable class is one whose state cannot be changed once it has been created. This post aims to give a guideline on how to make a class immutable. The post contains an example of creating an immutable class.The complete code is available on Github The … Continue reading Immutability in Java – What it takes to build an immutable class
TestNG is a testing framework which, inspired by JUnit and NUnit, but introduces things like dependency testing, grouping concept to make testing more powerful and easier to do. It is designed to cover all categories of tests: unit, functional, end-to-end, integration, etc...The NG in TestNG stands for Next Generation. TestNG requires JDK7 or higher.Reference: http://testng.org/doc/index.html … Continue reading Getting Started with TestNG
Sometimes it may be necessary to have two versions of java on your OSX, and to switch between the two in a fast, reliable and convenient manner. This post aims to show how this can be achieved. I am currently using version 10.9.4 of OSX, and I was required to have both JAVA6 and JAVA7 … Continue reading Multiple Java Installations on OSX and switching between them