SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Destacado

Destacado (8)

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

Similar a 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 a 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
 

Más de 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
 

Último

CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 

Último (20)

CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

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