SlideShare a Scribd company logo
1 of 16
JDBC –
Java DataBase Connectivity

java.lang
Class Class<T>
public final class Class<T>extends Objectimplements Serializable,
GenericDeclaration, Type, AnnotatedElement
 Instances of the class Class represent classes and interfaces in a
running Java application. An enum is a kind of class and an
annotation is a kind of interface. Every array also belongs to a class
that is reflected as a Class object that is shared by all arrays with
the same element type and number of dimensions. The primitive
Java types (boolean, byte, char, short, int, long, float, and double),
and the keyword void are also represented as Class objects.
 Class has no public constructor. Instead Class objects are
constructed automatically by the Java Virtual Machine as classes
are loaded and by calls to the defineClass method in the class
loader.
2
3
Class.forName() method
 This

method is used to load the class into
JVM’s memory . (without creating the object
also it will loads into the jvm’s memory.
Class.forname(“class”);
Or
Reference=Class.forName(“class”)

4








By using the Class.forName() we can load any class object into JVM’s memory without creating
the object.
Ex; Class c=Class.forName(“java.lang.ArraayList”);
When the class.forName() is executed the code it will create a class boject.
Inside the class object it plays the name of the class which is loaded into JVM and the name of
the package of the class which is loaded into the JVM.
It is a factory method( means capable of constructing its own java class object is called “factory
method”.

5
Ex:
 Class.forName("com.mysql.jdbc.Driver");
 When

this statement is executed, it contains
the static block of given jdbc Driver class, so
the static block executes automatically
 In this static block, there will be a logic to
create JDBC driver class object and to
register that object with driver manager
service through by calling
DriverManager.registerDriver()
6
 Class.forName()

loads the given jdbc Driver
class bcoz of the logic available in the static
block of that jdbc driver class, the jdbc driver
class object will be registered with Driver
Manager service

7
Static
{
mysql.jdbc.Driver jd= new mysql.jdbc.Driver();
Try
{
DriverManager.registerDriver(jd);
}
Catch(SQLException se)
{
se.printStackTrace();
}

8
 public

static Class<?> forName(String
className) throws
ClassNotFoundException

9
 Returns

the Class object associated with the
class or interface with the given string name.
Invoking this method is equivalent to:
Class.forName(className, true,
currentLoader) where currentLoader denotes
the defining class loader of the current
class.For example, the following code
fragment returns the runtime Class descriptor

10
 Class

t = Class.forName("java.lang.Thread")
A call to forName("X") causes the class
named X to be initialized.
 Parameters:className - the fully qualified
name of the desired
class.Returns:the Class object for the class
with the specified
name.Throws:LinkageError - if the linkage
failsExceptionInInitializerError - if the
initialization provoked by this method
failsClassNotFoundException - if the class

11
What is the diff b/w
Class.forName() and Class.forName().newInstance()?
package test;
public class Demo {
public Demo() {
System.out.println("Hi!");
}
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
Class clazz = Class.forName("test.Demo");
Demo demo = (Demo) clazz.newInstance();
}
}
12
What is the diff b/w
Class.forName() and Class.forName().newInstance()?







calling Class.forName(String) returns the Class object associated
with the class or interface with the given string name i.e. it 
returns test.Demo.class which is affected to the clazz variable of 
type Class.
Then, calling clazz.newInstance() creates a new instance of the
class represented by this Classobject. The class is instantiated as if
by a new expression with an empty argument list. In other words, 
this is here actually equivalent to a new Demo() and returns a new 
instance of Demo.
And running this Demo class thus prints the following output:
Hi!

13
What is the diff b/w
Class.forName() and Class.forName().newInstance()?




The big difference with the traditional new is 
that newInstance allows to instantiate a class that you don't know 
until runtime, making your code more dynamic.
A typical example is the JDBC API which loads, at runtime, the 
exact driver required to perform the work. EJBs containers, Servlet 
containers are other good examples: they use dynamic runtime 
loading to load and create components they don't know anything 
before the runtime.

14
What is the diff b/w
Class.forName() and Class.forName().newInstance()?








(...) A Driver class is loaded, and therefore automatically registered 
with the DriverManager, in one of two ways:
by calling the method Class.forName. This explicitly loads the driver 
class. Since it does not depend on any external setup, this way of 
loading a driver is the recommended one for using 
theDriverManager framework. The following code loads the 
class acme.db.Driver:
Class.forName("acme.db.Driver");If acme.db.Driver has been
written so that loading it causes an instance to be created and
also calls DriverManager.registerDriver with that instance as
the parameter (as it should do), then it is in the DriverManager's list 
of drivers and available for creating a connection.
(...)
15
What is the diff b/w
Class.forName() and Class.forName().newInstance()?


In both of these cases, it is the responsibility of the newlyloaded Driver class to register itself by 
calling DriverManager.registerDriver. As mentioned, this should be 
done automatically when the class is loaded.

16

More Related Content

What's hot

ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in javaAtul Sehdev
 
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Sagar Verma
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVAAbhilash Nair
 
Lect 1-class and object
Lect 1-class and objectLect 1-class and object
Lect 1-class and objectFajar Baskoro
 
Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introductionSohanur63
 
Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3Sagar Verma
 
Inner Classes & Multi Threading in JAVA
Inner Classes & Multi Threading in JAVAInner Classes & Multi Threading in JAVA
Inner Classes & Multi Threading in JAVATech_MX
 
object oriented programming language by c++
object oriented programming language by c++object oriented programming language by c++
object oriented programming language by c++Mohamad Al_hsan
 
Chapter18 class-and-objects
Chapter18 class-and-objectsChapter18 class-and-objects
Chapter18 class-and-objectsDeepak Singh
 

What's hot (18)

ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
 
Java chapter 4
Java chapter 4Java chapter 4
Java chapter 4
 
4 Classes & Objects
4 Classes & Objects4 Classes & Objects
4 Classes & Objects
 
Class and object in C++ By Pawan Thakur
Class and object in C++ By Pawan ThakurClass and object in C++ By Pawan Thakur
Class and object in C++ By Pawan Thakur
 
Java chapter 5
Java chapter 5Java chapter 5
Java chapter 5
 
Write First C++ class
Write First C++ classWrite First C++ class
Write First C++ class
 
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
 
Java Tutorial 1
Java Tutorial 1Java Tutorial 1
Java Tutorial 1
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
Lect 1-class and object
Lect 1-class and objectLect 1-class and object
Lect 1-class and object
 
Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introduction
 
Sonu wiziq
Sonu wiziqSonu wiziq
Sonu wiziq
 
Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3
 
Inner Classes & Multi Threading in JAVA
Inner Classes & Multi Threading in JAVAInner Classes & Multi Threading in JAVA
Inner Classes & Multi Threading in JAVA
 
object oriented programming language by c++
object oriented programming language by c++object oriented programming language by c++
object oriented programming language by c++
 
Chapter 7 java
Chapter 7 javaChapter 7 java
Chapter 7 java
 
Java Programming - 05 access control in java
Java Programming - 05 access control in javaJava Programming - 05 access control in java
Java Programming - 05 access control in java
 
Chapter18 class-and-objects
Chapter18 class-and-objectsChapter18 class-and-objects
Chapter18 class-and-objects
 

Viewers also liked

Viewers also liked (8)

Sessionex1
Sessionex1Sessionex1
Sessionex1
 
Class
ClassClass
Class
 
Get data
Get dataGet data
Get data
 
1 introduction to html
1 introduction to html1 introduction to html
1 introduction to html
 
Different waysconnect
Different waysconnectDifferent waysconnect
Different waysconnect
 
Exceptions
ExceptionsExceptions
Exceptions
 
Interface connection
Interface connectionInterface connection
Interface connection
 
2. attributes
2. attributes2. attributes
2. attributes
 

Similar to Class

Java class loading tips and tricks - Java Colombo Meetup, January, 2014
Java class loading  tips and tricks - Java Colombo Meetup, January, 2014Java class loading  tips and tricks - Java Colombo Meetup, January, 2014
Java class loading tips and tricks - Java Colombo Meetup, January, 2014Sameera Jayasoma
 
Java Interview Questions Answers Guide
Java Interview Questions Answers GuideJava Interview Questions Answers Guide
Java Interview Questions Answers GuideDaisyWatson5
 
Class loader basic
Class loader basicClass loader basic
Class loader basic명철 강
 
Advanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sirAdvanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sirAVINASH KUMAR
 
Advance java kvr -satya
Advance java  kvr -satyaAdvance java  kvr -satya
Advance java kvr -satyaSatya Johnny
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivityAtul Saurabh
 
Do you really get class loaders?
Do you really get class loaders? Do you really get class loaders?
Do you really get class loaders? guestd56374
 
Reflection in java
Reflection in javaReflection in java
Reflection in javaupen.rockin
 
jdbc_presentation.ppt
jdbc_presentation.pptjdbc_presentation.ppt
jdbc_presentation.pptDrMeenakshiS
 
A Scala tutorial
A Scala tutorialA Scala tutorial
A Scala tutorialDima Statz
 
Framework prototype
Framework prototypeFramework prototype
Framework prototypeDevMix
 
Framework prototype
Framework prototypeFramework prototype
Framework prototypeDevMix
 
Framework prototype
Framework prototypeFramework prototype
Framework prototypeDevMix
 

Similar to Class (20)

Java class loading tips and tricks - Java Colombo Meetup, January, 2014
Java class loading  tips and tricks - Java Colombo Meetup, January, 2014Java class loading  tips and tricks - Java Colombo Meetup, January, 2014
Java class loading tips and tricks - Java Colombo Meetup, January, 2014
 
Java Reflection Concept and Working
Java Reflection Concept and WorkingJava Reflection Concept and Working
Java Reflection Concept and Working
 
Java Interview Questions Answers Guide
Java Interview Questions Answers GuideJava Interview Questions Answers Guide
Java Interview Questions Answers Guide
 
Class loader basic
Class loader basicClass loader basic
Class loader basic
 
JDBC programming
JDBC programmingJDBC programming
JDBC programming
 
Java Class Loading
Java Class LoadingJava Class Loading
Java Class Loading
 
Diving into Java Class Loader
Diving into Java Class LoaderDiving into Java Class Loader
Diving into Java Class Loader
 
Advanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sirAdvanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sir
 
Adv kvr -satya
Adv  kvr -satyaAdv  kvr -satya
Adv kvr -satya
 
Advance java kvr -satya
Advance java  kvr -satyaAdvance java  kvr -satya
Advance java kvr -satya
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
 
Do you really get class loaders?
Do you really get class loaders? Do you really get class loaders?
Do you really get class loaders?
 
Reflection in java
Reflection in javaReflection in java
Reflection in java
 
jdbc_presentation.ppt
jdbc_presentation.pptjdbc_presentation.ppt
jdbc_presentation.ppt
 
A Scala tutorial
A Scala tutorialA Scala tutorial
A Scala tutorial
 
Java14
Java14Java14
Java14
 
Framework prototype
Framework prototypeFramework prototype
Framework prototype
 
Framework prototype
Framework prototypeFramework prototype
Framework prototype
 
Framework prototype
Framework prototypeFramework prototype
Framework prototype
 
JVM
JVMJVM
JVM
 

More from myrajendra (20)

Fundamentals
FundamentalsFundamentals
Fundamentals
 
Data type
Data typeData type
Data type
 
Hibernate example1
Hibernate example1Hibernate example1
Hibernate example1
 
Jdbc workflow
Jdbc workflowJdbc workflow
Jdbc workflow
 
2 jdbc drivers
2 jdbc drivers2 jdbc drivers
2 jdbc drivers
 
3 jdbc api
3 jdbc api3 jdbc api
3 jdbc api
 
4 jdbc step1
4 jdbc step14 jdbc step1
4 jdbc step1
 
Dao example
Dao exampleDao example
Dao example
 
Internal
InternalInternal
Internal
 
3. elements
3. elements3. elements
3. elements
 
Headings
HeadingsHeadings
Headings
 
Forms
FormsForms
Forms
 
Css
CssCss
Css
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Starting jdbc
Starting jdbcStarting jdbc
Starting jdbc
 
Properties
PropertiesProperties
Properties
 
Java.sql package
Java.sql packageJava.sql package
Java.sql package
 
Interface callable statement
Interface callable statementInterface callable statement
Interface callable statement
 

Recently uploaded

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

Class

  • 1. JDBC – Java DataBase Connectivity java.lang Class Class<T>
  • 2. public final class Class<T>extends Objectimplements Serializable, GenericDeclaration, Type, AnnotatedElement  Instances of the class Class represent classes and interfaces in a running Java application. An enum is a kind of class and an annotation is a kind of interface. Every array also belongs to a class that is reflected as a Class object that is shared by all arrays with the same element type and number of dimensions. The primitive Java types (boolean, byte, char, short, int, long, float, and double), and the keyword void are also represented as Class objects.  Class has no public constructor. Instead Class objects are constructed automatically by the Java Virtual Machine as classes are loaded and by calls to the defineClass method in the class loader. 2
  • 3. 3
  • 4. Class.forName() method  This method is used to load the class into JVM’s memory . (without creating the object also it will loads into the jvm’s memory. Class.forname(“class”); Or Reference=Class.forName(“class”) 4
  • 5.      By using the Class.forName() we can load any class object into JVM’s memory without creating the object. Ex; Class c=Class.forName(“java.lang.ArraayList”); When the class.forName() is executed the code it will create a class boject. Inside the class object it plays the name of the class which is loaded into JVM and the name of the package of the class which is loaded into the JVM. It is a factory method( means capable of constructing its own java class object is called “factory method”. 5
  • 6. Ex:  Class.forName("com.mysql.jdbc.Driver");  When this statement is executed, it contains the static block of given jdbc Driver class, so the static block executes automatically  In this static block, there will be a logic to create JDBC driver class object and to register that object with driver manager service through by calling DriverManager.registerDriver() 6
  • 7.  Class.forName() loads the given jdbc Driver class bcoz of the logic available in the static block of that jdbc driver class, the jdbc driver class object will be registered with Driver Manager service 7
  • 8. Static { mysql.jdbc.Driver jd= new mysql.jdbc.Driver(); Try { DriverManager.registerDriver(jd); } Catch(SQLException se) { se.printStackTrace(); } 8
  • 9.  public static Class<?> forName(String className) throws ClassNotFoundException 9
  • 10.  Returns the Class object associated with the class or interface with the given string name. Invoking this method is equivalent to: Class.forName(className, true, currentLoader) where currentLoader denotes the defining class loader of the current class.For example, the following code fragment returns the runtime Class descriptor 10
  • 11.  Class t = Class.forName("java.lang.Thread") A call to forName("X") causes the class named X to be initialized.  Parameters:className - the fully qualified name of the desired class.Returns:the Class object for the class with the specified name.Throws:LinkageError - if the linkage failsExceptionInInitializerError - if the initialization provoked by this method failsClassNotFoundException - if the class 11
  • 12. What is the diff b/w Class.forName() and Class.forName().newInstance()? package test; public class Demo { public Demo() { System.out.println("Hi!"); } @SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { Class clazz = Class.forName("test.Demo"); Demo demo = (Demo) clazz.newInstance(); } } 12
  • 13. What is the diff b/w Class.forName() and Class.forName().newInstance()?     calling Class.forName(String) returns the Class object associated with the class or interface with the given string name i.e. it  returns test.Demo.class which is affected to the clazz variable of  type Class. Then, calling clazz.newInstance() creates a new instance of the class represented by this Classobject. The class is instantiated as if by a new expression with an empty argument list. In other words,  this is here actually equivalent to a new Demo() and returns a new  instance of Demo. And running this Demo class thus prints the following output: Hi! 13
  • 14. What is the diff b/w Class.forName() and Class.forName().newInstance()?   The big difference with the traditional new is  that newInstance allows to instantiate a class that you don't know  until runtime, making your code more dynamic. A typical example is the JDBC API which loads, at runtime, the  exact driver required to perform the work. EJBs containers, Servlet  containers are other good examples: they use dynamic runtime  loading to load and create components they don't know anything  before the runtime. 14
  • 15. What is the diff b/w Class.forName() and Class.forName().newInstance()?     (...) A Driver class is loaded, and therefore automatically registered  with the DriverManager, in one of two ways: by calling the method Class.forName. This explicitly loads the driver  class. Since it does not depend on any external setup, this way of  loading a driver is the recommended one for using  theDriverManager framework. The following code loads the  class acme.db.Driver: Class.forName("acme.db.Driver");If acme.db.Driver has been written so that loading it causes an instance to be created and also calls DriverManager.registerDriver with that instance as the parameter (as it should do), then it is in the DriverManager's list  of drivers and available for creating a connection. (...) 15
  • 16. What is the diff b/w Class.forName() and Class.forName().newInstance()?  In both of these cases, it is the responsibility of the newlyloaded Driver class to register itself by  calling DriverManager.registerDriver. As mentioned, this should be  done automatically when the class is loaded. 16