What is Java Programming
Java is a simple, scalable object oriented, general purpose programming language with a multitude of uses. With the power to develop everything from simple web animations to high-end business applications that program hand-held devices, microwaves, cross platform server applications and more, it's no wonder why Java is on everyone's mind.
This practical "how to" course by Java expert, Arthur Griffith, starts from beginner level and uses practical examples to demonstrate the Java programming language. Source code is also provided for every example, so the user can follow right along. To get started, click one of the movie topics below. * This title may contain code using functions that will not compile with current Java version.
More generally, method declarations have six components, in order:
- Modifiers such as public, private, and others you will learn about later.
- The return type the data type of the value returned by the method, or void if the method does not return a value.
- The method name the rules for field names apply to method names as well, but the convention is a little different.
- The parameter list in parenthesis a comma-delimited list of input parameters, preceded by their data types, enclosed by parentheses, (). If there are no parameters, you must use empty parentheses.
- An exception list to be discussed later.
- The method body, enclosed between braces the method's code, including the declaration of local variables, goes here.
Definition: Two of the components of a method declaration comprise the method signature the method's name and the parameter types.
The signature of the method declared above is:
calculateAnswer(double, int, double, double)
Naming a Method
Although a method name can be any legal identifier, code conventions restrict method names. By convention, method names should be a verb in lowercase or a multi-word name that begins with a verb in lowercase, followed by adjectives, nouns, etc. In multi-word names, the first letter of each of the second and following words should be capitalized. Here are some examples for Java Programming:
- run
- runFast
- getBackground
- getFinalData
- compareTo
- setX
- isEmpty
Overloading Methods
The Java programming language supports overloading methods, and Java can distinguish between methods with different method signatures. This means that methods within a class can have the same name if they have different parameter lists (there are some qualifications to this that will be discussed in the lesson titled "Interfaces and Inheritance").
Suppose that you have a class that can use calligraphy to draw various types of data (strings, integers, and so on) and that contains a method for drawing each data type. It is cumbersome to use a new name for each method for example, drawString, drawInteger, drawFloat, and so on. In the Java programming language, you can use the same name for all the drawing methods but pass a different argument list to each method.