I am just beginning to learn Java, coming from C background.
How can the line "System.out.println()" be dissected?
I am just beginning to learn Java, coming from C background.
How can the line "System.out.println()" be dissected?
It's basically like puts
in C -- take a string and emit it on standard output.
System.out is a reference to the programs stdout. println works like it does in C. In your example passing no argument will simply return a newline.
Unlike C, Java is object oriented, so methods/functions and attributes/variables are bundled into objects such as "System". Take a look at the javadoc to see what else is available on the System object.
Java is an object-oriented language.
System
is a class that contains useful fields and methods. See the API.
out
refers to an object that is part of System that is the standard output, so it written as System.out
.
println("blah")
is a method for System.out
that prints a String as a line. When no argument is given (so println()
) it prints a blank line.
System is a class made available by Java to let you manipulate various operating system related objects. It's part of java.lang namespace.
out, being one of those objects, is a static publicly available object inside that class. The object itself, representing standard output, is an instance of java.io.PrintStream class. Standard output is, on most operating systems, console output.
println is a method of java.io.PrintStream class that lets you output some text into the stream and, as opposed to print() method, gets you to the new line after the text.
From here
PS: check google :)
The dot "." operator is used to specify a member (function) or variable internal to a class or object.
It is used in a similar fashion to the member selection operator "->" in C.
What "System.out.println()" is saying is:
Look in the System class for the out member, then look in the out member for the println function and run the println function.
see:
http://en.wikipedia.org/wiki/Object_composition
and
http://en.wikipedia.org/wiki/Function_composition_(computer_science)
System contains a number of class fields and methods including
out is of type PrintStream and refers to the standard output stream to which data can be written - this is essentially the display, but it can also be another device.
PrintStream contains a static method called println that allows data to be written. It appends a line separator string at the end of the data you attempt to write.
The static keyword essentially means that it belongs to the class rather than the instance.
So when you see:
System.out.println("Hello World");
It's writing the characters Hello World plus a line separator to the out stream which is connected to the Console.
For more information see:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html
You are advised to consult the java.lang.System.out
doc.
public static final PrintStream out
The "standard" output stream. This stream is already open and ready to accept output data. Typically this stream corresponds to display output or another output destination specified by the host environment or user.
For simple stand-alone Java applications, a typical way to write a line of output data is:
System.out.println(data)
and java.io.PrintStream.println()
:
public void println()
Terminates the current line by writing the line separator string. The line separator string is defined by the system property line.separator, and is not necessarily a single newline character ('\n').
Hi Geos
System.out.Println() is same as printf("\n");
System allows you to do various operations related to your operating system and "." is used to access the member functions and Println will print the data in a new line
System is a class which means that it's a blueprint, but a blueprint of what? According to the API,
The System class contains several useful class fields and methods.
Now, System has several properties or fields such as:
The API also tells us what out is. Out is actually another object, specifically, a PrintStream object.
Again by consulting the API, we will see that out, being a PrintStream object, it also has several properties as well as actions or methods associated with it.
Println is one of out's methods. What it does is it displays a string, or a number or what have you in the "standard output" or simply, your screen.
System.out.println
System is the class for the standard input and output streams while out is the object of the class. So we write it as System.out.
and println() is the method that is used to print the string as line.