SlideShare a Scribd company logo
Objects & OO Thinking
        for Java

             Prof. Jeff Sonstein
    Department of Information Technology
      Rochester Institute of Technology
                     jxsast@rit.edu
               http://www.it.rit.edu/~jxs/

         Center for the Handheld Web
                http://chw.rit.edu/blog/

   Mobile Web Best Practices Working Group
       http://www.w3.org/2005/MWI/BPWG/Group/
What is Object-
    Oriented Design?
• Objects are self-contained application
  components that work together
• Object-Oriented Design is the art (not
  science) of decomposing an application into
  some number of objects.


                  Prof. Jeff Sonstein
Why Decompose
      Problems?
• Simply put, meaningfully large systems &
  problems can be overwhelming to
  approach as a whole
• Breaking a big problem into many small
  problems is a useful way to manage
  complexity


                  Prof. Jeff Sonstein
Why Objects?

• Reuse (A lazy programmer is a good
  programmer)
• Encapsulate (that other idiot cannot mess
  up what they cannot access directly)



                  Prof. Jeff Sonstein
OO Decomposition
     Guidelines
• think in terms of interfaces first
• hide and abstract as much as you can
• use objects in their existing form as much
  as you can (composition, not inheritance)
• organize related objects into packages
• program as though there really is a
  tomorrow
                  Prof. Jeff Sonstein
Review: Some Key
Programming Concepts
• All computer programs are constructed of
  just 2 things
 1. data structures
 2. and algorithms to manipulate those data
    structures


                  Prof. Jeff Sonstein
Data Structures
• are simply containers to hold data
• examples of data structures:
   • lists
   • queues
   • arrays
   • etc
                   Prof. Jeff Sonstein
Data Structures:
       Example I
The list of ingredients at the top of a recipe
for making a chocolate cake




                  Prof. Jeff Sonstein
Data Structures:
      Example II
The queue of patrons waiting to buy movie
tickets




                Prof. Jeff Sonstein
Algorithms
• are simply instructions on how to manipulate
  data structures
• all algorithms are composed of only 3
  “control structures”:
   1. sequence
   2. selection
   3. iteration
                    Prof. Jeff Sonstein
Control Structures I:
       Sequence
• simply means:
  DO this 1st
  DO this 2nd
  DO this 3rd
  [and so on]


                  Prof. Jeff Sonstein
Control Structures II:
      Selection
• simply means:
 IF some condition is true
 THEN do this
 ELSE do something else
 (note: a “case” or “switch” statement is just a fancy set of IF statements)




                                 Prof. Jeff Sonstein
Control Structures III:
     Iteration
• “leading test”:
 WHILE some condition is true (may never be so)
 DO something
• “trailing test”:
 REPEAT something (always do at least once)
 UNTIL some condition is true

                      Prof. Jeff Sonstein
Data Structures &
            Algorithms Example
  Data
Structure




Algorithm




                   Prof. Jeff Sonstein
What Can an Object
      Contain?
• methods
• variables (data structures)
• initialization code
• and inner classes (really hidden)

                   Prof. Jeff Sonstein
Methods
• constructors
• accessors and mutators
  (also known as getters & setters -
  getWhatever and setWhatever methods)
• note method overloading (see
  java.io.PrintStream.print() methods, for
  example)
                    Prof. Jeff Sonstein
And What Can
     Methods Contain?

• local variables (data structures)
• and algorithms to manipulate those data
  structures
  (sound familiar?)



                      Prof. Jeff Sonstein
Method Overloading
     Example




       Prof. Jeff Sonstein
Variables

• things that can change during the running of
  a program
• hide them whenever possible (see
  discussion of accessors & mutators)



                  Prof. Jeff Sonstein
Initialization

• constructors have the same name as the
  class
• constructors say what to do when a new
  instance is created
• constructors can call other methods of
  their class as well as calling other classes


                   Prof. Jeff Sonstein
Inner Classes


• only visible to this particular instance of
  this particular class (revisit information
  hiding)




                   Prof. Jeff Sonstein
A Simplified GUI
           Example
• testHarness.java - a very simple (and
  simplified) example of an easily-modified GUI
  test container. Note that it is “smart” enough
  to run as either a standalone program or in a
  Web browser context.



                    Prof. Jeff Sonstein
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.*;

public class testHarness extends Applet {

    private randomNumbers myCurve;
    private TextArea myMessages = new TextArea();
    private String statusString = "Random Numbers in a Gaussian Distribution";

    public testHarness() {
      setLayout( new BorderLayout() );
      add( myMessages, BorderLayout.CENTER );
      add( new Label( statusString ), BorderLayout.SOUTH );
      // add( new myButton( myMessages ), BorderLayout.SOUTH );
      myCurve = new randomNumbers();
      int counter = 1;
      for ( Enumeration x = myCurve.getNumbers(); x.hasMoreElements(); ) {
        myMessages.append( counter + ":t" + (Double)x.nextElement() + "n" );
        counter++;
      }
    }

    public static void main( String[] args ) {
      Frame myFrame = new Frame ( "testHarness.java" );
      myFrame.setSize( 300, 300 );
      myFrame.add( new testHarness() );
      myFrame.addWindowListener( new WindowAdapter() {
        public void windowClosing( WindowEvent e ) {
          System.exit( 0 );
        }
      } );
      myFrame.show();
    }

}
                                                       Prof. Jeff Sonstein
A Simplified Support-
     Class Example

• and randomNumbers.java - a very simple
  (and simplified) example of an easily-
  modified random number generator.




                   Prof. Jeff Sonstein
import java.util.*;

public class randomNumbers {

    private static final int MAX_NUMBERS = 100;
    private Vector myVector;

    public randomNumbers() {
      setNumbers();
    }

    public void setNumbers() {
      Random myGenerator = new Random();
      myVector = new Vector();
      for ( int i = 0; i < MAX_NUMBERS; i++ ) {
        myVector.add( new Double( myGenerator.nextGaussian() ) );
      }
    }

    public Enumeration getNumbers() {
      return myVector.elements();
    }

}




                                                      Prof. Jeff Sonstein
Review: Object-
     Oriented Design
• Objects are self-contained application
  components that work together
• Object-Oriented Design is the art (not
  science) of decomposing an application into
  some number of objects.


                  Prof. Jeff Sonstein
Review: Decomposition

• Simply put, meaningfully large systems &
  problems can be overwhelming to
  approach as a whole
• Breaking a big problem into many small
  problems is a useful way to manage
  complexity


                  Prof. Jeff Sonstein
Review: What Good
   Programmers Do

• Reuse (A lazy programmer is a good
  programmer)
• Encapsulate (that other idiot cannot mess
  up what they cannot access directly)



                  Prof. Jeff Sonstein
Some Useful Online
        Resources
•   JavaDocs: Sun
    http://java.sun.com/reference/api/

•   Java Programming textbook: Wikibooks
    http://en.wikibooks.org/wiki/Java_Programming

•   Patterns Book: “Design Patterns: Elements of
    Reusable Object-Oriented Software”
    http://en.wikipedia.org/wiki/Design_Patterns_(book)

                          Prof. Jeff Sonstein
Objects & OO Thinking
        for Java

             Prof. Jeff Sonstein
    Department of Information Technology
      Rochester Institute of Technology
                     jxsast@rit.edu
               http://www.it.rit.edu/~jxs/

         Center for the Handheld Web
                http://chw.rit.edu/blog/

   Mobile Web Best Practices Working Group
       http://www.w3.org/2005/MWI/BPWG/Group/

More Related Content

Viewers also liked

Introduction to OO, Java and Eclipse/WebSphere
Introduction to OO, Java and Eclipse/WebSphereIntroduction to OO, Java and Eclipse/WebSphere
Introduction to OO, Java and Eclipse/WebSphere
eLink Business Innovations
 
Unified modelling language (UML)
Unified modelling language (UML)Unified modelling language (UML)
Unified modelling language (UML)
Hirra Sultan
 
OOP programming
OOP programmingOOP programming
OOP programminganhdbh
 
OO Development 3 - Models And UML
OO Development 3 - Models And UMLOO Development 3 - Models And UML
OO Development 3 - Models And UML
Randy Connolly
 
Enum Report
Enum ReportEnum Report
Enum Report
enumplatform
 
Java 102 intro to object-oriented programming in java - exercises
Java 102   intro to object-oriented programming in java - exercisesJava 102   intro to object-oriented programming in java - exercises
Java 102 intro to object-oriented programming in java - exercises
agorolabs
 
Introduction to Agile
Introduction to AgileIntroduction to Agile
Introduction to Agile
agorolabs
 
Data structures and algorithms lab5
Data structures and algorithms lab5Data structures and algorithms lab5
Data structures and algorithms lab5Bianca Teşilă
 
Module 3 Object Oriented Data Models Object Oriented notations
Module 3  Object Oriented Data Models Object Oriented notationsModule 3  Object Oriented Data Models Object Oriented notations
Module 3 Object Oriented Data Models Object Oriented notations
Taher Barodawala
 
data structure(tree operations)
data structure(tree operations)data structure(tree operations)
data structure(tree operations)
Waheed Khalid
 
Packaes & interfaces
Packaes & interfacesPackaes & interfaces
Packaes & interfaces
yugandhar vadlamudi
 
Java 101 Intro to Java Programming
Java 101 Intro to Java ProgrammingJava 101 Intro to Java Programming
Java 101 Intro to Java Programming
agorolabs
 
Java 201 Intro to Test Driven Development in Java
Java 201   Intro to Test Driven Development in JavaJava 201   Intro to Test Driven Development in Java
Java 201 Intro to Test Driven Development in Java
agorolabs
 
What does OOP stand for?
What does OOP stand for?What does OOP stand for?
What does OOP stand for?
Colin Riley
 

Viewers also liked (18)

OO & UML
OO & UMLOO & UML
OO & UML
 
Introduction to OO, Java and Eclipse/WebSphere
Introduction to OO, Java and Eclipse/WebSphereIntroduction to OO, Java and Eclipse/WebSphere
Introduction to OO, Java and Eclipse/WebSphere
 
Unified modelling language (UML)
Unified modelling language (UML)Unified modelling language (UML)
Unified modelling language (UML)
 
OOP programming
OOP programmingOOP programming
OOP programming
 
OO Development 3 - Models And UML
OO Development 3 - Models And UMLOO Development 3 - Models And UML
OO Development 3 - Models And UML
 
Java Day-7
Java Day-7Java Day-7
Java Day-7
 
Enum Report
Enum ReportEnum Report
Enum Report
 
Java Day-2
Java Day-2Java Day-2
Java Day-2
 
Java 102 intro to object-oriented programming in java - exercises
Java 102   intro to object-oriented programming in java - exercisesJava 102   intro to object-oriented programming in java - exercises
Java 102 intro to object-oriented programming in java - exercises
 
Introduction to Agile
Introduction to AgileIntroduction to Agile
Introduction to Agile
 
Data structures and algorithms lab5
Data structures and algorithms lab5Data structures and algorithms lab5
Data structures and algorithms lab5
 
Module 3 Object Oriented Data Models Object Oriented notations
Module 3  Object Oriented Data Models Object Oriented notationsModule 3  Object Oriented Data Models Object Oriented notations
Module 3 Object Oriented Data Models Object Oriented notations
 
data structure(tree operations)
data structure(tree operations)data structure(tree operations)
data structure(tree operations)
 
Java beans
Java beansJava beans
Java beans
 
Packaes & interfaces
Packaes & interfacesPackaes & interfaces
Packaes & interfaces
 
Java 101 Intro to Java Programming
Java 101 Intro to Java ProgrammingJava 101 Intro to Java Programming
Java 101 Intro to Java Programming
 
Java 201 Intro to Test Driven Development in Java
Java 201   Intro to Test Driven Development in JavaJava 201   Intro to Test Driven Development in Java
Java 201 Intro to Test Driven Development in Java
 
What does OOP stand for?
What does OOP stand for?What does OOP stand for?
What does OOP stand for?
 

Similar to Objects & OO Thinking for Java

FP vs OOP : Design Methodology by Harshad Nawathe
FP vs OOP : Design Methodology by Harshad NawatheFP vs OOP : Design Methodology by Harshad Nawathe
FP vs OOP : Design Methodology by Harshad Nawathe
Chandulal Kavar
 
Design patterns
Design patternsDesign patterns
Design patterns
mudabbirwarsi
 
Unit testing with Junit
Unit testing with JunitUnit testing with Junit
Unit testing with Junit
Valerio Maggio
 
Design Patterns & JDK Examples
Design Patterns & JDK ExamplesDesign Patterns & JDK Examples
Design Patterns & JDK Examples
Ender Aydin Orak
 
Unit testing Agile OpenSpace
Unit testing Agile OpenSpaceUnit testing Agile OpenSpace
Unit testing Agile OpenSpaceAndrei Savu
 
Java for android developers
Java for android developersJava for android developers
Java for android developers
Aly Abdelkareem
 
Revision of Scientific Method
Revision of Scientific MethodRevision of Scientific Method
Revision of Scientific Method
Lily Kotze
 
Visual thinking colin_ware_lectures_2013_10_research methods
Visual thinking colin_ware_lectures_2013_10_research methodsVisual thinking colin_ware_lectures_2013_10_research methods
Visual thinking colin_ware_lectures_2013_10_research methodsElsa von Licy
 
Debugging
DebuggingDebugging
Debugging
Olivier Teytaud
 
Model-based programming and AI-assisted software development
Model-based programming and AI-assisted software developmentModel-based programming and AI-assisted software development
Model-based programming and AI-assisted software development
Eficode
 
Automated testing of NASA Software - part 2
Automated testing of NASA Software - part 2Automated testing of NASA Software - part 2
Automated testing of NASA Software - part 2Dharmalingam Ganesan
 
Most Useful Design Patterns
Most Useful Design PatternsMost Useful Design Patterns
Most Useful Design Patterns
Steven Smith
 
2013 10-30-sbc361-reproducible designsandsustainablesoftware
2013 10-30-sbc361-reproducible designsandsustainablesoftware2013 10-30-sbc361-reproducible designsandsustainablesoftware
2013 10-30-sbc361-reproducible designsandsustainablesoftware
Yannick Wurm
 
Object oriented programming systems
Object oriented programming systemsObject oriented programming systems
Object oriented programming systems
rchakra
 
Java unit 7
Java unit 7Java unit 7
Java unit 7
Shipra Swati
 
Break through e2e-testing
Break through e2e-testingBreak through e2e-testing
Break through e2e-testingtameemahmed5
 
Open-source tools for generating and analyzing large materials data sets
Open-source tools for generating and analyzing large materials data setsOpen-source tools for generating and analyzing large materials data sets
Open-source tools for generating and analyzing large materials data sets
Anubhav Jain
 
Design_Patterns_Dr.CM.ppt
Design_Patterns_Dr.CM.pptDesign_Patterns_Dr.CM.ppt
Design_Patterns_Dr.CM.ppt
C Meenakshi Meyyappan
 
Modellbildung, Berechnung und Simulation in Forschung und Lehre
Modellbildung, Berechnung und Simulation in Forschung und LehreModellbildung, Berechnung und Simulation in Forschung und Lehre
Modellbildung, Berechnung und Simulation in Forschung und Lehre
Joachim Schlosser
 
Reproducibility: 10 Simple Rules
Reproducibility: 10 Simple RulesReproducibility: 10 Simple Rules
Reproducibility: 10 Simple Rules
Annika Eriksson
 

Similar to Objects & OO Thinking for Java (20)

FP vs OOP : Design Methodology by Harshad Nawathe
FP vs OOP : Design Methodology by Harshad NawatheFP vs OOP : Design Methodology by Harshad Nawathe
FP vs OOP : Design Methodology by Harshad Nawathe
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Unit testing with Junit
Unit testing with JunitUnit testing with Junit
Unit testing with Junit
 
Design Patterns & JDK Examples
Design Patterns & JDK ExamplesDesign Patterns & JDK Examples
Design Patterns & JDK Examples
 
Unit testing Agile OpenSpace
Unit testing Agile OpenSpaceUnit testing Agile OpenSpace
Unit testing Agile OpenSpace
 
Java for android developers
Java for android developersJava for android developers
Java for android developers
 
Revision of Scientific Method
Revision of Scientific MethodRevision of Scientific Method
Revision of Scientific Method
 
Visual thinking colin_ware_lectures_2013_10_research methods
Visual thinking colin_ware_lectures_2013_10_research methodsVisual thinking colin_ware_lectures_2013_10_research methods
Visual thinking colin_ware_lectures_2013_10_research methods
 
Debugging
DebuggingDebugging
Debugging
 
Model-based programming and AI-assisted software development
Model-based programming and AI-assisted software developmentModel-based programming and AI-assisted software development
Model-based programming and AI-assisted software development
 
Automated testing of NASA Software - part 2
Automated testing of NASA Software - part 2Automated testing of NASA Software - part 2
Automated testing of NASA Software - part 2
 
Most Useful Design Patterns
Most Useful Design PatternsMost Useful Design Patterns
Most Useful Design Patterns
 
2013 10-30-sbc361-reproducible designsandsustainablesoftware
2013 10-30-sbc361-reproducible designsandsustainablesoftware2013 10-30-sbc361-reproducible designsandsustainablesoftware
2013 10-30-sbc361-reproducible designsandsustainablesoftware
 
Object oriented programming systems
Object oriented programming systemsObject oriented programming systems
Object oriented programming systems
 
Java unit 7
Java unit 7Java unit 7
Java unit 7
 
Break through e2e-testing
Break through e2e-testingBreak through e2e-testing
Break through e2e-testing
 
Open-source tools for generating and analyzing large materials data sets
Open-source tools for generating and analyzing large materials data setsOpen-source tools for generating and analyzing large materials data sets
Open-source tools for generating and analyzing large materials data sets
 
Design_Patterns_Dr.CM.ppt
Design_Patterns_Dr.CM.pptDesign_Patterns_Dr.CM.ppt
Design_Patterns_Dr.CM.ppt
 
Modellbildung, Berechnung und Simulation in Forschung und Lehre
Modellbildung, Berechnung und Simulation in Forschung und LehreModellbildung, Berechnung und Simulation in Forschung und Lehre
Modellbildung, Berechnung und Simulation in Forschung und Lehre
 
Reproducibility: 10 Simple Rules
Reproducibility: 10 Simple RulesReproducibility: 10 Simple Rules
Reproducibility: 10 Simple Rules
 

Recently uploaded

2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
DhatriParmar
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 

Recently uploaded (20)

2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 

Objects & OO Thinking for Java

  • 1. Objects & OO Thinking for Java Prof. Jeff Sonstein Department of Information Technology Rochester Institute of Technology jxsast@rit.edu http://www.it.rit.edu/~jxs/ Center for the Handheld Web http://chw.rit.edu/blog/ Mobile Web Best Practices Working Group http://www.w3.org/2005/MWI/BPWG/Group/
  • 2. What is Object- Oriented Design? • Objects are self-contained application components that work together • Object-Oriented Design is the art (not science) of decomposing an application into some number of objects. Prof. Jeff Sonstein
  • 3. Why Decompose Problems? • Simply put, meaningfully large systems & problems can be overwhelming to approach as a whole • Breaking a big problem into many small problems is a useful way to manage complexity Prof. Jeff Sonstein
  • 4. Why Objects? • Reuse (A lazy programmer is a good programmer) • Encapsulate (that other idiot cannot mess up what they cannot access directly) Prof. Jeff Sonstein
  • 5. OO Decomposition Guidelines • think in terms of interfaces first • hide and abstract as much as you can • use objects in their existing form as much as you can (composition, not inheritance) • organize related objects into packages • program as though there really is a tomorrow Prof. Jeff Sonstein
  • 6. Review: Some Key Programming Concepts • All computer programs are constructed of just 2 things 1. data structures 2. and algorithms to manipulate those data structures Prof. Jeff Sonstein
  • 7. Data Structures • are simply containers to hold data • examples of data structures: • lists • queues • arrays • etc Prof. Jeff Sonstein
  • 8. Data Structures: Example I The list of ingredients at the top of a recipe for making a chocolate cake Prof. Jeff Sonstein
  • 9. Data Structures: Example II The queue of patrons waiting to buy movie tickets Prof. Jeff Sonstein
  • 10. Algorithms • are simply instructions on how to manipulate data structures • all algorithms are composed of only 3 “control structures”: 1. sequence 2. selection 3. iteration Prof. Jeff Sonstein
  • 11. Control Structures I: Sequence • simply means: DO this 1st DO this 2nd DO this 3rd [and so on] Prof. Jeff Sonstein
  • 12. Control Structures II: Selection • simply means: IF some condition is true THEN do this ELSE do something else (note: a “case” or “switch” statement is just a fancy set of IF statements) Prof. Jeff Sonstein
  • 13. Control Structures III: Iteration • “leading test”: WHILE some condition is true (may never be so) DO something • “trailing test”: REPEAT something (always do at least once) UNTIL some condition is true Prof. Jeff Sonstein
  • 14. Data Structures & Algorithms Example Data Structure Algorithm Prof. Jeff Sonstein
  • 15. What Can an Object Contain? • methods • variables (data structures) • initialization code • and inner classes (really hidden) Prof. Jeff Sonstein
  • 16. Methods • constructors • accessors and mutators (also known as getters & setters - getWhatever and setWhatever methods) • note method overloading (see java.io.PrintStream.print() methods, for example) Prof. Jeff Sonstein
  • 17. And What Can Methods Contain? • local variables (data structures) • and algorithms to manipulate those data structures (sound familiar?) Prof. Jeff Sonstein
  • 18. Method Overloading Example Prof. Jeff Sonstein
  • 19. Variables • things that can change during the running of a program • hide them whenever possible (see discussion of accessors & mutators) Prof. Jeff Sonstein
  • 20. Initialization • constructors have the same name as the class • constructors say what to do when a new instance is created • constructors can call other methods of their class as well as calling other classes Prof. Jeff Sonstein
  • 21. Inner Classes • only visible to this particular instance of this particular class (revisit information hiding) Prof. Jeff Sonstein
  • 22. A Simplified GUI Example • testHarness.java - a very simple (and simplified) example of an easily-modified GUI test container. Note that it is “smart” enough to run as either a standalone program or in a Web browser context. Prof. Jeff Sonstein
  • 23. import java.awt.*; import java.awt.event.*; import java.applet.*; import java.util.*; public class testHarness extends Applet { private randomNumbers myCurve; private TextArea myMessages = new TextArea(); private String statusString = "Random Numbers in a Gaussian Distribution"; public testHarness() { setLayout( new BorderLayout() ); add( myMessages, BorderLayout.CENTER ); add( new Label( statusString ), BorderLayout.SOUTH ); // add( new myButton( myMessages ), BorderLayout.SOUTH ); myCurve = new randomNumbers(); int counter = 1; for ( Enumeration x = myCurve.getNumbers(); x.hasMoreElements(); ) { myMessages.append( counter + ":t" + (Double)x.nextElement() + "n" ); counter++; } } public static void main( String[] args ) { Frame myFrame = new Frame ( "testHarness.java" ); myFrame.setSize( 300, 300 ); myFrame.add( new testHarness() ); myFrame.addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent e ) { System.exit( 0 ); } } ); myFrame.show(); } } Prof. Jeff Sonstein
  • 24. A Simplified Support- Class Example • and randomNumbers.java - a very simple (and simplified) example of an easily- modified random number generator. Prof. Jeff Sonstein
  • 25. import java.util.*; public class randomNumbers { private static final int MAX_NUMBERS = 100; private Vector myVector; public randomNumbers() { setNumbers(); } public void setNumbers() { Random myGenerator = new Random(); myVector = new Vector(); for ( int i = 0; i < MAX_NUMBERS; i++ ) { myVector.add( new Double( myGenerator.nextGaussian() ) ); } } public Enumeration getNumbers() { return myVector.elements(); } } Prof. Jeff Sonstein
  • 26. Review: Object- Oriented Design • Objects are self-contained application components that work together • Object-Oriented Design is the art (not science) of decomposing an application into some number of objects. Prof. Jeff Sonstein
  • 27. Review: Decomposition • Simply put, meaningfully large systems & problems can be overwhelming to approach as a whole • Breaking a big problem into many small problems is a useful way to manage complexity Prof. Jeff Sonstein
  • 28. Review: What Good Programmers Do • Reuse (A lazy programmer is a good programmer) • Encapsulate (that other idiot cannot mess up what they cannot access directly) Prof. Jeff Sonstein
  • 29. Some Useful Online Resources • JavaDocs: Sun http://java.sun.com/reference/api/ • Java Programming textbook: Wikibooks http://en.wikibooks.org/wiki/Java_Programming • Patterns Book: “Design Patterns: Elements of Reusable Object-Oriented Software” http://en.wikipedia.org/wiki/Design_Patterns_(book) Prof. Jeff Sonstein
  • 30. Objects & OO Thinking for Java Prof. Jeff Sonstein Department of Information Technology Rochester Institute of Technology jxsast@rit.edu http://www.it.rit.edu/~jxs/ Center for the Handheld Web http://chw.rit.edu/blog/ Mobile Web Best Practices Working Group http://www.w3.org/2005/MWI/BPWG/Group/