Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Windows device name such as Con as Java class name

Tags:

java

I am referring to my previous question but this time I used the java compiler and the compiler compiles the output- it gives a weird output. And this time I used this instead of super.

enter image description here

This is the code of the program.

class Con {
    int x = 10;
    Con() {
        this(2);
        System.out.println("x :" + x);
    }
    Con(int i) {
        x = i;
        System.out.println("x :" + x);
    }   
}

class DemoCon {
    public static void main(String args[]) {
        Con c1 = new Con();
    }
}

What do you think is the problem here? Is this a bug in Java?

Java version - 1.6.0 JDK

I used Eclipse to run the program and there is a Class not found exception. A.java is the file name... We did a minor edit and made a public class called A.java too but the results are same. We further found out that the problem lies in the compiler.

like image 844
Chan Avatar asked Nov 28 '22 14:11

Chan


2 Answers

On Windows it seems CON is reserved name and cannot be used for folders/directories or filenames.

The following

print "test" > Con.java

is not working.

Therefor the compiler is unable to create your Con.class and crashes.

From MSDN:

Do not use the following reserved device names for the name of a file:

CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9. Also avoid these names followed immediately by an extension; for example, NUL.txt is not recommended

like image 162
Vlad Avatar answered Dec 15 '22 23:12

Vlad


perhaps the problem exists because CON is a reserved file name (it was on MS-DOS -- see http://support.microsoft.com/kb/31157 http://www.computerhope.com/copyhlp.htm)

like image 27
BertNase Avatar answered Dec 16 '22 01:12

BertNase