Using Classes and Objects

Using Classes and Objects

The “Hello World” application is about the simplest Java program one can write that actually does something. Because it is such a simple program, it doesn’t need to define any classes except for HelloWorldApp.

The “Hello World” application does use another class–the System class–that is part of the API (application programming interface) provided with the Java environment. The System class provides system-independent access to system-dependent functionality.

The bold code in the following listing illustrates the use of a class variable of the System class, and of an instance method.

* 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.

Using a Class Method or Variable

Let’s take a look at the first segment of the statement:
System.out .println(“Hello World!”);
The construct System.out is the full name of the out variable in the System class.

Using an Instance Method or Variable

Methods and variables that are not class methods or class variables are known as instance methods and instance variables.

While System’s out variable is a class variable, it refers to an instance of the PrintStream class (a class provided with the Java development environment) that implements the standard output stream.

When the System class is loaded into the application, it instantiates PrintStream and assigns the new PrintStream object to the out class variable.

System.out.println(“Hello World!”);


This line of code displays “Hello World!” to the application’s standard output stream

Scroll to Top