Object-Oriented Programming Fundamentals. Comp 241, Fall 2004 2 Example Colored points on the screen What data goes into making one? Coordinates Color.

Slides:



Advertisements
Similar presentations
Classes And Objects II. Recall the LightSwitch Class class LightSwitch { boolean on = true; boolean isOn() { return on; } void switch() { on = !on; }
Advertisements

Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
The Line Class Suppose you are involved in the development of a large mathematical application, and this application needs an object to represent a Line.
Lecture 2: Object Oriented Programming I
Object Oriented Programming Teguh Sutanto Si | STIKOM Surabaya
CS 106 Introduction to Computer Science I 02 / 18 / 2008 Instructor: Michael Eckmann.
School of Computing Science CMT1000 © Ed Currie Middlesex University Lecture 9: 1 CMT1000: Introduction to Programming Ed Currie Lecture 11: Objects.
BASIC JAVA. Hello World n // Hello world program public class MyFirstJavaProgram { public static void main(String args[]) { char c = 'H'; String s =
CS 106 Introduction to Computer Science I 10 / 04 / 2006 Instructor: Michael Eckmann.
Objects & Object-Oriented Programming (OOP) CSC 1401: Introduction to Programming with Java Week 15 – Lecture 1 Wanda M. Kunkle.
Applying OO Concepts Using Java. In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The.
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
Introduction to Information and Computer Science Computer Programming Lecture c This material (Comp4_Unit5c), was developed by Oregon Health and Science.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
University of Limerick1 Work with API’s. University of Limerick2 Learning OO programming u Learning a programming language can be broadly split into two.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Moving from C to Java. The Java Syntax We Know Java Types Some of the types we know and love are still there  Integer: byte, short, char, int, long.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and Server Side Programming Very rich GUI libraries Portability (machine independence) A.
CSC Java Programming, Fall, 2008 Week 2: Java Data Types, Control Constructs, and their C++ counterparts, September 4.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Java Fundamentals 3 Input and Output statements. Standard Output Window Using System.out, we can output multiple lines of text to the standard output.
More arrays Primitive vs. reference parameters. Arrays as parameters to functions.
Objects, Classes and Syntax Dr. Andrew Wallace PhD BEng(hons) EurIng
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
Types in programming languages1 What are types, and why do we need them?
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
CS 11 java track: lecture 2 This week: more on object-oriented programming (OOP) objects vs. primitive types creating new objects with new calling methods.
Cs2220: Engineering Software Class 3: Java Semantics Fall 2010 University of Virginia David Evans.
Objects and Classes Chapter Nine. Definition “an object is a combination of some data (variables) and some actions (methods)”. Hopefully the data and.
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 3.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Types and Interfaces COMP.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Data Types Always data types will decide which type of information we are storing into variables In C programming language we are having 3 types of basic.
In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The import statement and using prewritten.
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
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.
CPSC 233 Tutorial 5 February 9 th /10 th, Java Classes Each Java class contains a set of instance variables and methods Instance Variables: Type.
JAVA METHODS (FUNCTIONS). Why are they called methods? Java is a strictly object-oriented programming language Methods are functions inside of objects.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
Object Oriented Programming Lecture 2: BallWorld.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Java: Base Types All information has a type or class designation
Objects as a programming concept
Java: Base Types All information has a type or class designation
Yanal Alahmad Java Workshop Yanal Alahmad
FUNDAMENTALS OF JAVA.
An Introduction to Java – Part I
Overloading and Constructors
Unit-2 Objects and Classes
null, true, and false are also reserved.
Introduction to Java Programming
Fundamentals 2.
Chapter 2: Java Fundamentals
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)
Applying OO Concepts Using Java
Programs and Classes A program is made up from classes
Core Concepts.
Chapter 2: Java Fundamentals
Java Programming Review 1
Java’s Central Casting
Subtype Substitution Principle
Presentation transcript:

Object-Oriented Programming Fundamentals

Comp 241, Fall Example Colored points on the screen What data goes into making one? Coordinates Color What should a point be able to do? Move itself Report its position

Comp 241, Fall

4 Java Terminology Each point is an object Each includes three fields Each has three methods Each is an instance of the same class

Comp 241, Fall Object-Oriented Style Solve problems using objects: little bundles of data that know how to do things to themselves Not the computer knows how to move the point, but rather the point knows how to move itself Object-oriented languages make this way of thinking and programming easier

public class Point { private int xCoord; private int yCoord; public Point() { xCoord = 0; yCoord = 0; } public int currentX() { return xCoord; } public int currentY() { return yCoord; } public void move (int newXCoord, int newYCoord) { xCoord = newXCoord; yCoord = newYCoord; }

public class PointTest{ public static void main( String args[]) { Point firstPoint; Point secondPoint; firstPoint = new Point(); secondPoint = new Point(); firstPoint.move(15, 25); secondPoint.move(35, 45); System.out.println(“The first point is at x = “ + firstPoint.currentX() + “ and y = “ + firstPoint.currentY() ); System.out.println(“The second point is at x = “ + secondPoint.currentX() + “ and y = “ + secondPoint.currentY()); }

Comp 241, Fall Objects and Variables Variables Local variables Variable types Type defines what set of values variable can take, i.e., its domain Two kinds of types in Java Primitive types: int, boolean, char, float, double, short, long, byte All other types are sets of objects java.* (e.g. java.lang, java.util, etc.) define some useful types String, Vector, … Other types we define ourselves

Comp 241, Fall Type Hierarchy public class Point { private int xCoord; private int yCoord; … } public class ColoredPoint extends Point { … private int color; public int getMyColor() { return color; } public class LabelledColoredPoint extends ColoredPoint { private String label; public String getMyLabel() { return label; }

Comp 241, Fall Overriding Methods public class Point { private int xCoord; private int yCoord; … public void printMyself() { System.out.print(“my x = “ + xCoord + “my y = “ + yCoord ); } public class ColoredPoint extends Point { private int color; … public void printMyself() { super.printMyself(); System.out.print(“ “ + “my color = “ + color); }