Download presentation
Presentation is loading. Please wait.
Published byMilton Watkins Modified over 9 years ago
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
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
Java Enumerations
8
Enumeration Methods enum instances always include these methods public String name() Returns String equal to actual instances' name public int ordinal() Position in listing where instance was declared Can also find all enumerated instances public static EnumName[] values() Returns array of values enumerated by EnumName
9
Java Enumerations Must be written in file EnumName.java public enum EnumName { Instance0, Instance1, Instance2; } Can be used in methods elsewhere: EnumName var = EnumName.Instance0; System.err.println(var.name()); if (var.ordinal() > 1) { System.err.println(“Got Instance2!”); } EnumName[] arr = EnumName.values();
10
Quick Quiz Should you be taking notes? Let’s see… 1. What are the 3 methods defined by each enum ? 2. What do each of these methods do? 3. Can you use ever compare an enum using “ > ”?
11
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 Should be in file named ClassNameGoesHere.java ClassNameGoesHere becomes type to use
12
Creating Instances Use instances of a class Keyword new creates instances: public class Kitty {... } new Kitty(...);
13
Reference Variables Variables of class type are references Must assign variable to instance before use Variable is null when not referring to any instance Work similar to a remote control Reference is not object, but refers to object TV telly = new TV(...);
14
Reference Variables Variables of class type are references Must assign variable to instance before use Variable is null when not referring to any instance Work similar to a remote control Reference is not object, but refers to object TV telly = new TV(...); telly
15
Reference Variables Variables of class type are references Must assign variable to instance before use Variable is null when not referring to any instance Work similar to a remote control Reference is not object, but refers to object TV telly = new TV(...); telly
16
Reference Variables Variables of class type are references Must assign variable to instance before use Variable is null when not referring to any instance Work similar to a remote control Reference is not object, but refers to object TV telly = new TV(...); telly
17
Using Instances Use instances of a class Each instance is unique Each instance is unique Kitty cat = new Kitty(...); cat
18
Using Instances Use instances of a class Each instance is unique Each instance is unique Kitty cat = new Kitty(...); Kitty tiger = new Kitty(...); cattiger
19
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
20
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
21
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
22
Working With References Assignments alias references Only way to create instance using new Refer to same instance when aliased
23
Working With References Assignments alias references Only way to create instance using new Refer to same instance when aliased Kitty cat, tiger; cat tiger
24
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
25
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
26
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
27
Aliased variables refer to same instance 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, kat; cat = new Kitty(...); tiger = new Kitty(...); kat = tiger; tiger = cat; cat = kat; tiger = null; Aliasing cat tiger kat
28
Your Turn Get into your groups and complete activity
29
For Next Lecture Reading from AF Chapters 8 & 9 for Wednesday 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 Wednesday’s lecture (via e-mail) Get back into the swing of writing Java code
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.