Category
Java
37 posts.
Jan 22, 2018
Insertion Sort Algorithm In Java
Insertion sort is a simple algorithm. Insertion sort logic works as follows: To insert an element in an already existing set, we make room for the new item
Jan 21, 2018
Selection Sort Algorithm in Java
Selection sort is one of the simplest sorting algorithms. It is easy to implement but it is not very efficient. The algorithm divides the input list into two pa
Jan 1, 2018
How to calculate the height of a Non-Binary Tree
Computing the height of a tree in Computer Science is very common. Most of the examples and online discussions talk about computing the height of a Binary Tree.
Dec 23, 2017
Easiest way to calculate elapsed time in Java
Quite often in our day-to-day programming, we need to compute how long a specific portion of the code takes to complete. For e.g; you might want to check how lo
Dec 8, 2017
Java Regular Expression to Validate Social Security Number (SSN)
Here is a utility method to check if a given String is a valid Social Security number using Java Regular Expression.
Dec 4, 2017
Java Regular Expression to check if a String is a numeric value
Here is another method from my String utility class. This method uses a regular expression to check if a String is a numeric value. Look at the code, then read
Dec 3, 2017
How to delete Workspace from Eclipse Launcher Selection
Launch Eclipse Click on Recent Workspaces Eclipse will list all previously used workspaces Right click on the workspace name that you want to remove Click on Re
Dec 1, 2017
How to generate random alpha numeric String in Java
Following code is an example of generating a random alpha-numeric string using Java Random class. It is designed to generate random String of varying length bas
Nov 28, 2017
Java Scanner’s unexpected behavior following nextInt or nextDouble call
Scanner is a utility class that provides methods to read command-line input. It is a very useful class, but you need to be aware of its unexpected behavior whil
Nov 25, 2017
How to compare Java Strings correctly
One of the most common bugs I’ve seen in Java programs is the use of the == operator to compare two String objects. Most of the time the result may be acc
Nov 24, 2017
Java RegEx to validate Gmail address
I’ve written about Java regular expression to validate email addresses before. Today I am sharing another Java regex to validate Gmail address. It
Nov 23, 2017
How to find largest and smallest numbers from input in Java
Following simple Java program shows how to read input values and then print smallest and largest values. It reads the input from standard input using Scanner an
Nov 22, 2017
Array Bubble Sort in Java
Although Java’s Arrays class has a built-in method to sort an array, it is important for good Java developers to know how to sort an array on their own. B
Sep 8, 2016
Top 10 Eclipse Keyboard shortcuts for Java developers
Here is a list of 10 commonly used Eclipse shortcuts for Java developers. Ctrl + Shift + T: Open a type (e.g.; a class, an interface) without browsing through l
May 21, 2010
Sort numbers in Java to find minimum and maximum values without using Array
Recently a reader contacted me with a question about sorting numbers in Java. After sorting the number the program then needs to print the largest and smallest
Feb 23, 2010
Java String comparison. The difference between == and equals().
Many Java beginners find it difficult to differentiate between == operator and the “equals()” method when comparing String variables in Java. They a
Nov 25, 2009
How to convert an ArrayList to array in Java
Today, I will share a very basic Java program that converts an ArrayList to an array. For most Java developers this is a routine task, but many newcomers to Jav
Nov 17, 2009
How to validate date using Java regular expression
My earlier post on how to validate email address, SSN and phone number validation using Java regex still attracts a lot of visitors. Today I realized that anoth
Nov 9, 2009
How to write to properties file in Java
One of most visited posts on this blog is How to read properties file in Java. In that post I explained how you can read from a properties file. But many people
Nov 2, 2009
Best way to check if a Java String is a number.
An example on how to validate if a String variable in Java has all numeric digits.
Oct 1, 2009
How to determine smallest and largest number in Java
A couple of weeks ago a reader asked me for a Java program to read command-line input from the user and then display the smallest value the user has entered. He
Sep 5, 2009
New features coming to Java 7
Joseph Darcy, the lead of Project Coin, formally announced the approved changes to the Java language to be included in JDK 7. Although there was no major chang
Jul 28, 2009
How to search for a string in a file using Java regular expression.
If you need to search for a phrase or a string in a text file Java regular expression is the easiest way to accomplish this task. Here is a simple example that
May 30, 2009
How to remove (delete) Eclipse workspace from the dropdown list.
Eclipse is my favorite Java IDE. To manage projects Eclipse uses ‘Workspaces’. Workspace is basically a folder on your disk where your project files
Feb 1, 2009
Ultimate Java Regular Expression to validate any email address.
My post about Java regular expression gets a lot of hits daily. Someone commented that the regular expression I included in that post does not block certain inv
Jan 23, 2009
How to read properties file in a Spring Application.
If you need to read the properties file in your Spring application all you need is to configure a PropertyPlaceholderConfigurer bean in your application context
Jan 4, 2009
How to configure multiple handlers in a Spring MVC web application
In Spring MVC, DispatcherServlet relies on handler mapping to determine which controller the request should be sent to. All handler mapping classes in Spring im
Aug 7, 2008
Extract substring from end of a Java String
Today I’ll show you how to extract last few characters (a substring) from a string in Java. Here is the code to do this.
Jul 19, 2008
How to add external jar files to Maven project POM
Maven has made compiling Java projects almost an effortless job. You no longer need to worry about placing all the required class files in your classpath. All y
May 21, 2008
Import static elements for more readable Java code
One of the welcome additions to Java language in Java 5 release is the static import declaration. static import works in the same way as traditional import decl
May 13, 2008
Test your Java skills.
Even with many years of experience with programming in Java one cannot claim that he or she has mastered the language. What I found out with experience is that
Apr 13, 2008
Three ways to find minimum and maximum values in a Java array of primitive types.
In Java you can find maximum or minimum value in a numeric array by looping through the array. Here is the code to do that. public static int getMaxValue(int[]
Apr 8, 2008
How to read properties file in Java.
Reading properties file in Java is much easier than you might have thought. Following example illustrates one simple way of reading properties from a properties
Jan 10, 2008
How to validate email, SSN, phone number in Java using Regular expressions.
Regular Expressions offer a concise and powerful search-and-replace mechanism. They are patterns of characters used to perform a search, extract or replace oper
Dec 20, 2007
Java Utility for JDBC
Code re-usability is one of the many benefits of object oriented programming. For example, in Java if you need to perform email validation in different classes,
Nov 2, 2007
Automatically Sort Vector Elements
Vector class in java.util package is very easy to use. You can add objects of any type in a vector. You don’t have to worry about declaring the size of th
Nov 1, 2007
#1 Programming Language – Java
According to TIOBE Programming Community Index Java is still the #1 programming language. TIOBE Index gives an indication of the popularity of a programming lan