aspose file tools*
The moose likes Beginning Java and the fly likes Details of Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Details of "System.out.println"" Watch "Details of "System.out.println"" New topic
Author

Details of "System.out.println"

Soumya Ghosh
Greenhorn

Joined: Dec 31, 2006
Posts: 26
Hi,
Can any one please explain individual of "System.out.println" ?

According to my thinking, System is a class. out is its object and println is the method called by out for printing some thing.
But, I think out belongs to printWriter object.

So, I am getting confused. Please help me.
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6657
    
    5

You almost have it. out is a reference to a Printwriter class and you can use this reference to access the Printwriter API from the System class. println() is a static method so you dont need an instance an object to reach this method. Is there any other confusion ?


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

System is a class.

out is a public static variable of that class, it is of the type PrintStream

println is a method of the PrintStream class.

Basically, you could think of the System class being coded like this (its not, but hopefully you've seen code like this before an it will give you the idea):

[ April 23, 2007: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6657
    
    5

Originally posted by Paul Sturrock:
System is a class.

out is a public static variable of that class, it is of the type PrintStream

println is a method of the PrintStream class.

Basically, you could think of the System class being coded like this (its not, but hopefully you've seen code like this before an it will give you the idea):


[ April 23, 2007: Message edited by: Paul Sturrock ]


Yikes ! I meant to say PrintStream.
prasad valeti
Greenhorn

Joined: Oct 18, 2005
Posts: 7
Here i'm writing one example where System class ,out object & println() method are explained

class A{

static B b;

}
class B{
void example(){
System.out.println("prasad");
}
}
class C{
public static void main(String s[]){
A a = new A();
a.b.example();
}
}
output:
prasad.

A-------->System class
b--------->out is a static variable of type PrintStream
B.........>PrintStream class
example()..........>println()
umamahesh javvadi
Greenhorn

Joined: Apr 22, 2007
Posts: 7
small Modification of A,B,C example
This code works ... check it and run

class A{//Assume this as System class
static B b1=new B();//create an object of B(assume B as PrintStream)
//create a final static variable(assume it as out varaible)
final static B b=b1;
}
class B{
public void example(){
System.out.println("mahesh");

}
}
class C {
public static void main(String as[]){
//A(System class).b(out of PrintStream //class).example()(println() in //PrintStream class
A.b.example();
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Details of "System.out.println"
 
Similar Threads
confused
Difference between "out" and "err"
internal doubt abou string and string buffer
Ambiguous method overloading
Extracting hierarchy of objects from Vector