JAVA

String is immutable

Overview We will find answers for following questions What is String pool. How does memory allocation works for String. Why are 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, the Read more…

By Ashish, ago
Collections

Collection Framework in Java – Overview

What Is a Collections Framework? A collections framework is a unified architecture for representing and manipulating collections. All collections frameworks contain the following: Interfaces Implementations Algorithms Benefits of the Java Collections Framework Reduces programming effort: By providing useful data structures and algorithms, the Collections Framework frees you to concentrate on Read more…

By Ashish, ago
JAVA

Difference between Comparable and Comparator in Java

Based on my previous posts related to Comparator and Comparable let’s see the difference. Comparable Comparator Should be used when sorting with one element only Should be used when sorting with multiple elements Need to implement compareTo(Obj ob) Need to implement compare(Obj e1, Obj e2) Found in java.lang package Found in java.util package Actual Read more…

By Ashish, ago
JAVA

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…

By Ashish, ago
JAVA

Sorting in Java (Comparable)

How do we sort in Java? We can go the traditional way by implementing Bubble Sort or Merge Sort etc We can use Java APIs In this post we will focus on Sorting using Java APIs Sort List of Integer Given an Integer List say [7, 4, 2, 9, 5, Read more…

By Ashish, ago
JAVA

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. Date can be in various format. Here are few Lets see an Example Note: Suppose we need to convert String Date format to Read more…

By Ashish, ago
JAVA

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…

By Ashish, ago
MAVEN

Setup Maven for Windows, Mac and Linux

Maven Maven is a build automation tool used primarily for Java projects. Consider a project consisting of 100s and 1000s of Java file. need to compile each and every .java file for .jar packing. Similarly in case of .ear or .war file we need to add all the dependencies needed Read more…

By Ashish, ago
JAVA

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 the blueprint from which individual objects are created. HelloWorld : Name of the class Line Read more…

By Ashish, ago