• 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

Unicode Problem

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much.. Extremely Thank You.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And that does not have anything to do with Unicode.
 
Marshal
Posts: 79183
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79183
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Never realised there was that difference. Thank you.
 
I found a beautiful pie. And a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic