We think you have liked this presentation. If you wish to download it, please recommend it to your friends in any social system. Share buttons are a little bit lower. Thank you!
Presentation is loading. Please wait.
Published byKareem Grays
Modified over 2 years ago
Java™ How to Program, 9/e © Copyright 1992-2012 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 1992-2012 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 1992-2012 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 1992-2012 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 1992-2012 by Pearson Education, Inc. All Rights Reserved.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Android How to Program, 2/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Jozef Goetz Credits: Copyright Pearson Education, Inc. All rights reserved. expanded by J. Goetz, 2016.
Visual C# 2012 for Programmers © by Pearson Education, Inc. All Rights Reserved.
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.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Finalizers, this reference and static Sangeetha Parthasarathy 06/13/2001.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
Dale Roberts Object Oriented Programming using Java - Final and Static Keywords Dale Roberts, Lecturer Computer Science, IUPUI
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 6 Object Oriented Programming in Java Language Basics Objects.
Introduction to Java 2 Programming Lecture 3 Writing Java Applications, Java Development Tools.
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look, Part 1.
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.
2005 Pearson Education, Inc. All rights reserved Classes and Objects: A Deeper Look.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 12 Inheritance and Class Design 1.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
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.
Spring 2008 Mark Fontenot CSE Honors Principles of Computer Science I Note Set 14.
Internet Computing Module II. Syllabus Creating & Using classes in Java – Methods and Classes – Inheritance – Super Class – Method Overriding – Packages.
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
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 Exception Handling.
Object Based Programming Chapter 8. 2 In This Chapter We will learn about classes Garbage Collection Data Abstraction and encapsulation.
2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look.
Creating Classes from Other Classes Appendix D © 2015 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Creating Classes from Other Classes Chapter 2 Slides by Steve Armstrong LeTourneau University Longview, TX 2007, Prentice Hall.
Object Based Programming. Summary Slide Instantiating An Object Encapsulation Inheritance Polymorphism –Overriding Methods –Overloading vs. Overriding.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
(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,
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.
Storage Management. The stack and the heap Dynamic storage allocation refers to allocating space for variables at run time Most modern languages support.
Reference Types. 2 Objectives Introduce reference types –class –array Discuss details of use –declaration –allocation –assignment –null –parameter –aggregation.
Session 7 Methods Strings Constructors this Inheritance.
Exceptions Chapter Throwing and Catching Exceptions When a program runs into a problem that it cannot handle, it throws an exception. Exceptions.
© 2004 Pearson Addison-Wesley. All rights reserved3-1 Objects Declaration: String title; title (object variable) of type String( Class ) title is just.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Sections © Copyright by Pearson Education, Inc. All Rights Reserved.
1 Exception and Event Handling (Based on:Concepts of Programming Languages, 8 th edition, by Robert W. Sebesta, 2007)
Chapter 4: More Object Concepts. Objectives Understand blocks and scope Overload a method Avoid ambiguity Create and call constructors with parameters.
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.
Object-Oriented Programming (OOP). Implementing an OOD in Java Each class is stored in a separate file. All files must be stored in the same package.
© 2017 SlidePlayer.com Inc. All rights reserved.