KEMBAR78
object oriented programming examples | PPTX
Chapter 1
Introduction to Object-Oriented
Programming
Outline
• Types of programming paradigm
• Overview of OO principles
• Overview of Java Programming and types of
Java Program
• Definition of Java Application, Java Applets
• Editing, Compiling and Interpreting
Types of programming paradigm
• The major programming paradigms:
– Imperative
– Logical
– Functional
– Object-Oriented
Types of programming paradigm (cont.)
Imperative
• assumes that the computer can maintain through
environments of variables any changes in a
computation process.
• Computations are performed through a guided
sequence of steps, in which these variables are
referred to or changed.
• The order of the steps is crucial, because a given step
will have different consequences depending on the
current values of variables when the step is executed.
“First do this and next do that”
Types of programming paradigm (cont.)
• There are two reasons for popularity:
– the imperative paradigm most closely resembles the actual
machine itself, so the programmer is much closer to the
machine.
– because of such closeness, the imperative paradigm was
the only one efficient enough for widespread use until
recently.
• Language representatives
– Fortran, Algol, Pascal, Basic, C
Types of programming paradigm (cont.)
• Advantages
– efficient;
– close to the machine;
– popular;
– familiar.
• Disadvantages
– The semantics of a program can be complex to understand
or prove;
– Debugging is harder;
– Abstraction is more limited than with some paradigms;
– Order is crucial, which doesn't always suit itself to
problems.
Types of programming paradigm (cont.)
Logical
• takes a declarative approach to problem-solving.
• Various logical assertions about a situation are
made, establishing all known facts. Then queries
are made.
• The role of the computer becomes maintaining
data and logical deduction.
“Answer a question via search for a solution”
Types of programming paradigm (cont.)
• Logical Paradigm Programming:
A logical program is divided into three sections:
– a series of definitions/declarations that define the problem domain
– statements of relevant facts
– statement of goals in the form of a query
• Any deducible solution to a query is returned. The definitions and
declarations are constructed entirely from relations. i.e. X is a member of
Y or X is in the internal between a and b etc.
• Advantages:
The advantages of logic oriented programming are bifold:
– The system solves the problem, so the programming steps themselves are kept to a
minimum;
– Proving the validity of a given program is simple.
Types of programming paradigm (cont.)
Functional
• views all subprograms as functions in the
mathematical sense-informally, they take in
arguments and return a single solution.
• The solution returned is based entirely on the
input.
“Evaluate an expression and use the resulting value for
something”
Types of programming paradigm (cont.)
Object-Oriented
• is a paradigm in which real-world objects are each viewed as
separate entities having their own state which is modified only by
built in procedures, called methods.
• Because objects operate independently, they are encapsulated into
modules which contain both local environments and methods.
• Communication with an object is done by message passing.
• Objects are organized into classes, from which they inherit methods
and equivalent variables.
• The object-oriented paradigm provides key benefits of reusable
code and code extensibility.
“Send messages between objects to simulate the temporal evolution of a
set of real world phenomena”
Types of programming paradigm (cont.)
Features & Benefits
• Data as well as operations are encapsulated in objects
• Information hiding is used to protect internal
properties of an object
• Inheritance gives OOP its chief benefit over other
programming paradigms - relatively easy code
reuse and extension without the need to change
existing source code.
• the derived class can also override behavior
corresponding to some of the methods of the base
class: there would be a different method to respond to
the same message.
Overview of OO principles
• In order for a programming language to
be object-oriented, it has to enable
working with classes and objects as well
as the implementation and use of the
fundamental object-oriented principles
and concepts: inheritance, abstraction,
encapsulation and polymorphism.
Overview of OO principles (cont.)
principles of OOP
• Encapsulation
– It is also called "information hiding".
– An object has to provide its users only with the essential
information for manipulation, without the internal details.
– A Secretary using a Laptop only knows about its screen,
keyboard and mouse. Everything else is hidden internally
under the cover. She does not know about the inner
workings of Laptop, because she doesn’t need to, and if
she does, she might make a mess. Therefore parts of the
properties and methods remain hidden to her.
Overview of OO principles (cont.)
• Inheritance
– It allows a class to "inherit" (behavior or
characteristics) of another, more general class.
– For example, a lion belongs to the biological family of
cats (Felidae). All cats that have four paws, are
predators and hunt their prey. This functionality can
be coded once in the Felidae class and all its predators
can reuse it
– Tiger, Puma, Bobcat, etc. Inheritance is described
as is-kind-of relationship, e.g. Tiger is kind of Animal.
Overview of OO principles(cont.)
• Abstraction
– means working with something we know how to
use without knowing how it works internally.
– A good example is a television set. We don’t need
to know the inner workings of a TV, in order to use
it. All we need is a remote control with a small set
of buttons (the interface of the remote) and we
will be able to watch TV.
Overview of OO principles(cont.)
• Polymorphism
– Polymorphism allows treating objects of a derived
class as objects of its base class.
– For example, big cats (base class) catch their prey
(a method) in different ways.
Overview of Java Programming and
types of Java Program
• Java programming language was originally developed by
Sun Microsystems which was initiated by James Gosling and
released in 1995 as core component of Sun Microsystems'
Java platform (Java 1.0 [J2SE]).
• The latest release of the Java Standard Edition is Java SE 8.
• With the advancement of Java and its widespread
popularity, multiple configurations were built to suit various
types of platforms. For example: J2EE for Enterprise
Applications, J2ME for Mobile Applications.
• The new J2 versions were renamed as Java SE, Java EE, and
Java ME respectively. Java is guaranteed to be Write Once,
Run Anywhere.
Overview of Java Programming(cont.)
Java is −
• Object Oriented − In Java, everything is an Object. Java can be easily extended
since it is based on the Object model.
• Platform Independent − Unlike many other programming languages including
C and C++, when Java is compiled, it is not compiled into platform specific
machine, rather into platform independent byte code. This byte code is
distributed over the web and interpreted by the Virtual Machine (JVM) on
whichever platform it is being run on.
• Simple − Java is designed to be easy to learn. If you understand the basic
concept of OOP Java, it would be easy to master.
• Secure − With Java's secure feature it enables to develop virus-free, tamper-
free systems. Authentication techniques are based on public-key encryption.
• Architecture-neutral − Java compiler generates an architecture-neutral object
file format, which makes the compiled code executable on many processors,
with the presence of Java runtime system.
Overview of Java Programming(cont.)
• Portable − Being architecture-neutral and having no implementation
dependent aspects of the specification makes Java portable.
• Robust − Java makes an effort to eliminate error prone situations by
emphasizing mainly on compile time error checking and runtime checking.
• Multithreaded − With Java's multithreaded feature it is possible to write
programs that can perform many tasks simultaneously.
• Interpreted − Java byte code is translated on the fly to native machine
instructions and is not stored anywhere.
• High Performance − With the use of Just-In-Time compilers, Java enables
high performance.
• Distributed − Java is designed for the distributed environment of the
internet.
• Dynamic − Java is considered to be more dynamic than C or C++ since it is
designed to adapt to an evolving environment.
Types of Java Program
• Java Applet - These are small programs written in java
and is usually stored on a website and is downloaded
and run on a client computer from within a web
browser
• Application - can only be run on the computer. If
online, it has to be downloaded before being run.
• Servlet - runs on a web server and helps to display web
pages.
• Swing application - is used to build an application that
has a GUI (windows, buttons, menus, etc.)
• EJB - runs on a web server and is used to develop large,
complex websites
Definition of Java Application, Java Applets
• Application is a Java class that has a main() method.
• An applet is a Java class which extends java.applet.Applet.
• Application is a stand-alone program, normally launched
from the command line, and which has unrestricted access
to the host system.
• An applet is a program which is run in the context of an
applet viewer or web browser, and which has strictly
limited access to the host system.
• For instance, an applet can normally not read or write files
on the host system whereas an application normally can.
• Applets may communicate with other applets running on
the same virtual machine.
Editing, Compiling and Interpreting
Editing
– all you need to write and edit Java code is a text
editor, such as the "NotePad" editor that we have
used to this point.
– each file must be saved under the
name classname.java
Compiling
• Before you can do anything with your Java code, you
have to compile it; "compiling" refers to the process by
which high-level, human-readable Java code is turned
into a long string of bytes (much like a machine language)
which can be understood by a Java interpreter.
Editing, Compiling and Interpreting (Cont.)
Interpreting
• "Interpreted" means that the computer looks at the
language, and then turns it into native machine language.
• The term Java interpreter refers to a program which
implements the JVM specification and actually executes the
bytecodes by running your program.
• Compiler versus Interpreter
• Compiling happens when the writing of the program is
finished like calling javac. Example:
– JAVAC Your_class_name.java
• Interpretation happens at runtime(which means while
running the Java program), Example:
– JAVA Your_class_name
object oriented programming examples

object oriented programming examples

  • 1.
    Chapter 1 Introduction toObject-Oriented Programming
  • 2.
    Outline • Types ofprogramming paradigm • Overview of OO principles • Overview of Java Programming and types of Java Program • Definition of Java Application, Java Applets • Editing, Compiling and Interpreting
  • 3.
    Types of programmingparadigm • The major programming paradigms: – Imperative – Logical – Functional – Object-Oriented
  • 4.
    Types of programmingparadigm (cont.) Imperative • assumes that the computer can maintain through environments of variables any changes in a computation process. • Computations are performed through a guided sequence of steps, in which these variables are referred to or changed. • The order of the steps is crucial, because a given step will have different consequences depending on the current values of variables when the step is executed. “First do this and next do that”
  • 5.
    Types of programmingparadigm (cont.) • There are two reasons for popularity: – the imperative paradigm most closely resembles the actual machine itself, so the programmer is much closer to the machine. – because of such closeness, the imperative paradigm was the only one efficient enough for widespread use until recently. • Language representatives – Fortran, Algol, Pascal, Basic, C
  • 6.
    Types of programmingparadigm (cont.) • Advantages – efficient; – close to the machine; – popular; – familiar. • Disadvantages – The semantics of a program can be complex to understand or prove; – Debugging is harder; – Abstraction is more limited than with some paradigms; – Order is crucial, which doesn't always suit itself to problems.
  • 7.
    Types of programmingparadigm (cont.) Logical • takes a declarative approach to problem-solving. • Various logical assertions about a situation are made, establishing all known facts. Then queries are made. • The role of the computer becomes maintaining data and logical deduction. “Answer a question via search for a solution”
  • 8.
    Types of programmingparadigm (cont.) • Logical Paradigm Programming: A logical program is divided into three sections: – a series of definitions/declarations that define the problem domain – statements of relevant facts – statement of goals in the form of a query • Any deducible solution to a query is returned. The definitions and declarations are constructed entirely from relations. i.e. X is a member of Y or X is in the internal between a and b etc. • Advantages: The advantages of logic oriented programming are bifold: – The system solves the problem, so the programming steps themselves are kept to a minimum; – Proving the validity of a given program is simple.
  • 9.
    Types of programmingparadigm (cont.) Functional • views all subprograms as functions in the mathematical sense-informally, they take in arguments and return a single solution. • The solution returned is based entirely on the input. “Evaluate an expression and use the resulting value for something”
  • 10.
    Types of programmingparadigm (cont.) Object-Oriented • is a paradigm in which real-world objects are each viewed as separate entities having their own state which is modified only by built in procedures, called methods. • Because objects operate independently, they are encapsulated into modules which contain both local environments and methods. • Communication with an object is done by message passing. • Objects are organized into classes, from which they inherit methods and equivalent variables. • The object-oriented paradigm provides key benefits of reusable code and code extensibility. “Send messages between objects to simulate the temporal evolution of a set of real world phenomena”
  • 11.
    Types of programmingparadigm (cont.) Features & Benefits • Data as well as operations are encapsulated in objects • Information hiding is used to protect internal properties of an object • Inheritance gives OOP its chief benefit over other programming paradigms - relatively easy code reuse and extension without the need to change existing source code. • the derived class can also override behavior corresponding to some of the methods of the base class: there would be a different method to respond to the same message.
  • 12.
    Overview of OOprinciples • In order for a programming language to be object-oriented, it has to enable working with classes and objects as well as the implementation and use of the fundamental object-oriented principles and concepts: inheritance, abstraction, encapsulation and polymorphism.
  • 13.
    Overview of OOprinciples (cont.) principles of OOP • Encapsulation – It is also called "information hiding". – An object has to provide its users only with the essential information for manipulation, without the internal details. – A Secretary using a Laptop only knows about its screen, keyboard and mouse. Everything else is hidden internally under the cover. She does not know about the inner workings of Laptop, because she doesn’t need to, and if she does, she might make a mess. Therefore parts of the properties and methods remain hidden to her.
  • 14.
    Overview of OOprinciples (cont.) • Inheritance – It allows a class to "inherit" (behavior or characteristics) of another, more general class. – For example, a lion belongs to the biological family of cats (Felidae). All cats that have four paws, are predators and hunt their prey. This functionality can be coded once in the Felidae class and all its predators can reuse it – Tiger, Puma, Bobcat, etc. Inheritance is described as is-kind-of relationship, e.g. Tiger is kind of Animal.
  • 15.
    Overview of OOprinciples(cont.) • Abstraction – means working with something we know how to use without knowing how it works internally. – A good example is a television set. We don’t need to know the inner workings of a TV, in order to use it. All we need is a remote control with a small set of buttons (the interface of the remote) and we will be able to watch TV.
  • 16.
    Overview of OOprinciples(cont.) • Polymorphism – Polymorphism allows treating objects of a derived class as objects of its base class. – For example, big cats (base class) catch their prey (a method) in different ways.
  • 17.
    Overview of JavaProgramming and types of Java Program • Java programming language was originally developed by Sun Microsystems which was initiated by James Gosling and released in 1995 as core component of Sun Microsystems' Java platform (Java 1.0 [J2SE]). • The latest release of the Java Standard Edition is Java SE 8. • With the advancement of Java and its widespread popularity, multiple configurations were built to suit various types of platforms. For example: J2EE for Enterprise Applications, J2ME for Mobile Applications. • The new J2 versions were renamed as Java SE, Java EE, and Java ME respectively. Java is guaranteed to be Write Once, Run Anywhere.
  • 18.
    Overview of JavaProgramming(cont.) Java is − • Object Oriented − In Java, everything is an Object. Java can be easily extended since it is based on the Object model. • Platform Independent − Unlike many other programming languages including C and C++, when Java is compiled, it is not compiled into platform specific machine, rather into platform independent byte code. This byte code is distributed over the web and interpreted by the Virtual Machine (JVM) on whichever platform it is being run on. • Simple − Java is designed to be easy to learn. If you understand the basic concept of OOP Java, it would be easy to master. • Secure − With Java's secure feature it enables to develop virus-free, tamper- free systems. Authentication techniques are based on public-key encryption. • Architecture-neutral − Java compiler generates an architecture-neutral object file format, which makes the compiled code executable on many processors, with the presence of Java runtime system.
  • 19.
    Overview of JavaProgramming(cont.) • Portable − Being architecture-neutral and having no implementation dependent aspects of the specification makes Java portable. • Robust − Java makes an effort to eliminate error prone situations by emphasizing mainly on compile time error checking and runtime checking. • Multithreaded − With Java's multithreaded feature it is possible to write programs that can perform many tasks simultaneously. • Interpreted − Java byte code is translated on the fly to native machine instructions and is not stored anywhere. • High Performance − With the use of Just-In-Time compilers, Java enables high performance. • Distributed − Java is designed for the distributed environment of the internet. • Dynamic − Java is considered to be more dynamic than C or C++ since it is designed to adapt to an evolving environment.
  • 20.
    Types of JavaProgram • Java Applet - These are small programs written in java and is usually stored on a website and is downloaded and run on a client computer from within a web browser • Application - can only be run on the computer. If online, it has to be downloaded before being run. • Servlet - runs on a web server and helps to display web pages. • Swing application - is used to build an application that has a GUI (windows, buttons, menus, etc.) • EJB - runs on a web server and is used to develop large, complex websites
  • 21.
    Definition of JavaApplication, Java Applets • Application is a Java class that has a main() method. • An applet is a Java class which extends java.applet.Applet. • Application is a stand-alone program, normally launched from the command line, and which has unrestricted access to the host system. • An applet is a program which is run in the context of an applet viewer or web browser, and which has strictly limited access to the host system. • For instance, an applet can normally not read or write files on the host system whereas an application normally can. • Applets may communicate with other applets running on the same virtual machine.
  • 22.
    Editing, Compiling andInterpreting Editing – all you need to write and edit Java code is a text editor, such as the "NotePad" editor that we have used to this point. – each file must be saved under the name classname.java Compiling • Before you can do anything with your Java code, you have to compile it; "compiling" refers to the process by which high-level, human-readable Java code is turned into a long string of bytes (much like a machine language) which can be understood by a Java interpreter.
  • 23.
    Editing, Compiling andInterpreting (Cont.) Interpreting • "Interpreted" means that the computer looks at the language, and then turns it into native machine language. • The term Java interpreter refers to a program which implements the JVM specification and actually executes the bytecodes by running your program. • Compiler versus Interpreter • Compiling happens when the writing of the program is finished like calling javac. Example: – JAVAC Your_class_name.java • Interpretation happens at runtime(which means while running the Java program), Example: – JAVA Your_class_name