JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.

Slides:



Advertisements
Similar presentations
Based on Java Software Development, 5th Ed. By Lewis &Loftus
Advertisements

Written by: Dr. JJ Shepherd
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
IMPLEMENTING CLASSES Chapter 3. Black Box  Something that magically does its thing!  You know what it does but not how.  You really don’t care how.
1 l Inheritance Basics l Programming with Inheritance l Dynamic Binding and Polymorphism Inheritance.
Chapter 6 Introduction to Defining Classes
CSCI 1100/1202 April 3, Testing A program should be executed multiple times with various input in an attempt to find errors Debugging is the process.
Road Map Introduction to object oriented programming. Classes
1. 2 Introduction to Methods  Method Calls  Parameters  Return Type  Method Overloading  Accessor & Mutator Methods  Student Class: Revisited.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
COMP 14 Introduction to Programming Miguel A. Otaduy May 25, 2004.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
1 Chapter 7 l Inheritance Basics l Programming with Inheritance l Dynamic Binding and Polymorphism Inheritance.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
Defining Classes and Methods Chapter 4.1. Key Features of Objects An object has identity (it acts as a single whole). An object has state (it has various.
Lecture From Chapter 6 & /8/10 1 Method of Classes.
COMP More About Classes Yi Hong May 22, 2015.
Writing Classes (Chapter 4)
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
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.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
APCS Java AB 2004 Review of CS1 and CS2 Review for AP test #1 Sources: 2003 Workshop notes from Chris Nevison (Colgate University) AP Study Guide to go.
Chapter 3: Developing Class Methods Object-Oriented Program Development Using Java: A Class-Centered Approach.
Introduction to Java Classes and Objects. What is a class A class is description of a structure that contains both data and methods – Describes a set.
1 Chapter 8 – Classes and Object: A Deeper Look Outline 1 Introduction 2 Implementing a Time Abstract Data Type with a Class 3 Class Scope 4 Controlling.
Chapter 4 -2 part Writing Classes 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
Computer Science 111 Fundamentals of Computer Programming I Working with our own classes.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 4.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
Designing Classes CS239 – Jan 26, Key points from yesterday’s lab  Enumerated types are abstract data types that define a set of values.  They.
Chapter 5 Introduction to Defining Classes
Copyright © 2002 W. A. Tucker1 Chapter 10 Lecture Notes Bill Tucker Austin Community College COSC 1315.
AP Computer Science A – Healdsburg High School 1 Unit 9 - Why Use Classes - Anatomy of a Class.
Chapter 3 Introduction to Classes and Objects Definitions Examples.
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
JAVA PROGRAMMING PART III. METHOD STATEMENT Form of method statement [ ] [static] ( [ ]) { } Example public static void main(String args[])
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
Classes - Intermediate
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
Java Classes Introduction. Contents Introduction Objects and Classes Using the Methods in a Java Class – References and Aliases Defining a Java Class.
Creating Java Applications (Software Development Life Cycle) 1. specify the problem requirements - clarify 2. analyze the problem - Input? Processes? Output.
1 Sections 6.4 – 6.5 Methods and Variables Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
Java 5 Class Anatomy. User Defined Classes To this point we’ve been using classes that have been defined in the Java standard class library. Creating.
Object Oriented Programming. Constructors  Constructors are like special methods that are called implicitly as soon as an object is instantiated (i.e.
Classes (Part 1) Lecture 3
Software Development Java Classes and Methods
Intro To Classes Review
Chapter 3: Using Methods, Classes, and Objects
Chapter 4: Writing Classes
Corresponds with Chapter 7
Defining Classes and Methods
Defining Classes and Methods
Outline Anatomy of a Class Encapsulation Anatomy of a Method
JAVA CLASSES.
Object-Oriented Programming
Defining Classes and Methods
CS 1054: Lecture 2, Chapter 1 Objects and Classes.
Corresponds with Chapter 5
Presentation transcript:

JAVA Classes Review

Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is run when an object is instantiated, usually to initialize that object’s instance variables Object – a collection of data and operations in which the data can be accessed and modified only by means of the operations.

Definitions Instance variable - storage for data in an object or an instance of a variable. Local variable – a name of a variable that is only valid and usable within a method or nested block of code. Оbject variable – a label or name of the object or one of its attributes.

Types of Methods Mutator method - is a method used to change the value of an attribute of an object Accessor method name is a method used to EXAMINE an attribute of an object without changing it.

Definitions Argument – a value or expression passed in a method call. Parameter list – a list of the arguments used in a method call (actual parameters) or in the method heading (formal parameter). Data type – a description of the set of values and the kind of data that a variable can have.

Definitions Actual Parameter – (or argument) a variable or expression contained in a method call and passed to that method. ex. S.setScore(1, testScore) Formal Parameter – the names of the variables in the method. ex. public void setScore (int i, int Score)

Parameter list of a Method data type variable EXAMPLES: public void checkGPA(double gpa) public int getGPA(double grade) private string getStudent(string nm)

Structure of a Method Definition EXAMPLES: public void checkGPA(double gpa) public int getGPA(double grade) private string getStudent(string nm)

Definition of Method items visibility modifier – used in the method definition to specify who should be able to see and use the method. Private specifies that is should be used only be this class (helper method). Public is used when the method should be available to clients of the defining class. T return type – the data type of variable returned by a method. It is specified in the method definition. Void is used when nothing is being returned by the method.

//Beginning of class Student public class Student { private String name; private double gpa; public Student(){ name = ""; gpa = 0.0; } public Student(String nm, double theGpa) { name = nm; gpa = theGpa; } //part 1 class Student Example of a CLASS

public void setName(String nm){ name = nm; } public void setGpa(double theGpa){ gpa = theGpa; } public String getName(){ return name; } public double getGpa(){ return gpa; } } //part 2 of class Student

public String toString(){ String str; str = "Name: "+name+"\n"; str+= "GPA: " + getGpa()+ "\n"; return str; } }//end of class Student

public class StudentTest { public static void main(String [] args){ Student s1 = new Student(); s1.setName("Bill"); s1.setGpa (4.0); Student s2 = new Student ("Carrie", 3.56); System.out.println(s1); System.out.println(s2); }

KEY (use for all classes) ∆ instance variable C constructor name О object variable X class name T return type P formal parameter M mutator method name A accessor method name □ argument (actual parameter) $ data type * local variable Mark EVERY occurance of each class part

Additional information Overloading: The process of using the same operator symbol or identifier to refer to many different functions. Encapsulation: The hiding of data within an object so that it cannot be directly accessed by clients of that object.

Additional information Identity: The property of an object that it is the same thing at different points in time, even though the values of its attributes might change. Instantiation: The process of creating an new object.

Additional information Scope: The largest area of program text in which an identifier is available. Lifetime: The time during which a data object or method call exists. Behavior: The set of actions that a class of objects supports. State: The set of all the values of the variables of a program at any point during its execution.

Additional information Garage Collecting: The automatic process of reclaiming memory when the data of a program is no longer needed. Information Hiding: A condition in which the user of the module does not know the details of how it is implemented, and the implementer of a module does not know the details of how it is used.

Tonight’s homework (due beginning of class) TO BE HAND WRITTEN, not done in BlueJ or NetBeans, etc. Pick an object and write a class that defines the object. The class needs to have at least 3 instance variables (use at least 2 different data types) 2 constructors (one “default” constructor with no parameters, and one constructor with at least 1 parameter), “get” methods for each instance variable (accessor methods) “set” methods for each instance variable (mutator methods) a toString( ) method that displays the state of the object (the values of the instance varibles) with appropriate labels. You DO NOT need to make a “main” class to test this…just write the Standard class.