You are on page 1of 7

Chapter 1 

Object Oriented Programming 

1.1 Introduction 
Object-oriented programming (OOP) is a programming paradigm based on the
concept of "objects", which are data structures that contain data, in the form of fields,
often known as attributes; and code, in the form of procedures, often known as
methods. A distinguishing feature of objects is that an object's procedures can access
and often modify the data fields of the object with which they are associated (objects
have a notion of "this"). In object-oriented programming, computer programs are
designed by making them out of objects that interact with one another.There is
significant diversity in object-oriented programming, but most popular languages are
class-based, meaning that objects are instances of classes, which typically also
determines their type. 
Many of the most widely used programming languages are multi-paradigm
programming languages that support object-oriented programming to a greater or
lesser degree, typically in combination with imperative, procedural programming.
Significant object-oriented languages include C++, Objective-C, Smalltalk, Delphi,
Java, C#, Perl, Python, Ruby and PHP. 

1.2 Fundamental features and concepts 
A survey by Deborah J. Armstrong of nearly 40 years of computing literature
identified a number of fundamental concepts found in the large majority of definitions
of OOP. 
Not all of these concepts appear in all object-oriented programming languages. For
example, object-oriented programming that uses classes is sometimes called classbased programming, while prototype-based programming does not typically use
classes. As a result, a significantly different yet analogous terminology is used to
define the concepts of object and instance. 
Benjamin C. Pierce and some other researchers view any attempt to distill OOP to a
minimal set of features as futile. He nonetheless identifies fundamental features that
support the OOP programming style in most object-oriented languages. 
- Encapsulation 
- Polymorphism 

Concepts in programming languages. which have been constructed via a class)  . and dynamic dispatch.  Additional concepts used in object-oriented programming include:  . Michael Lee Scott in Programming Language Pragmatics considers only encapsulation.Abstraction    1.Object inheritance        Similarly.Message passing  . John C..Encapsulation enforces modularity  Encapsulation refers to the creation of self-contained modules that bind processing .Classes of objects (object constructors)  .  . Mitchell identifies four main features: dynamic dispatch. abstraction.3 Additional features  .Instances of classes (objects. in his 2003 book. subtype polymorphism.Methods which act on the attached objects. inheritance. and inheritance.

only the processing and data associated with that unique step must be added. a class could be Manager. That means less programming is required when adding functions to complex systems. The ability to reuse existing objects is considered a major advantage of object technology. and polymorphism lets that cursor take simulating system behaviour. The routine to move the cursor on screen in response to mouse movement can be written for "cursor".functions to the data. and Pat and Jan could be two instances (two objects) of the Manager class. These user-defined data types are called "classes". which keeps routines separate and less prone to conflict with each other. and one instance of a class is an "object". in a payroll system. and inheritance lets the structure and methods in one class pass down the hierarchy. If a step is added at the bottom of a hierarchy. a screen cursor may change its shape from an arrow to a line depending on the program mode. Everything else above that step is inherited.  -Polymorphism takes any shape  Object-oriented programming lets programmers create procedures for objects whose exact type is not known until runtime.                              .  -Inheritance passes "knowledge" down  Classes are created in hierarchies. Encapsulation ensures good code modularity. For example. For example.

odbc. Import the required package .Java.Jdbc:OdbcDriver") system.forName("Sun. Load and register the driver The prototype for the class which is used is public static class forName(String) throws Class Not found Exception Class Jdbc Demo1 { public static void main (String []args) { try { class.outprintln("driver class successfully loaded") } catch(Class Not found Exception) {} } .jdbc.sql 2.Chapter 2 Database Connection using JDBC and Exception Handling Steps needed to connect the database using JDBC: 1.Javax.sql .

string. Create Statement object Our next step is to create an object which will be used to send SQL command to database Prototype isPublic statement createStatement() throws SQL Exception 5. Prototype is public static Connection gertConnection(String conn.forName("Sun.jdbc. String Password) Class Test { public static void main() { try { class.Jdbc:OdbcDriver") Connection conn = DriverManager."pass"). } catch(Class Not found Exception) {} } 4.getConnection ("jdbc:odbc:user". there are 2 types of SQL commands. To do this java provides a method called getConnection() which belongs to the Class DriverManager.public int executeUpdate(String) throws SQL Exception . Execute the query According to JDBC.odbc.3. Connect to the database Our next job is to connect with the database.public ResultSet executeQuery(String) throws SQL Exception ."username". String user.

Move the required pointer using . Disconnect with the database The final step in JDBC programming is to close the database connection which is done by the method of close of connection() method. etc. Its prototype isPublic void close() throws SQL Exception . Now to do this. we assume we have the data stored inside the resultSet.6.Retrieve the data stored in current row using public string getString(String). We need to take 2 steps. getData(). 7. getBoolean(). getInt(). Fetch the data Our next aim is to retrieve the data.

ResultSet. while(rs.odbc. Class MyDemoCode { { public static void main (String []args) { try { class.createStatement()."username".next()) { String str = rrs.executeQuery(“Select ename.sql.getConnection ("jdbc:odbc:user". salary from employee”).outprintln("driver class successfully loaded") } try { Connection conn = DriverManager. Statement st = = st. } catch(SQL Exception ex) {} } } . int amt = rs.Jdbc:OdbcDriver") system.Complete Program import java.forName("Sun.jdbc. system.out.getInt(2).getString(1)."pass").close().*. } conn.println(str + “\+” + amt).