Professional Documents
Culture Documents
cs4406 DF 4
cs4406 DF 4
Java method is a set of instructions that preforms an individual action. It is also a collection of
statements that are grouped together to perform an operation. A method must be declared within a
class. It is defined with the name of the method, followed by parentheses. Java methods usually look
like:
In order to use a method, we need to call it. There are two ways in which a method is called:
The general format of a Java method call is: methodName(argumentList)where the argumentList
is a comma-separated list of arguments (data being sent into the method)..
The calling process of a method is simple. When a program invokes a method, the program control
gets transferred to the called method. This called method then returns control to the caller in two
conditions:
PROPERTIES
Properties is a subclass. It is used to maintain lists of values in which the key is a String and the
value is also a String. The Properties class is used by many other Java classes. For example, it is
the type of object returned by System.getProperties( ) when obtaining environmental values.
Properties define the following instance variable. This variable holds a default property list
associated with a Properties object. The properties object contains key and value pair both as a
string. It can be used to get property value based on the property key. The Properties class provides
methods to get data from properties file and store data into properties file. Moreover, it can be used
to get properties of system.
A good advantage of properties is that in case some information change from the properties file,
we don't need to recompile the java class. It is used to store information which is to be changed
frequently.
capitals.put("Illinois", "Springfield");
capitals.put("Missouri", "Jefferson City");
capitals.put("Washington", "Olympia");
capitals.put("California", "Sacramento");
capitals.put("Indiana", "Indianapolis");
while(itr.hasNext()) {
str = (String) itr.next();
System.out.println("The capital of " + str + " is " +
capitals.getProperty(str) + ".");
}
System.out.println();
REFERENCES