Declaring a Method

Methods are truly the heart and soul of Java programs. They serve the same purpose in Java that functions do in C, C++, and Pascal—only the terminology is different. All execution that takes place in any application or applet takes place within a method. It is only by combining multiple dynamic methods that large-scale Java applications are written.

Like C++ functions, Java methods are the essence of each class and are responsible for managing all the tasks that can be performed. It is also true that methods exist only within classes in Java. There is no concept of a global function in Java that exists outside of a class.

Look at the parts of a method as shown in the following simple example:

 void simpleMethod(){ System.out.println("Inside ...

Get Special Edition Using Java 2 Standard Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.