[ACCEPTED]-Why classes compile to .class but interface does not to .interface-interface
Because the point is to indicate that the 2 file is Java byte code (and .class was the extension chosen 1 for that), not the specific language construction.
Java treats interfaces almost like classes, eg 14 they share the same namespace (you can't 13 have an interface that has the same name 12 as a class) and a compiled interface is 11 almost identical to a compiled abstract 10 class.
So it would not make any sense to 9 store them in a different format or with 8 a different file extension. On the contrary, this 7 would make many things harder. For example, when 6 you load a class or interface by name (Class.forName("my.class.name")) Java 5 does not know whether it is a class or an 4 interface. If there would be two different 3 extensions, Java would have try to find 2 a file "my/class/name.class" and then "my/class/name.interface", instead 1 of only trying the first one.
The physical representation of the byte-code on 3 the file system doesn't matter.
It's the 2 logical realization (whether class or interface) that 1 matters.
That's the way the language designers decided.
It 5 makes sense in several ways:
.class
files are a byproduct that you don't normally see or manipulate by hand.- The less different extensions a program uses, the easier it is to maintain.
- In many cases, there's no distinction in the code between a class and an interface, so it's logical that the binary files look alike.
Frankly, I can't 4 think of a good reason to have different 3 extensions for compiled classes and interfaces. Why 2 would it be important to distinguish between 1 them?
In java, you have source files, called .java 4 and binaries called .class. Its just a choice 3 of naming.
Also for java classes and interface's 2 don't differ that much (a class just contains 1 a lot of extra information like method bodies).
It is just a choice they made. I wouldn't 3 bother about it. It is a binary file anyway. One 2 way to think is "Even it is an interface 1 it is still in a file.java".
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.