// sample-compile-error.java: THIS FILE DOES NOT COMPILE, ON PURPOSE. // Free sample from 99helpers.com/file-types/java // // It holds three of the most common javac errors, so you can check how an // editor, a CI job or a code viewer reports them. Fixed, the program only // prints two lines. // // Try it: javac sample-compile-error.java // Expected: 3 errors, and no .class file. // 1. "class Broken is public, should be declared in a file named // Broken.java". A public class must live in a file with its exact name. // Fix: remove `public`, or rename the file to Broken.java. public class Broken { static int half(int n) { // 2. "incompatible types: possible lossy conversion from double to // int". Dividing by 2.0 gives a double, which doesn't fit an int. // Fix: `return n / 2;` or `return (int) (n / 2.0);` return n / 2.0; } public static void main(String[] args) { System.out.println(half(10)); // 3. "cannot find symbol". Java is case-sensitive: the String method // is `length()`, and `Length()` doesn't exist. // Fix: `text.length()`. String text = "hello"; System.out.println(text.Length()); } }