How to declare a method

Every Java program contains one or more methods, which are pieces of code that perfiom tasks.

Every application has a main method, or the entry point to the application.

public static void main(String[] args)

{

System.out.println("Welcome to the Invoice Total Calculaor");

}

How to name a method:

  • Use a strong action verb.
  • Start with a lower case word followed by capital letter words.
  • Use letters and numbers only

Use the prefixes get and set for getter and setter methods. Getter methods merely return the value of a instance variable; setter methods change the value of a instance variable.

  • getBalance – getter
  • setBalance – setter

If the method returns a boolean value, use is or has as the prefix for the method name.

  • hasCredit
  • isValidCustomer