aspose file tools*
The moose likes Beginning Java and the fly likes Unicode Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Unicode Problem" Watch "Unicode Problem" New topic
Author

Unicode Problem

Ranji Sura
Ranch Hand

Joined: Oct 28, 2012
Posts: 84


C H A P T E R 3
Lexical Structure

Line terminators are defined (§3.4) to support the different
conventions of existing host systems while maintaining consistent line numbers.



What does this mean in JLS ? Please help me to understand this...
Thank You..
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Different Operating Systems (OS X, *nix, Windows) have different 'symbols' for what constitutes the end of a line. There are two such symbols: the NewLine symbole (often call LF, and represented in Java Strings as "\n") and the CarriageReturn (CR, or "\r"). Some OSes (for example Windows) use both symbols in the order of CR LF ("\r\n") while others use just one symbol or the other.

What that sentence in the JLS is saying that it allows any of the 3 end-of-line conventions (CR, LF, or CR LF) to designate the end of a line of code, and that the line numbers will be consistent regardless of the convention used. For example, even though Windows uses two symbols for the end-of-line, the number of lines of code will still be counted as just one, not two.

This is important because it allows error messages to be reported the same way across platforms. For example if you take code with a compile error in it and copy it from Windows to Linux you would get the same reported line of code in the error message. So you know where the error occurs regardless of OS.


Steve
Ranji Sura
Ranch Hand

Joined: Oct 28, 2012
Posts: 84
Thank you very much.. Extremely Thank You.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14153
    
  18

And that does not have anything to do with Unicode.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38881
    
  23
There are actually six line terminators, which are listed in the Pattern class. You will encounter LF and CR‑LF frequently. CR alone was used by old Macs, but newer Macs use LF, as used by Unix and Linux. Windows® uses CR‑LF.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Campbell Ritchie wrote:There are actually six line terminators, which are listed in the Pattern class.

That may be true, but the line terminators recognized as such in the JLS for the purpose of ending code lines seem to be the three I had listed, not all six.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38881
    
  23
Never realised there was that difference. Thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unicode Problem