CIS234 Chapter06

CIS234 Chapter06 - Chapter 6 How to Define and Use Classes...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 6 ow to Define and Use Classes How to Define and Use Classes CIS 234 Java Object Oriented Programming 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Using Objects ± In previous examples we created objects and a Controller to control them ± Controls and interactions are found in each object rather than in a master controller ± Objects have Properties (attributes) and Methods ehaviors) (behaviors) ± Private Properties and Methods cannot be accessed from outside the object ± When the Properties and Methods are public they can be accessed through the object by using the “dot” notation. ± For example: ± String s = “Hello World”; ± System.out.println(s.toUpperCase()); Professor Hatim Mouissa CIS 234 2
Background image of page 2
The String Object ± The String object allows us to perform operations on String variables. ± The String object is created from a class that is already defined in Java. ± e do not need to import additional classes We do not need to import additional classes ± The String object has many predefined public Properties and Methods that we can access ± All we need is to know the name of the Property / Method tring s = “a”; System out print(s length()); ± String s = a ; System.out.print(s.length()); ± String s = “Hello”; System.out.print.indexOf(“e”); ± System.out.println(s.toUpperCase()); Professor Hatim Mouissa CIS 234 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Values vs References ± We looked at two types of variables in java ± Primitive variables and Object variables ± Java handles these variables differently ± boolean b = true; ± String s = “Hello world”; rimitive variables hold the value of the ± Primitive variables hold the value of the data we store in them ± Object variables hold a location reference to the data we want to store in them Professor Hatim Mouissa CIS 234 4
Background image of page 4
Values vs References ± If we create a variable without assigning it a reference to a value it is set to null ± String s; (java uses null to represent a missing g; ( j pg reference) ± To compare primitives we use “==“ ± To compare objects we use ± object1.equals(object2); ± The “==“ operation is used in objects to compare the references. ± If x and y are pointing to the same reference then (x == y) returns true ± If the value of the reference that k oints to te v a l u e o eeec e ta t po ts to equals the value of the reference that J points to then (k.equals(j)) returns true Professor Hatim Mouissa CIS 234 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Difference between by Value and by Reference ± int x = 5; int w = 5; teger y = new Integer(5); ± Integer y = new Integer(5); ± Integer z = new Integer(5); ± Integer k = y; Integer Primitive value x 5 w 5 Integer bject y k 5 Object Professor Hatim Mouissa CIS 234 6 z 5
Background image of page 6
By Value vs Reference ± Exercise heck if two string values are equal ± Check if two string values are equal ± Clicker Exercise ± Check if two objects are equal Professor Hatim Mouissa CIS 234 7
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Architecture of a multi-tier Application Presentation classes Presentation layer Business classes Middle layer Database classes Database layer Database CIS 234 Java Object Oriented Programming 8
Background image of page 8
How classes can be used to structure an
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/02/2008 for the course CIS 234 taught by Professor Dear during the Winter '08 term at Cal Poly Pomona.

Page1 / 26

CIS234 Chapter06 - Chapter 6 How to Define and Use Classes...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online