• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unicode Problem

 
Ranji Sura
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranji Sura
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much.. Extremely Thank You.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15459
42
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And that does not have anything to do with Unicode.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49865
71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49865
71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never realised there was that difference. Thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic