1000 Java Tips ebook
Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java
programming articles and tips. Please take your copy here.
Take your copy of free "Java Technology Screensaver"!.
Java: Methods - Introduction
JavaFAQ Home » Java Notes by Fred Swartz
The word method is commonly used in Object-Oriented Programming
and is used in Java. It means the same thing as function, procedure,
or subroutine in
other programming languages. Many programmers use these other terms, especially
function, but these notes will use method
Why use methods?
- For reusable code
- If you need to do the same thing, or almost the same thing,
many times, write a method to do it,
then call the method each time you have to do that task.
- To parameterize code
- In addition to making reusable code that is the same in
all cases, you will often want to use parameters that change the
way the method works.
- For top-down programming
- A very useful style of programming is called top-down
programming. You solve a
big problem (the "top") by breaking it down into little problems.
To do this in a program, you write a method
for solving your big problem by calling on other methods
to solve the smaller parts of the problem. And these methods
for solving the simpler problems similarly call on other methods
until you get down to simple methods which solve simple problems
- To create conceptual units
- Create methods to do something that is one action
in your mental view of the problem. This will make it much easier for you to work with your
- To simplify
- Because local variables and statements of a method
can not been seen from outside the method, they (and their complexity) are hidden
from other parts of the program, which prevents accidental
errors or confusion.
Printer Friendly Page
Send to a Friend
Search here again if you need more info!