System.out.println("my name is"+Firstname+" "+Secondname); Explain what is the need of " " in the middle?

string Firstname="David",secondname="mohan";

10/13/2016 6:36:00 PM

Shafiya Nizam

9 Answers

New Answer


Hello Shafiya, if you did not insert the " ", your output would be: my name is Davidmohan. As you inserted the space, you will have: my name is David mohan. Actually you could have set your first string to "David ", so the output would already have the "space", or you could also set the second string to " mohan", which would give you the same result. Hope it helped.


the +" "+ is to insert a whitespace between first and last name. The blank space between the quotations is what you are inserting.


the " " is the statement you want to print as your out put. so when you run it, it should say: my name is David mohan


It adds a space. The alternitive would be to write something like: string firstname = "David "


you need a " + " and do it so String Firstname ="David", secondname ="mohan"; thats Looks mich better i think


It's just SPACE character!


The " " in between actually creates a new string without creating a new variable, which helps to save memory. The + sign between the variable and the string actually serves the purpose of concatenating the tow strings


Thats because to show the JVM to print it there "In between"


to give space