O'Reilly logo

Data Structures and the Java Collections Framework, Third Edition by William J. Collins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 2

Additional Features of Programming and Java

In Chapter 1, the primary goal was to introduce object-oriented concepts, such as interfaces, inheritance and polymorphism, in the context of the Java programming language. This chapter introduces more topics on programming in general and Java in particular, and illustrates how they can aid your programming efforts. For example, Java's exception-handling mechanism provides programmers with significant control over what happens when errors occur.

CHAPTER OBJECTIVES

  1. Distinguish between static members and instance members.
  2. Be able to develop JUnit tests for a class's methods.
  3. Be able to create try blocks and catch blocks to handle exceptions.
  4. Compare file input/output with console input/output.
  5. Understand the fundamentals of the Java Virtual Machine.
  6. Be able to override the Object class's equals method.
  7. Understand the interplay between packages and visibility modifiers.

2.1 Static Variables, Constants and Methods

Recall, from Section 1.2.2, that a class member is either a field or method in the class1. Let's look at some of the different kinds of members in Java. There are two kinds of fields. An instance variable is a field associated with an object—that is, with an instance of a class. For example, in the FullTimeEmployee class from Chapter 1, name and grossPay are instance variables. Each FullTimeEmployee object will have its own pair of instance variables. Suppose we declare

FullTimeEmployee oldEmployee, currentEmployee, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required