Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is."— Presentation transcript:

1 JAVA Classes Review

2 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.

3 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.

4 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.

5 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.

6 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)

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

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

9 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.

10 //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

11 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

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

13 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); }

14 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

15

16

17 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.

18 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.

19 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.

20 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.

21 Tonight’s homework (due Friday @ 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.


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

Similar presentations


Ads by Google