• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 577
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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

Regards,
Narendranath
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 577
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Naren Chivukula
Ranch Hand
Posts: 577
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is that combination "\r\n" or "\r\f"?
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 577
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic