29
L2-Object Oriented Programming (OOP) JAVA- Dr Vish Kallimani 1

L2 Obj Oriented Program.ppt

  • Upload
    adi

  • View
    232

  • Download
    0

Embed Size (px)

Citation preview

  • L2-Object Oriented Programming (OOP)

    JAVA-

    Dr Vish Kallimani

    *

  • *Road map

    Programming languagesSoftware Engineering OOPJAVAObjects and Class

  • *Paradigms of Programming Languages

    The Paradigms of programming Language gives the model to the programmer to write the programs.The different Paradigms of programming languages are,

    Unstructured Programming (or) Monolithic ProgrammingProcedural ProgrammingStructural ProgrammingObject Oriented Programming

  • *ConventionalProgramming :Modular programming Top down programmingBottom up programmingStructured programming

    C is a structured program proved powerful but failed for the larger program.OOPS ( Object Oriented Program ) eliminate some pitfalls of conventional programming.Ex : Small Talk , C++ , JAVA.

  • *Structured Programming (top-down programming)

    in 1970s and into the 80s, the primary software engineering methodology wasstructured programming.

    To solve a large problem, break the problem into several pieces and work on each piece separately;

    To solve each piece, treat it as a new problem which can itself be broken down into smaller problems;

    eventually, you will work your way down to problems that can be solved directly, without further decomposition.

    top-down design is often combined withbottom-up design.

  • *Bottom-up design

    the approach is to start "at the bottom," with problems that you already know how to solve

    From there, you can work upwards towards a solution to the overall problem

  • *

  • *SOFTWARE ENGINEERING

    PROGRAMS MUST BE DESIGNED.

    The discipline calledsoftware engineeringis concerned with the construction of correct, working, well-written programs.

    The software engineer tries to use accepted and proven methods for analyzing the problem to be solved and for designing a program to solve that problem.

  • *Object Oriented (OOP) Concepts :

    Modules that could support this kind of information-hiding became common in programming languages in the early 1980s

    Since then, a more advanced form of the same idea has more or less taken over software engineering. This approach is calledobject-oriented programming,

    The central concept of object-oriented programming is theobject, which is a kind of module containing data and subroutines.

    an object is a kind of self-sufficient entity that has an internalstate(the data it contains) and that can respond tomessages(calls to its subroutines).

  • *The OOP approach to software engineering is to start by identifying the objects involved in a problem and the messages that those objects should respond to.

    The program that results is a collection of objects, each with its own data and its own set of responsibilities.

    The objects interact by sending messages to each other. There is not much "top-down" in the large-scale design of such a program, and people used to more traditional programs can have a hard time getting used to OOP.

    object-oriented programs tend to be better models of the way the world itself works, easier to write, easier to understand, and more likely to be correct.

  • *In CRISP OOP :

    To eliminate flaws of procedural approach.Treats the data as a critical element & does not allow it to flow freely around the system.Allows to decompose a problem in to a no of entities called objects and then build data and functions ( Methods ) around these entities .The combination of data and methods make up an object.

  • *(contd..)

    Data structure are designed such that they characterize the objects

    Methods that operate on data of an object are tied together in data structure.

    Data is hidden and can not be accessed by the external functions.

    Objects may communicate with each other through methods

  • *DrawableObject, MultipointObject, and TwoPointObject would be classes in the program. MultipointObject and TwoPointObject would besubclassesof DrawableObject. Example:Consider a drawing program that lets the user draw lines, rectangles, ovals, polygons, and curves on the screen. In the program, each visible object on the screen could be represented by a software object in the program. There would be five classes of objects in the program, one for each type of visible object that can be drawn. All the lines would belong to one class, all the rectangles to another class, and so on.

  • *OOP Concept mind map

  • *Java is an Object Oriented Language.

    As a language that has the Object Oriented feature Java supports the following fundamental concepts:

    Objects and classes Data Abstraction and EncapsulationInstanceMethodDynamic BindingInheritance PolymorphismMessage ParsingMessage Communication

  • *In Crisp

    Class: Collection of objects is called class. It is a logical entity.

    Inheritance: When one object acquires all the properties and behaviours of parent object

    Polymorphism: When one task is performed by different ways. In java, we use method overloading and method overriding to achieve polymorphism.

    Abstraction: Hiding internal details and showing functionality is known as abstraction. For example: phone call, we don't know the internal processing. In java, we use abstract class and interface to achieve abstraction.

    Encapsulation: Binding (or wrapping) code and data together into a single unit is known as encapsulation. For example: capsule, it is wrapped with different medicines.

  • *Features of Java:Compiled and interpreted Platform independent Object OrientedRobust and secureDistributedSimple and smallMulti threaded and interactive High Performance Dynamic and extensible Internet (server side and browser side,Real time JavaMobile communications

    Benefits of OOP:Quality ProductsLower maintenance cost.Through Inheritance redundant code can be eliminatedImproves security due to data hidingMultiple objects can coexist without interference.Can be easily updated from small to large programs.

    Applications:Real time systems, Internet , Simulation and modeling, Object oriented Database, Hyper Text, hypermedia, AI,Neural Network,CAD

  • *Web Applets (Internet) Stand alone applicationsJAVA Java is Compiled and interpretedUsually computer language is either compiled or interpreted. Java combines both (two stage system). Stage 1: Java compiler translates source code into bytecode instructions. Byte codes are not machine instructions Stage 2:Java interpreter generates machine code that can be directly executed by the machine that is running the Java program. Thus Java can be both a compiled and an interpreted language eitheror

  • *ObjectAn Object may be a person, Place , Account ,user defined data.. Objects have states and behaviors. Each object contain code and data to manipulate the data.Objects can interact without knowing each others code and data.

    Example: A dog has states-color, name, breed as well as behaviors -wagging, barking, eating. An object is an instance of a class

  • *

  • *INSTANCE

    An object that belongs to a class is said to be an instance of that class.

    The variables that the object contains are called instance variables.

    The subroutines that the object contains are called instance methods.

  • Instance variables :

    Instance variables are declared in a class, but outside a method, constructor or any block.When a space is allocated for an object in the heap a slot for each instance variable value is created.

    Instance variables are created when an object is created with the use of the key word 'new' and destroyed when the object is destroyed.Instance variables can be declared in class level before or after use.

    Access modifiers can be given for instance variables.The instance variables are visible for all methods, constructors and block in the class.

  • *CLASSits a specification or a pattern which we define and every object we define will follow that pattern.

    What does Java Class Consist

    When we create class in java the first step is keyword class and then name of the class or identifier we can say.

    Next is class body which starts with curly braces {} and between this all things related with that class means their property and method will come here.

  • CLASS is:The entire set of data and code of an object can be made a user defined type using the concept called the class.

    A class as a Data Type Objectas a variable type

    Once class is created any no of objects can be created belonging to that class.A class is the collection of Objects of similar types.

    Ex: ClassFruit,

    Objects: Mango , Apple , Orange .

  • *What are members of Class?Field:field is nothing but the property of the class or object which we are going to create. Method:method is nothing but the operation that an object can perform it define the behavior of object how an object can interact with outside world .startMethod (), shutdownMethod ().Access Level of members: Access level is nothing but where we can use that members of the class.Each field and method has anaccess level:private: accessible only in this classpackage or default: accessible only in this packageprotected: accessible only in this package and in all subclasses of this classpublic: accessible everywhere this class is availablestatic in java is used for memory management mainly. We can apply java static keyword with variables, methods, blocks and nested class. The static keyword belongs to the class than instance of the class.The static can be:variable (also known as class variable)method (also known as class method)blocknested class

  • *CLASSTemplate is:

    Class (name of the class) {

    (Here define member of class)

    }

  • *CLASS..Consider a simple class whose job is to group together a few static member variables. For example, the following class could be used to store information about the person who is using the program:

    class UserData { static String name; static int age;}

    In Java, no variable can ever hold an object. A variable can only hold a reference to an object.

  • *

  • *Summary

    Conventional programming and their limitations. OOP concepts

    THANK YOU