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!

Slides:



Advertisements
Similar presentations
Classes And Objects II. Recall the LightSwitch Class class LightSwitch { boolean on = true; boolean isOn() { return on; } void switch() { on = !on; }
Advertisements

STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Today’s lecture Review of Chapter 1 Go over homework exercises for chapter 1.
Primitives, References and Wrappers Java has the following types defined as part of the java language; int float double byte char boolean long short These.
Lecture 9: More on objects, classes, strings discuss hw3 assign hw4 default values for variables scope of variables and shadowing null reference and NullPointerException.
AAA. Today’s lecture Review of Chapter 6 Go over examples.
Defining classes and methods Recitation – 09/(25,26)/2008 CS 180 Department of Computer Science, Purdue University.
Week 10: Objects and Classes 1.  There are two classifications of types in Java  Primitive types:  int  double  boolean  char  Object types: 
CSC Programming for Science Lecture 30: Pointers.
CS 177 Recitation Week 8 – Methods. Questions? Announcements  Project 3 milestone due next Thursday 10/22 9pm  Turn in with: turnin –c cs177=xxxx –p.
Introduction to Java, OO and IDEs ICW Lecture 2 Errol Thompson Room 134.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Object References. Objects An array is a collection of values, all of the same type An object is a collection of values, which may be of different types.
CSC 107 – Programming For Science. Today’s Goal  Learn how pointers really used with arrays  Exploit the similarity between pointers & arrays  Take.
Week 10 - Monday.  What did we talk about last time?  Method overloading  Lab 9.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
Question of the Day  What card(s) must you flip to verify the following statement: Cards with a vowel on one side, have an even number on the other side.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
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.
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.
CSC 212 – Data Structures Lecture 12: Java Review.
Question of the Day  What card(s) must you flip to verify the following statement: Cards with a vowel on one side, have an even number on the other side.
CSC 107 – Programming For Science. Announcements  Textbook available from library’s closed reserve.
CSC 212 Object-Oriented Programming and Java Part 1.
Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage.
Comp 248 Introduction to Programming Chapter 6 Arrays Part B Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University,
Basic Java Syntax CSE301 University of Sunderland Harry R Erwin, PhD.
English Conundrum s  In English, add “s” to end of word to make plural s  But for 1 special word, adding an “s” at the end:  Makes word go from plural.
CSC 107 – Programming For Science. History of C  Dennis Ritchie developed C from 1969 – 1973  Based upon B (& other) earlier languages  Since its creation,
CS 11 java track: lecture 4 This week: arrays interfaces listener classes inner classes GUI callbacks.
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
CSE 232: C++ pointers, arrays, and references Overview of References and Pointers Often need to refer to another object –Without making a copy of the object.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Problem of the Day  Why are manhole covers round?
Problem of the Day  Why are manhole covers round?
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.
CS107 References and Arrays By Chris Pable Spring 2009.
CSC 107 – Programming For Science. Today’s Goal  When lecture over, start understanding pointers  What a pointer is and what it is not  Why pointers.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 6: Object-Oriented Programming.
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
Question of the Day You overhear a boy & his mother talking: Mom:What is ? Boy: That's easy, 33. Mom: Good. What's ? Boy:Simple. It's 40. Mom:Excellent!
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Copyright Curt Hill Variables What are they? Why do we need them?
Classes and Objects CS177 Rec 10. Announcements Project 4 is posted ◦ Milestone due on Nov. 12. ◦ Final submission due on Nov. 19. Exam 2 on Nov. 4 ◦
CSC 212 – Data Structures Lecture 2: Primitives, References, & Classes.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Memory Management in Java Computer Science 3 Gerb Objective: Understand references to composite types in Java.
Object Oriented Software Development 4. C# data types, objects and references.
Question of the Day You overhear a boy & his mother talking: Mom:What is ? Boy: That's easy, 33. Mom: Good. What's ? Boy:Simple. It's 40. Mom:Excellent!
Week 10 - Wednesday.  What did we talk about last time?  Method example  Roulette simulation  Types in Java.
CSE 332: C++ pointers, arrays, and references Overview of Pointers and References Often need to refer to another object –Without making a copy of the object.
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
Week 10 - Monday.  What did we talk about last time?  Method overloading  Lab 9.
LECTURE 21: RECURSION & LINKED LIST REVIEW CSC 212 – Data Structures.
CSC 107 – Programming For Science. Today’s Goal  Discover best uses of structures in a program  How we can mix pointers inside structures  Assigning.
Structured Programming Dr. Atif Alhejali Lecture 4 Modifiers Parameters passing 1Structured Programming.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Chapter 9 Introduction to Arrays Fundamentals of Java.
Problem of the Day  Why are manhole covers round?
Chapter 1 Object Orientation: Objects and Classes.
Lecture 2: Primitives & References
CSE 116/504 – Intro. To Computer Science for Majors II
Selenium WebDriver Web Test Tool Training
Principles of Computer Programming (using Java) Chapter 2, Part 1
Grouped Data Arrays, and Array Lists.
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Presentation transcript:

Question of the Day You overhear a boy & his mother talking: Mom:What is ? Boy: That's easy, 33. Mom: Good. What's ? Boy:Simple. It's 40. Mom:Excellent! Now what's ? 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?

Question of the Day You overhear a boy & his mother talking: Mom:What is ? Boy: That's easy, 33. Mom: Good. What's ? Boy:Simple. It's 40. Mom:Excellent! Now what's ? 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

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

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

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

Java Enumerations

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

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();

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 “ > ”?

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

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

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(...);

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

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

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

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

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

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

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

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

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

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

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

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

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

 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

Your Turn  Get into your groups and complete activity

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 )  Get back into the swing of writing Java code