All posts tagged java

Java puzzle 2: Extra long Unicode literals

Another simple Java puzzle. Does the following code compile? If so, what does it do when you run it? public class Unicode { public static void main(String[] args) { System.out.println(“\uuuuuuuuuuuuuuuu0055″); } } Answer: Show ▼ It prints “U”. Unicode literals in Java are usually of the form \uxxxx, where xxxx is the hexadecimal form of […]

Java puzzle 1: fun with Loggers

I’ve been a fan of Java Puzzlers by Joshua Bloch and Neal Gafter since a colleague lent me a copy about a year ago. Every now and again, I come across weird things in Java that I think would make a good puzzle. In the spirit of Java Puzzlers, consider the following piece of code. […]

Is a random set of bytes a UTF-8 string?

UTF-8 is an encoding for Unicode text with several nice properties: Any Unicode string can be encoded For pure ASCII text (characters under 128), the UTF-8 encoded form is the same as the ASCII form It’s pretty well universally recognised as a text-interchange format on the Internet Random byte streams are unlikely to be misinterpreted […]