You are previewing Core Java™: Volume I—Fundamentals, Ninth Edition.

Core Java™: Volume I—Fundamentals, Ninth Edition

Cover of Core Java™: Volume I—Fundamentals, Ninth Edition by Cay S. Horstmann... Published by Prentice Hall
  1. Title Page
  2. Copyright Page
  3. Contents
  4. Preface
    1. To the Reader
    2. A Tour of This Book
    3. Conventions
    4. Sample Code
  5. Acknowledgments
  6. Chapter 1. An Introduction to Java
    1. 1.1. Java As a Programming Platform
    2. 1.2. The Java “White Paper” Buzzwords
    3. 1.3. Java Applets and the Internet
    4. 1.4. A Short History of Java
    5. 1.5. Common Misconceptions about Java
  7. Chapter 2. The Java Programming Environment
    1. 2.1. Installing the Java Development Kit
    2. 2.2. Choosing a Development Environment
    3. 2.3. Using the Command-Line Tools
    4. 2.4. Using an Integrated Development Environment
    5. 2.5. Running a Graphical Application
    6. 2.6. Building and Running Applets
  8. Chapter 3. Fundamental Programming Structures in Java
    1. 3.1. A Simple Java Program
    2. 3.2. Comments
    3. 3.3. Data Types
    4. 3.4. Variables
    5. 3.5. Operators
    6. 3.6. Strings
    7. 3.7. Input and Output
    8. 3.8. Control Flow
    9. 3.9. Big Numbers
    10. 3.10. Arrays
  9. Chapter 4. Objects and Classes
    1. 4.1. Introduction to Object-Oriented Programming
    2. 4.2. Using Predefined Classes
    3. 4.3. Defining Your Own Classes
    4. 4.4. Static Fields and Methods
    5. 4.5. Method Parameters
    6. 4.6. Object Construction
    7. 4.7. Packages
    8. 4.8. The Class Path
    9. 4.9. Documentation Comments
    10. 4.10. Class Design Hints
  10. Chapter 5. Inheritance
    1. 5.1. Classes, Superclasses, and Subclasses
    2. 5.2. Object: The Cosmic Superclass
    3. 5.3. Generic Array Lists
    4. 5.4. Object Wrappers and Autoboxing
    5. 5.5. Methods with a Variable Number of Parameters
    6. 5.6. Enumeration Classes
    7. 5.7. Reflection
    8. 5.8. Design Hints for Inheritance
  11. Chapter 6. Interfaces and Inner Classes
    1. 6.1. Interfaces
    2. 6.2. Object Cloning
    3. 6.3. Interfaces and Callbacks
    4. 6.4. Inner Classes
    5. 6.5. Proxies
  12. Chapter 7. Graphics Programming
    1. 7.1. Introducing Swing
    2. 7.2. Creating a Frame
    3. 7.3. Positioning a Frame
    4. 7.4. Displaying Information in a Component
    5. 7.5. Working with 2D Shapes
    6. 7.6. Using Color
    7. 7.7. Using Special Fonts for Text
    8. 7.8. Displaying Images
  13. Chapter 8. Event Handling
    1. 8.1. Basics of Event Handling
    2. 8.2. Actions
    3. 8.3. Mouse Events
    4. 8.4. The AWT Event Hierarchy
  14. Chapter 9. User Interface Components with Swing
    1. 9.1. Swing and the Model-View-Controller Design Pattern
    2. 9.2. Introduction to Layout Management
    3. 9.3. Text Input
    4. 9.4. Choice Components
    5. 9.5. Menus
    6. 9.6. Sophisticated Layout Management
    7. 9.7. Dialog Boxes
  15. Chapter 10. Deploying Applications and Applets
    1. 10.1. JAR Files
    2. 10.2. Java Web Start
    3. 10.3. Applets
    4. 10.4. Storage of Application Preferences
  16. Chapter 11. Exceptions, Assertions, Logging, and Debugging
    1. 11.1. Dealing with Errors
    2. 11.2. Catching Exceptions
    3. 11.3. Tips for Using Exceptions
    4. 11.4. Using Assertions
    5. 11.5. Logging
    6. 11.6. Debugging Tips
    7. 11.7. Tips for Troubleshooting GUI Programs
    8. 11.8. Using a Debugger
  17. Chapter 12. Generic Programming
    1. 12.1. Why Generic Programming?
    2. 12.2. Defining a Simple Generic Class
    3. 12.3. Generic Methods
    4. 12.4. Bounds for Type Variables
    5. 12.5. Generic Code and the Virtual Machine
    6. 12.6. Restrictions and Limitations
    7. 12.7. Inheritance Rules for Generic Types
    8. 12.8. Wildcard Types
    9. 12.9. Reflection and Generics
  18. Chapter 13. Collections
    1. 13.1. Collection Interfaces
    2. 13.2. Concrete Collections
    3. 13.3. The Collections Framework
    4. 13.4. Algorithms
    5. 13.5. Legacy Collections
  19. Chapter 14. Multithreading
    1. 14.1. What Are Threads?
    2. 14.2. Interrupting Threads
    3. 14.3. Thread States
    4. 14.4. Thread Properties
    5. 14.5. Synchronization
    6. 14.6. Blocking Queues
    7. 14.7. Thread-Safe Collections
    8. 14.8. Callables and Futures
    9. 14.9. Executors
    10. 14.10. Synchronizers
    11. 14.11. Threads and Swing
  20. Appendix A. Java Keywords
  21. Index
O'Reilly logo

Chapter 6. Interfaces and Inner Classes

You have now seen all the basic tools for object-oriented programming in Java. This chapter shows you several advanced techniques that are commonly used. Despite their less obvious nature, you will need to master them to complete your Java tool chest.

The first technique, called interfaces, is a way of describing what classes should do, without specifying how they should do it. A class can implement one or more interfaces. You can then use objects of these implementing classes whenever conformance to the interface is required. After we cover interfaces, we take up cloning an object (or deep copying, as it ...

The best content for your career. Discover unlimited learning on demand for around $1/day.