Backend Development 8 min read

Eight Little‑Known Java Facts You Might Not Know

This article explores eight obscure Java language facts—from the unused goto keyword and integer caching to Unicode‑escaped comments, flexible array declarations, hidden object creation with new String, JVM instruction reordering, and a study showing most Java code adds little value—providing concise explanations and code examples for each.

Full-Stack Internet Architecture
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Eight Little‑Known Java Facts You Might Not Know

Inspired by a popular Chinese song about obscure characters, the article presents a collection of lesser‑known Java language quirks that can surprise developers.

1. goto is a reserved keyword in Java – although it appears in the keyword list, the language never uses it; developers can achieve similar jumps with a labeled break statement, as shown in the example:

label:
for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
        System.out.println("%i" + i + ",j" + j);
        if (i > j)
            break label;
    }
}

2. Integer values from -128 to 127 are cached – the IntegerCache class stores these values, so Integer.valueOf(100) returns a cached object while values outside the range create new instances. This explains why a == b is true for 100 but c == d is false for 200.

public static Integer valueOf(int i) {
    if (i >= IntegerCache.low && i <= IntegerCache.high)
        return IntegerCache.cache[i + (-IntegerCache.low)];
    return new Integer(i);
}

3. Unicode escapes are processed before comment removal – a comment containing \u000d is still interpreted, turning the line into executable code that prints "Hello World!".

public static void main(String[] args) {
    // \u000d System.out.println("Hello World!");
}

4. Array declarations are flexible – Java allows several syntaxes such as int[] arr; , int arr[]; , int[] arr[]; , and mixed declarations like int[] arr, arr2[]; , though the first form is preferred for clarity.

int[] arr;
int arr[];
int[] arr[];
int[] arr, arr2[];

5. new String("xyz") creates two objects – one in the heap and one in the string constant pool, unless the literal already exists in the pool, in which case only the heap object is created.

String str = new String("xyz");
String str = "xyz"; // only pool object if not present

6. JVM may reorder instructions – without data dependencies, the JIT can reorder bytecode, leading to surprising multithreaded results such as (0,0) in the provided example. Understanding the Java Memory Model, "as‑if‑serial" semantics, and happens‑before relationships helps explain this behavior.

public class PossibleReordering {
    static int x = 0, y = 0;
    static int a = 0, b = 0;
    public static void main(String[] args) throws InterruptedException {
        Thread one = new Thread(() -> { a = 1; x = b; });
        Thread other = new Thread(() -> { b = 1; y = a; });
        one.start();
        other.start();
        one.join();
        other.join();
        System.out.println("(" + x + "," + y + ")");
    }
}

7. A study of 100 million lines of Java code found that over 95 % of the code provides little value – a reminder that much of production code is boilerplate or low‑impact logic.

8. Conclusion – while these facts may seem trivial to seasoned developers, they reinforce solid fundamentals that can improve code readability, performance, and correctness in everyday Java programming.

JavaperformanceconcurrencyProgrammingMemorytipsLanguage
Full-Stack Internet Architecture
Written by

Full-Stack Internet Architecture

Introducing full-stack Internet architecture technologies centered on Java

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.