StringBuffer vs StringBuilder

  According to javadoc, StringBuilder is designed as a replacement for StringBuffer in single-threaded usage. Their key differences in simple term: StringBuffer is designed to be thread-safe and all public methods in StringBuffer are synchronized. StringBuilder does not handle thread-safety issue and none of its methods is synchronized. StringBuilder has better performance than StringBuffer under ...

executeQuery, executeUpdate and execute

executeQuery public ResultSet executeQuery() throws SQLException Executes the SQL query in this PreparedStatement object and returns the ResultSet object generated by the query. Returns: a ResultSet object that contains the data produced by the query; never null Throws: SQLException – if a database access error occurs or the SQL statement does not return a ResultSet ...

TreeMap

The TreeMap class implements the Map interface by using a tree. A TreeMap provides an efficient means of storing key/value pairs in sorted order, and allows rapid retrieval. You should note that, unlike a hash map, a tree map guarantees that its elements will be sorted in ascending key order. The TreeMap class supports four ...

Why use Generics in Java?

Generics add a way to specify concrete types to general purpose classes and methods that operated on Object before.   Code that uses generics has many benefits over non-generic code: 1. Stronger type checks at compile time(Compile-time type safety). A Java compiler applies strong type checking to generic code and issues errors if the code violates ...

What is Object-Relational mapping (ORM) framework? 1

Object-relational mapping (ORM, O/RM or O/R mapping) in computer software is a programming technique for converting data between incompatible type systems in relational databases and object-oriented programming languages. This creates, in effect, a “virtual object database” that can be used from within the programming language. There are both free and commercial packages available that perform ...

UnsupportedClassVersionError

Description : java.lang.UnsupportedClassVersionError:Bad version number in .class file  Cause: When code was compiled on a new version of Java and user is trying to run it on the older version of Java Possible Solution :  Make sure that both the versions are same.  

Understanding Hashcodes

Understanding Hashcodes
Imagine a set of buckets lined up on the floor. Someone hands you a piece of paper with a name on it. You take the name and calculate an integer code from it by using A is 1, B is 2, and so on, and adding the numeric values of all the letters in the ...

Transient variables in Java

Java’s serialization provides an elegant, and easy to use mechanism for making an object’s state persistent. While controlling object serialization, we might have a particular object data member that we do not want the serialization mechanism to save.   The modifier transient can be applied to field members of a class to turn off serialization ...

The ‘Rare’ static imports

The static import declaration imports static members from classes, allowing them to be used without class reference.   for example: import static java.lang.System.*; class A { public static void main(String args[]) { out.println("project code bank"); } }   output: project code bank   Note : Try to avoid this feature, because over a period you may ...

Synchronized Methods and Synchronized Blocks

If you declare a method to be synchronized, then the entire body of the method becomes synchronized; if you use the synchronized block, however, then you can surround just the “critical section” of the method in the synchronized block, while leaving the rest of the method out of the block.   If the entire method ...