Slides05 - Object Oriented Programming Using Java - LA1026 - V1.2
Slides05 - Object Oriented Programming Using Java - LA1026 - V1.2
Intermediate Level
ER/CORP/CRS/ LA1026 Confidential Ver. No.: 1.1 Copyright © 2008, Infosys Technologies Ltd.
General Guideline
This document contains valuable confidential and proprietary information of Infosys. Such
confidential and proprietary information includes, amongst others, proprietary intellectual
property which can be legally protected and commercialized. Such information is furnished
herein for training purposes only. Except with the express prior written permission of Infosys,
this document and the information contained herein may not be published, disclosed, or used
for any other purpose.
Inheritance
Method Overriding
Interfaces
Packages
If the class implements the interface, the class must implement all
the methods defined in an interface or declare itself abstract
interface Customer{
void setCustomerName(String name);
String getCustomerName();
}
interface Employee{ Define an Interface
Implementing an Interface
class InterfaceExample{
public static void main(String args[]){
Trainee trobj=new Trainee();
trobj.setCustomerName("Alphy");
System.out.println("Customer Name:"+trobj.getCustomerName());
trobj.setEmployeeNo(1001);
System.out.println("Employee No:"+trobj.getEmployeeNo());
trobj.setBatchName("Mar09");
System.out.println("Batch Name:"+trobj.getBatchName());
}
}
Customer Name:Alphy
Employee No:1001
Batch Name:Mar09
class InterfaceExample{
public static void main(String args[]){
Trainee trobj=new Trainee();
trobj.setCustomerName("Alphy");
System.out.println("Customer Name:"+trobj.getCustomerName());
trobj.setEmployeeNo(1001);
System.out.println("Employee No:"+trobj.getEmployeeNo());
trobj.setBatchName("Mar09");
System.out.println("Batch Name:"+trobj.getBatchName());
}
}
Customer Name:Alphy
Employee No:1001
Batch Name:Mar09
A class can extend from another class and at the same time can
implement any number of interfaces
An Interface can extend from one another interface with the help of
the keyword extends
Packages
ER/CORP/CRS/ LA1026 Confidential Ver. No.: 1.1 Copyright © 2008, Infosys Technologies Ltd.
Packages
package
classes
class/instance variables
methods
local variables
statements
…….
Method 1:
Using fully qualified class name
– java.lang.lang.Math.sqrt(varOne);
Method 2:
Import package and use class name directly
– import java.lang.Math
– Math.sqrt(varOne);
Package statement
package calculation;
class PackEx{
fully qualified class name
public static void main(String args[]){
addition.AddTwo obj=new addition.AddTwo();
obj.calSum(23,46);
}
}
Sum=69
package addition;
import statement
import addition.AddTwo;
class PackEx{
public static void main(String args[]){
AddTwo obj=new AddTwo();
obj.calSum(23,46);
}
Sum=69
}
Classes and Interfaces can have either the public access or the
default access
java.lang
Contains classes that are essential for developing basic Java
programs
The String class, System class etc, belong to this package
There is no need to explicitly import this package
java.io
Helps to perform various input and output operations
Java.sql
Provides classes and interface that helps to connect to the
database like SQL server, oracle easily
java.awt
Classes for implementing GUI Application eg: windows,
buttons, menus etc.
java.net
Classes for networking
How can
extra level of
security be
provided
ER/CORP/CRS/ LA1026 Confidential Ver. No.: 1.1 Copyright © 2008, Infosys Technologies Ltd.
Terminology…
36
Copyright © 2008, Infosys Technologies Ltd. 36 Confidential
Object Oriented Process(Developer’s Perspective )
Identify the
classes and
Objects
Identify the
relationships
UML
Construct Specify
Enables mapping from a Building models that are
model in the UML to OO precise, unambiguous
Languages such as Java,
C++, or C#
Generalization
(included in a hierarchy) Customer
include
Customer
Customer
Name of the class
- Represents private
-customerNo:int
access specifier
-customerName:String
+getCustomerNo():int Attributes of the class
+setCustomerNo(int)
+ Represents public +getCustomerName():String
access specifier Methods or activities in
+setCustomerName(String) the class
+displayBillAmount()
Represents is-a
relationship
RegisteredCustomer RegularCustomer
-dateOfRegistration:date -creditPoint:int
-discount:float +getCreditPoint():int
+getDateOfRegistration():Date + setCreditPoint(int)
+ setDateOfRegistration(Date)
+getDiscount():float
+setDiscount(float)
Generalization
Specialization
has-a
relationship(Aggregation)
Uses –a
relationship(Association)
ER/CORP/CRS/ LA1026 Confidential Ver. No.: 1.1 Copyright © 2008, Infosys Technologies Ltd.
UML Tools
IBM Rational Rose
Rational Rose modeling tool is from IBM Rational Software
Corporation. Rose stands for "Rational Object-oriented Software
Engineering") is a visual modeling tool for UML
Poseidon:
Poseidon from Gentleware has its roots in the ArgoUML open source
project which evolved as an open source effort and is a useful, full-
featured UML tool freely available under the Open Publication
License
Interfaces
Packages
“The contents of this document are proprietary and confidential to Infosys Technologies Ltd. and may
not be disclosed in whole or in part at any time, to any third party without the prior written consent of
Infosys Technologies Ltd.”
“© 2008 Infosys Technologies Ltd. All rights reserved. Copyright in the whole and any part of this
document belongs to Infosys Technologies Ltd. This work may not be used, sold, transferred, adapted,
abridged, copied or reproduced in whole or in part, in any manner or form, or in any media, without the
prior written consent of Infosys Technologies Ltd.”
Appendix
ER/CORP/CRS/ LA1026 Confidential Ver. No.: 1.1 Copyright © 2008, Infosys Technologies Ltd.
Appendix - UML Diagrams
UML Diagrams Meaning of the diagrams
Use Case Diagram Shows use cases, actors, and their interrelationships
Class Diagram Shows a collection of classes and types, their contents, and their
relationships
Object Diagram Depicts objects and their relationships at a point in time, it is a special
case of a class diagram
State Diagram Describes the states an object and the transitions between states
Component Diagram Depicts the components that compose an application, their
interrelationships, interactions, and their public interfaces are shown
in this diagram.
Deployment Diagram Shows how the application is deployed, the hardware or software
execution environments, as well as the middleware connecting them
Collaboration diagram Shows how the objects send and receive messages, ie.
Communication
Sequence Diagram Shows sequence/time ordering between messages
Activity Diagram Shows high-level business processes, data flow, and how to model
the logic within the system