Accepted answer

they silence a warning that eclipse emits when it encounters string literals (and has been configured to complain).

the idea is that ui messages should not be embedded as string literals, but rather sourced from a resource file (so that they can be translated, proofed, etc). consequently, eclipse can be configured to detect string literals, so that you don't accidentally have leave unexternalized ui strings in the code; however, there are strings which should not be externalized (such as regexps) and so, //$non-nls-1$ gives you a way to communicate that fact to the compiler.


it tells the compiler not to complain about a non externalized string, and that it doesn't require localization.


it's used by eclipse to indicate that a string doesn't need to be translated, probably because it's not going to be seen by the application's users.


if you are an android developer. all strings the user may see should be in the resource file /res/values/strings.xml to read strings.xml file in the code you use r.string.. by adding the tag //$non-nls-$ you are noting that the string will not be seen by users.

the warning in eclipse helios may be turned on at window -> preferences -> java -> compiler -> code style -> "non-externalized strings (missing/unused &non-nls$ tag).

if you are planning on programming your activity to be multi-language, it would be recommended to turn this on. and then adding the &non-nls$ tag to strings that are internal to you activity. eclipse will add &non-nls$ tag in the quick-fix if you right click on the warning or error.


non-nls means non-national language support.
wikipedia proposes also non-native language support (nls) but this last one is not very used.

nls is about internationalizing your application. eclipse help to locate hard-coded strings in your code. to indicate a string is not part of the internationalization, append the comment //$non-nls-x$ where x is the position of the string. on the following example both "!" are hard-coded strings not part of the internationalization:

 public string foo(string key) { 
   return "!" + key + "!"; //$non-nls-1$ //$non-nls-2$ 


  • the leading // is necessary each time
  • no global $non-nls$ for multiple strings within the same line
    (e.g. if your line has six strings, you have to write six times //$non-nls-x$)

the book emf: eclipse modeling framework at page 250 says:

non-nls markers— eclipse's java compiler has the ability to flag non-externalized strings as a warning or error, in order to facilitate enablement of national language support (nls). emf-generated code does not use hard coded strings for messages that the user will see; however, string literals do appear frequently, for example, as keys for lookup of externalized strings in a property file. this property controls whether to include comments that mark those literals as non-translatable, so that the compiler will not flag them.

for more details see also the pages the generator gui and how to internationalize your eclipse plug-in.

you can enable/disable this feature. on eclipse neon go to
project > properties > java compiler > errors/warnings
and select the field
non-externalized strings (missing/unused $non-nls$ tag)

window of the project properties on eclipse


the string is not translatable. it tells the eclipse editor to not flag the string as unresourced. this is important for multilingual applications.

Related Query

More Query from same tag