On the System.out.println line of code I get confused with the quotation marks and + sign and how to properly use a single quotation or double quotation. Can someone please explain when and how to use it properly and what does the code mean?
Using one System.out.println or print we can print multiple Strings and primitive types.
As a example
the output : string1-string2--1-2--c--3-4.
You can see in above example I have set to print multiple data types in a single print method on line 6. And I have used + to connect them each other. Therefor we can use + to connect various data types like strings and primitives to a single string.
And You can see in above example I have used '-' and "--" to define dashes. By using single quotations we can add only single characters.
As I use '-' represent single dash in above example. And if we try to define multiple symbols and characters like '--' in a single quotation it will be a reason to a complier error.
So to define multiple characters we have to use double quotations. Like I used in the example "--".
Actually it's not a function and it's not really System.out.println();
There is the System class, which represents the computer you are using. It has a static field called out, which is a PrintStream. So when you write System.out, you get your hands on out which you can find a bit more about here.
If you look up System.out, as I said, you find it is a PrintStream, and that link tells you it is println methods. You can click on those and find out more details. Alternatively, you can click one of the underlined PrintStream links, and you find lots more about it, and other methods you can use. So it's not simply System.out.println(). It's three things:
I didn't mean function as in a method or constructor, i just meant that it is a part of java..
And thanks ;]
Joined: Oct 13, 2005
Methods and constructors aren't functions either. A function gives one output (so a void method can't be a function), and really it should always be the same output for the same input. So a method like Math#log represents a function, and you find from the Java™ tutorials that a Map models a function.