Class filename is different from Java filename

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Class filename is different from Java filename

  1. #1
    Join Date
    May 2004

    Class filename is different from Java filename


    I have just tried to run a program in the command line. Here is the code:

    import javax.swing.*;
    class myFirstProgram
    public static void main(String[] arg)
    JOptionPane.showMessageDialog(null, "It works!");

    When I typed in javac, there was a short pause.

    Then I typed in java MyFirstProgram and I got an error that said something about "wrong name: myFirstProgram". So at the command line I typed java myFirstProgram and the program ran. So my java file is called and my class file is called myFirstProgram.class. Why did it change the filename from "My" to "my"?


  2. #2
    Join Date
    Sep 2004
    Couple of things here. Java is case sensitive, so since your class is named "myFirstProgram" it has to be called as "java myFirstProgram"..

    In the first scenario when you did "java MyFirstProgram" it was able to find the file just fine, but then the case didn't match with what you had in your class declaration.

    The reason "java myFirstProgram" works (even though the actual filename is capitalized), is the windows file system is not case sensitive.

    So java was able to locate the file, and then your class declaration matched up as well.

    An easy solution in your case would be to edit the .java file and change the class name to "MyFirstProgram". Class names are supposed to be capitalized anyway. Then recompile it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center