In the previous lesson we looked at static members.
Understanding System.out.println()
You have several times used the System.out.println() statement to send text to the Output window, and its syntax looks slightly unusual in that there are two dots. If you look at the API for the System class, you will see the following:
- That
outis apublicvariable (you will find it under the Field Summary section) and therefore available to be referenced from other classes. The variables you have so far created have all been private, and this is the normal situation. However, this shows that occasionally it can be useful for variables to bepublic - That
outis declared to bestatic, meaning that you don't need to instantiate aSystemobject to use it - That
outis declared asfinal, meaning its reference cannot be modified - That
outis a variable of typePrintStream - If you now click the
PrintStreamlink you will find several methods including one calledprintlnand which takes an argument of typeString.
You can therefore read the statement as being: "Invoke the println() method of the out static variable that is a PrintStream object that exists within the System class".
In the next lesson you will learn about Java constants.
Comments