println method - what do the last 2 letters (l & n) stand for?
Asked Answered
R

5

17

I guess it's related to println()'s newline functionality ('\n'), but in abbreviated letter-based form, that would be nl rather than ln. Thank you for any comments.

Rollicking answered 25/11, 2013 at 9:47 Comment(4)
println - print line. Meaning it will use \n at the end of the printed line.Tolman
Its not asking to print new line but it prints the given line with \n at the end.Canoe
println - Print a line(a complete line, which is terminated with a new line character(default line separator) or the line separator property).Blate
If you got your answer, go ahead and accept it. Please do not add it to your question. It defeats the whole purpose of a Q&A if you're going to include the answer in your question itself. Or else, if you've something new to share with us(which hasn't been posted already), you can post a new answer to your own question also.Blate
B
25

It's historic.

Pascal had write and writeln.

write would output a string, leaving the cursor at the end of that string.

writeln (where ln was short for "line") would write a whole line of text and move the cursor to the start of the next line, typically by automatically appending a CRLF or some other OS-dependent control sequence.

Java inherited the abbreviation, but used print instead of write.

Bleachers answered 25/11, 2013 at 9:58 Comment(3)
I'll consider this in my future language. I'll call it maroun and marounln.Adept
just an example of bad naming IMHOEndplay
Really? When I learned Java, I first thought, that it is PrintIn() (with the upper case i) :-)Veda
D
3

Hi check if this is helpful..

http://docs.oracle.com/javase/7/docs/api/java/io/PrintStream.html

You can find it under the heading Class PrintStream

ln simply means LINE - it prints the character/string in a NEW LINE.

Disoperation answered 25/11, 2013 at 9:49 Comment(8)
This doesn't answer the question.Pattiepattin
Why not? He just wanted to know what ln stands for and a link to verify thatDisoperation
@Aishvarya agree, however I wouldn't post an answer but rather a comment to answer this question.Tolman
Hi check if this is helpful. - This really shouldn't be the first line of an answer, IMHO. It looks like a suggestion at the most.Blate
What he is saying is convincing, ln stands for Line not New Line, and that why its ln not nlRaviv
@R.J agree with you on that, it's confusing.Tolman
actually it doesn't print it in a new line. It ensures that the next output will appear on a new line.Bleachers
@Tolman Fair enough. Link only answers already on board now. And the last line might be some light yet OP him self proposed that :)Kazantzakis
S
1

println stands for printline.

There is nothing special about it :P It will print a new line instead of printing it on the same line.

Sheena answered 25/11, 2013 at 9:48 Comment(9)
A source would be welcome. OP asks what it stands for, and it's possible to find other hypothesis, like the fact "ln" looks like "\n".Pattiepattin
Referring to your edit - It will print a new line instead of printing it on the same line. Wrong. it'll print the line and end it with a new line character.Blate
@R.J According to docs.oracle.com/javase/7/docs/api/java/io/…, it will print the string and then invoke println() meaning it will print a new empty line.Sheena
The order is important here. If nothing is specified, it prints nothing(blank) and terminates it with the new line character.Blate
@dystroy IMO OP is just overthinking it. Confusing \n with nl or ln. In regards to his question of what "ln" stands for: it stands for line.Sheena
@dystroy the source is history - other languages used fooln to mean do foo followed by a move to next line operation.Bleachers
@Bleachers I know that. What I'm curious about is if historically "ln" stands for "\n" (like print + \n) or for an abbreviation of line. But that interesting part of the question is probably off-topic for SO.Pattiepattin
@dystroy no, it doesn't (and AFAIK cannot) stand for \n because that's a "C"ism, and Pascal had writeln before C existed.Bleachers
@Bleachers That's a damn good point there. I had totally forgotten the pascal literals (#13#10 wasn't it ?).Pattiepattin
C
0

println() method Terminates the current line by writing the line separator string. The line separator string is defined by the system property line.separator, and is not necessarily a single newline character ('\n').

 public void println() {
     newLine();
 }

Also, there are overloaded methods println(String s), println(Char c), println(Double d), println(Float f), println(Long l), println(int i), println(bool b).

Here is a link which gives all code.
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/io/PrintStream.java#PrintStream.println%28%29.

Carman answered 25/11, 2013 at 10:7 Comment(0)
C
0

println -> print line.

That means that it will print the line you gave it through the parameter, and goes with the cursor to the next line, waiting for another input.

Callipash answered 25/11, 2013 at 10:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.