Hello Java community,
I recently encountered an issue where I named my Java class as Con, it took me a whole day to find out that there was no problem in my code but the name CON is forbidden to create a file in windows and since java create a file of all class my code was not running. This led to compilation errors,
Exception in thread "main" java.lang.NoClassDefFoundError: com/run/Con at PracticeFolder/com.run.Main.main(Main.java:11) Caused by: java.lang.ClassNotFoundException: com.run.Con at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526) ... 1 more
and this is the simple version of the code that caused me problem
class Con {
private int a=10;
public void show(){
System.out.println(a);
}
}
public class Main {
public static void main(String[] args) {
Con obj = new Con();
obj.show();
}
}
They could have handle the exception by creating a error that using Con name as class name is forbidden in windows.
I realized that such clashes could affect other developers as well.
I propose that Java tools (such as the compiler or IDEs) provide a warning when a class name matches a reserved Windows device name. This would help prevent unintentional conflicts and improve code portability across platforms.