+ All Categories
Home > Documents > 02-CCFP4.0_OOP Using Java

02-CCFP4.0_OOP Using Java

Date post: 20-Feb-2018
Category:
Upload: vishal-iyer
View: 218 times
Download: 1 times
Share this document with a friend

of 45

Transcript
  • 7/24/2019 02-CCFP4.0_OOP Using Java

    1/45

    OO programming using Java

    Education, Training and AssessmentWe enable you to leverage knowledge anytime,

    anywhere!

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    2/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Copyright Guideline

    2013 Infosys Limited, Bangalore, India. All Rights Reserved.

    Infosys believes the information in this document is accurate as of its publication date; such

    information is subject to change without notice. Infosys acknowledges the proprietary rights of

    other companies to the trademarks, product names and such other intellectual property rights

    mentioned in this document. Except as expressly permitted, neither this documentation nor

    any part of it may be reproduced, stored in a retrieval system, or transmitted in any form or by

    any means, electronic, mechanical, printing, photocopying, recording or otherwise, without the

    prior permission of Infosys Limited and/ or any named intellectual property rights holders

    under this document.

    2

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    3/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Confidential Information

    This Document is confidential to Infosys Limited. This document contains information and data that

    Infosys considers confidential and proprietary (Confidential Information).

    Confidential Information includes, but is not limited to, the following:

    Corporate and Infrastructure information about Infosys

    Infosys project management and quality processes

    Project experiences provided included as illustrative case studies

    Any disclosure of Confidential Information to, or use of it by a third party, will be damaging to Infosys.

    Ownership of all Infosys Confidential Information, no matter in what media it resides, remains with

    Infosys.

    Confidential information in this document shall not be disclosed, duplicated or used in whole or in part

    for any purpose other than reading without specific written permission of an authorized representative of

    Infosys.

    This document also contains third party confidential and proprietary information. Such third party

    information has been included by Infosys after receiving due written permissions and authorizations fromthe party/ies. Such third party confidential and proprietary information shall not be disclosed, duplicated

    or used in whole or in part for any purpose other than reading without specific written permission of

    an authorized representative of Infosys.

    3

    3

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    4/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Course Information

    Course Code: CCFP4.0-OOP

    Course Name: OO programming using Java

    Document Number: OOP-02

    Version Number: V4.0

    4

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    5/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Recap

    Topics covered on Programming Fundamentals

    Problem Solving skills

    Identifiers

    Variables

    Data types

    Declaration of variables

    Operators

    Control Structures

    Type casting and conversion

    5

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    6/45

    OO Fundamentals

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    7/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    OO Fundamentals - Topics SDLC Overview

    OO Concepts

    Introduction to UML

    OO Fundamentals Implementation in Java

    7

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    8/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    A peek into history..

    8

    Why do you

    think the

    ship sank?

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    9/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    A system engineers story.

    Now lets listen to a software engineering story

    Roy, a system engineer, in Infosys has something to tell youRead on

    To summarize, for Roy and team to go ahead with the application development,

    they need

    An engineering approach towards application development like SDLC (Software

    Development Life Cycle)

    To address the challenges and develop the business application

    9

    Guided Activi ty: Programming Fundamentals-Part II - Assignment 21

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    10/45

    Software Development LifecycleOverview

    Education, Training and AssessmentWe enable you to leverage knowledge anytime,

    anywhere!

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    11/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Software Development Lifecycle (SDLC) Overview

    Phases of software development

    11

    SystemEngineering

    Requirementsanalysis

    Design Development Test Deploy

    Scope of the project is defined

    User requirements are

    gathered

    Requirements are analyzed

    Software Requirements

    Specification (SRS) document is

    created

    Design is created based on

    requirements

    High level design document and

    Detail level design document are

    created

    Code is developed based on

    design

    Unit testing is done on the

    code

    Integration and system testing areperformed

    Acceptance Testing is done by the

    client/customer

    As a system engineer, you will be contributing mainly to

    this phase and this course will also be focusing on this

    phase of SDLC

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    12/45

    Need for Object OrientedApproach

    Education, Training and AssessmentWe enable you to leverage knowledge anytime,

    anywhere!

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    13/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Need for Object Oriented Approach

    Challenges in developing a business application

    Integration of modules/applications

    Extensibility of existing code

    High level of flexibility and illusion of simplicity

    If these challenges are not addressed it may lead to Software Crisis

    Features needed in the business application to meet these challenges:

    Modularity, Extendibility, Reusability, Interoperability, Security

    Challenges can be addressed using object oriented approach

    13

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    14/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Need for Object Oriented Approach

    Properties of a business application

    Clear separation of functionalities

    Exhibits hierarchy

    Composed of subsystems

    These properties can be implemented using object oriented approach

    14

    Easy Shop application is a complex business application & object oriented approach may

    be used to develop this system

    Road Ahead - Need to understand object oriented concepts

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    15/45

    Object Oriented Concepts

    Education, Training and AssessmentWe enable you to leverage knowledge anytime,

    anywhere!

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    16/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Classes & Objects (1 of 2)

    16

    Customer Id:

    1001

    Customer Name:

    Cameron

    Telephone Number:

    9901911445

    Address:No.31, Silver Shine,Bangalore, India

    Customer Id:

    1002

    Customer Name:

    Alphonso

    Telephone Number:

    9496244655

    Address:No.255, Brigade,Bangalore, India

    Values of

    attributes of

    Customer

    Attributes of

    Customer

    Cameron & Alphonso are

    two instances

    /examples/objects of Easy

    Shop customers

    Let us look at some customers

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    17/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Classes & Objects (2 of 2)

    A class is a software design that describes the common attributes and activities

    (behavior) of objects

    17

    Example : Customer Id, Name, Telephonenumber and AddressAttributes

    Activities(behavior) exhibited by theclass to external world

    Example: Purchasing items from theretail shop

    Behavior/Activity

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    18/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Abstraction Guided Activity

    Users of the retail application Billing staff, Admin, Retail outlet manager

    Each user needs to know some details and need not know other details

    18

    ABSTRACTION : Process of identi fying the essent ial details to be known and

    ignoring the non-essential detai ls from the perspective of the user of the system

    Billing staff (

    Billing of

    customers )

    Admin (Registration

    of customers)Retail Outlet

    Manager

    (Registration of

    users)

    Whoaretheusersof

    theretailapplication?

    What

    are

    the

    things

    each

    user

    must

    know

    to

    perform

    their

    activities?

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    19/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Encapsulation Guided Activity

    Swipe machine in a retail store Used by billing staff to key the amount

    Used by admin to record payment

    19

    ENCAPSULATION : A mechanism of hiding the internal detai ls and allowing a simple

    interface which ensures that the object can be used without having to know how itworks

    How

    is

    a

    swipe

    machine

    used

    for

    payment

    of

    bill

    in

    a

    retail

    store?

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    20/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Inheritance Guided Activity

    Customers are of two kinds

    Regular

    Privileged

    20

    The regular customer in addition is given discounts

    All customers have Customer Id, Name, Telephone

    Number and Address

    RegularCustomersPrivileged

    CustomersThe privileged customer gets a membership cardbased on which gifts are given

    All customers have some generic features. The different kinds of customers have all

    generic features in addition to some specific features

    INHERITANCE : Is a mechanism which al lows to def ine general ized characteristics

    and behavior and also create special ized ones. The special ized ones automat ical ly

    tend to inherit al l the properties of the generic ones

    What

    are

    the

    two

    different

    types

    of

    customers

    you

    can

    see

    intheretail

    application?

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    21/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Polymorphism Guided Activity

    Payment of bill - Two modes

    Cash (Calculation includes VAT)

    Credit card(Calculation includes processing charge and VAT)

    21

    TotalAmount=Purchaseamount+VAT+Processingcharge

    TotalAmount=Purchaseamount+VAT

    The activity of paying the bill is the same. But the formula for calculation of bill

    differs as per the mode of payment

    POLYMORPHISM: Refers to the abil ity of an object/operation to behave

    differently in different situations

    What

    do

    you

    observe

    in

    this

    retail

    store

    scenario?

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    22/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Object Oriented Approach Benefits

    Leads to development of smaller but stable subsystems

    The subsystems are resilient to change

    Reduces the risk factor in building large systems as they are built incrementally

    from subsystems which are stable

    22

    Hence Object Orientation is suitable for developing extremely complex business

    systems

    Quiz: Object Oriented Fundamentals - Assignment 22

    Road Ahead - Need to understand object oriented system development

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    23/45

    Introduction to UML

    Education, Training and AssessmentWe enable you to leverage knowledge anytime,

    anywhere!

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    24/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Object Oriented System Development

    Like SDLC, Object oriented approach also involves-

    Object oriented analysis

    Object oriented design

    Object oriented programming

    Testing

    24

    Juan, the client representative, has just informed that

    as first phase, the Easy Shop management, wants to

    automate the purchase of items by customers and the

    billing process .

    CCFP4.0-Retail Application_Phase I_Problem Statement_OOP.docx

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    25/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Object Oriented System Development

    Object Oriented Analysis and Design involve -

    Modeling the system based on requirements

    Identification of classes and relationship between them

    Identification of attributes and methods

    Constructing the logical and physical object models

    The representation of design is done using UML

    25

    Road Ahead - Need to understand representation of design using UML

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    26/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    The Unified Modelling Language (UML)

    The Unified Modelling Language (UML) is a language for visualizing, specifying,

    constructing and documenting the software system and its components

    [OMG03a]

    26

    Visual

    UML is a graphicallanguage

    Notations of UML are

    well-defined

    Specify

    Building models that areprecise, unambiguous

    Document

    Enables documentation ofsystem architecture and

    details

    Construct

    Enables mapping from amodel in the UML to OO

    Languages such as Java,C++, or C#

    UML

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    27/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    UML Diagrams

    There are thirteen standard diagrams used in different phases

    27

    UseCaseDiagram

    Class

    Diagram

    ObjectDiagram

    ComponentDiagram

    CompositeStructureDiagram

    PackageDiagram

    DeploymentDiagram

    State

    Machine Diagram

    ActivityDiagram

    SequenceDiagram

    Communication Diagram

    TimingDiagram

    Interaction OverviewDiagram

    We will be focusing on use case diagrams and class diagrams in this course

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    28/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Use Case Diagram

    Helps in identification of the system under development

    Use-case is a technique to capture business process from the users perspective

    i.e., a way of documenting system functionality expected by the user

    Notations used

    28

    Demo: CCFP4.0_Retail Application_Phase I_Use case diagram_OOP.pdf

    Refer to the use case specifications provided

    in the pdf

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    29/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Class Diagram

    Classes are the basic components of an OO system

    Class diagram shows the collection of classes and the relationships among them

    A class is represented by a rectangular box with three compartments :

    Class Name

    Attributes

    Behavior

    29

    Demo: CCFP4.0_Retail Application_Phase I_Class Diagram_OOP.docx

    Guided Activity: OO Fundamentals - Assignment 23

    Links: ht tp://www.uml-diagrams.org/

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    30/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    OO Fundamentals we have learnt

    SDLC Overview

    OO Concepts

    Classes & Objects

    Abstraction

    Encapsulation

    Inheritance

    Polymorphism

    Introduction to UML

    Use case diagram

    Class diagram

    30

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    31/45

    OO Fundamentals Implementation in Java

    Education, Training and AssessmentWe enable you to leverage knowledge anytime,

    anywhere!

    32

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    32/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    OO Fundamentals Java Implementation

    Object Oriented Fundamentals

    Instance Variables

    Methods

    Access Specifiers

    Classes & Objects

    Coding Standards

    32

    33

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    33/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Instance Variables Guided Activity

    Variables used for representing the state of an object/attributes of a class are

    called member variables/instance variables

    33

    customerId

    and

    telephoneNo

    Identifythemember

    variables

    of

    the

    Customerclass?

    What

    can

    be

    the

    data

    types

    used

    for

    thesemember

    variables?

    customerId can

    be

    int and

    telephoneNo can

    be

    long

    34

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    34/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Access Specifiers

    Used to expose or hide the attribute and behavior of a class

    Used to specify the access permitted on a member

    public(+)

    A declaration that is accessible to all classes

    Keyword used is public

    private(-)

    A declaration that is accessible only to the class in which it is declared

    Keyword used is private

    protected(#)

    Keyword used is protected

    34

    More on this access specifier will be discussed as part of

    Inheritance and abstract keyword

    35

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    35/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Methods (1 of 2)

    Methods define the behavior of an object

    All the methods should be defined inside the class with an access specifier

    Values that are passed to methods are known as arguments/parameters

    Value that is returned from a method is known as return value

    A method can return only one value at a time and it can be done using the return

    statement

    Implementation of a method requires the following:

    Method Header

    Method Definition

    Method Invocation/Method Call

    35

    36

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    36/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Detailsofpassingargumentstomethodswillbedealtlater

    Methods (2 of 2)

    36

    public voidsetCustomerId(int id){

    customerId

    =

    id;}

    public void

    setTelephoneNo(long

    teleNo){

    telephoneNo=teleNo;

    }

    public intgetCustomerId(){

    return

    customerId

    ;}

    publiclonggetTelephoneNo(){

    returntelephoneNo;

    }

    Observations:

    The datatype of the returnvalue matches the return

    type mentioned in the

    header of the method

    Some methods takearguments ex.

    setTelephoneNo() and some

    methods do not take

    arguments ex.

    getTelephoneNo()

    Some methods do not returnexplicit values ex.setTelephoneNo()

    Return

    type

    Name

    of

    the

    method

    Returnvalue

    Method

    definition

    Arguments/parameters

    Accessspecifier

    Methodheader

    I l t ti f Cl i J G id d37

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    37/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Implementation of a Class in Java GuidedActivity

    classCustomer{

    privateintcustomerId;

    private

    long

    telephoneNo;publicvoidsetCustomerId(int id){

    customerId=id;

    }

    publicvoidsetTelephoneNo(longteleNo){

    telephoneNo=teleNo;}

    publicintgetCustomerId(){

    returncustomerId;

    }

    public

    long

    getTelephoneNo(){returntelephoneNo;

    }

    }

    Abstraction

    &

    Encapsulation

    Identify

    the

    OO

    feature

    implemented

    using

    this

    code?

    instance

    variables

    class

    How

    can

    this

    class

    be

    used

    to

    createan

    instanceofa

    customer?

    BycreatingobjectsofCustomerclass

    methods

    38

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    38/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Creation of Objects

    Class is a blueprint for the creation of objects

    To realize a class, an object or an instance of the class needs to be created

    There can be many instances for a class and each instance will have its own data

    In Java, the operator new allocates memory for objects during run time ie.

    dynamic memory allocation

    The following statement creates an object of the class Customer and returns a

    reference to the newly created object

    new

    Customer();

    39

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    39/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Reference Variables

    The reference returned by a newly created object must be assigned to a variable

    and that variable is known as reference variable

    Following syntax can be used to create a reference variable for the Customer

    class and make it point to a Customer object

    Reference variable can be assigned null to show that it is not referring to anyobject nullisakeyword

    CustomercustObj =null;

    Customer

    custObj =

    new

    Customer();

    40

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    40/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    A complete Java Program

    Access Specifiers

    Variables Local and Instance variables

    Methods

    Starter class

    Creation of objects

    Reference variables

    Compilation and Execution of a java program

    Guided Activity: OO Fundamentals - Assignment 24

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    41/45

    Coding Standards

    Education, Training and AssessmentWe enable you to leverage knowledge anytime,

    anywhere!

    42

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    42/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Coding Standards

    Set of guidelines

    Enhance the readability and clarity of the program

    Make it easy to debug and maintain the program

    Should follow Pascal Case

    First letter should be Uppercase

    First letter of each internal word should be

    capitalized(if it is present)

    Class Name

    Should follow Camel Case

    First letter should be Lowercase First letter of each internal word should be

    capitalized(if it is present)

    Instance variable,

    ReferenceVariable &

    Method Name

    43

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    43/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Bad Code versus Good Code

    Bad Code Good Code

    class A{

    private int i;

    public void methodone(int a){i=a;

    }

    public int methodtwo(){

    return i;

    }}

    class Customer{

    private int customerId;

    public void setCustomerId(int id){customerId = id;

    }

    public int getCustomerId(){

    return customerId;

    }}

    Guided Activity: OO Fundamentals - Assignment 25

    44

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    44/45

    Copyright 2013-2014, Infosys Limited ConfidentialConfidential

    Self-Study

    1. Refer to udacity course: https://www.udacity.com/courses

    Course name: Introduction to Programming in Java

    Lessons: Introduction, Objects, Classes, Fundamental Data Types

    3. Links: http://www.uml-diagrams.org/

  • 7/24/2019 02-CCFP4.0_OOP Using Java

    45/45

    2013Infosys Limited, Bangalore, India. All Rights Reserved. Infosys believes theinformation in thisdocument is accurate as of its publication date; such information is subject to changewithout notice. Infosys acknowledgesthe proprietaryrights of other companiesto thetrademarks,product names andsuch other intellectual property rightsmentioned in this document.Exceptasexpressly permitted,neither thisdocumentation nor anypart of it maybe reproduced,stored in a retrievalsystem,or transmittedin anyform or by anymeans, electronic, mechanical,printing,photocopying,recordingor otherwise,withoutthe prior permissionof Infosys Limitedand/or anynamedintellectual property rightsholdersunderthis document.

    Thank You


Recommended