Why do IDEA and NetBeans give different output from my Java code?

I spend a lot of time using IDEA 11.1 or NetBeans 7.3 and switching between. So I like to be sure that they work in the way I expect and also give consistent results. I was intrigued to find that on my Mac, some tests gave slightly different output or each IDE….

Both of them are running the same JDK (1.7_07) with the same heap size. But my results were different. So I examined the changes and they were some altered text characters. The issue was that IDEA and NetBeans have been set to use different encodings for text characters on the Mac – NetBeans is on UTF8 while IDEA uses MacRoman encoding. Aligning them and bingo – I get identical results!

So it was a good reminder that there are other factors that can effect how your Java code works. Here are the 2 properties locations so you can align your values.

Do you have any tips for working with NetBeans and IDEA?

This post is part of our “NetBeans article Index” series. In these articles, we aim to explore NetBeans in different ways, from useful hint and tips, to our how-to’s, experiences and usage of the NetBeans IDE.

 

The following two tabs change content below.

Mark Stephens

System Architect and Lead Developer at IDRSolutions
Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

Related Posts:

Markee174

About Mark Stephens

Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

5 thoughts on “Why do IDEA and NetBeans give different output from my Java code?

  1. Frisian

    What sort of code did you write in the first place, that is dependent on the source file encoding?

    • I was writing out some test files which contain specific german text chars which map differently on UTF8 and MacRoman encoding.

      • Frisian

        Thanks, I see. That’s why encoding should always be made explicit when using streams in Java. Default encoding (and default locale, for that matter) are only for those, who enjoy a daily surprise…

  2. jack

    Your post is a bit deceiving.
    You should have mentioned in the first place you wrote some non-Latin characters in the files.
    Or you should try renaming the post…you have to read half of it to find out that it’s about characters encoding.

    • The whole point of the article was to remind people that there are several things like encoding which can lead to different results but which are easily overlooked. I did not know I had non latin characters until I drilled down to see what the problem was.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>