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.

Slides:



Advertisements
Similar presentations
Copyright © Texas Education Agency, Computer Programming Class Basics.
Advertisements

Week 11 - Friday.  What did we talk about last time?  Object methods  Accessors  Mutators  Constructors  Defining classes.
Introduction to Object-Oriented Programming CS 21a: Introduction to Computing I First Semester,
1 Composition A whole-part relationship (e.g. Dog-Tail) Whole and part objects have same lifetime –Whole creates instance of part in its constructor In.
Classes and Objects in Java
Objects & Object-Oriented Programming (OOP) CSC 1401: Introduction to Programming with Java Week 15 – Lecture 1 Wanda M. Kunkle.
What is a class? a class definition is a blueprint to build objects its like you use the blueprint for a house to build many houses in the same way you.
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
Copyright 2010 by Pearson Education Building Java Programs Chapter 8 Lecture 8-2: Object Behavior (Methods) and Constructors reading:
COMP Classes Yi Hong May 22, Announcement  Lab 2 & 3 due today.
CS 121 – Intro to Programming:Java - Lecture 3 Announcements Course home page: Owl due Friday;
CSC 212 – Data Structures Lecture 3: Fields, Methods, & Constructors.
Question of the Day  Write valid mathematical equation using: one addition operator (‘+’) one equality operator (‘=’)  Should have equal values.
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.
Introduction to Programming Writing Java Beginning Java Programs.
CSC 212 – Data Structures Lecture 12: Java Review.
Introduction to Object-Oriented Programming
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 212 Object-Oriented Programming and Java Part 1.
1 Chapter 3 and 6– Classes, Objects and Methods Object-Oriented Programming Concepts – Read it from Java TutorialJava Tutorial Definition: A class is a.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage.
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
Problem of the Day  Why are manhole covers round?
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
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.
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.
Classes and Objects in Java
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 7: Methods & User Input.
Introduction to Programming Writing Java Beginning Java Programs.
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!
Question of the Day  Thieves guild states it will sell to members: lock picking kits  $0.67 each 40’ rope  $2.12 each Wire cutters  $4.49 each How.
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
CSC 212 – Data Structures Lecture 2: Primitives, References, & Classes.
COMP 110 Classes Luv Kohli October 1, 2008 MWF 2-2:50 pm Sitterson 014.
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
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 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!
1 Class and Object Lecture 7. 2 Classes Classes are constructs that define objects of the same type. A Java class uses instance variables to define data.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
CSC 212 – Data Structures Lecture 6: Static and non-static members.
Problem of the Day  Why are manhole covers round?
Basic Class Structure. Class vs. Object class - a template for building an object –defines the instance data that the object will hold –defines instance.
Class Definitions: The Fundamentals Chapter 6 3/30/15 & 4/2/15 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
CLASSES IN JAVA Primitive Types Example of a Class Allocating Objects of a Class Protecting Class data Constructors Static data and Static Methods.
Question of the Day  How do you add 5 matches to these 6 & make 9?
Defining Your Own Classes II
Objects as a programming concept
Lecture 3: Fields, Methods, & Constructors
CSE 8A Lecture 17 Reading for next class: None (interm exam 4)
Classes and Objects in Java
Interfaces.
Building Java Programs
Classes and Objects in Java
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)
Building Java Programs
CLASSES, AND OBJECTS A FIRST LOOK
Overview of Java 6-Apr-19.
Java Programming Language
Introduction to Object-Oriented Programming
Lecture 8-2: Object Behavior (Methods) and Constructors
Classes and Objects in Java
Previous Lecture: Today’s Lecture: Reading (JV):
INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Presentation transcript:

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. A A B B

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. A A B B

Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage

Classes vs. Objects  Classes are blueprints describing data type  On their own, classes (usually) cannot do anything  Objects are instances of a class  New objects created (instantiated) using new  Fields describe state of an object  Object’s behavior represented by methods

Instance Variables  All of class's instances have same fields…  … but values can differ between each instance  In a class, each field must have unique name  Different classes can duplicate names of fields  Field declaration must include data type  Will act like variables of that type  Can be primitive, enum, or reference type

Class Example public class Car { /** What kind of car & who made it */ private String makeAndModel; /** Color of the car. */ private String color; /** Percent full the gas tank is */ private float tankLevel; /** Miles recorded on the odometer */ private int odometerReading; /* Definition continues from here */

Using Fields (1) Car profHertzCar = new Car(); profHertzCar.makeAndModel = “BMW Z4”; profHertzCar.color = “Deep Green Metallic”; profHertzCar.tankLevel = 1.0; profHertzCar.odometerReading = 10000; Car actualCar = new Car(); actualCar.makeAndModel = “Subaru Outback"; actualCar.color = “Brown”; actualCar.tankLevel = ; actualCar.odometerReading = 67634;

Using Fields (2) Car dreamCar = new Car(); dreamCar.makeAndModel = “BMW Z4”; dreamCar.color = “Deep Green Metallic”; dreamCar.tankLevel = 1.0; dreamCar.odometerReading = 10000;

Using Fields (2) Car dreamCar = new Car(); dreamCar.makeAndModel = “BMW Z4”; dreamCar.color = “Deep Green Metallic”; dreamCar.tankLevel = 1.0; dreamCar.odometerReading = 10000; Car realCar = dreamCar; realCar.makeAndModel = “Subaru Outback”; realCar.color = “Silver”; realCar.tankLevel = ; realCar.odometerReading = 67634;

Using Fields (2) Car dreamCar = new Car(); dreamCar.makeAndModel = “BMW Z4”; dreamCar.color = “Deep Green Metallic”; dreamCar.tankLevel = 1.0; dreamCar.odometerReading = 10000; Car realCar = dreamCar; realCar.makeAndModel = “Subaru Outback”; realCar.color = “Silver”; realCar.tankLevel = ; realCar.odometerReading = 67634;

static Fields  Some data belongs to class, not instance Float.MAX_VALUE Citizen.nationalPopulation Instructor.bestProfessor  static fields used for any class-based data  All of the class’s instances see same value  Do not need an instance to access this value  Can be updated via any instance or via class

static Code Use Example public class Player { public static int num; public String name; public static void main(String[] args) { Player player1, player2, player3; player1 = new Player(); player1.name = "Homer"; player1.num += 1; player2 = new Player(); player2.name = “JJ"; Player.num += 1; player3 = player2; player3.name = "Hertz"; System.out.print(player2.name+" "+player1.num); } }

Tracing With Objects & Fields public static void main(String[] args) { Player player1, player2, player3; player1 = new Player(); player1.name = "Homer"; player1.num += 1; player2 = new Player(); player2.name = “JJ"; Player.num += 1; player3 = player2; player3.name = "Hertz"; System.out.print(player2.name+" "+player1.num); }

static v. non- static Review static fieldsnon- static fields  Belong to class as a whole  No instance needed to use  Can set value at any time  No limit on use in code  Primitive or reference okay static  Declare in class using: static type name;  Values are instance-based  Must specify instance to use  Can set value at any time  No limit on use in code  Primitive or reference okay  Declare in class using: type name;

Your Turn  Get into your groups and complete activity

For Next Lecture  Keep reviewing your Java lessons  Will be discussing methods & constructors Friday  Really need to be back up-to-speed at that point  There is weekly assignment problem on Angel  Due next Tuesday at 5PM but could start earlier  With this finish removing rust from lazy summer