• Post Reply Bookmark Topic Watch Topic
  • New Topic

System  RSS feed

 
Prashanth Bhanu
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to all,
can any one help me to understand "System.out.println()".Thanx in advance.
 
Uma Balu
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
System ----- > Class present in the java.lang package which cannot be instantiated.
out -------- > Static final variable declared in the System class.Hence, you say System.out(without creating a instance of the Sustem class). It is of the type java.io.PrintStream.
println ---- > Method present in the PrintStream class to send the output to the specified stream.Since, out is an instance of PrintStream, we say out.println to invoke this method.

Uma
 
Brian R. Wainwright
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also the print() and println() methods (println() adds a carriage return, print() does not) when passed an Object, automatically uses that object's toString() method to render the output. In the case of a String object, this is the string value of the object. In the event of another kind of object it is either the result of an overridden implentation of toString() or Object.toString() (which all objects inherit and, if not overriden, which prints the object's class name + @ + hexadecimal representation of the hash code of the object).
From the Object javadocs:
The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
--BW
[ November 25, 2003: Message edited by: Brian R. Wainwright ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!