Introduction to Object Oriented Programming

9
Object Oriented Programming Object Technology Concepts What is Object Technology? Object Technology is developing software based on objects. Object - combination of data and function. Procedural or structural programming focused mainly on functions. -Data and functions were considered separately. What Object Technology IS NOT! -Just another programming language. -A silver bullet -A flash in the pan -Magic The focus of procedural programming is to break down a programming task into a collection of variables, data structures, and subroutines, whereas in object-oriented programming it is to break down a programming task into classes with each "class" encapsulating its own methods (subroutines). The most important distinction is whereas procedural programming uses procedures to operate on data structures, object-oriented programming bundles the two together so an "object", which is an instance of a class, operates on its "own" data structure. The difference between Procedural and Objects: Procedural - A programming language that requires programming discipline. – data and function are considered separately. There is no common way to access data could be enforced easily. Objects – data and function are combined. The use of an object requires knowledge of the function names. Objects are key to understanding object-oriented technology. Look around right now and you'll find many examples of real-world objects: your dog, your desk, your television set, your bicycle.

description

Introduction to Object Oriented Programming

Transcript of Introduction to Object Oriented Programming

Page 1: Introduction to Object Oriented Programming

Object Oriented Programming

Object Technology Concepts

What is Object Technology?

Object Technology is developing software based on objects.

Object - combination of data and function.

Procedural or structural programming focused mainly on functions.

-Data and functions were considered separately.

What Object Technology IS NOT!

-Just another programming language.

-A silver bullet

-A flash in the pan

-Magic

The focus of procedural programming is to break down a programming task into a collection of variables, data structures, and subroutines, whereas in object-oriented programming it is to break down a programming task into classes with each "class" encapsulating its own methods (subroutines). The most important distinction is whereas procedural programming uses procedures to operate on data structures, object-oriented programming bundles the two together so an "object", which is an instance of a class, operates on its "own" data structure.

The difference between Procedural and Objects:

Procedural - A programming language that requires programming discipline.

– data and function are considered separately. There is no common way to access data could be enforced easily.

Objects – data and function are combined. The use of an object requires knowledge of the function names. Objects are key to understanding object-oriented technology. Look around right now and you'll find many examples of real-world objects: your dog, your desk, your television set, your bicycle.

In terms of Re-use

Procedural – hard to identify reusable code opportunities because of the lack of encapsulation.

Objects – There is the re-use of code

Charles Alfred Cruz, 06/09/15,
a specific, fail-safe solution to a problem (from the notion that a bullet made of silver is necessary to kill a werewolf)
Charles Alfred Cruz, 06/09/15,
briefly successful or popular
Page 2: Introduction to Object Oriented Programming

Why Object Technology?

-A natural way of thinking

-Ability to support change

OOP is a programming methodology that views a program as similarly consisting of objects that interact with one another by means of action.

OOP is a software development methodology in which a program is conceptualized as a group of objects that work together. The biggest challenge for a new Java Programmer is learning OOP at the same time as Java Language. OOP is an approach to building computer programs that mimics how objects are assembled in physical world.

An Object is a thing both tangible and intangible that you can imagine. A program written in object oriented style will consist of interacting objects. It is a program construction that has data (or information) associated with it and that can perform certain actions. When a program is run, the objects interact with one another in order to accomplish whatever the program is designed to do.

Methods – The actions performed by objects.

Class is a type or kind of object. All objects in the same class have the same kinds of data and the same methods.

What is Java?

An object-oriented programming language developed at SUN Microsystems.

A set of standardized Class Libraries (packages) that support predefined reusable functionality. Has virtual machine that can be embedded in Web browsers and Operating System.

Java [slang for "coffee"] is kind of a streamlined version of C++, designed for portability. Its key advantage is that Java programs can be run on any operating system for which a Java "virtual environment" is available. (Programs in most other languages have to be modified and recompiled to go from one OS to another.)

Aims of Java

1. Object -Orientation2. Portability3. Performance4. Security5. Internationalization

Page 3: Introduction to Object Oriented Programming

Java Virtual Machine (JVM)

A self contained environment that acts as if it is a separate computer.

Java Technologies

Application – a stand alone Java program that runs via the java command with no security restrictions, and contains a main method.

Applets – webpage applications that require a Web browsers, has a limited access rights to a client.

Servlets – sever side application, set of HTML pages that interacts with the user then sends collected data to the servlet to be processed

JSP’s – server (Java Server Pages) – Server side application, HTML page with special embedded tags which determine the actual content of the HTML at the time of it’s delivering to the client.

EJB’s (Enterprise Java Beans) – framework for creating extensible, scalable, object oriented systems.

Charles Alfred Cruz, 06/09/15,
Enterprise Java Beans (EJB) is a development architecture for building highly scalable and robust enterprise level applications to be deployed on J2EE compliant Application Server such as JBOSS, Web Logic etc.EJB 3.0 is being a great shift from EJB 2.0 and makes development ofEJB based applications quite easy.runs on a web server and is used to develop large, complex websites is a framework that allows one to develop Enterprise applications more easily using Java Enterprise Edition. It does this by using standard components. These components specify how an application works. This is usually called business logic.
Charles Alfred Cruz, 06/09/15,
JavaServer Pages (JSP) is a server-side programming technology that enables the creation of dynamic, platform-independent method for building Web-based applications. JSP have access to the entire family of Java APIs, including the JDBC API to access enterprise databases.An Applet is for client side execution, generally graphical components.Servlet is for server side execution, with no graphical components, but can return HTML or any kind of data (generally called a service).
Charles Alfred Cruz, 06/09/15,
A servlet is a small Java program that runs within a Web server.Servlets receive and respond to requests from Web clients, usually across HTTP, the HyperText Transfer Protocol.
Charles Alfred Cruz, 06/09/15,
Applets are typical examples of transient and auxiliary applications that don't monopolize the user's attention. Applets are not full-featured application programs, and are intended to be easily accessible. The word applet was first used in 1990 in PC Magazine.
Charles Alfred Cruz, 06/09/15,
Application can only be run from a computer.
Page 4: Introduction to Object Oriented Programming

JavaBytecode .class

Linux

JVM

Windows

JVM

Unix

JVM

javac

java

.javaJavaSource

Java Development Cycle

Java Keywords

abstract defaultif private this

boolean do implements protected throw

break double Import public throws

byte else instanceof return transient

case extends int short try

catch final interface static void

char finally long strctfp volatile

class float native super while

const for new switch

continue goto package synchronized

Page 5: Introduction to Object Oriented Programming

Java 8 Primitive Data Types

Variable – a place where information can be stored while a program is running. The value can be changed at any point in the program. Operators

Escape Characters

\” Double quote

\” Single quote

\\ Backslash

\n New line

\t Tab

// Add Comment

Type name

Description

byte Integer

short Integer

int Integer

long Integer

float Real number

double Real number

char 16 bit Unicode

character

boolean Boolean – true/false

Operator Description

[] Array index

++ Increment

-- Decrement

+ Positive

- Negative

! Not

* Multiplied

/ Divided

% Remainder

+ Added

- Subtracted

== Is equal to

!= Not equal to

&& AND

|| OR

Page 6: Introduction to Object Oriented Programming

Brief History of Java

Project Green was started and needed a language for software development

1991 – Java was first developed and called Oak, later changed to Java for copyright reasons

1992 – release of the first product called”7” – intelligent remote control

1993-1994 – selling and no buyers

1994 – Development of Hot Java

1996(early) – first version of Java was released 1.02

1996(late) – much better version 1.1

1998 – Version 1.2 with new GUI support (now called Java2)

Java Basic Syntax

About Java programs, it is very important to keep in mind the following points.

Case Sensitivity - Java is case sensitive, which means identifier Hello and hello would have different meaning in Java.

Class Names - For all class names the first letter should be in Upper Case. If several words are used to form a name of the class, each inner word's first letter should be in Upper Case.

Example class MyFirstJavaClass

Method Names - All method names should start with a Lower Case letter. If several words are used to form the name of the method, then each inner word's first letter should be in Upper Case.

Example public void myMethodName()

Program File Name - Name of the program file should exactly match the class name. When saving the file, you should save it using the class name (Remember Java is case sensitive) and append '.java' to the end of the name (if the file name and the class name do not match your program will not compile).

Example : Assume 'MyFirstJavaProgram' is the class name. Then the file should be saved as'MyFirstJavaProgram.java'

public static void main(String args[]) - Java program processing starts from the main() method which is a mandatory part of every Java program..

Page 7: Introduction to Object Oriented Programming

Java Identifiers

All Java components require names. Names used for classes, variables and methods are called identifiers.

In Java, there are several points to remember about identifiers. They are as follows:

All identifiers should begin with a letter (A to Z or a to z), currency character ($) or an underscore (_).

After the first character identifiers can have any combination of characters. A key word cannot be used as an identifier. Most importantly identifiers are case sensitive. Examples of legal identifiers: age, $salary, _value, __1_value Examples of illegal identifiers: 123abc, -salary