Hi , can any one explain me this code
public class Howcome {
public static void main(String[] args) {
System.out.println(“Bank of America”);
https://www.bankofamerica.com
System.out.println(“Online Banking”);
}

even though https:// BofA lyin as orphan string in between this codes compiles and executes fine..???

Dani AI

Generated

As pointed out, the stray URL in your source is not a string literal to the Java compiler — it gets parsed as a label plus a single-line comment, so the compiler ignores the rest of that line and the label simply attaches to the next statement. Concretely: https is a valid identifier, the colon (:) makes it a labeled statement, and the // that follows starts a comment so the remainder of the URL is skipped. That is why the program still compiles and you see both printouts.

Labels in Java have the form Identifier: Statement and can be used (rarely) with break or continue to affect outer loops. Labels bind to the very next statement, so whitespace and comments between the label and that statement are allowed. Example of a common, valid use of a label is breaking out of nested loops:

outer:
for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
        if (i == 1 && j == 1) break outer;
    }
}

To avoid accidental confusion: always post code in code tags (as suggested) so forum formatting does not turn your text into hyperlinks or replace straight quotes with “smart” quotes; put URLs inside string literals or explicit comments if you intend them to be data, e.g. String url = "https://example.com";; and expect some static analyzers to flag unused labels as confusing. For authoritative details on the lexical rules and labels see the Oracle tutorials on comments and labels: and .

Recommended Answers

All 4 Replies

Please post your code in code tags to preserve formatting and to show the real code without there being a hyperlink in the middle of it.

In java you can create a label to use with loops, break & continue statements. See for an example of how this works. The syntax for creating a label is an identifier, followed by a colon. Then remember that single-line comments in java start with //. So the code you asked about is interpreted as a label ("https:") and then a comment (//www.bankofamerica.com).

commented: very good +3

kramerd: that is so neat. Thanks for making my day! J

Thank you very much for replying... have a great day guys!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.