Computing 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. The example method I am sharing can be used to compute the height of any tree. So even if you have a non-Binary tree, you can use this method …
Quite often in our day to day programming, we need to compute how long does a specific portion of the code takes to complete. For e.g; you might want to check how long does a method take to complete. In Java, the simplest way to accomplish this is to use System.nanoTime() method. Following example shows …
Here is a utility method to check if a given String is a valid Social Security number using Java Regular Expression.
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 through the explanation that follows
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 Remove from Launcher Selection text. This will remove the workspace from the drop-down list
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 based on the input parameter.
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 while reading numeric inputs. Consider following example.
One of the most common bugs I’ve seen in Java programs in the use of == operator to compare two String objects. Most of the times the result may be accurate but it is not always guaranteed. We need to understand the difference between == and the Object.equals method.
I’ve written about Java regular expression to validate email addresses before. Today I am sharing another Java regex to validate Gmail address. It is quite simple and self-explanatory.
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 and then uses methods from Math class to determine the largest and smallest numbers entered by the user.