SlideShare a Scribd company logo
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)

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

IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIES VE
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutesconfluent
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeCzechDreamin
 
Agentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdfAgentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdfChristopherTHyatt
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomCzechDreamin
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Product School
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Julian Hyde
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxAbida Shariff
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...CzechDreamin
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupCatarinaPereira64715
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024Stephanie Beckett
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...CzechDreamin
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityScyllaDB
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyJohn Staveley
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1DianaGray10
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsPaul Groth
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekCzechDreamin
 

Recently uploaded (20)

IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Agentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdfAgentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdf
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 

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