What are available drivers in JDBC?

JDBC is a set of Java API for executing SQL statements. This API consists of a set of classes and interfaces to enable programs to write pure Java Database applications. JDBC technology drivers fit into one of four categories: A JDBC-ODBC bridgeprovides JDBC API access via one or more ODBC drivers. Note that some ODBC native … Read more

Now, what if you have your own custom class like a Dog, Cat, etc instead of a library class like String, Integer, etc?

Here is an example of a JavaTechnology custom object that implements a default sorting logic based on the rank (i.e popularity). public class JavaTechnology implements Comparable<JavaTechnology>{   private String name; private int rank;   // popularity lower value means more popular   public JavaTechnology(String name, int rank){ this.name = name; this.rank = rank; }   //default … Read more

Is there anything wrong with the above code?

Yes, 2 things — firstly, the above sort is case sensitive, that is the uppercase takes priority over lowercase pushing ‘Java’ after ‘JSP’. Secondly, if the collection had any null values, it will throw a NullpointerException. These two issues can be rectified by providing a custom sorting implementation that ignores case and handles null values … Read more

Can you write code to sort the following string values naturally (i.e. in alphabetical order)? (JEE, Java, Servlets, JMS, JNDI, JDBC, JSP, and EJB)

Here is the sample code that makes use of the default compareTo( ) provided in the String class as it implements the Comparable interface and the Collections utility class that provides a sorting method, which internally uses the efficient “merge sort” algorithm. import java.util.Arrays; import java.util.Collections; import java.util.List;   public class Sort1 { public static … Read more

Illustrate – domain or value object class to compare different object fields in an equals method

cmd/designated folder/ jar cf name.jar *.* Create a file: META-INF/MANIFEST.MF Add a line: Main-Class: com.myco.calc.CalculatorDemo Include META-INF/MANIFEST.MF in calculator.jar Run with java -jar calculator.jar This is useful in domain or value object class to compare different object fields in an equals method public class DomainObject {   //protected because only inheriting domain classes can use … Read more