Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a "driver class"?

Tags:

I was reading through a Java textbook, and it mentions something called a "driver class". What is it, and how is it different from a normal class?

like image 992
lfaraone Avatar asked Apr 19 '09 17:04

lfaraone


2 Answers

A "Driver class" is often just the class that contains a main. In a real project, you may often have numerous "Driver classes" for testing and whatnot, or you can build a main into any of your objects and select the runnable class through your IDE, or by simply specifying "java classname."

like image 81
Stefan Kendall Avatar answered Sep 30 '22 04:09

Stefan Kendall


Without context, it's hard to tell. Is it talking about a JDBC driver, perhaps? If so, the driver class is responsible for implementing the java.sql.Driver interface for a particular database, so that clients can write code in a db-agnostic way. The JDBC infrastructure works out which driver to use based on the connection string.

If the book wasn't talking about JDBC though, we'll need more context.

like image 26
Jon Skeet Avatar answered Sep 30 '22 04:09

Jon Skeet