Is this static println
function in out
class from System
namespace?
namespace System { class out { static println ...
Because out is being called with the System
class name itself, not an instance of a class (an object), So out
must be a static variable belonging to the class System
. out
must be instance of a class, because it is invoking the method println()
.
// the System class belongs to java.lang package
class System {
public static final PrintStream out;
}
class PrintStream {
public void println();
}
System
is a class of java.lang
package, out
is an object of PrintStream
class and also static
data member of System
class, print()
and println()
is an instance method of PrintStream
class.
it is provide soft output on console.
No. Actually out
is a static member in the System
class (not as in .NET), being an instance of PrintStream
. And println
is a normal (overloaded) method of the PrintStream
class.
See http://download.oracle.com/javase/6/docs/api/java/lang/System.html#out.
Actually, if out
/err
/in
were classes, they would be named with capital character (Out
/Err
/In
) due to the naming convention (ignoring grammar).
System
is a class, that has a public static field out
. So it's more like
class System
{
public static PrintStream out;
}
class PrintStream
{
public void println ...
}
This is a slight oversimplification, as the PrintStream
class is actually in the java.io
package, but it's good enough to show the relationship of stuff.
System.out.println("Hello World");
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
. Since java.lang
package is imported in every java program by default,therefore java.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 class
System
.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
:The println()
is method of out
object that
takes the text string as an argument and displays it to the standard
output i.e on monitor screen.Note
System
-Class
out
-static Object
println()
-method
Remember a function (in java function is called method) always has the format function()
System
: is predefined class of java.lang
package.
out
: is a static
member of printStream
class and its connect with console.
Println
: is a method of printstream
class and its not a static
.