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, 2, 3] to sort We will use the Java Collection Framework to do this. Points to Note: List<Integer> => The Integer class wraps a value of 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 to another String Date format. Implementing above rules, Convert String => Date => String Handling Timezone To get Date time for a particular timezone just pass 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 try block, it is thrown. Your code can catch this exception (using catch) and handle it in some rational manner. To manually throw an exception, use Read more…

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 the case of .ear or .war file, we need to add all the dependencies needed along with .jar files. You can see compiling and adding dependencies for 100s of files is a serious task. This is the place where 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 2  static : static is a keyword that allows main( ) to be called without having to instantiate a particular instance of the class. void Read more…