Engineering Full Stack Apps with Java and JavaScript
You are allowed to put a label on any statement. Labels are given points in code mainly used along with goto in some other languages. Labels are rarely needed in Java, which lacks a goto statement like some other languages.
In java, labels are mainly used by break and continue statements which normally terminate or continue the innermost block.
outer:
for( i=0; i<10; i++ ){
for( j=10; j>0; j--){
if( j == 5 ) {
break outer; // exit entire loop
}
}
}
Many programmers strongly discourage the use of break and continue which are are leftovers from the days of C and should be avoided since they can make your code hard to read. However in many of the source codes of library functions in java, we can see their usage.
Question 1
Find the output:
public static void main(String[] args) {
System.out.print("before:");
http://www.google.com;
System.out.println(":after");
}
Answer 1
It simply prints before::after. The URL that appears in the middle of the program is a statement label (http:) followed by a line comment starting with // (//www.google.com;).