BPJ444: Business Programming Using Java Classes and Objects Tim McKenna

Slides:



Advertisements
Similar presentations
Chapter 21 Implementing lists: array implementation.
Advertisements

Chapter 6 Objects and Classes F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive data type and.
Based on Java Software Development, 5th Ed. By Lewis &Loftus
Web Application Development Slides Credit Umair Javed LUMS.
Road Map Introduction to object oriented programming. Classes
Objectives Learn about objects and reference variables Explore how to use predefined methods in a program.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Introduction to Java Programming, 4E Y. Daniel Liang.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
OOP Languages: Java vs C++
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
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 # 8 Constructors Overloading. Topics We will discuss the following main topics: – Static Class Members – Overloaded Methods – Overloaded Constructors.
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
Objects and Classes Chapter 6 CSCI CSCI 1302 – Objects and Classes2 Outline Introduction Defining Classes for Objects Constructing Objects Accessing.
Objects, Classes and Syntax Dr. Andrew Wallace PhD BEng(hons) EurIng
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.
ECE122 Feb. 22, Any question on Vehicle sample code?
Classes In C++ 1. What is a class Can make a new type in C++ by declaring a class. A class is an expanded concept of a data structure: instead of holding.
 Classes in c++ Presentation Topic  A collection of objects with same properties and functions is known as class. A class is used to define the characteristics.
Chapter 8 Objects and Classes Object Oriented programming Instructor: Dr. Essam H. Houssein.
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
CSE 501N Fall ‘09 04: Introduction to Objects 08 September 2009 Nick Leidenfrost.
Objects and Classes Mostafa Abdallah
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi.
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 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Objects and Classes.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Objects and Classes.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 6 Objects and Classes.
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
1 Chapter 6 Programming with Objects and Classes F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive.
CS 139 Objects Based on a lecture by Dr. Farzana Rahman Assistant Professor Department of Computer Science.
Topic 8Classes, Objects and Methods 1 Topic 8 l Class and Method Definitions l Information Hiding and Encapsulation l Objects and Reference Classes, Objects,
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Introduction To Objects Oriented Programming Instructor: Mohammed Faisal.
YG - CS Concept of Encapsulation What is encapsulation? - data and functions/methods are packaged together in the class normally.
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.
Class Fundamentals BCIS 3680 Enterprise Programming.
Reference Types CSCI-1302 Lakshmish Ramaswamy. Reference Variables Java supports 8 primitive types All other types are reference types Reference variable.
Lecture 9: Object and Classes Michael Hsu CSULA. 2 OO Programming Concepts Object-oriented programming (OOP) involves programming using objects. An object.
JAVA ACCESS MODIFIERS. Access Modifiers Access modifiers control which classes may use a feature. A classes features are: - The class itself - Its member.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Lecture 3: Introduction to Object and Classes Michael Hsu CSULA.
Lecture 3: Introduction to Object and Classes Michael Hsu CSULA.
Objects and Classes. F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive data type and object type.
Topic: Classes and Objects
Lecture 3: Introduction to Object and Classes
Intro To Classes Review
Chapter 3: Using Methods, Classes, and Objects
Road Map Introduction to object oriented programming. Classes
Corresponds with Chapter 7
Classes & Objects: Examples
Assessment – Java Basics: Part 1
Chapter 6 Objects and Classes
Java Programming Language
Chapter 9 Objects and Classes Part 01
Creating and Using Classes
Chapter 7 Objects and Classes
SPL – PS3 C++ Classes.
Chapter 5 Classes.
Presentation transcript:

BPJ444: Business Programming Using Java Classes and Objects Tim McKenna

Outline Classes and Objects in Java Method Overloading The Lifetime of an Object Access Control

Classes and Objects in Java members of a class are: fields or variables  a class or object's state or attributes methods  a class or object's behaviour constructors  to make objects each has access control

Types of Members fields or variables  instanceunique values for each object  classuses the static modifier same value for all objects methods  instancework with both instance and static variables  classuses static modifier works with static variables

Fields or Variables field or variable holds a single value is strongly typed: must be declared type specifies the kind of value and the variable's behaviour int i = 123;// integer primitive Point pt = null;// object reference pt = new Point (x, y); // coordinates pt has the value of the Point object's address, not the x, y coordinates

Constructors a special kind of method to construct an instance of an object from a class template default constructor is ClassName()  created if the class has no constructors instance fields are initialized to default values automatically (see next slide) overloaded constructors: same name with different parameter lists use of “this” to call another constructor Example: Fruit.java

Java automatically initializes class (static) and object (instance) fields Primitive Data TypeDefault Value boolean false int, etc. 0 Object Reference Type null - not yet referring to an object

Constructor initializes an object's instance fields class MyClass { int maximum; int counter; boolean isBelowMax = true; // override default MyClass(int maximum) { this.maximum = maximum; } MyClass() { this(100); } // calls this class's constructor MyClass(int maximum, int counter) { this.maximum = maximum; // assign local field value this.counter = counter; // to this object's instance isBelowMax = counter < maximum; }

Methods overloading is supported: same method name, different parameter lists parameters passed by value, i.e. by copy  primitive data types and object reference types  copy of object reference is not a copy of the object type of primitive/object returned or void Example: SwapDemo2.java  demonstrates parameter passing

The Lifetime Of An Object an object exists as long as it is referenced in some active method an object can exist beyond the method in which it is instantiated as long as a reference to that object persists automatic garbage collection: reclaims memory of unreferenced objects Example: LifeTime.java

Four Levels of Access to a Class or object's members private: accessible from within this class only  should be standard practice on instance fields to support OO encapsulation default (if you don't specify): accessible from any class in the package protected: accessible from any subclass or any class in the package public: accessible from any class anywhere

Access Control Levels accessclass subclasspackageworld modifier private x default x x protected x x x public x x x x