aspose file tools*
The moose likes Beginning Java and the fly likes system.out.println() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "system.out.println()" Watch "system.out.println()" New topic
Author

system.out.println()

nimish kumar
Ranch Hand

Joined: Dec 04, 2009
Posts: 56
Hi,
Explain System.out.println()

As per my knowledge, System is a class in java, what abt out and println()
does System class has out() method and again println() method in out. I was confused in an interview on this qstn. someone please explain?


IBM-IBM WebSphere Application Server Network Deployment V7.0, Core Administration.
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3164
    
  47

nimish kumar wrote:does system class has out method and....

If out was a method, you should have to call it with brackets as System.out().println() - in fact, just having a short glance at System.out.println() we can identify that 'out' is NOT a method, for sure.

Can you identify what exactly 'out' is by having a look at the documentation of System class ?

Devaka


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Inder Kumar Rathore
Ranch Hand

Joined: Apr 14, 2010
Posts: 41
I am fully agreed with Devika,
just remember the simple concepts and java naming conventions every thing would be easy..

Here I will help you little but I want you to explore by checking documentation, as It looks that you don't use it frequently.
I suppose Java docs is just like dictionary for every java developer, and we should keep it in our pocket.

now comming to your question

System.out.println();

here S of System is capital so it should be a class
o of out is small so it should be a variable
and println() is a method as () is present.
Now we are accessing out using class that means it is a static variable.
and as println() is called upon out so out must be an object type variable.

so the whole story is like this

System
{
........
........
static SomeClass out;
.......
.......
}


SomeClass
{

....
....
void println()
{
........
........
}

}

now just go throug documentation and tell me what is that SomeClass..

Good luck


Thanks

Living is easy with your eyes closed.....
nimish kumar
Ranch Hand

Joined: Dec 04, 2009
Posts: 56
Devaka Cooray wrote:
nimish kumar wrote:does system class has out method and....

If out was a method, you should have to call it with brackets as System.out().println() - in fact, just having a short glance at System.out.println() we can identify that 'out' is NOT a method, for sure.

Can you identify what exactly 'out' is by having a look at the documentation of System class ?

Devaka


Thanks Devaka,
After reading i understand that, in system class we have class field in,out,err. The class fields out and err are of printstream type and in is of inputstream type. println() is a method of printstream.
nimish kumar
Ranch Hand

Joined: Dec 04, 2009
Posts: 56
Inder Kumar Rathore wrote:I am fully agreed with Devika,
just remember the simple concepts and java naming conventions every thing would be easy..
...
now just go throug documentation and tell me what is that SomeClass..

Good luck


Thanks Inder.
That someclass is PrintStream.
Inder Kumar Rathore
Ranch Hand

Joined: Apr 14, 2010
Posts: 41
Thats great.....

Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3164
    
  47

Inder Kumar Rathore wrote:I am fully agreed with Devika

Whooo?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11406
    
  16

just to be a pain...

There is no such thing as the 'system' class. There is, however, a 'System' class.

Java is case sensitive. If you try using 'system', you'll get errors.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Inder Kumar Rathore
Ranch Hand

Joined: Apr 14, 2010
Posts: 41
sorry for that Devaka..
I thought you won't get this but you spotted mistake....
anyways
just chilll
Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
In your posts, when referring to Java types and members, you should always use
proper capitalization; say System rather than system, OutputStream rather than
outputstream. And add the brackets to method names; show println() rather than
just println. This greatly enhances efficient and accurate communication and
reduces possible confusion. Take a minute to do this editing.

Jim ... ...


BEE MBA PMP SCJP-6
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3164
    
  47

Inder Kumar Rathore wrote:I thought you won't get this but you spotted mistake.


nimish kumar
Ranch Hand

Joined: Dec 04, 2009
Posts: 56
Jim Hoglund wrote:In your posts, when referring to Java types and members, you should always use
proper capitalization; say System rather than system, OutputStream rather than
outputstream. And add the brackets to method names; show println() rather than
just println. This greatly enhances efficient and accurate communication and
reduces possible confusion. Take a minute to do this editing.

Jim ... ...


Thanks for pointing that, I edited ....
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: system.out.println()