-
Class filename is different from Java filename
Hello,
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!");
System.exit(0);
}
}
When I typed in javac MyFirstProgram.java, 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 MyFirstProgram.java and my class file is called myFirstProgram.class. Why did it change the filename from "My" to "my"?
Thanks,
Eric
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks