I can't figure out why DrJava won't output Unicode symbols
Asked Answered
K

3

23

I'd like to apologize upfront for my incredible newb-ness with regard to Java and programming in general. But I've searched everywhere for an answer to this and I just can't seem to find one.

So I'm simply trying to run the following:

public class WriteSquares2
{
  public static void main(String[] args)
  {
    for (int i=1; i<=10; i++)
    {
      System.out.println(i + " \u2261 " + (i % 7) + " modulo 7");
    }
  }
}

The Unicode character \u2261 is the congruence sign (≡). DrJava shows the following as output:

1 ? 1 modulo 7
2 ? 2 modulo 7
3 ? 3 modulo 7
4 ? 4 modulo 7
5 ? 5 modulo 7
6 ? 6 modulo 7
7 ? 0 modulo 7
8 ? 1 modulo 7
9 ? 2 modulo 7
10 ? 3 modulo 7

What's weirdest about this is that when I simply type

'\u2261'

into the Interactions box, I get the equivalence character in single quotes:

'≡'

I've tried simply putting '\u2261' in the code instead of " \u2261 ", but then I get stuff like this:

8803 modulo 7
8805 modulo 7
8807 modulo 7

I also tried just simply inserting the unicode character into the code, but that just gave an error message. Can anyone figure out what's going on or what I'm doing wrong? Your help is much appreciated.

[I should add that this isn't a homework assignment or anything, as our book barely even mentions Unicode - just trying to figure this out ... and when I started, I didn't think it would be this hard!]

EDIT: I'm using Mac OS 10.7.5 and Dr Java says its build is "drjava-20120818-r5686".

EDIT #2: Here's a screenshot using Monospaced 12 as my main font. It still shows up as question marks, even though I can get the console to return me the symbol if I type it in directly, but with single quotes.

enter image description here

Kirby answered 22/5, 2013 at 3:44 Comment(5)
It works for me without a problem when I checked in eclipse. Don't have drjava....Furthermost
It doesn't work for me when I checked in eclipse. Also don't have drjava; you're not alone :SYan
Perhaps the font used on your system does not have a glyph for that character?Sedgewinn
I think it is more related to the settings for the "terminal". For example, under Windows command prompt, if you are using a code page that do not contains the character you want, then character conversion will fail and give you a ?. Check your code page by chcp. Under Unix, similarly, it is affected by the locale settings. Check the LANG (do I remember it right?) env variable to make sure that the encoding contains the char you needIaria
@William I can type all the characters fine on my computer - for some reason they just won't show up in DrJava. I'd say that it's not allocating the fonts correctly or something? I'm not really a computer "geek" (in the positive sense) so I'm not very knowledgeable about much beyond the basic GUI. @ Adrian I should have added that I'm using a Mac... not quite sure if I understand your directions. Perhaps it's a Windows thing?Kirby
S
8

The issue has to do with the font you're using, it is not a problem with your code. See DrJava's settings under Edit > Preferences > Display Options > Fonts > Main Font.

DrJava using default font (Monospaced 12) on Linux: DrJava on Linux with "Main Font" set to default (Monospaced 12)

DrJava using a different font (PT Sans 12) on Linux: DrJava on Linux with "Main Font" set to "PT Sans 12"

Both screenshots are from the same instance of DrJava; I didn't even have to shut it down. Note that in the Interactions pane, the glyph is correct for my Monospaced font and is a generic placeholder for PT Sans. The same occurs in the Console tab (not shown).

Sedgewinn answered 22/5, 2013 at 6:36 Comment(4)
The specific monospaced font is DejaVu Sans Mono.Feltner
Thank you for the answer. It made sense to me and I thought it would work, but unfortunately, when I changed the font to Monospaced 12, I still got question marks in place of congruence symbols. Now I'm really not sure what's going on...Kirby
(I added a screenshot to my original post.)Kirby
My example was to show that it is likely a font glyph issue. "Monospaced 12" may map to different fonts on different platforms. Since my example was from a Linux machine and you're on OS X, you may need to try other fonts that are installed on your system.Sedgewinn
C
2

I did a bit research, and I found a solution that was found before from another question here

So in this case, it might be something similar. Not really your code, but the way DrJava handles unicode depending on your system.

" Character encoding depends on the system. Depending on your box, it may print the 16 bits of the UTF-16 encoding (which is 9794), the high 8 bits (which would be 38) or, as in your case, the low 8 bits (which is 66).

9794 / 256 = 38
9794 % 256 = 66

"

Carapace answered 15/5, 2017 at 16:40 Comment(0)
C
0

Have you changed your prompt to output in unicode.(note Java default in the english speaking world is IS0-8859-1).

Carbon answered 22/5, 2013 at 4:37 Comment(1)
I'm not sure what you mean. By prompt, do you mean in the Dr Java console window? I've looked in all the menus and found no mention of Unicode. It seems like such a simple thing...Kirby

© 2022 - 2024 — McMap. All rights reserved.