O'Reilly logo

Beginning Programming with Java For Dummies, 5th Edition by Barry A. Burd

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 19

Creating New Java Methods

IN THIS CHAPTER

check Writing methods that work with existing values

check Building methods that modify existing values

check Making methods that return new values

In Chapters 3 and 4, I introduce Java methods. I show you how to create a main method and how to call the System.out.println method. Between that chapter and this one, I make very little noise about methods. In Chapter 18, I introduce a bunch of new methods for you to call, but that’s only half of the story.

This chapter completes the circle. In this chapter, you create your own Java methods — not the tired old main method that you’ve been using all along, but rather some new, powerful Java methods.

Defining a Method within a Class

In Chapter 18, Figure 18-6 introduces an interesting notion — a notion that’s at the core of object-oriented programming. Each Java string has its own equals method. That is, each string has, built within it, the functionality to compare itself to other strings. That’s an important point. When you do object-oriented programming, you bundle data and functionality into a lump called a class. Just remember Barry’s immortal words from Chapter 17:

A class … describes the way ...

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