Wednesday, August 27, 2008

Tricky Java Code

Java class without main method:

class Main
{
static
{
System.out.println("This java program have run without the run method");
System.exit(0);
}
}

Java syntax quirk:

public class Oddity
{
public static void main(String[] args)
{
http://amadamala.blogger.com
System.out.println("Why is the URL allowed above?");
}
}

Ans:
----
http://amadamala.blogger.com == lable : // comment here
| |
| |
v v
http: //amadamala.blogger.com


References:
[1] http://www.java-tips.org/
[2] http://www.javapuzzlers.com/