Is this static println
function in out
class from System
namespace?
namespace System { class out { static println ... }
How can I interpret this name? And where in JRE this function is defined? In java.lang.System
/java.lang.Object
?
Is this static println
function in out
class from System
namespace?
namespace System { class out { static println ... }
How can I interpret this name? And where in JRE this function is defined? In java.lang.System
/java.lang.Object
?
From the javadoc about
System
, here's what the doc says:Regarding
System.out
Regarding println();
For simple stand-alone Java applications, a typical way to write a line of output data is:
System
: is predefined class ofjava.lang
package.out
: is astatic
member ofprintStream
class and its connect with console.Println
: is a method ofprintstream
class and its not astatic
.System
is the classout
is a variable in theSystem
class and it is astatic
and variable type isPrintStream
.Here is the
out
variable inSystem
class:You can see implementation of
System
here.println()
is a overloaded method inPrintStream
class.PrintStream
includes three overloaded printing methods, those are:print()
println()
printf()
You can see implementation of
PrintStream
here.You cannot instantiate
System
class and it is child class ofObject
and theObject
is the father(superclass) of every classes including classes that you defined.Here is what the oracle docs says:
If you donot know what is meant by instantiate, read this questioh. It is C# question but the concept is same.
Also, What is the difference between an Instance and an Object?
If you donot know what is meant by overload read this quesiotn.
Check following link:
http://download.oracle.com/javase/1.5.0/docs/api/java/lang/System.html
You will clearly see that:
System
is a class in thejava.lang
package.out
is a static member of theSystem
class, and is an instance ofjava.io.PrintStream
.println
is a method ofjava.io.PrintStream
. This method is overloaded to print message to output destination, which is typically a console or file.System
is a class, that has a public static fieldout
. So it's more likeThis is a slight oversimplification, as the
PrintStream
class is actually in thejava.io
package, but it's good enough to show the relationship of stuff.System
: It is the name of standard class that contains objects that encapsulates the standard I/O devices of your system.It is contained in the package
java.lang
. Sincejava.lang
package is imported in every java program by default,thereforejava.lang
package is the only package in Java API which does not require an import declaration.out
:The object out represents output stream(i.e Command window)and is the static data member of the classSystem
.So note here
System.out
(System
-Class &out
- static object i.e why its simply referred to by classname and we need not create any object).println
:Theprintln()
is method ofout
object that takes the text string as an argument and displays it to the standard output i.e on monitor screen.Note
System
-Classout
-static Objectprintln()
-methodRemember a function (in java function is called method) always has the format function()