Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connection

 
Glenny Dsilva
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to understand connection pooling

and i came across a following code

As i know that we cannot create

an object of Connection class by the following code:

Connection con = new Connection(); // since connection class is abstract

But how does it allow

Connection [] con = new Connection[4];

Pls. explain ...
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Glenny Dsilva:

Connection con = new Connection(); // since connection class is abstract



You can not instantiate Connection as It is an Interface, It is not a class or abstract class.

This is OOP concepts that you can typecast your class to connection which is implementing same.
And this has answer of your question below



Originally posted by Glenny Dsilva:
But how does it allow

Connection [] con = new Connection[4];


This line of code doesn't create 4 objects of Connection rather this create an Array of Connection type which can hold 4 COnnections

Originally posted by Glenny Dsilva:
I am trying to understand connection pooling


Connection pooling is concept of reusing a connection instead of creating everytime you need.
Connection pooling can increase performance of your application exponentially because Creating and closing connection every time you need them is considered expensive, also it involves network trip to perform such operations.

hope this answer your query

Shailesh
 
Glenny Dsilva
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx a lot ..
 
Kapil Shrivastava
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Connection is not a class, its an interface.
So if we write
Connection[] con=new Connection[4];
we are defining a array which will contain elements of type Connection.
Does this explain the reason or not???
 
Harinath Kuntamukkala
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Connection is an interface. So you can't create object for an interface.Bur you can instantiate thorw the class which is implementing that inteface.
 
illindra brahmaji
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Glenny Dsilva:
I am trying to understand connection pooling

and i came across a following code

As i know that we cannot create

an object of Connection class by the following code:

Connection con = new Connection(); // since connection class is abstract

But how does it allow

Connection [] con = new Connection[4];

Pls. explain ...
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Illindra,
Welcome to JavaRanch!

Note that you can edit your post by clicking the pencil and paper icon on the first line. Or you can just reply to this thread with the text.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic