It gives an error "Could not find the main class: filename.java" How do I set the filename to be independent of the class names?
-
8Use a language other than Java? – Sergey Kalinichenko Feb 03 '12 at 18:48
-
2Why would you like to do that? If you elaborate more about the concrete problem for which you thought that ignoring the filename would be the solution, we may be able to propose the *right* solutions for that (there may not necessarily be any solution if the problem is just caused by developer's own ignorance or laziness, though). – BalusC Feb 03 '12 at 18:48
-
1Oh, please don't. That would mess with anybody ever looking at your code. – Dave Newton Feb 03 '12 at 18:49
-
3I would help if you elaborated a bit. What is "it"? What command do you execute? – JB Nizet Feb 03 '12 at 18:49
-
I keep version numbers in the filename. – nnn Feb 03 '12 at 18:52
-
Please don't edit new questions into your previous one. If you have additional unrelated questions, ask them separately. – eldarerathis Feb 03 '12 at 19:13
5 Answers
You can't ... In Java the file name has to match the name of the public class in the file
See Why are filenames in Java the same as the class name? for an explanation

- 1
- 1

- 6,702
- 1
- 22
- 25
-
-
1
-
Don't put multiple classes in the same file unless you have a good reason to. – Dodd10x Feb 03 '12 at 18:51
-
-
-
I hope you went with "one file per class" and not "make the others non-public" ... – klaustopher Feb 03 '12 at 18:57
Short Answer: You can't. One class per file is the java way. Accept that or find another language.
Longer Answer: You can but you probably don't want to.
If you have one public class and x number of non-public classes, you can put the all in the same file by nesting the non-public classes inside the public class. For example (in BlowFish.java):
public class BlowFish
{
class Hooty
{
}
class Sushi
{
}
}

- 37,124
- 11
- 56
- 82
maybe is into the manifesto file where you are defining this class as your main class

- 109
- 9
Sure you can. Just put version numbers in your classnames, as well.
Or keep the newest as the classname.java, with older versions getting version numbers.
Or drop the version numbers and use source code control.

- 8,968
- 3
- 34
- 47