• Post Reply Bookmark Topic Watch Topic
  • New Topic

How System.out.println() works?  RSS feed

 
dasun sam
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



the result of running above code is this-->Exception in thread "main" java.lang.NullPointerException
at src.TestSop.main(TestSop.java:15)

but after changing the code like this

it gives the correct result.
But i cannot find any place that we can assign an PrintStream object to out variable in class System.public static void setOut(PrintStream out) method can do that but then it must be invoked by jvm automatically.Is that the actualy happening?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dasun sam wrote:But i cannot find any place that we can assign an PrintStream object to out variable in class System.public static void setOut(PrintStream out) method can do that but then it must be invoked by jvm automatically.Is that the actualy happening?


It's done by the System class itself when it's initialised. If you look at the source code, and follow it, eventually it involves calling a native method (so something that's implemented in the JVM) that provides a handle to the standard output of the underlying environment.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!