• Post Reply Bookmark Topic Watch Topic
  • New Topic

//$NON-NLS-1$  RSS feed

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Who in this world will ever utilize //$NON-NLS-1$ in their codes?

Is there any chance that hardcoded String literal cause a problem to the compiler or JVM?
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
better check it
 
Marshal
Posts: 56608
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pakawat Gibson LP:
Who in this world will ever utilize //$NON-NLS-1$ in their codes?

Is there any chance that hardcoded String literal cause a problem to the compiler or JVM?
No.

I looked up non-nls on Google, which you ought to do; it has to do with telling automated tools which Strings have and which have not been externalised.
Externalisation means telling the JVM to check a String whether it is identical to a literal anywhere in the String pool and if it is, to use that object. As a beginner you won't notice any difference.

And if you are a real beginner I suggest you abandon your IDE until are familiar with use of text editors and the command line.
 
Pakawat Gibson LP
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Cambell

'//$NON-NLS-1$' is actually inserted to my instruction by the IDE.

Before I can tell what's behind the scenes in the Java, I'd rather fade away from my IDE for a big while.
 
Campbell Ritchie
Marshal
Posts: 56608
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use Microsoft Notepad; if you are on Windows try Notepad2 or Notepad++ which support syntax highlighting and bracket matching, which make them much more useful for programming.
 
Greenhorn
Posts: 1
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Since this page comes up as one of the first links for a query of "non-nls" in Google, I figured that I should add some clarifications.

There seems to be some confusion here regarding the differences between externalization, internalization, and internationalization:

  • What was previously described--how Java creates a pool of strings, without duplicates--is internalization. Not externalization, as it was labelled.
  • Externalization is when most of the strings used by a program are stored in resource files, rather than compiled into the binary. This usually goes along with internationalization.
  • Internationalization is when a program supports multiple languages. The most common way of doing this is through externalization. The resource files can be swapped out based on the language.

$NON-NLS$ is specifically for externalization and internationalization. It marks a string as being inappropriate for externalization. Eclipse and potentially other IDEs can be configured to present warnings when strings are hardcoded into a program so that programmers remember to externalize. NLS stands for National Language Support.

On the topic of IDEs: new programmers should most definitely start off using tools that strictly enforce good programming practices. A good IDE will complain if you forget an @Override annotation, for example. Without IDEs, beginners will never acquire good programming ethics. When they finally do start using IDEs, they'll be more likely to be annoyed by the IDEs' warnings and disable them altogether, rather than change their programming styles.

On top of that, manually deleting .class files and running javac each time you need to compile an application is not a good programming practice. The same goes for basic batch scripts. Using tools like Ant for automated building--such as the implementation integrated into NetBeans, and with some extra effort, Eclipse--is a good programming practice. Until you know how to write build scripts from scratch, you should allow the IDE to do that part for you. Once you're ready, you can start messing with the pre-generated scripts. This way, when you're out in the "real world", using continuous integration servers that compile, test, and distribute for you, you'll already be used to the process, the tools, and the languages.

 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Paul, and thanks for your clarifications.
 
Rancher
Posts: 999
5
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Buonopane wrote:Without IDEs, beginners will never acquire good programming ethics. When they finally do start using IDEs, they'll be more likely to be annoyed by the IDEs' warnings and disable them altogether, rather than change their programming styles.



On the other hand when newbies begin with an IDE they run the danger of learning the IDE's intricacies and idiosynchrasies instead of learning java basics (source files, classes, directory hierarchy, options including the dreaded classpath etc.)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!