| Overview of Java Language |
| |
| Defining a Class |
| |
| The first bold line in the following listing begins a class definition block. |
| |
/**
* The HelloWorldApp class implements an application that
* simply displays "Hello World!" to the standard output.
*/
class HelloWorldApp
{
public static void main(String[] args)
{
System.out.println("Hello World!"); //Display the string.
}
}
|
|
| |
| |
A class--the basic building block of an object-oriented
language such as Java--is a template that describes the data and behavior associated with instances of that class.
The data associated with a class or object is stored in variables; the behavior
associated with a class or object is implemented with methods. Methods are
similar to the functions or procedures in procedural languages such as C.
In the Java language, the simplest form of a class definition is |
| |
class name {
. . .
} |
| |
| The
keyword class begins
the class definition for a class named name.
|
| The variables and methods of the class
are embraced by the curly brackets that begin and end the class definition block.
The "Hello World" application has no variables and has a single method
named main. |
| |
| |
|
|
| |
| |