File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is wrong with this?

 
Dustin Eldridge
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am going through the book Head First Java and thought I would do this little code piece for the practice but I get the error of

doobee.java:1: class DooBee is public, should be declared in a file named DooBee.java
public class DooBee {
^
1 error


This is my code I am trying to compile:

public class DooBee {

public static void main (String [] args) {
int x=1;
while (x<3) {
System.out.print ("Doo");
System.out.print ("Bee");
x=x+1;
}
if (x==3) {
System.out.print ("Do");
}
}
}
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33694
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dustin,
I think it is complaining because the case of "doobee" differs between the file name and the class definition.
 
Dustin Eldridge
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ding ding ding.

Thank you very much that was the answer. I dont recall the book saying anything about keeping the class file name the same as the declared class name. But if that is the case I will do that from now on. Thanks again and now I must get back to work.

Dustin
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dustin Eldridge:
...I dont recall the book saying anything about keeping the class file name the same as the declared class name. But if that is the case I will do that from now on...

This is required if the class or interface definition is public. There can be at most one public class or interface definition per file, and the file name must match that class or interface name exactly (case sensitive).

But a .java source file may contain additional class or interface definitions that are not public, and the file name does not need to match these.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic