Review – Primitive Data What is primitive data? What are 3 examples of primitive data types? How is a piece of primitive data different from an object?

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Topic 10 Java Memory Management. 1-2 Memory Allocation in Java When a program is being executed, separate areas of memory are allocated for each class.
Animation Mrs. C. Furman. Animation  We can animate our crab by switching the image between two pictures.  crab.png and crab2.png.
Road Map Introduction to object oriented programming. Classes
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Copyright 2010 by Pearson Education Building Java Programs Chapter 8 Lecture 8-2: Object Behavior (Methods) and Constructors reading:
Programming Principles Data types and Variables. Data types Variables are nothing but reserved memory locations to store values. This means that when.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Classes, Objects, and Methods
Applications in Java Towson University *Ref:
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
More with Methods (parameters, reference vs. value, array processing) Corresponds with Chapters 5 and 6.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
Lecture 2: Classes and Objects, using Scanner and String.
Lecture # 8 Constructors Overloading. Topics We will discuss the following main topics: – Static Class Members – Overloaded Methods – Overloaded Constructors.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Objects, Classes and Syntax Dr. Andrew Wallace PhD BEng(hons) EurIng
Slides prepared by Rose Williams, Binghamton University Chapter 5 Defining Classes II.
More About Objects and Methods Chapter 5. Outline Programming with Methods Static Methods and Static Variables Designing Methods Overloading Constructors.
OOP in Java : © W. Milner 2005 : Slide 1 Java and OOP Part 2 – Classes and objects.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
1 FUNCTIONS - I Chapter 5 Functions help us write more complex programs.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Methods: A Deeper Look. Template for Class Definition public class { } A.Import Statement B.Class Comments C.Class Name D.Data members E.Methods (inc.
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 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.
IT108 Objects and Classes Part I George Mason University Revised 4/3/2012.
Static. 2 Objectives Introduce static keyword –examine syntax –describe common uses.
1 Week 8 l Methods l Parameter passing Methods. 2 Using Methods l Methods are actions that an object can perform. l To use a method you invoke or call.
Topic 8Classes, Objects and Methods 1 Topic 8 l Class and Method Definitions l Information Hiding and Encapsulation l Objects and Reference Classes, Objects,
Chapter 4Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapters 4 and 5: Excerpts l Class and Method Definitions l Information.
Chapter 5 Defining Classes II Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
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.
 Static  Example for Static Field  Example for Static Method  Math class methods  Casting  Scope of Declaration  Method Overloading  Constructor.
Classes - Intermediate
Java: Variables and Methods By Joshua Li Created for the allAboutJavaClasses wikispace.
OOP Basics Classes & Methods (c) IDMS/SQL News
Utilities (Part 2) Implementing static features 1.
Structured Programming Dr. Atif Alhejali Lecture 4 Modifiers Parameters passing 1Structured Programming.
CSCI 51 Introduction to Programming Dr. Joshua Stough February 24, 2009.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Eastside Robotics Alliance / Newport Robotics Group 1 T/Th, 6:30 – 8:30 PM Big Picture School Day 3 · 10/9/2014.
Methods, classes, and Objects Dr. Jim Burns. Question  Which of the following access modifiers is the default modifier?  public  private  protected.
A Simple Object Oriented Program public class Simple { public static void main (String [] args) { System.out.println(“howdy”); } System.out is an object.
Topic: Classes and Objects
Static data members Constructors and Destructors
Chapter 3: Using Methods, Classes, and Objects
Methods The real power of an object-oriented programming language takes place when you start to manipulate objects. A method defines an action that allows.
More Object Oriented Programming
CMSC 202 Static Methods.
Subroutines Idea: useful code can be saved and re-used, with different data values Example: Our function to find the largest element of an array might.
Classes, Objects, and Methods
The this Reference The this reference allows an object to refer to itself That is, the this reference, used inside a method, refers to the object through.
Classes and Objects 5th Lecture
Building Java Programs
Exam 2 EXAM 2 Thursday!!! 25% of Final Grade
Unit 1 Lab16.
Unit 1 Test 1 Redo Friday at 8am here or Friday 4th BLOCK in Math Lab
JAVA Constructors.
Unit 1 Lab14 & Lab15.
Building Java Programs
Classes and Objects Static Methods
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
In this class, we will cover:
Classes, Objects and Methods
A+ Computer Science PARAMETERS
Presentation transcript:

Review – Primitive Data What is primitive data? What are 3 examples of primitive data types? How is a piece of primitive data different from an object? Storing simple data like numbers int – to store an integer double – to store a decimal number boolean – to store a true or false It is not connected to data fields or methods

Review – Constructors What is a constructor? What part of the constructor definition should you look at when determining how to USE the constructor? Example: Climber Constructor Definition: public Climber(int x)  HEADER { super(x, 1, Display.NORTH, 1); } How can you tell the difference between a method and a constructor? Specifies how to create an object Header They have the same name as the class When you USE the constructor, you must put 1 integer value in as a parameter: Climber c = new Climber(3);

Athlete Constructors 2 How many constructors does Athlete have? When we make an Athlete, how many parameters can we use? What happens to them? They get sent to the Robot constructor 0 or 4

Climber Constructor 1 How many constructors does Climber have? When we make a Climber, how many parameters can we use? What happens to it? It becomes x and then gets sent to the Athlete constructor 1 public class Climber extends Athlete { public Climber(int x) { super(x, 1, Display.NORTH, 1); } public void climbUpRight() { …

Computer Math Unit 1 Lab04

Class/Static Methods Often changes an entire environment – Example: Display.setSize(x,y) Can be defined and used in different classes: – openWorld, setSpeed, setSize are DEFINED in the Display class, but USED in the Lab00, Lab01, etc classes. – Invoked through CLASS name: Display.setSpeed(5);

Class/Static Methods contd Sometimes only needed for a specific program (we don’t need to use the method more than once. – In this case, defined and used inside of the same class – Unlike turnRight() which is defined in Athlete and used in Lab02 All class methods are marked by the keyword static Defined inside the class, before the main method

Instance Methods Invoked by an object name: karel.turnLeft() Change individual objects

Lab04 Take the Field We will define a class/static method called takeTheField The definition will go INSIDE of the class and above the main method (not inside of main). Why? Everything inside of main automatically runs. We do not want this method to run unless we tell it to.

Method Header takeTheField’s method header looks like this: public static void takeTheField(Athlete arg) What does “Athlete arg” mean? keywordsName of method Parameter/Argument When we use the method, we must put in the name of an Athlete as a parameter

Method Header contd. Formal parameter/argument: in the definition Actual parameter/argument: value we put in when we are using the constructor/method public Climber(int x) Climber bill = new Climber(4); public static void takeTheField(Athlete a) takeTheField(bob); Formal argument Actual argument

How to get started Copy and paste Lab03, modifying the Display information as needed Let’s look at page 16 in the TJ packet and enter the takeTheField method after the class heading and { (public class Lab04), but before the main method header (public static void main(String[] args) Read the specification to see how many Athletes to make and what they should do