© A+ Computer Science - www.apluscompsci.com. In Java, any variable that refers to an Object is a reference variable. The variable stores the memory.

Slides:



Advertisements
Similar presentations
Building Java Programs Interactive Programs w/ Scanner What is a class? What is an object? What is the difference between primitive and object variables?
Advertisements

Program Memory MIPS memory operations Getting Variable Addresses Advanced structures.
Data Structures (Second Part) Lecture 2 : Pointers Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University.
1 Chapter 8 Objects and Classes Lecture 2 Prepared by Muhanad Alkhalisy.
Syntax & terminology review While the following slides are not exactly what we did on the board (object diagrams are not shown here) they cover most of.
CS 206 Introduction to Computer Science II 01 / 21 / 2009 Instructor: Michael Eckmann.
School of Computing Science CMT1000 © Ed Currie Middlesex University Lecture 9: 1 CMT1000: Introduction to Programming Ed Currie Lecture 11: Objects.
Pointers Ethan Cerami Fundamentals of Computer New York University.
Chapter 3 Using Classes and Objects. 2 Creating Objects  A variable holds either a primitive type or a reference to an object  A class name can be used.
© A+ Computer Science - ArrayList © A+ Computer Science - Lab 16.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Writing a Class (defining a data-type). Create a new project : Project (uncheck the “Create Main Class”)
Copyright 2010 by Pearson Education Building Java Programs Chapter 8 Lecture 8-2: Object Behavior (Methods) and Constructors reading:
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
Chapter 2 Practice.
Arrays (Part 1) Computer Science Erwin High School Fall 2014.
© A+ Computer Science - Inheritance © A+ Computer Science - Lab 20.
Number Systems What is the Standard Base we
© A+ Computer Science - public Triangle() { setSides(0,0,0); } Constructors are similar to methods. Constructors set the properties.
© A+ Computer Science - Chicken yeller = new Chicken();
CS442: ADVANCED PROGRAMMING USING JAVA Lab 6: Classes and objects Computer Science Department.
Programming Review. Java Class Structure All Java statements are part of a class public class ClassName { }
© A+ Computer Science - Variables Data Types © A+ Computer Science - Lab 0B.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
Memory Management in Java Computer Science 3 Gerb Objective: Understand references to composite types in Java.
© A+ Computer Science - A reference variable stores the memory address of an object. Monster fred = new Monster(); Monster sally.
Lecture 10: 2/17/2003CS148 Spring CS148 Introduction to Programming II Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
CS 139 Objects Based on a lecture by Dr. Farzana Rahman Assistant Professor Department of Computer Science.
© A+ Computer Science - In Java, any variable that refers to an Object is a reference variable. The variable stores the memory.
Today’s lecture Review chapter 5 go over exercises.
Powerpoint slides from A+ Computer Science Modified by Mr. Smith for his course.
College Board Topics – A.P. Computer Science A Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
Java Scanner Class Keyboard Class. User Interaction So far when we created a program there was no human interaction Our programs just simply showed one.
Powerpoint slides from A+ Computer Science Modified by Mr. Smith for his course.
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
© A+ Computer Science - Elevens is a lab about classes and Lists. List is a major concept being tested by the Elevens lab. Elevens.
OOP Powerpoint slides from A+ Computer Science
Multiple Choice -answer the easiest question 1st
Lesson A4 – Object Behavior
An Introduction to Java – Part II
CSC 113: Computer programming II
A+ Computer Science INPUT.
© A+ Computer Science - GridWorld © A+ Computer Science -
© A+ Computer Science - Arrays and Lists © A+ Computer Science -
Using PARAMETERS In Java.
A+ Computer Science METHODS.
Building Java Programs
Example with Static Variable
Cs212: Data Structures Computer Science Department Lecture 2: Arrays.
© A+ Computer Science - OOP © A+ Computer Science -
The Matrix A b a d e a a a a a a a A b a d e a a a a a a a
Class Everything if Java is in a class. The class has a constructor that creates the object. public class ClassName private Field data (instance variables)
© A+ Computer Science - Classes And Objects © A+ Computer Science -
© A+ Computer Science - OOP Pieces © A+ Computer Science -
Which best describes the relationship between classes and objects?
Building Java Programs
A+ Computer Science INPUT.
A+ Computer Science METHODS.
See requirements for practice program on next slide.
© A+ Computer Science - GridWorld The GridWorld case study provides a graphical environment where visual objects inhabit and interact.
Instance Method – CSC142 Computer Science II
Building Java Programs
Building Java Programs
© A+ Computer Science - GridWorld © A+ Computer Science -
A+ Computer Science PARAMETERS
© A+ Computer Science - GridWorld © A+ Computer Science -
What is a String? String s = "compsci"; s c o m p s i
Presentation transcript:

© A+ Computer Science -

In Java, any variable that refers to an Object is a reference variable. The variable stores the memory address of the actual Object.

© A+ Computer Science - String x = new String("Chuck"); String y = x; x and y store the same memory address. "Chuck" xy 0x2B3

© A+ Computer Science - String x = "Chuck"; String y = "Chuck"; x and y store the same memory address. "Chuck" x y 0x2B7

© A+ Computer Science - "Chuck" String x = new String("Chuck"); String y = new String("Chuck"); x and y store different memory addresses. x y 0x2B7 0x2FE

© A+ Computer Science - String x = "Chuck"; String y = "Chuck"; "Chuck" x y 0x2B7 x = null; null

© A+ Computer Science -

String[] list = new String[50]; //all 50 spots are null null

© A+ Computer Science null 0x7null "fred" list[3] = "fred";

© A+ Computer Science -

public class Monster { // instance variables public Monster(){ code } public Monster( int ht ) { code } public Monster(int ht, int wt) { code } public Monster(int ht, int wt, int age) { code } }

© A+ Computer Science - new Monster(); MONSTER Properties – height – 0 weight - 0 age - 0 methods m m is a reference variable that refers to a Monster object. Monster m =

© A+ Computer Science - Monster m = new Monster(23); m is a reference variable that refers to a Monster object. MONSTER Properties – height – 23 weight – 0 age - 0 methods m 0x234

© A+ Computer Science - Monster m = new Monster(23, 45); m is a reference variable that refers to a Monster object. MONSTER Properties – height – 23 weight – 45 age - 0 methods m 0x239

© A+ Computer Science - Monster m = new Monster(23, 45, 11); m is a reference variable that refers to a Monster object. MONSTER Properties – height – 23 weight – 45 age - 11 methods m 0x2B3

© A+ Computer Science - Monster[] list = new Monster[5]; out.println(list[0]); out.println(list[1]); out.println(list[2]); out.println(list[3]); out.println(list[4]); OUTPUT null null null null null

© A+ Computer Science - Monster[] list = new Monster[5]; list[0] = new Monster(); list[1] = new Monster(33); list[2] = new Monster(3,4,5); out.println(list[0]); out.println(list[1]); out.println(list[2]); out.println(list[3]); OUTPUT null

© A+ Computer Science MONSTER Properties – height – 0 weight – 0 age - 0 methods 0x234 MONSTER Properties – height – 33 weight – 0 age - 0 methods 0x238 MONSTER Properties – height – 3 weight – 4 age - 5 methods 0x242 0x2340x2380x242null

© A+ Computer Science MONSTER Properties – height – 0 weight – 0 age - 0 methods 0x234 MONSTER Properties – height – 33 weight – 0 age - 0 methods 0x238 MONSTER Properties – height – 3 weight – 4 age - 5 methods 0x242 0x2340x2380x242null ray[2]=ray[1]; 0x238

© A+ Computer Science -

public class Creature { //data and constructors now shown public void setSize(int girth){ size=girth; } //toString not shown }

© A+ Computer Science - Creature[] creatures = new Creature[3]; creatures[0]=new Creature(4); creatures[1]=new Creature(9); creatures[2]=new Creature(1); out.println(creatures[0]); creatures[0].setSize(7); out.println(creatures[0]); out.println(creatures[2]); OUTPUT 4 7 1

© A+ Computer Science - creatures[0] What does the. dot do? setSize(7);. What does this store? Creature 0x242 The. dot grants access to the Object at the stored address.

© A+ Computer Science -