Object Oriented Programming Concepts

Description

OOP in JAVA
agni bharathi
Note by agni bharathi, updated more than 1 year ago More Less
Cmagapu
Created by Cmagapu over 9 years ago
agni bharathi
Copied by agni bharathi over 8 years ago
8
0

Resource summary

Page 1

OBJECT ORIENTED PROGRAMMING CONCEPTS

Object Oriented Programming (OOP) is at the core of Java. It is an approach that provides a way for modularizing programs by creating partitioned memory area for both data and functions.

Computer programs consist of 2 elements:1. Code2. DataTherefore, a program can be conceptually organised in 2 ways:1.around its code(Process-oriented) -BASIC2.around its data(object oriented)-Java

The Object-Oriented Model organizes the program around its data and a set of interfaces to that data.

An object can be considered as a partitioned area of computer memory that stores data and a set of operations that can access that data.

ABSTRACTION-AN IMPORTANT FEATURE OF OOP:It is to represent the essential features of a system without getting involved with the complexity of the entire system

A way to manage abstraction is to use hierarchical classification(layering the complex systems into manageable pieces). It can be applied to programs

* Programs --------> Transformed by abstraction into --------> component objects* A sequence of process steps can become a collection of messages between these objectsTHUS, EACH OBJECT WILL DEFINE ITS OWN UNIQUE BEHAVIOUR

Objects (FORMALLY CALLED INSTANCES) share three characteristics. they all have:1. Identity (name) 2. State (maintained in 1 or more variables WHICH ARE FORMALLY CALLED INSTANCE VARIABLES)3. Behaviour(implemented by methods WHICH ARE FORMALLY CALLED INSTANCE METHODS)Therefore,AN OBJECT IS A SOFTWARE BUNDLE OF VARIABLES AND RELATED METHODS

When an object is mapped into software representation, it consists of 2 parts:1. Data Structure (referred to as attributes) variables2. Processes that may correctly change the data structure(referred to as methods) functions

MESSAGES:In a software application, an object usually appears as a component of a larger program that contains many other objects. Through the interaction of these objects, programmers achieve functionality of the program. Software objects interact and communicate with each other using messages.

Data Messaging: an object passes and receives information from another object using member functions during program execution

A class is a blueprint or prototype, that defines the variables and the methods common to all objects of a certain kind. A class is called object factory because by using a class type, numerous objects can be created with similar characteristics. A class determines the nature(state and behaviour of all objects of its type.

When you create an instance of a class, the system allocates enough memory for the object and all its instance variables. Each instance gets its own copy of all the instance variables defined in the class.

In addition to instance variables and methods, classes can define:1. Class variables( Static variables): Contain information shared by all members of the class2. Class methods(Static Methods): which can be invoked directly from the class

Classes vs. Objects:*Class is a template from which an object is created. *Objects will exist in the memory of the computer, whereas a class will not.

A Class has three parts:1. Attributes/fields/member variables: Properties of any object of the class. There is a type(set of values with operations defined on those values) associated with each field. The type constrains the kind of values the field can store.2. Constructors: Used to create objects of a class.3.Behaviour/public interface/functions: Set of operations/functions/methods which can be invoked on an object

Three OOP Principles:1. ENCAPSULATION:Mechanism that binds together code and the data it manipulates. This keeps it safe from outside interference and misuse. THE BASIS OF ENCAPSULATION IS THE CLASS. Primary benefits of encapsulation are:* Modularity- Source code for an object can be written and maintained independently of the source code of other objects - Object can be used easily by someone else in the system.*Information hiding- object can maintain private information and methods which can be changed any time without affecting the other objects that depend on it 2. INHERITANCE:It is the process by which one object acquires the properties of another.It is the capability of a class(DERIVED CLASS to use the properties and methods of another class (BASE CLASS) while adding its own functionalityAdvantage: Any Data Member can be reused without defining3.POLYMORPHISM: Allows 2 or more classes to respond to the same message in different waysCapability of an interface to do two different things based on the data of different type it accepts and give the desired output accordingly.Types of polymorphism:*Overloading*Overriding

a variable's data type determines the:*values it may contain*operations that may be performed on it

Data types:1.Primitive(predefined by the language, named by a reserved keyword)*int*byte*short*long*float*double*boolean*char2.Composite

Literals-Source code representation of a fixed value. Represented directly in the program code without requiring computation.

CONTROL FLOW STATEMENTS:Expression- construct made up of variables, operators and method invocations that evaluates to a single value.Statements-complete units of executionBlock-group of 1 or more statements between a pair of curly braces. Can be used anywhere a single statement is allowedCONTROL FLOW STATEMENTS - Statements that break up the flow of execution by employing decision making, looping, and branching to enable a program to conditionally execute only particular blocks of code.

Show full summary Hide full summary

Similar

Useful String Methods
Shannon Anderson-Rush
HTTPS explained with Carrier Pigeons
Shannon Anderson-Rush
Historical Development of Computer Languages
Shannon Anderson-Rush
Java Week 5 Object Oriented Programming
Troy Bowlin
Flvs foundations of programming dba 2
mariaha vassar
Concepts of Objects and Classes
BK Modding
Introduction to Java
BK Modding
Programing Languages History
Ricardo Sol
Python Quiz
karljmurphy
computer systems and programming quiz
Molly Batch
Think Python
tsilvo2001