Java Codes for commonly used functions