# Month: May 2014

## SimpleDateFormat is not thread safe in Java

Objective: To prove SimpleDateFormat is not thread safe in Java To make SimpleDateFormat thread-safe Proof: import java.text.ParseException; import java.text.SimpleDateFormat; public class SDFNotThreadsafeDemo { private final static SimpleDateFormat sdf1 = new …

## Find max and min in array in Java using minimum number of comparisons

Problem: Find max and min in array of integers with minimum number of comparisons. The array is unsorted.   Solution: Efficiency is heart of any algorithm. Solving a problem …

## Fastest way to check if a number is power of 2 in Java

Problem: How to check if a number is power of 2 in Java? In this article we will see various ways to check if a number is power of …

## Find the maximum difference in an array

Problem: Given an array arr, find the maximum j – i such that arr > arr. We have to find the maximum difference in an array. Solution: We will …

## Find the equilibrium position of the array

Problem: Write a program to find the equilibrium position of the array. Ex: given an array: 1,2,3,4,5,6,7,8       equilibrium position should be 5(element 6) i.e  sum of numbers before …

## Find missing characters in a string

Problem: Find missing characters in a string. There is a string , where a character is missing.Print the missing character.The range is present in the string and the characters …

## Anagrams: Check if two strings are anagrams or not

Problem: Write a Java program to check if two strings are anagrams or not? This is one of the famous programming interview question. This program was asked in online …

## Frequency of elements in array

Problem: Find frequency of elements in an array of integers. Count number of occurrences of an element in an array. We have to find out frequency of each element in …

## When to use StringBuilder over ‘+’ and StringBuffer?

Introduction: Strings are used so frequently in Java. To construct strings StringBuilder is used. This article discusses about StringBuilder, string concatenation and when to use StrngBuilder over other concatenation …

## Cyclic inheritance in Java is not allowed?

Topic: Cyclic inheritance is not allowed in Java. In this topic we will discuss about cyclic inheritance in java. Content: What is inheritance in OOP? What is cyclic inheritance? …