Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Java (http://www.programmingforums.org/forum17.html)
-   -   Naming Rules (http://www.programmingforums.org/showthread.php?t=13570)

357mag Jul 16th, 2007 3:24 PM

Naming Rules
 
I thought that the name of your class must be the same as the name of your project or file. I'm using JDeveloper and I just named a project "Gears of War." Then I named my class "GearsOfWarBaby", and I expected it to fail but it ran just fine. I don't get it.

titaniumdecoy Jul 16th, 2007 3:51 PM

The code for a class must be in a file with the same name; eg, the code for the class GearsOfWarBaby must be in a file named GearsOfWarBaby.java. A project in an IDE such as JDeveloper may contain many such files.

357mag Jul 16th, 2007 6:23 PM

Okay after expanding the nodes it looks like there is a file called GearsOfWarBaby that has a .java extension after it. That must be it then?
But it looks like I can name my program/project anything I want. I can even put a space between the words like Gears of War.

lectricpharaoh Jul 16th, 2007 6:55 PM

Quote:

Originally Posted by 357mag
Okay after expanding the nodes it looks like there is a file called GearsOfWarBaby that has a .java extension after it. That must be it then?

Yup. The only rule is that your source file's name, before the .java extension, must exactly match the outermost class in that file. Of course, you can't have spaces or certain characters such as dashes; even though the file system might allow such characters, they are not allowed as part of Java symbols (including class names). Therefore, your file must match accordingly.
Quote:

Originally Posted by 357mag
But it looks like I can name my program/project anything I want. I can even put a space between the words like Gears of War.

The files associated with your IDE, such as project files, workspace files, configuration files (for the editor font size, tab distance, etc) have nothing to do with Java. You could erase them and compile your source files from the command line with javac.


All times are GMT -5. The time now is 4:22 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC