Everybody needs break once in a while. If you're a hard-working student of the Java programming language, you should take time off to look at some programming language quirks — peculiar things you find in Java and other programming languages. Most of these quirks are amusing, and some of them are downright mind-boggling!

Obfuscated code

If you visit https://weblogs.java.net/blog/forax/archive/2006/10/obfuscated_java.html, you find one of the strangest Java programs ever written:

/*   Just Java
     Peter van der Linden
     April 1, 1996.

To the naked eye, the program looks like one big comment. And if you paste the code into an Eclipse editor, most of the code is green (meaning that it's part of a comment). When you run the code, nothing should happen. But looks are deceiving. When you run this code, the output is


This code is an example of an obfuscated program. An obfuscated program is one that's intentionally difficult for people to read and understand. There are two reasons for creating obfuscated code: (1) for fun, and (2) to keep other people from understanding your coding tricks and stealing your ideas.

Many commercial products can turn regular code into obfuscated code, but the most amusing examples come from people who write obfuscated code from scratch. For other examples of obfuscated Java code, visit Semantic Designs and the blog Note to self.

Surprising language behavior

Some languages have features that defy intuitions. The following example (and many others) are from stackoverflow.com.

function writeStuff()
  document.writeln('5' + 3)
  document.writeln('5' - 3)
<body onload="writeStuff()">

In this example, the lines between the <script> and </script> tags are JavaScript code. JavaScript has little to do with Java. (The names Java and JavaScript are similar only for historical reasons.) People use JavaScript primarily as a language for embedding code inside web pages.

In JavaScript, the expressions '5' + 3 and '5' - 3 are very similar, so you'd guess that the two expressions behave the same way. But it's just not so! If you visit this section's code in a web browser, you see


The plus sign concatenates the character 5 and the character 3; the minus sign subtracts the number 3 from the number 5. You'd never guess it!

Self-reproducing programs

A Quine is a program that outputs a copy of itself, despite the fact that it receives no input. The site The Quine Page is a repository for Quine examples. The site contains Quines in about 50 different programming languages. The following program (created by Bertram Felgenhauer) is almost a Quine — "almost," because to make it a Quine, you have to type the entire program on one line with no line breaks. (For the purposes of this article, the line breaks are present so you can see all the code at once.)

class S{public static void main(String[]a){
String s="class S{public static void main(String[]a){
String s=;char c=34;System.out.println
char c=34;System.out.println

The world of programming languages

You may hear some fresh faced programmers say that they want to learn to code in all the programming languages. Good Luck! There are thousands of computer programming languages. (You can see the influences that popular languages have on each other by visiting IBM.com.)

The page esolangs.org lists about 800 of the more obscure languages. Roughly one in ten of these languages were created as jokes. (The joke languages have their own special page at http://esolangs.org/wiki/Joke_language_list.)

One favorite language isn't in the Esolang list. It's the Unbounded Register Machine language which has only three statement types. You can add 1 to a variable, subtract 1 from a variable, or loop while a variable's value isn't zero.

while (myVar != 0) {

That's all you can do in the Unbounded Register Machine language. But here's the punch line: By combining statements, one after another, in this language, you can implement any strategy that you can implement in Java (or in any other general-purpose, industrial-strength programming language). For more information, visit Portland State University's page.