Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

This code will work perfectly ...

 
Varun Khanna
Ranch Hand
Posts: 1400
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I m just posting this code coz it looks funny,
-------------------------------------------------
public class Test{
public static void main(String args[]){
System.out.println("Hello");
http://www.javaranch.com
System.out.println("World");
}
}
------------------------------------------------
but it will compile and work perfectly,
at first glance many ppl may say it will give complilation error.
 
Javan Li
Ranch Hand
Posts: 84
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah, really very funny, but i wonder why??
 
Rahul Mahindrakar
Ranch Hand
Posts: 1868
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Varun the
//www.javaranch is a line comment so this part is fine
now why the compiler does not complain bout "http:" is a problem.
If you check out htt p: the compiler complains
if you check out abcde: the compiler does not complain
so word hanging that ends with a : will compile fine. The compiler will "ignore such lines"
Thus if you have in your program
public class Test{
public static void main(String args[]){
System.out.println("Hello");
http:
abc:
def:
jhi:
System.out.println("World");
}
}
Compiles fine!!!
 
Rahul Mahindrakar
Ranch Hand
Posts: 1868
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any one knows this one!!!
 
Varun Khanna
Ranch Hand
Posts: 1400
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah if u open this in any editor things will become simple and straight forward,
regarding "http:" compiler is treating it as a label, as we used for goto.
-Varun
 
Varun Khanna
Ranch Hand
Posts: 1400
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rahul Mahindrakar:
The compiler will "ignore such lines"

Compiler will not ignore,
This example may illustrate it:
-----------------------------------------
public class test{
public static void main(String args[]){
System.out.println("Hello");
http://www.javaranch.com
for(int i =1;i<10;i++){
System.out.println("World");
if(i==6)
break http;//Checkout this line
}
}
}
-----------------------------
if you remove http:..... it will not compile, compiler treats it as a valid label.
[ January 09, 2003: Message edited by: varun Khanna ]
 
Rahul Mahindrakar
Ranch Hand
Posts: 1868
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Varun you are right
I just forgot labels. Never used them!!!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic