This file induces the top 20 error messages in Java. This particular example was prepared by Byron Hart. The version I created for the anti-patterns survey was unforuntely deleted before being archived. To produce the desired error message, uncomment the problematic line of code.
Created
February 21, 2025 11:15
-
-
Save eddieantonio/e200db878745cfbe3ccefd04a62b9b64 to your computer and use it in GitHub Desktop.
Induce top 20 Java errors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//package x does not exist | |
//import x.*; | |
public class Main { | |
//public Main(){ | |
//} | |
public static void main(String[] args) { | |
//int x = 10 | |
if (1 > 0) | |
int y = 10; | |
Math.pow(2, 3); | |
//’;’ expected | |
//System.out.println("Hello world!") | |
//’(’ expected | |
//if 2<3) { | |
//System.out.println(2); | |
//} | |
//’)' expected | |
//if (2<3 { | |
//System.out.println(2); | |
//} | |
//cannot find symbol - class Integerx | |
//Integerx x = new Integerx(); | |
//cannot find symbol - method noMethod() | |
//noMethod(); | |
//cannot find symbol - variable x | |
//System.out.println(x); | |
//’.class’ expected | |
//int one = 1; | |
//int two = int one; | |
//constructor Main in class Main cannot be applied to given types... | |
//Main badCon = new Main(3); | |
//illegal start of expression | |
//public int three = 5; | |
//incompatible types: String cannot be converted to java.lang.Double | |
//String def = "Hi"; | |
//Double cast = (Double) def; | |
//non-static method nonStatic() cannot be referenced from a static context | |
//nonStatic(); | |
//not a statement | |
//2<3; | |
//variable i is already defined in method main() | |
//int def = 20; | |
//String def = "Hello"; | |
} | |
//<identifier> expected | |
//x; | |
//illegal start of type | |
//return 2; | |
//invalid method declaration; return type required | |
//public noType(){ | |
//System.out.println("LOL"); | |
//} | |
//missing return statement | |
//public int noReturn() { | |
//System.out.println("Nope."); | |
//} | |
//non-static method nonStatic() cannot be referenced from a static context | |
//public int nonStatic(){ | |
//return 1; | |
//} | |
} | |
//class, interface, or enum expected | |
//return 2; | |
//reached end of file while parsing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment