• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

system.out.println()

 
nimish kumar
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4594
302
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Inder Kumar Rathore
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
nimish kumar
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats great.....

 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4594
302
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inder Kumar Rathore wrote:I am fully agreed with Devika

Whooo?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12186
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Inder Kumar Rathore
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry for that Devaka..
I thought you won't get this but you spotted mistake....
anyways
just chilll
 
Jim Hoglund
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ... ...
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4594
302
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inder Kumar Rathore wrote:I thought you won't get this but you spotted mistake.


 
nimish kumar
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic