This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes when and why we use FF and CR i,e.. \f and \r Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "when and why we use FF and CR i,e.. \f and \r" Watch "when and why we use FF and CR i,e.. \f and \r" New topic
Author

when and why we use FF and CR i,e.. \f and \r

Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 576

Hi,

When and why we use FF and CR i,e.. \f and \r?

Regards,
Narendranath


Cheers,
Naren
(OCEEJBD6, SCWCD5, SCDJWS, SCJP1.4 and Oracle SQL 1Z0-051)
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Printers recognize these. FF advances to the top of the next page. Back when we had terminals based on IBM typewriters you could send somebody a message (like IM) with a hundred form feeds and watch the paper fly across the room. Heh heh heh.

CR moves the print head to the beginning of the line without advancing to the next line. With impact printers you can overwrite the same text for bold, add underscores, etc.

I haven't tried either of these with modern printers or console apps. See if they do anything!


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343


NOTE: How these characters are interpreted depends on your environment. The above code works using a Windows 2000 Command Prompt.
[ June 02, 2005: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Now I'm on a Mac (whew, that's better). The above Spin.java code also works in Mac's Terminal (bash). In addition, the following code also works on a Mac, using the form feed character to display a slanted line of asterisks...

However, this code does not work in the Windows console, where the \f displays as a symbol instead of "feeding" to the next line.
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 576

Hi,

I got something out of your replies. Let me correct if I'm wrong in paraphrasing..

\r makes the control to come to the start of the line without going to next line

\f makes only to take the control to next line(next line or next page I'm not sure)

Now we can interpret \n as combination of \r\f

Thanks and Regards,
Narendranath
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by Naren Chivukula:
Hi,

I got something out of your replies. Let me correct if I'm wrong in paraphrasing..

\r makes the control to come to the start of the line without going to next line

\f makes only to take the control to next line(next line or next page I'm not sure)

Now we can interpret \n as combination of \r\f

Thanks and Regards,
Narendranath

Like the above posts all describe, the interpretation of these characters depend on what hardware you are using. I believe if you are sending data to a printer, then '\f' will start a new page. Typically, '\r' and '\n' are used in some combination to indicate a new line (meaning take the control to the first character in the next line). Once again, the exact interpretation depends on what operating system you are using. For example, Unix-based systems use '\n' to start a new line. However, DOS and Windows use a combination of "\r\n". (I can never remember which order they are in. Maybe it doesn't matter.) Traditionally, Macs use '\r' to start a new line. However, the newer versions of Mac OS are based on BSD which is a Unix-like operating system.

I hope this helps.

Layne


Java API Documentation
The Java Tutorial
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 576

Is that combination "\r\n" or "\r\f"?
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by Naren Chivukula:
Is that combination "\r\n" or "\r\f"?


It's "\r\n" or "\n\r". (I can never remember if the order actually matters.)

Layne
[ June 06, 2005: Message edited by: Layne Lund ]
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 576

Originally posted by Layne Lund:
It's "\r\n" or "\n\r"


You are mentioning the combination "\r\n". But, I mean to say that \n is the combination of "\r\f". Kindly observe the escape sequences carefully and reply me.

Thanks and Regards,
Narendranath
Timmy Marks
Ranch Hand

Joined: Dec 01, 2003
Posts: 226
You are mentioning the combination "\r\n". But, I mean to say that \n is the combination of "\r\f". Kindly observe the escape sequences carefully and reply me.



\f is called form feed, which on printers goes to the top of the next page.

\n is the newline character, which goes to the next line. Some OSes (along with Java) will go to the beginning of the next line with \n, some just go down a line. With OSes that only go down a line, you must combine the \n with a \r (AFAIK, order is unimportant).

So to answer your original question, a \n is not equivalent to \f\r.

By the way, this has all been said on the thread already.
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
Originally posted by Timmy Marks:



\f is called form feed, which on printers goes to the top of the next page.

\n is the newline character, which goes to the next line. Some OSes (along with Java) will go to the beginning of the next line with \n, some just go down a line. With OSes that only go down a line, you must combine the \n with a \r (AFAIK, order is unimportant).

So to answer your original question, a \n is not equivalent to \f\r.

By the way, this has all been said on the thread already.


This thread is being used as a reference to a recent thread and portrays fallacy.
\n is not a newline character, but a line feed (Unicode 4.0).
Some OSes, not including the Java platform, treat the line feed character as a newline character. Some OSes use a two character sequence(\r\n), a single carriage return (\r), and some OSes even use character(s) that are in the Unicode set, but not the ASCII set (since ASCII is a subset).

Java uses an abstraction from all of this by way of a system property called "line.separator", which resolves to a String (an abstraction from a sequence of characters). There are various core APIs which provide yet another abstraction that makes the detail of the existence of this system property transparent, for example, the java.io.PrintWriter.println(*) method.

http://jqa.tmorris.net/GetQAndA.action?qids=62&showAnswers=true


Tony Morris
Java Q&A (FAQ, Trivia)
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[Tony]: \n is not a newline character, but a line feed (Unicode 4.0).

And yet the relevant Unicode code chart clearly says that 000A is a line feed (LF) = new line (NL) = end of line (EOL). These three terms are apparently synonymous. Meanwhile pages 116-119 of the Unicode 4.1.0 standard (in Chapter 5) contradict this by using "newline" the way Tony does above - which is pretty much synonymous with the notion of "line separator" in Java. So, Unicode is contradictory on what a newline is. Unless we're supposed to distinguish between "new line" and "newline" - ugh. Better to avoid the term whenever possible I think. "Line feed" and "line separator" are both clear, but "newline"/"new line" is ambiguous.

Note that as far as I know, whenever the Sun Java documentation uses the term "newline", they mean \n, a line feed. Wrong or right, at least they seem to be consistent on this point. (If not, please let me know.) So for anyone reading Sun Java documentation, it's good to know what they mean by "newline", regardless of what it may mean in other contexts.

So: in the above thread, when Timmy says newline, he means a line feed, and when Tony says newline, he means a line separator. Likewise when Sun documentation says newline, it's a line feed, and when the Unicode standard says newline, it's a line separator - except of course when it's a line feed.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: when and why we use FF and CR i,e.. \f and \r
 
Similar Threads
linebreaks
How to run .java file from Runnable
Problem Using Bitmap Font In Text Area LWUIT
why does the file content created by RandomAccessFile.writeType method look weird
Can get the Form Feed "\f" to work!