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 publicfinal 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
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.
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
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!
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.
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.
Sometimes the only way things ever got fixed is because people became uncomfortable.
Their achilles heel is the noogie! Give them noogies tiny ad!