0
votes

So i had this .java file named as 'anagram.java'. After compiling with javac the resultant .class file i get is named 'Anagram.class' (with a capital A) This may seem inconsequential but so far, I've managed to get the same name in both the code and compiled file. Would anyone know why this happened? You can see a picture of the commandline here

1
is your class called Anagram or anagram? - nneonneo
What's the name of the class in anagram.java? I'll bet it's Anagram (and not anagram). Thus the name of the .class file is Angram.class, not anagram.class, in spite of the source file being anagram.java rather than Anagram.java. In other words, the name of the .class file comes from the name of the class, not the name of the Java source file. - Kevin Anderson
.class file take up the name of the Class that contains the main method, so if it is class Anagram, it'll be Anagram.class - vicki
Oh right, I see. my class was named Anagram. That makes more sense but i had been under the impression that the main class has to have the same name as the source file. I'm surprised the code even ran. Thanks a lot for the help :) - ilaggy

1 Answers

2
votes

Note that javac is case-insensitive for Windows, but not for Linux, for example. Your class name in the anagram.java file is capitalized, i.e. it is class Anagram (as it should be), so javac is using this capitalized version to make your class file. In general, keep java filenames capitalized as well since it is convention, and depending on the operating system, javac may not work with discrepancies in capitalization.