• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

system.out.println()

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thats great.....

 
Devaka Cooray
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Inder Kumar Rathore wrote:I am fully agreed with Devika


Whooo?
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry for that Devaka..
I thought you won't get this but you spotted mistake....
anyways
just chilll
 
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ....
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic