<< Chapter < Page Chapter >> Page >
  • public static final PrintStream out
  • public static final InputStream in
  • public static final PrintStream err

(Note that these class variables are also declared final , causing them to behave as constants.)

A ccess the out variable without an object

Because out is a class variable, System.out returns the contents of the class variable named out (an object of the System class is not required in order to access a class variable of the System class).

In general, (ignoring the possibility of subclasses and interfaces) because out is a reference variable of type PrintStream , the returned value must either be null (no object reference) or a reference to a valid PrintStream object.

Object of the PrintStream class

When the Java Virtual Machine starts an application running, it automatically instantiates an object of the PrintStream class and connects it to the standard output device . (By default, the standard output device is typically the computer screen, but it can be redirected at theoperating system level to be some other device. The following discussion assumes that the screen is the standard output device.)

Assign object's reference to out variable

When the PrintStream object is instantiated by the virtual machine, the object's reference is assigned to the class variable of the System class named out . (Because the variable named out is final, the contents of the variable cannot be modified later.)

Reference to a PrintStream object

Therefore, the expression System.out returns a reference to the PrintStream object, which is connected to the standard output device.

Many instance methods

An object of the PrintStream class contains many instance methods. This includes numerous overloaded versions of a method named println . The signature of one of those overloaded versions of the println method follows :

public void println(Object x)

Textual representation of an object

The purpose of this overloaded version of the println method is to:

  • Create a textual representation of the object referred to by the incoming parameter of type Object (because Object is a totally generic type, this version of the println method can accept an incoming parameter that is a reference to any type of object)
  • Send that textual representation to the output device

In general...

A new PrintStream object can be connected to a variety of output devices when it is instantiated. However, in the special case of the PrintStream object instantiated by the virtual machine when the program starts, whosereference is stored in the class variable named out of the System class, the purpose of the object is to provide a display path to the standard output device.

Our old friend, the toString method

To accomplish this, the code in the version of the println method shown above calls the toString method on the incoming reference. (I discussed the toString method in detail in earlier modules in this collection.) The toString method may, or may not, have been overridden in the definition of the class from which the object wasinstantiated, or in some superclass of the class from which the object was instantiated.

Questions & Answers

what is phylogeny
Odigie Reply
evolutionary history and relationship of an organism or group of organisms
AI-Robot
ok
Deng
what is biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
what is biology
Victoria Reply
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Object-oriented programming (oop) with java. OpenStax CNX. Jun 29, 2016 Download for free at https://legacy.cnx.org/content/col11441/1.201
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?

Ask