Presentation is loading. Please wait.

Presentation is loading. Please wait.

Question of the Day You overhear a boy & his mother talking: Mom:What is 25 + 8? Boy: That's easy, 33. Mom: Good. What's 33 + 7? Boy:Simple. It's 40. Mom:Excellent!

Similar presentations


Presentation on theme: "Question of the Day You overhear a boy & his mother talking: Mom:What is 25 + 8? Boy: That's easy, 33. Mom: Good. What's 33 + 7? Boy:Simple. It's 40. Mom:Excellent!"— Presentation transcript:

1 Question of the Day You overhear a boy & his mother talking: Mom:What is 25 + 8? Boy: That's easy, 33. Mom: Good. What's 33 + 7? Boy:Simple. It's 40. Mom:Excellent! Now what's 40 + 23? Boy: Boring. The answer is 37. Mom:Perfect! Once you see how the boy is dressed it all makes sense. What is the boy wearing?

2 Question of the Day You overhear a boy & his mother talking: Mom:What is 25 + 8? Boy: That's easy, 33. Mom: Good. What's 33 + 7? Boy:Simple. It's 40. Mom:Excellent! Now what's 40 + 23? Boy: Boring. The answer is 37. Mom:Perfect! Once you see how the boy is dressed it all makes sense. What is the boy wearing? A football uniform

3

4 Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage  Weekly assignments problems due before class  Remove rust from summer and get back into coding  Problems designed to help learn new material, too

5 Data Types  8+1 primitive data types  Examples: boolean, byte, char, int, double, String *  Only types that work with Java operators  Operators include: +, -, %, &&, ||, >=, <, !  Primitives used natively by computers  Means that using them is very quick  Implies greater support within the language

6 Primitive Types  Primitive variables are simple to use  Each variable is a “xerox” holding a value  Assignment copies value  Update variable being assigned only

7 Tracing Primitives  Write variable’s name in “box” which contains it  After the name put equal sign or arrow to name name = or name <-  Write variable’s value at end of this line  For assignment, cross out value & write new one

8 Classes  Real world needs more than primitives  Additional types defined by classes in Java  Classes usually begin with: public class ClassNameGoesHere {  By convention, name starts with capital letter  Use interior capitals to highlight words in name  Must be in file named ClassNameGoesHere.java  ClassNameGoesHere becomes type to use

9 Creating Instances  Use instances of a class  Keyword new creates instances: public class Kitty {... } new Kitty(...);

10 Reference Variables  Variables of class type are references  Must assign variable to instance before use  Uses special value, null, when not referring to instance  Work similar to a remote control  Reference is not object, but refers to object TV telly = new TV(...);

11 Reference Variables  Variables of class type are references  Must assign variable to instance before use  Uses special value, null, when not referring to instance  Work similar to a remote control  Reference is not object, but refers to object TV telly = new TV(...); telly

12 Reference Variables  Variables of class type are references  Must assign variable to instance before use  Uses special value, null, when not referring to instance  Work similar to a remote control  Reference is not object, but refers to object TV telly = new TV(...); telly

13 Reference Variables  Variables of class type are references  Must assign variable to instance before use  Uses special value, null, when not referring to instance  Work similar to a remote control  Reference is not object, but refers to object TV telly = new TV(...); telly

14 Using Instances  Use instances of a class  Each instance is unique  Each instance is unique Kitty cat = new Kitty(); cat

15 Using Instances  Use instances of a class  Each instance is unique  Each instance is unique Kitty cat = new Kitty(); Kitty tiger = new Kitty(); cattiger

16 Using Instances  Use instances of a class  Each instance is unique  Each instance is unique Kitty cat = new Kitty(); Kitty tiger = new Kitty(); cat = new Kitty(); cattiger

17 Using Instances  Use instances of a class  Each instance is unique  Each instance is unique Kitty cat = new Kitty(); Kitty tiger = new Kitty(); cat = new Kitty(); cattiger

18 Using Instances  Use instances of a class  Each instance is unique  Each instance is unique Kitty cat = new Kitty(); Kitty tiger = new Kitty(); cat = new Kitty(); cattiger

19 Working With References  Assignments alias references  Only way to create instance using new  Refer to same instance when aliased

20 Working With References  Assignments alias references  Only way to create instance using new  Refer to same instance when aliased Kitty cat, tiger; cat tiger

21 Working With References  Assignments alias references  Only way to create instance using new  Refer to same instance when aliased Kitty cat, tiger; cat = new Kitty(...); cat tiger

22 Working With References  Assignments alias references  Only way to create instance using new  Refer to same instance when aliased Kitty cat, tiger; cat = new Kitty(...); tiger = new Kitty(...); cat tiger

23 Working With References  Assignments alias references  Only way to create instance using new  Refer to same instance when aliased Kitty cat, tiger; cat = new Kitty(...); tiger = new Kitty(...); tiger = cat; cat tiger

24  Instance is aliased NOT the variables  Single instance get changes to aliased variables  Aliased variables see all changes that are made  But, assignments only affect the one variable Kitty cat, tiger; cat = new Kitty(...); tiger = new Kitty(...); tiger = cat; cat tiger

25  Instance is aliased NOT the variables  Single instance get changes to aliased variables  Aliased variables see all changes that are made  But, assignments only affect the one variable Kitty cat, tiger; cat = new Kitty(...); tiger = new Kitty(...); tiger = cat; Kitty kat = tiger; cat tiger kat

26  Instance is aliased NOT the variables  Single instance get changes to aliased variables  Aliased variables see all changes that are made  But, assignments only affect the one variable Kitty cat, tiger; cat = new Kitty(...); tiger = new Kitty(...); tiger = cat; Kitty kat = tiger; tiger = new Kitty(...); cat tiger kat

27  Instance is aliased NOT the variables  Single instance get changes to aliased variables  Aliased variables see all changes that are made  But, assignments only affect the one variable Kitty cat, tiger; cat = new Kitty(...); tiger = new Kitty(...); tiger = cat; Kitty kat = tiger; tiger = new Kitty(...); cat = null; cat tiger kat

28 Transition to Tracing Object o, o2, o3; o = new Object(); o2 = new Object(); o3 = o; o = null; o3 = o2; o2 = o; o = new Object();

29 Your Turn  Get into your groups and complete activity

30 For Next Lecture  Reading continues for Friday  What is the advantages of using arrays?  When & why can it suck to use arrays?  Are arrays like primitives or references?  There is weekly assignment problem on Angel  Due before Friday’s lecture to help remind you of Java  We WILL have lab tomorrow at usual time  I wanted the BBQ also, but must be in SH1008 at start


Download ppt "Question of the Day You overhear a boy & his mother talking: Mom:What is 25 + 8? Boy: That's easy, 33. Mom: Good. What's 33 + 7? Boy:Simple. It's 40. Mom:Excellent!"

Similar presentations


Ads by Google