Classes: user-defined types. Organizing method with a class A class is used to organize methods * Methods that compute Mathematical functions * The Scanner.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Using Classes to Store Data Computer Science 2 Gerb.
CS0007: Introduction to Computer Programming Introduction to Classes and Objects.
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)
Lecture 2 Basics of C#. Members of a Class A field is a variable of any type that is declared directly in a class. Fields are members of their containing.
Summary of the lecture We discussed –variable scope –instance variable declarations –variable lifetime.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Syntax & terminology review While the following slides are not exactly what we did on the board (object diagrams are not shown here) they cover most of.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
1 Composition A whole-part relationship (e.g. Dog-Tail) Whole and part objects have same lifetime –Whole creates instance of part in its constructor In.
Road Map Introduction to object oriented programming. Classes
Objectives Learn about objects and reference variables Explore how to use predefined methods in a program.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Run-Time Storage Organization
Week 5 Recap CSE 115 Spring Composition Informally called “has a” Represented in UML with a diamond- headed arc In code: Declare an instance variable.
Basic Definitions Data Structures: Data Structures: A data structure is a systematic way of organizing and accessing data. Or, It’s the logical relationship.
LESSON 4 - Variables JAVA PROGRAMMING. Variables Variable is a named storage location that stores data and the value of the data may change while the.
©2004 Brooks/Cole Chapter 10 More on Classes. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Object assignment With primitive types, setting.
1 Memory Model of A Program, Methods Overview l Memory Model of JVM »Method Area »Heap »Stack.
Introduction to Java Programming, 4E Y. Daniel Liang.
The different kinds of variables in a Java program.
The different types of variables in a Java program.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Classes and Class Members Chapter 3. 3 Public Interface Contract between class and its clients to fulfill certain responsibilities The client is an object.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
BPJ444: Business Programming Using Java Classes and Objects Tim McKenna
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.
Lecture # 5 Methods and Classes. What is a Method 2 A method is a set of code which is referred to by name and can be called (invoked) at any point in.
Lecture :2 1.  DEFENTION : Java is a programming language expressly designed for use in the distributed environment of the Internet. It was designed.
Chapter 4 Procedural Methods. Learning Java through Alice © Daly and Wrigley Objectives Identify classes, objects, and methods. Identify the difference.
1. 2 Reference... Student stu; Reference of Student stu When the reference is created it points to a null value. Before access the reference, objects.
Local Variables Garbage collection. © 2006 Pearson EducationParameters2 of 10 Using Accessors and Mutators Together What if you want to get a property.
CH 8 : Enhancing Classes - Review QUICK REVIEW : A Class defines an entity’s (Object’s) data and the actions or behaviors (Methods) associated with that.
Java Objects and Classes. Overview n Creating objects that belong to the classes in the standard Java library n Creating your own classes.
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.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Object Oriented Programming (OOP) Lecture No. 11.
CSC241 Object-Oriented Programming (OOP) Lecture No. 6.
RECITATION 4. Classes public class Student { } Data Members public class Student { private String name; public String id; }
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
The life time of local variables (in a method). Local variables Local variable: A local variable is used to store information that is relevant for the.
Dale Roberts Object Oriented Programming using Java - Final and Static Keywords Dale Roberts, Lecturer Computer Science, IUPUI
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
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.
Chapter 3: Developing Class Methods Object-Oriented Program Development Using Java: A Class-Centered Approach.
ISBN Object-Oriented Programming Chapter Chapter
Programming Languages and Paradigms Activation Records in Java.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Classes, Arrays & Pointers. Compiler & Linker expectations file1.cppfile2.cppfilen.cpp …. file1.ofile2.ofilen.o …. Linker application (executable) Compiler.
CS 139 Objects Based on a lecture by Dr. Farzana Rahman Assistant Professor Department of Computer Science.
Chapter 9 Life & Death of an Object Stacks & Heaps; Constructors Garbage Collector (gc)
Structured Programming Dr. Atif Alhejali Lecture 4 Modifiers Parameters passing 1Structured Programming.
CPSC 233 Tutorial 12 March 4/5 th, TopHat Quiz int[] a = {0}; int[] b = {1}; a = b; What is the value of a[0] i) 0 ii) 1.
Classes and OOP.
Haidong Xue Summer 2011, at GSU
Haidong Xue Summer 2011, at GSU
Chapter 4 Procedural Methods.
METHODS AND BEHAVIORS AKEEL AHMED.
Unit-1 Introduction to Java
Subprograms Functions.
Arrays .
Assessment – Java Basics: Part 1
Chapter 7 Procedural Methods.
ITE “A” GROUP 2 ENCAPSULATION.
Object Oriented Programming (OOP) Lecture No. 12
Presentation transcript:

Classes: user-defined types

Organizing method with a class A class is used to organize methods * Methods that compute Mathematical functions * The Scanner class

Organizing information with a class A class can also be used to organize information It defines a group of related information that belong to the same entity

Instance Variables (1) Java has 4 different kinds of variables 1. Local variables 2. Parameter variables

Instance Variables (2) 3. Class variables

Instance Variables (3) 4. Instance variables are defined inside some class are defined outside every method of that class. are defined without using the keyword static

Creating an object in Java (1) 1.Define a variable to store the location of the object. 1.Create the object

Creating an object in Java (1)

Creating an object in Java (2)

Accessing the information stored inside an object (1)

Accessing the information stored inside an object (2)

Accessibility rule for instance variables The accessibility of instance variables are controlled by access modifiers public = can be accessed in a method inside any class private = can be accessed in a method inside the same class

Lifetime of Instance variables (1)

Lifetime of Instance variables (2) These instance variables will cease to exist after the garbage collection procedure has completed execution

Methods using a object variable as parameter (1) A class in Java is equivalent to a data type

Methods using a object variable as parameter (2) Variable x and variable stu1 will access the same memory locations

Changing the values of a variable inside an object