A way to pull together related data A Shape Class would contain the following data: x, y, height, width Then associate methods with that data A Shape.

Slides:



Advertisements
Similar presentations
Recursion CS 367 – Introduction to Data Structures.
Advertisements

The Fundamental Rule for Testing Methods Every method should be tested in a program in which every other method in the testing program has already been.
Intro Programming By Trevor Decker Team 1743 By Trevor Decker Team 1743.
Animation Mrs. C. Furman. Animation  We can animate our crab by switching the image between two pictures.  crab.png and crab2.png.
Variable types We have already encountered the idea of a variable type. It is also possible to think about variables in terms of their kind, namely: 1)
10-Jun-15 Just Enough Java. Variables A variable is a “box” that holds data Every variable has a name Examples: name, age, address, isMarried Variables.
IAT 800 Lab 1: Loops, Animation, and Simple User Interaction.
29-Jun-15 Using Objects. 2 Classes and objects The type of an object is the class that describes that object If we say int count, the type of count is.
CS 106 Introduction to Computer Science I 10 / 15 / 2007 Instructor: Michael Eckmann.
Day 4 Objectives Constructors Wrapper Classes Operators Java Control Statements Practice the language.
MIT AITI 2003 Lecture 7 Class and Object - Part I.
Week 10 - Monday.  What did we talk about last time?  Method overloading  Lab 9.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Classes / Objects An introduction to object-oriented programming.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
Overview of Previous Lesson(s) Over View  OOP  A class is a data type that you define to suit customized application requirements.  A class can be.
Data Objects (revisited) Recall that values are stored in data objects, and that each data object holds one value of a particular type. Data objects may.
Introduction to Programming with Java. Overview What are the tools we are using – What is Java? This is the language that you use to write your program.
Computer Program A sequence of step-by-step instructions for the computer to follow Why bother? Demo: Human vs. Computer following instructions.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Week 6 - Wednesday.  What did we talk about last time?  Exam 1 post-mortem  Recursive running time.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
Lecture # 8 Constructors Overloading. Topics We will discuss the following main topics: – Static Class Members – Overloaded Methods – Overloaded Constructors.
Arrays and ArrayLists in Java L. Kedigh. Array Characteristics List of values. A list of values where every member is of the same type. Each member in.
Chapter 1 Object Orientation: Objects and Classes.
Programming in Processing Taught by Ms. Madsen Assistants: Ms. Fischer and Ms. Yen Winsor School, 2/6/08.
Local Variables Garbage collection. © 2006 Pearson EducationParameters2 of 10 Using Accessors and Mutators Together What if you want to get a property.
CS212: Object Oriented Analysis and Design Lecture 7: Arrays, Pointers and Dynamic Memory Allocation.
Checking Equality of Reference Variables. Arrays and objects are both “reference” types n They are allocated a chunk of memory in the address space n.
Constructors CMSC 202. Object Creation Objects are created by using the operator new in statements such as… The following expression invokes a special.
CSE 114 Computer Science I Objects Lake Superior, Michigan.
Working With Objects Tonga Institute of Higher Education.
Questions? Suggestions?. References References Revisited What happens when we say: int x; double y; char c; ???
Applications Development
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
VARIABLES Programmes work by manipulating data placed in memory. The data can be numbers, text, objects, pointers to other memory areas, and more besides.
CMSC 150 CLASSES CS 150: Mon 6 Feb 2012 Images: Library of Congress.
Working With Objects Tonga Institute of Higher Education.
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 ◦
CS305j Introduction to Computing Classes II 1 Topic 24 Classes Part II "Object-oriented programming as it emerged in Simula 67 allows software structure.
Memory Management in Java Computer Science 3 Gerb Objective: Understand references to composite types in Java.
CSI 3125, Preliminaries, page 1 Class. CSI 3125, Preliminaries, page 2 Class The most important thing to understand about a class is that it defines a.
CMSC 202 Advanced Section Classes and Objects: Object Creation and Constructors.
Arrays-. An array is a way to hold more than one value at a time. It's like a list of items.
Methods Awesomeness!!!. Methods Methods give a name to a section of code Methods give a name to a section of code Methods have a number of important uses.
Written by: Dr. JJ Shepherd
Week 10 - Wednesday.  What did we talk about last time?  Method example  Roulette simulation  Types in Java.
Object Oriented Programming and Data Abstraction Rowan University Earl Huff.
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Object Oriented Programming(Objects& Class) Classes are an expanded concept of data structures: like.
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Creating and using Objects.
ITP © Ron Poet Lecture 15 1 Helper Objects Again.
Structured Programming Dr. Atif Alhejali Lecture 4 Modifiers Parameters passing 1Structured Programming.
ENEE150 – 0102 ANDREW GOFFIN Abstract Data Types.
Internet Computing Module II. Syllabus Creating & Using classes in Java – Methods and Classes – Inheritance – Super Class – Method Overriding – Packages.
“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.
Week91 APCS-A: Java Problem Solving November 2, 2005.
INTRODUCTION Java is a true OO language the underlying structure of all Java programs is classes. Everything must be encapsulated in a class that defines.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Objects as a programming concept
COMP Objects and References
C Basics.
Object Oriented Programming (OOP) LAB # 8
Object Oriented Programming (OOP) LAB # 5
Java Programming Language
IAT 800 Foundations of Computational Art and Design
Classes and Objects Object Creation
CMSC 202 Constructors Version 9/10.
Presentation transcript:

A way to pull together related data A Shape Class would contain the following data: x, y, height, width Then associate methods with that data A Shape Class would contain the following methods: moveUp(), moveDown(), moveLeft(), moveRight(), grow(), shrink()

class NameOfClass { //variable – the values that define the object //methods – what they do }

Haven’t we already been using classes? The answer is yes because JAVA is exclusively an object oriented programming language. So all code must be placed in a class declaration. The first method called is the main method.

A class only tells the computer what goes into the “object” when constructed and how it behaves. Kind of like a blue print. In order to use it, we have to use the new operator similar to how we used it when we declared our jKarel Robots. Ex: Robot bob = new Robot(); Ex: Color background = new Color(10, 223, 97);

Smiley face Location (x & y) radius Color (Red, Green, and Blue values) Eyes (x, y, size, Color, isOpen) Mouth(x, y, size, Color, isOpen, isSmile) Karel the Robot Location (x & y) numBeepers direction Image

Have four key parts: Name – what the method is called Arguments – data (variables & other objects) passed into the method Return Type – what if anything that the method returns when called Code – what the method does

returnTypemethodName(arguments){ //method code }

Can be a: primitive (double, int, char) another object nothing (void)

Use the “.” operator Ex: theRobot.move(); aCircle.radius = 3;

The Constructor is a method that is called whenever an object is created using the new operator. Has the (exact) same name as the class. In it you should set up variables and whatever else is needed any time an object of this class is created. Just like any other method, it can take in variables. Even if you do not provide one, JAVA will provide one for you even if it does nothing(just like C++).

All class variables and methods are either public or private or protected. All variables should be made either private or protected This is needed so that objects do not behave in such a way that is not programmer defined. It also helps protect access to various information. Variables can still be changed but they should changed in methods that you define.

When you declare an object in JAVA, you are only creating a reference to an Object. It is kind of like declaring an address that gives a location for something. That is why you have to create an object using the new operator. If you create another object and assign it to the Object name then the old object is no longer reference and JAVA will delete it. An object can refer to itself using the keyword “this”

Because Objects are complex things, you can not compare them using ==. JAVA will let you but == will not compare the objects themselves but instead check that the reference the same location in memory. When checking for equality, you will want to define the.equals method.

Variables declared inside the class can be accessed by anywhere inside of the class. Variables declared inside of a method can only be accessed inside of that method and no longer exist once the method finishes executing There can be a class variable and a method variable by the same name. That should be avoided but if it does happen, the class variable can be referenced using “this.” followed by the class variable name.