Java™ How to Program, 9/e © Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 3 Writing Java Applications, Java Development Tools.
Advertisements

Java Programming 2 Dr. Priti Srinivas Sajja Introductory concepts of java programming as specified in PGDCA 203:Object Technology, S P University.
Spring 2008 Mark Fontenot CSE Honors Principles of Computer Science I Note Set 14.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 6 Object Oriented Programming in Java Language Basics Objects.
Creating Classes from Other Classes Chapter 2 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
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.
Reference Types. 2 Objectives Introduce reference types –class –array Discuss details of use –declaration –allocation –assignment –null –parameter –aggregation.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Object Based Programming. Summary Slide  Instantiating An Object  Encapsulation  Inheritance  Polymorphism –Overriding Methods –Overloading vs. Overriding.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look.
 2006 Pearson Education, Inc. All rights reserved Exception Handling.
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.
 2005 Pearson Education, Inc. All rights reserved Classes and Objects: A Deeper Look.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Storage Management. The stack and the heap Dynamic storage allocation refers to allocating space for variables at run time Most modern languages support.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Chapter 10 Classes and Objects: A Deeper Look Visual C# 2010 for Programmers © by Pearson Education, Inc. All Rights Reserved.
Object Based Programming Chapter 8. 2 In This Chapter We will learn about classes Garbage Collection Data Abstraction and encapsulation.
Android How to Program, 2/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Exception Handling Unit-6. Introduction An exception is a problem that arises during the execution of a program. An exception can occur for many different.
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.
Android How to Program, 2/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Copyright © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are.
1 Dynamic Memory Allocation –The need –malloc/free –Memory Leaks –Dangling Pointers and Garbage Collection Today’s Material.
Visual C# 2012 for Programmers © by Pearson Education, Inc. All Rights Reserved.
Visual C# 2012 for Programmers © by Pearson Education, Inc. All Rights Reserved.
 All calls to method toString and earnings are resolved at execution time, based on the type of the object to which currentEmployee refers.  Known as.
Dale Roberts Object Oriented Programming using Java - Final and Static Keywords Dale Roberts, Lecturer Computer Science, IUPUI
 2005 Pearson Education, Inc. All rights reserved Classes and Objects: A Deeper Look.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
Object-Oriented Programming Chapter Chapter
Finalizers, this reference and static Sangeetha Parthasarathy 06/13/2001.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
CSI 3125, Preliminaries, page 1 Class. CSI 3125, Preliminaries, page 2 Class The most important thing to understand about a class is that it defines a.
Creating Classes from Other Classes Appendix D © 2015 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 12 Inheritance and Class Design 1.
Object-Based Programming in VB.NET. Must Understand Following: Encapsulation Information hiding Abstract Data Type Class, Instance, Reference Variable.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look, Part 1.
Chapter 4: More Object Concepts. Objectives Understand blocks and scope Overload a method Avoid ambiguity Create and call constructors with parameters.
Jozef Goetz Credits: Copyright  Pearson Education, Inc. All rights reserved. expanded by J. Goetz, 2016.
Internet Computing Module II. Syllabus Creating & Using classes in Java – Methods and Classes – Inheritance – Super Class – Method Overriding – Packages.
(C) 2010 Pearson Education, Inc. All rights reserved.  Best way to develop and maintain a large program is to construct it from small, simple pieces,
© 2004 Pearson Addison-Wesley. All rights reserved3-1 Objects Declaration: String title;  title (object variable) of type String( Class )  title is just.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
Appendix H Exception Handling: A Deeper Look
Core Java Garbage Collection LEVEL – PRACTITIONER.
Lecture 6 Object Oriented Programming Using Java
Unit-2 Objects and Classes
Storage Management.
Classes and Objects: A Deeper Look (Chapter 8)
Constructor Overloading
Object Based Programming
Section 5.1 Composite Functions
Chapter 6 Methods: A Deeper Look
Tonga Institute of Higher Education
Finalization 17: Finalization
Object Oriented Programming in java
The Inverse Trigonometric Functions (Continued)
Definition Copyright © 2013 Pearson Education, Inc.. All rights reserved.
2.1 Introduction to Object-Oriented Programming
Chapter 8 Classes and Objects: A Deeper Look
Section 10.5 The Dot Product
Unit 4 Review Answers.
Section 5.1 Composite Functions
Presentation transcript:

Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.

 A class can have references to objects of other classes as members.  This is called composition and is sometimes referred to as a has-a relationship.  Example: An AlarmClock object needs to know the current time and the time when it’s supposed to sound its alarm, so it’s reasonable to include two references to Time objects in an AlarmClock object. © Copyright by Pearson Education, Inc. All Rights Reserved.

 Every class in Java has the methods of class Object (package java.lang ), one of which is the finalize method.  Rarely used because it can cause performance problems and there is some uncertainty as to whether it will get called.  Every object uses system resources, such as memory.  Need a disciplined way to give resources back to the system when they’re no longer needed; otherwise, “resource leaks” might occur.  The JVM performs automatic garbage collection to reclaim the memory occupied by objects that are no longer used.  When there are no more references to an object, the object is eligible to be collected.  This typically occurs when the JVM executes its garbage collector. © Copyright by Pearson Education, Inc. All Rights Reserved.

 So, memory leaks that are common in other languages like C and C++ (because memory is not automatically reclaimed in those languages) are less likely in Java, but some can still happen in subtle ways.  Other types of resource leaks can occur.  An application may open a file on disk to modify its contents.  If it does not close the file, the application must terminate before any other application can use it. © Copyright by Pearson Education, Inc. All Rights Reserved.

 The finalize method is called by the garbage collector to perform termination housekeeping on an object just before the garbage collector reclaims the object’s memory.  Method finalize does not take parameters and has return type void.  A problem with method finalize is that the garbage collector is not guaranteed to execute at a specified time.  The garbage collector may never execute before a program terminates.  Thus, it’s unclear if, or when, method finalize will be called.  For this reason, most programmers should avoid method finalize. © Copyright by Pearson Education, Inc. All Rights Reserved.