> What does System.out.println() in java mean?

What does System.out.println() in java mean?

Posted at: 2014-12-18 
Yes, it's a static method of the System class.

The problem with static methods and instance variables is with finding them by name without specifying which object they are in.

An instance variable name doesn't refer to once item. It refers to a different item in every object ("instance") of the class type. Java needs to know which object to get that variable from. This is true for every use of an instance variable. Java has to know which object's copy of that variable you want to use.

When an instance method runs, it associated with one specific object of the class type, and the "this" variable is a reference to that object, and Java uses that by default to find instance variables in the same class as the method. Maybe that's Java unnecessarily simplifying things?

Back to println(), when an argument is passed to a method, the caller supplies the value. It's the caller's responsibility to say which object the variable is in, if it's an instance variable, and pass a copy to the called method.

You are calling the non-static println() method of an instance of the PrintStream class.

This instance is stored in System.out; a static variable of the System class.

Basically:

class System {

public static PrintStream out = new PrintStream(...); // console output stream

...

}

System is a class.

out is a public static field of the System class, with type PrintStream.

println() is a method of the PrintStream class. It is not static.

Hence, System.out is not a class name; it is reference to the static field called out in the System class.

This is not that different than, for example, calling Math.PI (where PI is a public static field of type double).

I don't think this is that complicated.

The javadocs is always a good place to start.

System is a class:

http://docs.oracle.com/javase/7/docs/api...

System.out is a static field of type PrintStream:

http://docs.oracle.com/javase/7/docs/api...

System.out.println() is a method:

http://docs.oracle.com/javase/7/docs/api...

I would like to know if println() is a static method or not. if yes, how is System.out a class name? if no, how could it refer to a instance variable of the class println() is located in?

doesn't java complicate things unnecessarily?