aspose file tools*
The moose likes Beginning Java and the fly likes This code will work perfectly ... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "This code will work perfectly ..." Watch "This code will work perfectly ..." New topic
Author

This code will work perfectly ...

Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
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.


- Varun
Javan Li
Ranch Hand

Joined: Jul 24, 2002
Posts: 84
yeah, really very funny, but i wonder why??
Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1851
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

Joined: Jul 28, 2000
Posts: 1851
Any one knows this one!!!
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
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

Joined: May 30, 2002
Posts: 1400
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

Joined: Jul 28, 2000
Posts: 1851
Yes Varun you are right
I just forgot labels. Never used them!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: This code will work perfectly ...