IBM Enterprise IT and Asset Management 7.1: Java for
Customization
Student’s Training Guide
S150-3087-00
May 2009
Copyright Notice
Copyright © 2009 IBM Corporation, including this documentation and all software. All rights
reserved. May...
•
•
•
•
•
I
Table of Contents
Preface
Course Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....
II IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009
•
•
•
•
•
Table of Content...
©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization III
•
•
•
•
•
Table of Conten...
IV IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009
•
•
•
•
•
Table of Content...
©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization V
•
•
•
•
•
Table of Contents...
VI IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009
•
•
•
•
•
Table of Content...
©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization VII
•
•
•
•
•
Table of Conten...
VIII IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009
•
•
•
•
•
Table of Conte...
•
•
•
•
•
IX
Preface
© 2009 IBM Corporation
Student Guide
X IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009
•
•
•
•
•
Preface
Course ma...
©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization XI
•
•
•
•
•
Preface
Course m...
XII IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009
•
•
•
•
•
Preface
Course ...
©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization XIII
•
•
•
•
•
Preface
Course...
XIV IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009
•
•
•
•
•
Preface
Course ...
•
•
•
•
•
1-1
Unit 1: Objects and Object-Oriented
Programming
© 2009 IBM Corporation
Unit 1: Objects and Object-oriented
P...
1-2 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009
•
•
•
•
•
Unit 1: Objects...
©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-3
•
•
•
•
•
Unit 1: Objects...
1-4 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009
•
•
•
•
•
Unit 1: Objects...
©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-5
•
•
•
•
•
Unit 1: Objects...
1-6 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009
•
•
•
•
•
Unit 1: Objects...
©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-7
•
•
•
•
•
Unit 1: Objects...
1-8 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009
•
•
•
•
•
Unit 1: Objects...
©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-9
•
•
•
•
•
Unit 1: Objects...
1-10 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009
•
•
•
•
•
Unit 1: Object...
©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-11
•
•
•
•
•
Unit 1: Object...
1-12 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009
•
•
•
•
•
Unit 1: Object...
©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-13
•
•
•
•
•
Unit 1: Object...
1-14 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009
•
•
•
•
•
Unit 1: Object...
©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-15
•
•
•
•
•
Unit 1: Object...
1-16 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009
•
•
•
•
•
Unit 1: Object...
©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-17
•
•
•
•
•
Unit 1: Object...
1-18 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009
•
•
•
•
•
Unit 1: Object...
©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-19
•
•
•
•
•
Unit 1: Object...
1-20 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009
•
•
•
•
•
Unit 1: Object...
©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-21
•
•
•
•
•
Unit 1: Object...
1-22 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009
•
•
•
•
•
Unit 1: Object...
©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-23
•
•
•
•
•
Unit 1: Object...
1-24 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009
•
•
•
•
•
Unit 1: Object...
©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-25
•
•
•
•
•
Unit 1: Object...
1-26 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009
•
•
•
•
•
Unit 1: Object...
©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-27
•
•
•
•
•
Unit 1: Object...
1-28 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009
•
•
•
•
•
Unit 1: Object...
©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-29
•
•
•
•
•
Unit 1: Object...
1-30 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009
•
•
•
•
•
Unit 1: Object...
©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-31
•
•
•
•
•
Unit 1: Object...
1-32 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009
•
•
•
•
•
Unit 1: Object...
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Ibm enterprise it and asset management 7.1 java for customization training
Upcoming SlideShare
Loading in …5
×

Ibm enterprise it and asset management 7.1 java for customization training

837 views

Published on

java basic

Published in: Education, Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
837
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
45
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Ibm enterprise it and asset management 7.1 java for customization training

  1. 1. IBM Enterprise IT and Asset Management 7.1: Java for Customization Student’s Training Guide S150-3087-00 May 2009
  2. 2. Copyright Notice Copyright © 2009 IBM Corporation, including this documentation and all software. All rights reserved. May only be used pursuant to a Tivoli Systems Software License Agreement, an IBM Soft- ware License Agreement, or Addendum for Tivoli Products to IBM Customer or License Agreement. No part of this publication may be reproduced, transmitted, transcribed, stored in a retrieval system, or translated into any computer language, in any form or by any means, electronic, mechanical, magnetic, optical, chemical, manual, or otherwise, without prior written permission of IBM Corpora- tion. IBM Corporation grants you limited permission to make hardcopy or other reproductions of any machine-readable documentation for your own use, provided that each such reproduction shall carry the IBM Corporation copyright notice. No other rights under copyright are granted without prior writ- ten permission of IBM Corporation. The document is not intended for production and is furnished “as is” without warranty of any kind. All warranties on this document are hereby disclaimed, including the warranties of merchantability and fitness for a particular purpose. Note to U.S. Government Users—Documentation related to restricted rights—Use, duplication or disclosure is subject to restrictions set forth in GSA ADP Schedule Contract with IBM Corporation. Trademarks The following are trademarks of IBM Corporation or Tivoli Systems Inc.: IBM, Tivoli, AIX, Cross-Site, NetView, OS/2, Planet Tivoli, RS/6000, Tivoli Certified, Tivoli Enterprise, Tivoli Ready, TME. In Den- mark, Tivoli is a trademark licensed from Kjøbenhavns Sommer - Tivoli A/S. Microsoft, Windows, Windows NT, and the Windows logo are trademarks of Microsoft Corporation in the United States, other countries, or both. UNIX is a registered trademark of The Open Group in the United States and other countries. C-bus is a trademark of Corollary, Inc. in the United States, other countries, or both. Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both. Lotus is a registered trademark of Lotus Development Corporation. PC Direct is a trademark of Ziff Communications Company in the United States, other countries, or both and is used by IBM Corporation under license. ActionMedia, LANDesk, MMX, Pentium, and ProShare are trademarks of Intel Corporation in the United States, other countries, or both. SET and the SET Logo are trademarks owned by SET Secure Electronic Transaction LLC. For fur- ther information, see http://www.setco.org/aboutmark.html. Other company, product, and service names may be trademarks or service marks of others. Notices References in this publication to Tivoli Systems or IBM products, programs, or services do not imply that they will be available in all countries in which Tivoli Systems or IBM operates. Any reference to these products, programs, or services is not intended to imply that only Tivoli Systems or IBM prod- ucts, programs, or services can be used. Subject to valid intellectual property or other legally pro- tectable right of Tivoli Systems or IBM, any functionally equivalent product, program, or service can be used instead of the referenced product, program, or service. The evaluation and verification of operation in conjunction with other products, except those expressly designated by Tivoli Systems or IBM, are the responsibility of the user. Tivoli Systems or IBM may have patents or pending patent applications covering subject matter in this document. The furnishing of this document does not give you any license to these patents. You can send license inquiries, in writing, to the IBM Director of Licensing, IBM Corporation, North Castle Drive, Armonk, New York 10504-1785, U.S.A. Printed in Ireland.
  3. 3. • • • • • I Table of Contents Preface Course Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .X Audience . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .X IBM Tivoli Technical Education . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .X Tivoli User Group Community . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .X Course Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . XI Course Outline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . XI Typographical Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . XIII Product Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . XIII Product Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . XIII Unit 1: Objects and Object-Oriented Programming Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 Evolution to Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3 Software Evolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4 Modeling Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5 Everything Is an Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6 Object Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7 Similar Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8 Keys to Object-Oriented Technology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9 Characteristics of an Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-10 Car Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-11 A Class Is the Blueprint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-12 Classes and Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-14 The Car Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-15 An Object’s Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-17 Abstraction and Encapsulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-18 Data Abstraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-19 Inheritance and Composition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-20 Subclasses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-21 Object Interaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-22 Representing an Entity with Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-23 Classes and Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-24 Object Interaction and Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-25 Class Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-26 Object-Oriented Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-27 Encapsulation and Information Hiding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-28 Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-29 Class Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-30 Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-31 One Interface, Multiple Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-32 Polymorphism and Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-33 Shape Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-34 Explaining Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-35 Key Concepts and Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-36 Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-37 Review Answers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-38 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-39
  4. 4. II IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009 • • • • • Table of Contents Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Unit 2: Programming with Java Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 Lesson 1: The Java Programming Language . . . . . . . . . . . . . . . . . . . . . . . . . .2-3 The Java Platform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4 Platform Independence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5 Just-in-Time Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6 Language Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-7 JDK, JRE, and JVM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8 Java API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-9 Types of Java Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10 Lesson 2: Development Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-11 Using the Eclipse IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-12 Creating Projects, Classes, and Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-13 Running Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-14 Run Configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-15 Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16 Debugging Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-17 Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-18 Setting Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19 Debug Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-20 Student Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-21 Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-22 Review Answers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-24 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-25 Unit 3: Java Basics and Operators Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2 Lesson 1: Class Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-3 File Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5 Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6 Package Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7 import Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-8 import Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-9 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-11 Lesson 2: Language Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-13 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-14 Variable Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 Built-in Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-17 Wrapper Classes for Primitives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-18 Primitives and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-19 Common Wrapper Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20 Assignment Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-22 Variables in Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-23 Concatenation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-24 Print Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-25 Printing Newlines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-26 Lesson 3: Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-27 Assignment with Combination Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-28 Assignment Using the ++ and -- Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-29 Relational Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-30 Relational Operator Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-31
  5. 5. ©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization III • • • • • Table of Contents Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Relational Operator Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-32 Common Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-33 Comparing Primitives and Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-34 Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-35 Ternary ? Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-36 Bitwise Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-37 Bitwise Shift Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-38 Operator Precedence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-39 Student Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-40 Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-41 Review Answers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-42 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-43 Unit 4: Java Basics and Programming Syntax Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2 Variable Declaration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3 Variable Access Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4 Method Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-5 Method Access Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-6 main() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-7 main() Method Signature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-8 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-9 Array Declaration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10 Allocating an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-11 Arrays in Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-12 Arrays Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-13 Arrays of Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-14 Declare an Array of Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-15 Different Dimensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-16 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-17 Variable Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-18 Initial Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-19 Casting Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-20 Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-21 if and if-else Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-23 if-else Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-24 if-else if Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-26 switch Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-27 break and continue Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-29 break Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-30 Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-31 while Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-32 for Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-33 Comparing for and while Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-34 do-while Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-36 Infinite Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-37 foreach statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-38 Scope of a Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-39 Printing Program Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-40 Add Program Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-41 Conversions from String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-42 Class Sum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-43 Student Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-44 Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-45 Review Answers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-46 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-47
  6. 6. IV IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009 • • • • • Table of Contents Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Unit 5: Classes, Constructors, and Strings Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2 Lesson 1: Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-3 Create Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4 Classes and Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5 Using new . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6 Garbage Collection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-7 Lesson 2: Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-8 Default Constructor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-9 Using the Keyword this . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-10 Using the super() Keyword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-11 Constructors versus Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-12 Order of Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-13 Object Creation with Instance Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-14 Static Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-15 Static Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-16 Calling Static Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-17 Lesson 3: Java Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-18 Java Documentation Navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-19 Documentation Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-20 Lesson 4: String Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-21 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-22 String Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-23 String Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-24 More String Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-26 Using String Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-27 Conversion Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-28 Comparison Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-29 Searching Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-30 Regular Expression Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-31 Conversions from String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-32 Conversions to String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-33 Using the split() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-34 ConvertTemperature Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-35 ConvertTemperature Class Variation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-36 The convert() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-37 Student Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-38 Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-39 Review Answers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-40 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-41 Unit 6: Java Exceptions, I/O, and Inheritance Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2 Lesson 1: Access Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-3 Access Control Modifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4 Access Control Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-5 abstract, final, and static Modifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-6 Using the Keyword this . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-7 this Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-8 Passing Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-10 Pass by Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-11
  7. 7. ©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization V • • • • • Table of Contents Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Passing Objects by Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-12 Passing an Object Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-13 A Copy of an Object Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-14 Pass by Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-15 Garbage Collection Revisited . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-16 Garbage Collection and Object References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-17 Memory Leaks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-18 Overloading Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-20 Guidelines for Overloading Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-21 Overloading versus Overriding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-23 Lesson 2: Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-24 Exception Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-25 Exception Propagation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-26 Methods and Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-27 Catching Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-28 Rethrowing an Exception . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-29 To Catch or Throw . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-31 Java Exception Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-32 User-Defined Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-33 Catch Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-34 try...finally Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-35 finally . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-36 Lesson 3: Java I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-37 Streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-38 Key Classes in java.io Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-39 Efficient I/O Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-40 The PrintWriter Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-41 Using Text Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-42 File I/O Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-44 Changing File Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-45 Lesson 4: Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-46 Principles of Object-Oriented Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-47 The Object Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-48 The extends Keyword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-49 Constructor Execution Revisited . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-50 Constructor Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-51 Constructors with and without Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-53 Abstract Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-55 Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-56 Multiple Inheritance with Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-57 Casting within the Class Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-59 Casting Primitives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-60 Automatic Class Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-61 Automatic Interface Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-62 Explicit Casts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-63 Upcasting and Downcasting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-65 Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-66 Dynamic Binding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-67 Student Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-68 Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-69 Review Answers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-70 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-72
  8. 8. VI IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009 • • • • • Table of Contents Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Unit 7: Design Patterns, Interfaces, and the Collections Framework Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2 Lesson 1: Design Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-3 Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4 Singleton Design Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-6 Using the Singleton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-7 Proxy Design Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-8 Adapter Design Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-9 Immutable Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-10 Iterator Design Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-11 Generic Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-12 Lesson 2: Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-13 An Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-14 Implementing an Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-15 Abstract Classes versus Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-16 Implementing Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-17 Interfaces and Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-18 Extending Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-19 Extending Multiple Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-20 Nested and Inner Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-22 Lesson 3: The Collections Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-23 Java Collections Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-24 Basic Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-25 Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-26 Linked List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-27 Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-28 Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-29 Collection Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-30 Interface Implementations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-31 Navigating a Collection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-32 Original Enumeration Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-33 Student Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-34 Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-35 Review Answers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-36 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-37 Unit 8: Strings, Arrays, and Collection Classes Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2 Lesson 1: StringBuffer and StringBuilder . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-3 StringBuilder Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-4 StringBuilder Methods and Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-6 StringBuilder Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-8 Immutable Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-9 Lesson 2: Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-11 Using Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-12 Length of an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-13 foreach Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-14 Array Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-15 ArrayList Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-16
  9. 9. ©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization VII • • • • • Table of Contents Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Lesson 3: Collections Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-17 Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-18 Collection Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-19 Collections Classes and Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-20 Map Classes and Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-21 Lesson 4: ArrayList<E> Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-22 Choosing an ArrayList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-23 ArrayList Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-24 Searching, Adding, and Deleting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-25 Looping over an ArrayList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-27 Iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-29 Iterator Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-30 Iterator Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-31 ListIterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-32 ListIterator Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-33 Using an Iterator and Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-34 LinkedList Class Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-35 LinkedList Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-36 Adding to a Linked List with fillList() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-38 Iterating through a LinkedList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-39 Autoboxing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-40 Student Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-41 Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-42 Review Answers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-44 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-45 Unit 9: Threads Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-2 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-2 Lesson 1: Threading Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-3 Multithreaded Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-4 Advantages and Disadvantages of Using Multiple Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-5 The Life Cycle of a Thread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-6 Threads and the Operating System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-7 Preemptive Threading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-8 Priorities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-9 Thread States . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-10 Blocking and Yielding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-11 Locks and Critical Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-12 Deadlock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-13 Semaphore . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-14 Starvation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-15 Lesson 2: Implementing Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-16 The Thread Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-17 The Runnable Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-18 Starting a Thread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-19 Thread Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-20 Extending the Thread Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-21 Running the Thread Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-22 Implementing the Runnable Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-24 Running the Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-25 Synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-26 Synchronization Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-27 The Producer-Consumer Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-29 Synchronized Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-32
  10. 10. VIII IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009 • • • • • Table of Contents Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Using wait() and notify() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-33 Student Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-35 Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-36 Review Answers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-38 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-39 Unit 10: Serialization and Remote Method Invocation Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2 Lesson 1: Serialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-3 Serialization of an Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-4 Why Use Serialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-5 Static and Transient Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-6 Making a Class Serializable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-7 Implementing the Serializable Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-8 Instance and Superclass State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-9 equals() and hashCode() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-10 Serialization Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-11 writeObject() and readObject() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-12 Serialization Implementation Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-13 Serialization Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-14 Lesson 2: Remote Method Invocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-15 Distributed Computing and RMI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-16 Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-17 Client and Server Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-18 RMI Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-19 Proxy Stubs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-20 Remote Reference and Transport Layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-21 Finding RMI Remote Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-22 RMI System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-23 HelloRemote Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-24 Hello Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-25 RMIServer Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-26 RMIClient Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-28 Invoking Remote Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-30 Student Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-31 Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-32 Review Answers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-34 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-35 Tivoli Professional Certification Special Offer for Having Taken This Course . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . I Reasons for Certification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . I Role-based Certification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . I When to Attempt a Certification Exam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . II Location and Cost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . II Sources of Additional Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . II
  11. 11. • • • • • IX Preface © 2009 IBM Corporation Student Guide
  12. 12. X IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009 • • • • • Preface Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Course Description The IBM Enterprise IT and Asset Management 7.1 Java for Customization course provides hands-on training to learn Java™ programming skills using the Eclipse Integrated Development Environment. This course includes Java and object-oriented fundamentals in addition to advanced features of the language. These topics are prerequisite knowledge for the IBM Enterprise IT and Asset Management 7.1 Customizing Business Objects course and the IBM Integration Framework 7.1 Customization course. Audience This course is designed for developers, implementers, and administrators who want to learn how to design, build, and debug Java applications. This course is also appropriate for those who want to learn the more advanced Java topics presented in this course before attending the IBM Enterprise IT and Asset Management 7.1 Customizing Business Objects course or the IBM Integration Framework 7.1 Customization course. IBM Tivoli Technical Education The latest information about IBM Tivoli education offerings can be found online at http://www.ibm.com/software/tivoli/education/ If you have any questions about education offerings, send an e-mail to the appropriate alias for your region: • Americas: tivamedu@us.ibm.com • Asia Pacific: tivtrainingap@au1.ibm.com • EMEA: tived@uk.ibm.com Tivoli User Group Community You can get even more out of Tivoli software by joining and participating in one of the 91 independently run Tivoli User Groups around the world. Learn about online and in-person Tivoli User Group opportunities near you at www.tivoli-ug.org.
  13. 13. ©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization XI • • • • • Preface Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Course Objectives Course Outline The following outline is a high-level description of the contents of this course. Each unit has an overview presentation, and most units have a series of student exercises designed to reinforce the concepts presented. The course contains the following units: • Unit 1: Objects and Object-Oriented Programming This course covers the basics of the Java programming language. It also includes classes and constructs specific to customizing integration framework and related business objects. It does not include any graphical user interface or applet programming. • Unit 2: Programming with Java This unit examines Java’s architecture and the basics of compiling and running programs using the Java platform. Java allows you to write a program once and run it on any platform. IBM Software Group | Tivoli software 2 Course Objectives Upon completion of this course, you will be able to: • Identify object-oriented concepts and their advantages • Write code using Java classes, operations, and program control structures • Use Java to design and code classes based on inheritance, composition, and polymorphism • Write and troubleshoot programs using the Eclipse IDE • Use different classes included in the Java API (I/O, Collection Framework, Strings, and so on) • Write code that uses serialization, remote method invocation (RMI), and threads
  14. 14. XII IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009 • • • • • Preface Course materials may not be reproduced in whole or in part without the prior written permission of IBM. • Unit 3: Java Basics and Operators This unit covers basic Java programming constructs and concepts. • Unit 4: Java Basics and Programming Syntax This unit covers the basics of the Java programming language and syntax. • Unit 5: Classes, Constructors, and Strings This unit examines the difference between classes and objects, and how objects are constructed. The String class and its methods are introduced. • Unit 6: Java Exceptions, I/O, and Inheritance This unit covers access control for data and methods in more detail, in addition to implementing inheritance and polymorphism with abstract classes and interfaces. You will also implement Java exception handing and Java I/O basics. • Unit 7: Design Patterns, Interfaces, and the Collections Framework This unit covers design patterns, interfaces, and the Java Collections Framework. • Unit 8: Strings, Arrays, and Collection Classes This unit examines some of the Java Collection classes introduced in Unit 7 in more detail. • Unit 9: Threads This unit focuses on extending the Thread class to create multiple threads, and implementing the Runnable interface. • Unit 10: Serialization and Remote Method Invocation This unit covers object serialization and Remote Method Invocation. Using serialization, you can save and reconstruct an object’s state. This process is used when implementing Remote Method Invocation.
  15. 15. ©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization XIII • • • • • Preface Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Typographical Conventions In this course, the following typographical conventions are used. Product Information Product Documentation In some cases IBM Tivoli product documentation is available in the classroom or on the Instructor Resources CD. For access to documentation outside the classroom environment, visit the IBM Web site. Convention Usage Bold Commands, keywords, file names, authorization roles, URLs, or other information that you must use literally appear in bold. Italics Variables and values that you must provide appear in italics. Words and phrases that are emphasized also appear in italics. Bold Italics New terms appear in bold italics when they are defined in the text. Monospace Code examples, output, and system messages appear in a monospace font. > In this manual, the arrow character is used as a path arrow. The arrow indicates the path to the named window.
  16. 16. XIV IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009 • • • • • Preface Course materials may not be reproduced in whole or in part without the prior written permission of IBM.
  17. 17. • • • • • 1-1 Unit 1: Objects and Object-Oriented Programming © 2009 IBM Corporation Unit 1: Objects and Object-oriented Programming
  18. 18. 1-2 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Introduction This course covers the basics of the Java programming language. It also includes classes and constructs specific to customizing integration framework and related business objects. It does not include any graphical user interface or applet programming. Objectives IBM Software Group | Tivoli software 2 Objectives Upon completion of this unit, you will be able to: Describe the following basic concepts of object-oriented programming: – Abstraction – Encapsulation – Inheritance – Polymorphism
  19. 19. ©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-3 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Evolution to Objects Large-scale software programs today are highly complex. Over time, the increasing complexity of these systems gradually led to the need for a powerful, effective software solution. That solution was object-oriented programming. Complex systems, whether large businesses, public organizations, a cell phone, or a hospital, can be modeled as objects. IBM Software Group | Tivoli software 3 Evolution to Objects • Today’s business solutions are complex • Objects can reflect the components of a complex solution • Objects are used to model systems and their components
  20. 20. 1-4 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Software Evolution Software evolution defines the process by which programs change and adapt. Programming paradigms have undergone major shifts in the past 50 years to handle the complexity of software development. Modular programming allowed programs to branch to another part of the program. Structured programming used a top-down design model and the overall program structure maps to separate subsections. A function or set of similar functions were coded in separate modules or submodules. Later, stored procedures, a subroutine available to applications accessing a relational database system, provided additional functionality. In the mid-1980s, object-oriented programming became the industry standard using classes written in C++. Ten years later, the Java programming language was introduced. Its ability to be written once and run on multiple platforms has made Java the current programming language of choice. The older languages did not enforce any property or method boundaries, which often resulted in unwanted side effects. Variables were changed or affected in unexpected ways, and the code was difficult to understand and maintain. IBM Software Group | Tivoli software 4 Software Evolution
  21. 21. ©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-5 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Modeling Objects Complex systems exist everywhere. They can be independent or they can interact with defined dependencies. Objects represent these systems. An object can be used to model anything, such as a car engine, the human body, or a large- scale organization. IBM Software Group | Tivoli software 5 Modeling Objects • Objects are everywhere • Objects can be independent • Objects can interact
  22. 22. 1-6 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Everything Is an Object Anything can be modeled as an object. For example, a car engine with multiple interacting parts can be represented as an object that contains a collection of interacting objects. A cell (of the organic variety) also can be represented as an object. It has unique characteristics and can interact with other cells, because complex organisms are multicellular, with cooperative organ systems that perform complex activities. A collection of objects is itself an object. A list is an object, and every object contained in the list is also an object. IBM Software Group | Tivoli software 6 Everything Is an Object • Anything can be modeled as an object • A collection of objects is itself an object Car engine Hospital Home theater system • The contents of a collection are objects Car engine contains an ignition, starter, and battery object Hospital contains doctor, patient, lab test, and test request objects Home theater system contains a DVD, speaker, and screen object
  23. 23. ©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-7 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Object Hierarchy Consider that a human body consists of many structures, including muscle, blood, and nerve. Each of these structures is further composed of a collection of cells, and inside each cell is yet another level of complexity. The parts form a hierarchy, and each level of this hierarchy embodies its own complexity. This arrangement can be represented as a hierarchy of objects. A hospital could contain a laboratory, and the laboratory could be separated into a blood laboratory, an X-ray laboratory, a pathology laboratory, and an ultrasound laboratory. Object hierarchies model the specialization of objects. IBM Software Group | Tivoli software 7 Object Hierarchy • Represents specialization of a more basic object • Parent, base class, or superclass • Child, subclasses, or derived classes
  24. 24. 1-8 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Similar Objects Objects might have a common interface but a dissimilar function. For example, a saw and a table knife can both cut, and they both have a blade and handle, but their purpose is functionally different. With object-oriented programming, you can use this commonality between otherwise unrelated objects and treat them identically. IBM Software Group | Tivoli software 8 Similar Objects • Common interface • Functionally similar but different purpose • Both objects have a blade and can cut
  25. 25. ©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-9 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Keys to Object-Oriented Technology The objects themselves are the building blocks that provide the advantages of object- oriented programming. The power of Java lies in its use of object hierarchies and establishment of well-defined interaction between the objects. IBM Software Group | Tivoli software 9 Keys to Object-Oriented Technology • Objects • Interaction between objects • Hierarchy of objects • Object composition
  26. 26. 1-10 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Characteristics of an Object An object models anything that is a part of an entity, or the entity itself. Objects are described by their behavior and state. An object has methods, and its methods reflect behavior. An object also contains variables, and its variables reflect its state. Most objects are dependent. They typically are part of another object, or they collaborate with other objects. IBM Software Group | Tivoli software 10 Characteristics of an Object • Any object can be anything that models a thing: a truck, a car, or a bank statement • An object has two aspects: state and behavior • An object’s methods reflect an object’s behavior • An object’s variables reflect an object’s state • Most objects act as part of a system: a sound system, a human body, or an engine
  27. 27. ©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-11 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Car Object An car object might contain an engine and a chassis, travel at a particular speed in a certain direction, and contain a specific amount of fuel. These characteristics represent the car’s properties. They are called data members, attributes, fields, variables, or state. The behavior of the car might include starting, stopping, and turning. Behaviors are called functions, methods, or member functions. These actions represent the car object’s functionality. IBM Software Group | Tivoli software 11 Car Object • An object has attributes Attributes, data members, fields, properties, data • An object has functionality Functions, methods, behaviors, member functions
  28. 28. 1-12 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. A Class Is the Blueprint A class serves as a template or blueprint for an object. There might be tens of thousands of cars that were created to match a design blueprint and are exactly the same. A single car is an instance of the class of objects known as car. A class is the blueprint (or template) from which individual objects are created. The following Car class is a possible implementation of a car: class Car { String color; String engineType; int numberDoors = 4; void start() { ... } void stop() { ... } void turn() { } } IBM Software Group | Tivoli software 12 A Class Is the Blueprint
  29. 29. ©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-13 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. The variables represent the object’s state, and the methods (functions) allow the object to interact with other objects.
  30. 30. 1-14 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Classes and Objects A class is a description of the objects that it represents. A class is used to instantiate (create an instance of) an object. A class is the blueprint or template of an object; it is not the actual object itself. An object is an instantiation of a class. It models something in the real world. An object has data (states) and methods (behaviors) as defined for the class of objects to which it belongs. A class defines a new data type. A char, boolean, int, String, or Array is a data type. The class Car creates another data type that can be used in the system. IBM Software Group | Tivoli software 13 Classes and Objects
  31. 31. ©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-15 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. The Car Class The Car class includes (or encapsulates) attributes and methods that all instances of a Car object will have. The class is made up of the properties and behavior that a Car object represents. The following example creates an instance of a Car object: class Car { private int aProperty; private int anotherProperty; public void aMethod() { } public void anotherMethod() { } } public class MainApplication { public static void main(String[] arg) { Car carA = new Car(); Car carB = new Car(); } IBM Software Group | Tivoli software 14 The Car Class
  32. 32. 1-16 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. An object has the properties and behaviors defined in a class. After you write the class definition, you create one or more objects of that class using the new keyword. To create a new object, type the word new followed by the name of the class, followed by parentheses. You can also specify arguments in the parentheses when creating new objects. When a new object is created, memory is allocated to hold the class variable plus additional memory required by all objects.
  33. 33. ©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-17 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. An Object’s Interface An object’s interface is how it represents itself to other objects. Note: Do not confuse this term with the concept of interfaces, which will be covered in Unit 7. The methods and instance variables refer to functions and data that are stored in each object. All variables and methods can be referenced using dot notation. To reference an instance variable, type the object name, a dot, and then the variable name. IBM Software Group | Tivoli software 15 An Object’s Interface
  34. 34. 1-18 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Abstraction and Encapsulation There are always clear boundaries between the outside and the inside of a specific level of abstraction. For example, the parts of a muscle work together to provide the functionality of the muscle as a whole. However, they have little or no direct interaction with the elementary parts of blood. There is a distinct separation among the parts at different levels of abstraction. Abstraction and encapsulation are different but closely related object-oriented concepts. • Abstraction denotes an entity that is represented with a specific level of detail, and unnecessary details are ignored. • Encapsulation is the technique by which an object’s internal information and functionality is hidden, and what is visible is intended to be visible. You can get information from an object without all of its data being directly accessible. IBM Software Group | Tivoli software 16 Abstraction and Encapsulation • Encapsulation and information hiding • Data encapsulation versus data abstraction
  35. 35. ©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-19 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Data Abstraction All parts at the same level of abstraction interact in well-defined ways. For example, at a high level of abstraction in a living body, muscle is controlled by the nervous system. At lower levels of abstraction, muscle interacts with blood, which transports nutrients to the muscles. The muscles in turn use the nutrients provided by the blood to produce energy and respond to nerve stimuli. In a similar manner, a car engine contains parts that interact in a well-defined way. An ignition switch responds to the turn of a key. Battery voltage creates a magnet effect inside the solenoid. When this connection is completed, current flows to start the engine. Every object in these processes haves characteristics and well-defined functionality. The highest level of abstraction is the engine itself. The next level could be a few components. The lowest level could be millions of objects representing aluminium atoms. IBM Software Group | Tivoli software 17 Data Abstraction • Data abstraction versus levels of abstraction
  36. 36. 1-20 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Inheritance and Composition Good object-oriented design includes establishing relationships between classes. Classes are usually related through inheritance or composition. A car is composed of many objects. It has an engine object, a chassis object, and so on. The human body is also composed of many objects. The relationship is one of composition and is characterized by a has-a relationship. A Prius™ is a type of car. The relationship is one of inheritance and is characterized as an is-a type, which can be modeled with a hierarchical diagram. Inheritance is a way of reusing behavior and data. Similar classes of objects can be organized into categories to form class hierarchies. The subclasses can use the behavior of higher classes (superclasses) in the hierarchy. IBM Software Group | Tivoli software 18 Inheritance and Composition • Inheritance is an is-a relationship between objects • Composition is a has-a relationship between objects
  37. 37. ©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-21 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Subclasses Classes can be derived from other classes. The derived class is called a subclass (or child class). The class from which it is derived is called the superclass (or parent class). A subclass inherits properties and behavior from all of its parent classes. The term superclass refers to the direct parent, and all of the parent classes, of a class. Use the extends clause in your class declaration to create a subclass of another class. As a subclass, your class inherits member variables and methods from its superclass in addition to adding its own. The subclass can use the inherited items from the superclass as is, or the subclass can hide variables or override methods inherited from its superclass. In Java, all classes are derived from some root class. The topmost class from which all classes are derived is the Object class, which is defined in java.lang. As the root of the class hierarchy, all objects inherit directly or indirectly from the Object class. IBM Software Group | Tivoli software 19 Subclasses
  38. 38. 1-22 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Object Interaction Typically, individual objects are each responsible for a small part in a single larger process. There might be centralized objects that directly coordinate the activities of lower-level objects. Some objects might act as independent agents, each of which might show highly complex behavior and might contribute to many higher-level functions. High-level functionality is realized through the mutual cooperation of meaningful collections of objects. A business can be a complex system: Multinational corporations contain companies, which are made up of divisions, which contain branches, and so on. The relationships among the various parts of a large organization are like those found among the cells in a living system. The processes of employee interaction and the sharing of common facilities to accomplish their tasks are defined and enforced with restrictive boundaries and business rules. IBM Software Group | Tivoli software 20 Object Interaction • Object design is about behavior • Object design emphasizes the interplay between objects • Objects have responsibilities • Objects act independently and cooperatively • Object relationships and interaction determine design
  39. 39. ©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-23 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Representing an Entity with Objects Drawing an analogy between objects and a car engine or human cells can help you better understand this concept. A car engine encapsulates its complexity under the vehicle hood. The human cell encapsulates its internal complexity behind a cell membrane. The car engine components communicate through electrical messages or signal to each other. Cells communicate by sending chemical signals, each uniquely coded to elicit a particular response from a cell when it penetrates the cell’s membrane. Similar to the car engine or cell membrane, an object’s interface hides the object’s internal complexity from the outside world. Communication with the object is achieved by sending preestablished messages through the interface. IBM Software Group | Tivoli software 21 Representing an Entity with Objects • Object complexity should be abstracted from user • Complexity is encapsulated within the object itself • Object’s interface should hide its internal complexity • Object components communicate by sending messages and requests to each other • Communication is established through the object interface
  40. 40. 1-24 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Classes and Interfaces A class definition is a template from which objects can be created. A class definition includes the variables (state information) and the capabilities (behaviors or methods) for instances of that class. The class definition defines how an object (instance) of that class behaves, but the class definition is not an object. An interface is similar to a class but it has no instances. Interfaces are used to facilitate the sharing of behavior among similar, more specialized classes. They are also used for sharing behavior between objects that do not have a class relationship. IBM Software Group | Tivoli software 22 Classes and Interfaces • A class definition is a template • The class definition is not an object • An interface is similar to a class: Cannot be instantiated Models similarities between otherwise unrelated objects
  41. 41. ©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-25 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Object Interaction and Methods Methods are how objects communicate. An object makes a request from another object by sending a message in the form of a method call. There are two types of methods: instance and static. • Instance methods are associated with an instance of an object. These methods use the instance variables of the object. From outside the defining class, an instance method is called by using an object name as a prefix, such as: object1.setText("Hello"); • Static methods are associated with the class itself. They do not use instance variables of any object of the class they are defined in. A static method is called by using a class name as a prefix, such as: Math.min(i,j); IBM Software Group | Tivoli software 23 Object Interaction and Methods There are two types of methods: instance and static. • Instance methods are associated with an instance of the object: object1.setText("Hello"); • Static methods are associated with the class itself: Math.min(i,j);
  42. 42. 1-26 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Class Example Classes are composed of a name, attributes, and methods. The slide illustrates an example of a class. IBM Software Group | Tivoli software 24 Class Example
  43. 43. ©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-27 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Object-Oriented Concepts All object-oriented programming languages provide mechanisms that help you implement the object-oriented paradigm. These mechanisms are encapsulation, inheritance, and polymorphism. • Encapsulation is the means to get information from an object without its data being directly accessible. • Inheritance is a way of reusing behavior and data within a class. Similar classes of objects can be organized into categories to form class hierarchies. The subclasses can use the behavior of higher classes (superclasses) in the hierarchy. • With the polymorphism feature, one interface can be used for a general set of actions. The specific action is determined by the exact context of the situation. IBM Software Group | Tivoli software 25 Object-oriented Concepts Fundamental mechanisms provided by object-oriented languages: Encapsulation Inheritance Polymorphism
  44. 44. 1-28 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Encapsulation and Information Hiding The basis of encapsulation is the class. A class defines the data and behavior to be shared by a set of objects. Each object of a class contains the structure and behavior defined by that class. A class is a logical construct. An object has physical reality. When you create a class, you specify the methods and data that constitute that class. The data defined by the class is referred to as member variables or instance variables. The operations on that data are referred to as methods. The methods define how the member variables can be used. The purpose of a class is to encapsulate complexity. There are mechanisms for hiding the complexity of the implementation inside the class. Each method or variable in a class can be marked public or private. The public interface of a class represents everything that other objects can access. The private methods and private data can only be accessed by methods of the class itself. Code that does not belong to the class cannot access a private method or variable. The private data members of a class can only be accessed by other parts of your program through the public methods of the class. You can prevent undesirable actions by designing the public interface to limit exposure to a class. IBM Software Group | Tivoli software 26 Encapsulation and Information Hiding • Basis of encapsulation is the class • Methods define how the variables are used by other objects • The class encapsulates complexity of the implementation • The methods provide the class interface and ensure that unwanted actions do not occur
  45. 45. ©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-29 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Inheritance Inheritance is the process by which one object acquires the properties of another object. This important process supports the concept of hierarchical classification. As mentioned earlier, many relationship are made manageable by hierarchical (that is, top-down) classifications. Dog is part of the classification Mammal, which is under the larger classification Animal. Without the use of hierarchies, each object would have to define all of its characteristics explicitly. However, by using inheritance, an object must only define those qualities that make it unique within its class. It can inherit its general attributes from its parent. Thus, the inheritance mechanism makes it possible for one object to be a specific instance of a more general case. IBM Software Group | Tivoli software 27 Inheritance • Inheritance is a way for objects to define relationships with each other • Objects inherit characteristics from a parent object • Parent object must be able to pass its state and methods to its children • Parent and child objects must have characteristics in common • Child objects (subclasses) are more specialized versions of the parent object (superclass)
  46. 46. 1-30 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Class Hierarchy Most people naturally view the world as made up of objects that are related to each other in a hierarchical way, such as animals, mammals, and cows. To describe animals in an abstract way, you would say that they have some attributes, such as size, intelligence, and type of skeletal system. Animals also have certain behavioral aspects; they eat, breathe, and sleep. This description of attributes and behavior is the class definition for animals. To describe a more specific class of animals, such as mammals, you would use more specific attributes, such as type of teeth, and mammary glands. This category is known as a subclass of animals, where animals are referred to as mammals’ superclass. Because mammals are simply more precisely specified animals, they inherit all of the attributes from animals. A deeply inherited subclass inherits all of the attributes from each of its ancestors in the class hierarchy. IBM Software Group | Tivoli software 28 Class Hierarchy • Real-world objects can form natural hierarchies • A base class (superclass) can be described in an abstract way • A more specialized class can be described in a more concrete way • The specialized class inherits everything from the more general classes in the hierarchy
  47. 47. ©Copyright IBM Corp. 2009 IBM Enterprise IT and Asset Management 7.1: Java for Customization 1-31 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. Polymorphism With the polymorphism (meaning many forms) feature, one interface can be used for a general class of actions. The specific action is determined by the exact nature of the situation. Polymorphism is one of the fundamental principles of object-oriented programming. You must understand inheritance before learning about polymorphism. IBM Software Group | Tivoli software 29 Polymorphism • Means many forms • One interface can be used to specify a general action
  48. 48. 1-32 IBM Enterprise IT and Asset Management 7.1: Java for Customization ©Copyright IBM Corp. 2009 • • • • • Unit 1: Objects and Object-Oriented Programming Course materials may not be reproduced in whole or in part without the prior written permission of IBM. One Interface, Multiple Methods More generally, the concept of polymorphism is often expressed by the phrase “one interface, multiple methods.” This phrase means that you can design a generic interface to a group of related activities. Being able to use the same interface to specify a general class of action helps reduce complexity. It is the compiler’s job to select the specific action (that is, method) as it applies to each situation. You, the programmer, do not have to make this selection manually. You must only remember and use the general interface. IBM Software Group | Tivoli software 30 One Interface, Multiple Methods

×