aspose file tools*
The moose likes Beginning Java and the fly likes what is wrong with this? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what is wrong with this?" Watch "what is wrong with this?" New topic
Author

what is wrong with this?

Dustin Eldridge
Greenhorn

Joined: Feb 04, 2008
Posts: 20
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30506
    
150

Dustin,
I think it is complaining because the case of "doobee" differs between the file name and the class definition.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Dustin Eldridge
Greenhorn

Joined: Feb 04, 2008
Posts: 20
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

Joined: Aug 31, 2004
Posts: 11343

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.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is wrong with this?