1 of 40

20CS09-OOPS THROUGH JAVA

1

Dr.S.Naganjaneyulu

Professor

Department of IT

LAKIREDDY BALI REDDY COLLEGE OF ENGINEERING,Mylavaram

Krishna Dist, Andhra Pradesh

2 of 40

Course Educational Objective

  • Concentrates on the methodological and technical aspects of software design and Programming based on OOP. Acquire the basic knowledge and skills necessary to implement object-oriented Programming techniques in software development through JAVA. Know about the importance of GUI based applications and the development of those Applications through JAVA. Get sufficient knowledge to enter the job market related to Web development.

2

3 of 40

Course Outcomes

At the end of the course, the student will be able to:

  • CO1: Identify Object Oriented concepts through constructs of JAVA.

  • CO2: Analyze the role of Inheritance, Polymorphism and implement Packages, Interfaces in Program design using JAVA.

  • CO3: Explore Exception handling and Multi-threading concepts in program design using JAVA.

  • CO4: Develop GUI based applications using Applet class and explore the concept of Event Handling using JAVA.

  • CO5: Design some examples of GUI based applications using AWT controls and Swings

3

4 of 40

4

5 of 40

5

6 of 40

6

OS/Hardware

machine code

C source code

myprog.c

gcc

myprog.exe

Platform Dependent

JVM

bytecode

Java source code

myprog.java

javac

myprog.class

OS/Hardware

Platform Independent

7 of 40

Issues:

    • Portability
    • Platform Independence
    • Security
    • Reliability
    • Reusability / Extensibility
    • Shareability( Networking)

7

8 of 40

  • Overview and Characteristics of Procedure-Oriented Programming
  • Overview and Characteristics of Object-Oriented Programming
  • Object-Oriented Programming – Definition
  • Basic Concepts of Object-Oriented Programming
  • Benefits of Object-Oriented Programming

8

9 of 40

Hierarchy of programming paradigms:

9

10 of 40

Procedure Oriented Programming

10

  • In procedure oriented approach the problem is viewed as a sequence of things to be done such as reading, calculating and printing. A number of functions are required to perform (or) accomplish these tasks.

  • A program in a procedural language is a list of instruction where each statement tells the computer to do something. It focuses on procedure (function) & algorithm is needed to perform the derived computation.

  • In procedure oriented approach, When a program become larger, it is divided into function & each function has clearly defined purpose. Dividing the program into functions & module is one of the cornerstones of structured programming.

Examples : COBOL,FORTRAN,PASCAL and C

When we concentrate on the development of functions, very little attention is given to the data that is being used by various functions. Global data is the data that is being shared by all the functions and each function has its own local data as shown in figure.

11 of 40

Procedure Oriented Programming

11

  • Examples : COBOL,FORTRAN,PASCAL and C
  • When we concentrate on the development of functions,

very little attention is given to the data that is being used

by various functions.

The following diagrams shows the example of procedure oriented programming.

  • Global data is the data that is being shared by all the

functions and each function has its own local data as

shown in the figure.

12 of 40

Characteristics of Procedure-Oriented Programming

  • Emphasis is on doing things.
  • Large programs are divided into smaller programs known as functions.
  • Most of the functions share global data.
  • Data move openly around the system from function to function.
  • Functions transform data from one form to another.
  • Employs top-down approach in program design.

12

13 of 40

Procedure Oriented Programming �advantages & disadvantages

  • Advantages:
  • Its relative simplicity, and ease of implementation of compilers and interpreters
  • The ability to re-use the same code at different places in the program without copying it.
  • An easier way to keep track of program flow.
  • The ability to be strongly modular or structured.
  • Needs only less memory.

13

  • Disadvantages:
  • Data is exposed to whole program, so no security for data.
  • Difficult to relate with real world objects.
  • Difficult to create new data types reduces extensibility.
  • Importance is given to the operation on data rather than the data.

14 of 40

Software Design Approaches:Top down vs bottom up:

14

15 of 40

Characteristics of Procedure-Oriented Programming

  • Emphasis is on doing things.
  • Large programs are divided into smaller programs known as functions.
  • Most of the functions share global data.
  • Data move openly around the system from function to function.
  • Functions transform data from one form to another.
  • Employs top-down approach in program design.

16 of 40

Object-Oriented Programming

  • OOP treat data as a critical element in the program development and does not allow it to flow freely around the system.
  • It ties data more closely to the functions that operate on it, and protects it from accidental modification from outside functions.
  • OOP allows decomposition of a problem into a number of entities called objects and then build data functions around these objects.
  • The data of an object can be accessed only by the functions associated with that object.
  • Functions of one object can access the functions of another objects.

17 of 40

Organization of data and functions in OOP

Data

Functions

Object A

Data

Functions

Object B

Data

Functions

Object C

Communication

18 of 40

Characteristics of Object-Oriented Programming�

  • Emphasis is on data rather than procedure.
  • Programs are divided into objects.
  • Data structures are designed such that they characterize the objects.
  • Functions that operate on the data of an object are tied together in the data structure.
  • Data is hidden and can not be accessed by external functions.

19 of 40

Characteristics of Object-Oriented Programming

  • Objects may communicate with each other through functions.
  • New data and functions can be added easily whenever necessary.
  • Follows bottom-up approach in program design.

continue …

20 of 40

Object-Oriented Programming

  • Definition:

It is an approach that provides a way of modularizing programs by creating partitioned memory area for both data and functions that can be used as templates for creating copies of such modules on demand. Thus the object is considered to be a partitioned area of computer memory that stores data and set of operations that can access that data.

21 of 40

Basic Concepts of Object-Oriented Programming

  • Objects
  • Classes
  • Data Abstraction and Encapsulation
  • Inheritance
  • Polymorphism
  • Dynamic Binding
  • Message Passing

22 of 40

Basic Concepts of OOP

  • Objects: Objects are the basic run-time entities in an object-oriented system. They may represent a person, a place, a bank account, etc. Objects take up space in the memory and have an associated address like a structure in C.

When a program is executed, the objects interact by sending messages to one another.

continue …

23 of 40

23

24 of 40

24

25 of 40

Basic Concepts of OOP

  • Objects

Object : CUSTOMER

DATA

AC No.

Name of AC Holder

Address

FUNCTIONS

Deposit

Withdrawal

AC Balance Display

Object : ACCOUNT

DATA

AC No.

AC Balance

Type of Account

FUNCTIONS

Account Balance

continue …

26 of 40

Basic Concepts of OOP

  • Classes

Classes are user-defined data types.

The entire set of data and code of an object can be made a user-defined data type with the help of a class. Objects are variables of the type class. Once a class has been defined, we can create any number of objects belonging to that class. Each object is associated with the data of type class with which they are created.

A class is a collection of objects of similar type.

continue …

27 of 40

Basic Concepts of OOP

  • Classes

continue …

28 of 40

Basic Concepts of OOP

  • Classes

I

continue …

29 of 40

Basic Concepts of OOP

  • Data Abstraction and Encapsulation
    • The wrapping up of data and functions into a single unit is known as encapsulation.

    • The data is not accessible to the outside world, and only those functions which are wrapped in the class can access it.

    • These functions provide the interface between the object’s data and the program. This insulation of the data from direct access by the program is called data hiding or information hiding.

continue …

30 of 40

Basic Concepts of OOP

  • Data Abstraction and Encapsulation

The attributes wrapped in the classes are called data members and the functions that operate on these data are called methods or member functions.

Since the classes use the concept of data abstraction, they are known as Abstracted Data Types (ADT).

continue …

31 of 40

Basic Concepts of OOP

  • Inheritance
    • Inheritance is the process by which objects of one class acquire the properties of objects of another class.

    • It supports the concept of hierarchical classification.

    • Each derived class shares common characteristics with the class from which it is derived.

continue …

32 of 40

Property Inheritance

Bird

Attributes:

Feathers

Lay eggs

Flying Bird

Attributes:

------------

------------

Non-flying Bird

Attributes:

------------

------------

Robin

Attributes:

------------

------------

Swallow

Attributes:

------------

------------

Penguin

Attributes:

------------

------------

Kiwi

Attributes:

------------

------------

33 of 40

Basic Concepts of OOP

  • Inheritance
    • Inheritance provides the idea of reusability.

      • We can add additional features to an existing class without modifying it.

(By deriving new class from existing one. The new class will have the combined features of both the classes.)

continue …

34 of 40

Basic Concepts of OOP

  • Polymorphism - ability to take more than one form
    • An operation may exhibit different behaviours in different instances.
    • The behaviour depends upon the types of data used in the operation.
    • add( 3, 5) gives 8
    • Add(“hello”, “-world”) gives “hello-world”

continue …

35 of 40

Basic Concepts of OOP

  • Polymorphism - ability to take more than one form
    • The process of making an operator to exhibit different behaviours in different instances is known as operator overloading.
    • << Insertion Operator
    • << Left-shift bit-wise operator
    • Using a single function name to perform different types of tasks is known as function overloading.
    • add( 3, 5) gives 8
    • Add(“hello”, “-world”) gives “hello-world”

continue …

36 of 40

Basic Concepts of OOP

  • Dynamic Binding

Binding refers to the linking of a procedure call to the code to be executed in response to the call.

Dynamic binding ( late binding ) means that the code associated with a given procedure call is not known until the time of the call at run-time.

It is associated with polymorphism and inheritance.

continue …

37 of 40

Basic Concepts of OOP

  • Message Passing
    • An oop consists of a set of objects that communicate with each other.
    • Oop involves the following steps:
      • Creating classes that define objects and their behaviour.
      • Creating objects from class definitions.
      • Establishing communication among objects.
    • Objects communicate with one another by sending and receiving information.

continue …

38 of 40

Basic Concepts of OOP

  • Message Passing
    • A message for an object is a request for execution of a procedure.
    • The receiving object will invoke a function and generates results.
    • Message passing involves specifying:
      • The name of the Object.
      • The name of the Function.
      • The information to be send.

continue …

39 of 40

Benefits of OOP

  • Inheritance – eliminate redundant code and extend the use of existing classes.
  • We can build programs from the standard working module, no need of starting from the scratch.
  • Data hiding helps the programmer to build secure programs that can not be invaded by code in other parts of the program.

40 of 40

Benefits of OOP

  • Multiple instances of an objects can co-exists with out any interference.
  • It is easy to partition the work in a project based on objects.
  • Object-oriented system can be easily upgraded from small to large systems.
  • Message passing techniques for communication between objects makes the interface descriptions with external systems much simpler.
  • Software complexity can be easily managed.

continue …