public class ExampleEuroPound {
public static void main(String args[]){
String euro = "\u20ac";
String pound = "\u00a3";
System.out.println("pound = " + pound);
System.out.println("euro = " + euro);
}
}
Answer from Boris Pavlović on Stack Overflowpublic class ExampleEuroPound {
public static void main(String args[]){
String euro = "\u20ac";
String pound = "\u00a3";
System.out.println("pound = " + pound);
System.out.println("euro = " + euro);
}
}
If you can't type it then you could use the unicode value for euro:
String euro = "\u20AC";
System.out.println(euro);
If you're doing this however, best practice is to comment it and / or save it as a constant field for clarity (unexplained unicode literals in code are just plain confusing!):
public static final String POUND = "\u00A3";
public static final String EURO = "\u20AC";
If the question is just about the Euro sign getting garbled—that is, the program
import java.io.*;
public class Foo {
public static void main (String args[])
throws Exception
{
System.out.println("\u20ac");
}
}
Then, first you must read The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!).
Then you need to make the encoding that Java sends out match the encoding expected by the thing displaying Java’s output. I’m assuming you’re working at a command line.
On Linux this should just work. Everything is UTF-8 by default.
On the Mac, in Terminal.app, this won’t work because for some ridiculous reason the default text encoding for Java is the ancient MacRoman character set [Update: this shouldn’t still be a problem, I believe the default was fixed starting with Java 7] which doesn’t have the Euro. But Terminal.app totally supports UTF-8. Technically you can turn that off in Terminal → Preferences → Settings → Advanced → International, but it’s UTF-8 by default.
To set java to use UTF-8 output, you can pass the command line argument
java -Dfile.encoding=UTF-8 Foo
But that only works if you can control the startup of your program. If you’re sending JARs or .class files for others to run, that won’t work. You can set up the encoding yourself by creating an object that will write to System.out with a different encoding:
import java.io.*;
public class Foo {
public static void main (String args[])
throws Exception
{
PrintWriter out = new PrintWriter(
new OutputStreamWriter(System.out, "UTF-8"), true);
out.println("\u20ac");
}
}
So long as you remember to always use your new out variable for printing instead of System.out.
- On Windows it gets crazier. The default encoding at the command prompt varies between different language versions of Windows. On the English version of Windows, it’s Cp850. On Russian Windows, it’s Cp866. Neither has the Euro symbol! You can change the encoding with the
chcpcommand, but even if you change it to an encoding that does have the Euro symbol, the default command prompt font doesn’t have the Euro symbol!
You may be able to detect from Java that you are running at the Windows command prompt, change the encoding and font programmatically, and then output your string, but—that’s a lot of work. You’re probably better off just using the above code to force UTF-8 output, and include instructions with your code that if it is to be run at the Windows command prompt, that the user will first need to:
1. Run `chcp 65001` to switch the command prompt encoding to UTF-8
2. Switch the font to Lucida Console by clicking the icon in the upper left corner, selecting Properties, and going to the Font tab.
To make things easier for you, but to increase the chances that the code you write will work on your computer only, you can also change the default command prompt code page to UTF-8.

If the output is garbled, rather than a Euro sign, it's probably a problem with the console where you are running the program. Make sure it's capable of printing € and that the default character encoding for the platform matches the console's character encoding.
That's enconding issue. You will have to use unicode if you want to print euro symbol and anothers symbols.
Example of printing euro symbol with unicode
System.out.println("\u20ac");
However, check this question Displaying euro symbol using unicode and changing characters to uppercase and take a look of andrewdotn's answer, it's really well explained.
You should be able to use attempt 2, with one change: when using Charset.forName, you should not pass UTF-8 as the charset, but rather "Cp858" (given by the supported encodings documentation for Java). The encoding should be based on the codepage the printer expects, and the fact that the Java source is UTF-8 is not relevant to this conversion.
You may be using separate encoding. Browsers may be using UTF-8, Whereas adobe reader may be using ANSI or another localization of UTF. (Note these are not necessarily the encoding they use, just an example) so check your preferences, and try again.
You can use the actual UTF-8 Euro symbol which makes the code more readable.
private static final DecimalFormat EURO_FORMAT = new DecimalFormat("€0.00");
private String formatValue (double price){
return EURO_FORMAT.format(price);
}
But the java.util.NumberFormat is a better choice since you can use the Locale for the correct number format. In France, Germany and the Netherlands the comma is used instead of the decimal point before the cents. But the format for thousands is different. See below for an example:
public class NumberFormatLocaleExample {
public static void main(final String[] args) {
double price = 1249.69;
System.out.println(formatValueGermany(price));
System.out.println(formatValueFrance(price));
}
private static final NumberFormat EURO_FORMAT_GER = NumberFormat.getCurrencyInstance(Locale.GERMAN);
private static String formatValueGermany(double price){
return String.format("€%s", EURO_FORMAT_GER.format(price));
}
private static final NumberFormat EURO_FORMAT_FRANCE = NumberFormat.getCurrencyInstance(Locale.FRENCH);
private static String formatValueFrance(double price){
return String.format("€%s", EURO_FORMAT_FRANCE.format(price));
}
}