Section 7i

The main Method


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

public static void main

The Ultimate Method

So far in this reference, you have been using the main method for your programs. From this point forward, you will be writing a lot of supporting and utilitarian methods. However, you should already know that all (correctly operating) Java programs start and end in the main method. When you run your program, the main method is called by the operating system in order to conduct its business.

The operating system does not care what the main method does, as long as it does not try to cause trouble for the system, so your program will run until it is done with its given tasks. Working with individual methods or tasks will bring you closer to what it is like to work in the professional programming environment. The main method is just the one that gets called by the operating system to run the program.

Calling all Methods. In Java, everything happens inside a method. The main method is called by the Java runtime environment, and the whole program works through methods called from that same main method. The main method can call other methods, which can call other methods, and so on. It has been mentioned in a previous topic that this process of calling a variety of other methods or modules to solve the problem or create the solution makes the main method a driver. While all other methods must be designed and implemented in such a way that they focus tightly on specific goals or tasks, the main method is the program and thus, accomplishes many different tasks. Like all the other methods, it does only conduct one activity, but that activity is the program execution.

Methods are the building blocks of any program. They need to be small, reusable, and modular components so they work together to form an easily readable, effective, and correct program. With this in mind, methods and modular development are the only way to handle programming at a large and/or complicated scale, and they can be used to make problem solving and task completion a well managed process. Methods are a powerful tool with which you will continue your learning of Computer Science in the next topics.

This is the last section in the chapter on methods. However, it is only the beginning for your work with methods. In the next chapter, you will put them to work in a carefully structured programming process that will help you learn to develop well-structured and well-organized programs.