Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

could we say 'out' is inner class of 'System' class ?

 
Saed Hussein
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this Friday i have been studying inner classes, after studying i think that i got something to apply, and that is:
suppose could i say that is inner class of and is static method of inner class .

 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saed Hussein wrote:this Friday i have been studying inner classes, after studying i think that i got something to apply, and that is:

First of all, why are you studying inner classes That's not on the OCA exam at all. It's one of the famous topics on the OCP exam.

But out is definitely not an inner class of the System class! out is nothing more but a public final class (static) variable of the System class and the println (and print) method is simply an instance method of the type of class variable out. So the System class looks similar toAnd you can use this custom System class as well

Hope it helps!
Kind regards,
Roel
 
Saed Hussein
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why i'm studying inner classes is, Inner classes has subtopic of anonymous classes which are prerequisite to understand lambda expression as I think.
any how thank you for your reply; also your reply will help me letter and also other newbies.
 
Nigel Browne
Ranch Hand
Posts: 703
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look at the Java API docs, you'll see that out is a public staic final field of type PrintStream. The print & println methods all reside in the java.io.PrintStream class and not in the System class
 
Paweł Baczyński
Bartender
Posts: 1877
35
Firefox Browser IntelliJ IDE Java Linux Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if System.out was a static nested class it would probably be called System.Out because of the naming convention.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saed Hussein wrote:Why i'm studying inner classes is, Inner classes has subtopic of anonymous classes which are prerequisite to understand lambda expression as I think.

Anonymous inner classes are indeed a kind of inner classes. But are not required to understand lambda expressions. And although lambda expressions can (and will) definitely be used to replace anonymous inner class, you don't need to know about anonymous inner classes to understand (and create) simple lambda expressions (which is one of the OCA exam objectives).

Assume this (functional) interfaceYou could create a class which implements this interfaceOr you could create an instance of an anonymous inner class implementing this interfacePrior to Java 8, you had to create either a class (implementing this interface) or creating an instance of an anonymous inner class implementing this interface. And as you can see from the above code snippets, you have 5 lines of code, but only two lines are really important, 3 are utterly boring. Since Java 8 you could create a lambda expression and reduce it to one single, easy to read lineAnd as you can see from this code snippet, all 3 alternatives are equivalent and produce the same outputFrom the above code snippets, you could see the lambda expression (on line1) as a more concise way of class Concat. And class Concat is nothing more but a very simple class which implements an interface with just one method (which are all OCA exam objectives). So in my opinion there is no need to learn the tricky syntax of anonymous inner class (an OCP exam objective) to understand lambda expressions.

Hope it helps!
Kind regards,
Roel

Disclaimer: anonymous inner classes is not a topic of the OCA certification exam. I used them for demonstration purposes only. So if you don't understand what's happening, don't worry and just move on! Inner (or nested) classes (including anonymous inner classes) is an OCP exam objective.
 
Tim Holloway
Saloon Keeper
Posts: 18362
56
Android Eclipse IDE Linux
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Everything else aside, the clue is the name: "out". If it was a class (and named according to standards), it would have been named "Out" instead, because the convention is that class names start with a capital letter.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic