String is immutable

Overview We will find answers for the following questions What is String pool? How does memory allocation work for String? Why is String immutable. String pool String pool is a special storage area in Java heap. When a string is created and if the string already exists in the pool, Read more…

Sorting in Java (Comparator)

In my previous post, we saw Comparable and it’s implementation. Java provides another way to compare objects. Instead of implementing the comparable interface, we can implement the Comparator interface. The main difference between these two interfaces is that the comparable interface defines one method compareTo(), which takes one parameter. The Comparator interface defines Read more…

Date Conversion in Java

Let’s start with 2 basic rules to follow Convert Date (java.util.Date) into String => format Convert String into Date => parse I have used SimpleDateFormat which extends DateFormat of java.text package. A date can be in various formats. Here are few Let’s see an Example Note: Suppose we need to convert String Date format Read more…

Exception Handling in Java

An exception is an abnormal condition that arises in a code sequence at run time. Java exception handling is managed via five keywords: try, catch, throw, throws, and finally. Workflow Program statements that you want to monitor for exceptions are contained within a try block. If an exception occurs within the Read more…

Hello World

Let’s start with a little program in java to print a line “Hello World” Line 1 public : One of Access Modifiers. It makes this piece of code visible to the world. class : A class is a blueprint from which individual objects are created. HelloWorld : Name of the class Line Read more…