2

i understand that out is a field in System class and it reference some object of PrintStream as print(System.out.getClass()); returns class java.io.PrintStream.

also i presume declaration of out in System class should be something like public static PrintStream out;

My query here is what actually is the value of 'out' field in System Class.
it can not be like
public static PrintStream out = new PrintStream(System.out);

Just Curious

Shashi
  • 746
  • 10
  • 39

3 Answers3

3

When you check the source code of System class, you can see it is set via native method calls:

 private static native void setOut0(PrintStream out);
Juvanis
  • 25,802
  • 5
  • 69
  • 87
  • frankly speaking, i don't know where to look for source code of System class on my pc. started learning java just a month ago. i would be thankful if u could teach me how to do that or any reference regarding that. i'm on linux ubuntu and running java 7 update 25 – Shashi Sep 04 '13 at 11:10
  • @Shashi Java is open-source, just do a google-search with the terms "System class source code". – Juvanis Sep 04 '13 at 11:11
  • @Shashi http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/lang/System.java#System.setOut%28java.io.PrintStream%29 – Suresh Atta Sep 04 '13 at 11:12
  • 1
    @Shashi in your JDK installation directory you have a file `src.zip` which contains the source code of the standard Java classes. – Jesper Sep 04 '13 at 11:43
1

The declaration of out is like this (taken from System src)

public final static PrintStream out = null;

and it is initialized in this method

private static void initializeSystemClass() {
    ...
    setOut0(new PrintStream(new BufferedOutputStream(fdOut, 128), true));

...

which is called by JVM

Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275
0

out is a static member in the System class and is an instance of PrintStream. From System class

public static final PrintStream out;
sr01853
  • 6,043
  • 1
  • 19
  • 39