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
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Advertisements

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.
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.
Pointer. Warning! Dangerous Curves C (and C++) have just about the most powerful, flexible and dangerous pointers in the world. –Most other languages.
Java Syntax Primitive data types Operators Control statements.
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.
Programming Principles Data types and Variables. Data types Variables are nothing but reserved memory locations to store values. This means that when.
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.
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.
P Object type and wrapper classes p Object methods p Generic classes p Interfaces and iterators Generic Programming Data Structures and Other Objects Using.
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.
Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage.
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,
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.
Problem of the Day  Why are manhole covers round?
PHY 107 – Programming For Science. History of C  Dennis Ritchie developed C from 1969 – 1973  Based upon B (& other) earlier languages  Since its creation,
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
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.
Primitive Variables.
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.
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.
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!
CSC 107 – Programming For Science. The Week’s Goal.
CSC 107 – Programming For Science. Announcements  Locations of Macs to use outside of lab time  Can find on Library ground floor (6) & main floor (6)
CSC 107 – Programming For Science. History of C  Dennis Ritchie developed C from 1969 – 1973  While at Bell Labs, created language to develop Unix 
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 6: Object-Oriented Programming.
Java Basics.  To checkout, use: svn co scb07f12/UTORid  Before starting coding always use: svn update.
Introduction to Programming Writing Java Beginning Java Programs.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Primitive Variables.
Copyright Curt Hill Variables What are they? Why do we need them?
Getting Started Java Fundamentals CSC207 – Software Design Summer 2011 – University of Toronto – Department of Computer Science.
Lab 4 - Variables. Information Hiding General Principle: – Restrict the access to variables and methods as much as possible Can label instance variables.
CSC 212 – Data Structures Lecture 2: Primitives, References, & Classes.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Memory Management in Java Computer Science 3 Gerb Objective: Understand references to composite types in Java.
CSC 212 – Data Structures Lecture 5: Variables. Problem of the Day Why do underground subway stations always have more escalators going up than down?
Question of the Day  What three letter word completes the first word and starts the second one: DON???CAR.
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!
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 06 – Java Datatypes Webpage:
CSC 142 F 1 CSC 142 References and Primitives. CSC 142 F 2 Review: references and primitives  Reference: the name of an object. The type of the object.
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.
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
02/09/2005 Introduction to Programming with Java, for Beginners Arrays (of primitives)
For Friday Read No quiz Program 6 due. Program 6 Any questions?
“Unboxing” means taking an Integer object and assigning its value to a primitive int. This is done using the.intValue( ) method. Example; Integer z = new.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Problem of the Day  Why are manhole covers round?
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Lecture 2: Primitives & References
CSE 116/504 – Intro. To Computer Science for Majors II
Selenium WebDriver Web Test Tool Training
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Java Programming Review 1
Primitive Types and Expressions
Winter 2019 CMPE212 5/10/2019 CMPE212 – Reminders
Topic 25 - more array algorithms
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

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

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

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

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

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

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

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

 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

 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

 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

 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

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

Your Turn  Get into your groups and complete activity

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