Understanding Java’s Everyday System.out.println();
You used it for “Hello World”, but do you understand its true meaning?
Let’s break it down further using our understanding of the language and more general OOP concepts.
System is a class located in the java.lang.System package.
Though it cannot be instantiated directly due to its private constructor, it houses capabilities regarding standard IO, error streams, environment, the filesystem, and more.
out is a static field of the System class.
Note that its static nature means it can be accessed without instantiating System, just like Math.PI.
out is of type PrintStream, allowing it to output data to the “standard” output stream at any point. In most cases, this occurs in the form of displaying text in the environment’s command prompt.
printLn() is a void method that outputs its parameter to the output stream, as previously described.
In typical Java fashion, printLn() is overloaded to accept multiple types, such as String, boolean, char, int, long, double, Object, etc.
A similar function, print(), belongs to the Out field that accomplishes the same purpose, but does not append the newline (‘\n’) character to the output stream.
It’s all OOP
Interesting… diving deeper into one of Java’s most fundamental functions leads us to encounter several core concepts of Object Oriented Programming (OOP): Constructors, Visibility Modifiers, Static Fields, Overloading, and even more not mentioned here.
I challenge you to critically inspect your favorite language, finding how its design and architecture is showcased within code segments that are taken for granted.