Is Class.forName("") really required..

.. or not?

As usual, lets start with a code sample:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
 
public class DriverManagerTest {
 
    final static String URL = "jdbc:h2:tcp://localhost:9092/~/h2dbs/studentform";
 
    public static void main(String[] args) throws Exception {
        final Connection connection = DriverManager.getConnection(URL, "sa", "");
        final Statement statement = connection.createStatement();
        final ResultSet resultSet = statement.executeQuery("SELECT * FROM STUDENT");
        while (resultSet.next()) {
            System.out.println(resultSet.getString("FULLNAME"));
        }
        connection.close();
    }
}

I can hear you saying "so..?". Well you know how DriverManager tutorials usually have a statement like:
Class.forName("org.h2.Driver");

Well, this example, does not. So, will it work?

This is the directory layout I have:

And lets compile and run..

Ok, what kind of dark magic is going on in here? Quoting from this page:

The DriverManager methods getConnection and getDrivers have been enhanced to support the Java Standard Edition Service Provider mechanism. 

JDBC 4.0 Drivers must include the file META-INF/services/java.sql.Driver. This file contains the name of the JDBC drivers implementation of java.sql.Driver. For example, to load the my.sql.Driver class, the META-INF/services/java.sql.Driver file would contain the entry:

my.sql.Driver

Applications no longer need to explictly load JDBC drivers using Class.forName(). Existing programs which currently load JDBC drivers using Class.forName() will continue to work without modification.

When the method getConnection is called, the DriverManager will attempt to locate a suitable driver from amongst those loaded at initialization and those loaded explicitly using the same classloader as the current applet or application.

When you unzip the h2-1.4.192.jar you will see:

and the file java.sql.Driver contents is as follows:
org.h2.Driver

Yihuuu!