File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Source File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Source File" Watch "Source File" New topic
Author

Source File

Rana Thakur
Greenhorn

Joined: Feb 26, 2001
Posts: 26
"If there is no public class or interface defined within a source code file, then the file must take on a name that is different that its classes and interfaces."
However the fillowing code compiles and runs fine. Am I missing out something??
//File:: test.java
class test {
public static void main (String args[]){
System.out.println ("hello");
}
}
Bala Arul
Greenhorn

Joined: Feb 09, 2001
Posts: 29
Hi,
If there is no public class or interface defined in a source file, then the source file can get any name.
Arul.

Siva Prasad
Ranch Hand

Joined: Feb 22, 2001
Posts: 104
If you have two or more classes in a source file and one of them is public and the other or not, then the file name should the the class name which is declared as public.
If you try to declare more than one public class in a single source file, the compiler will give an error to write each public class in a different file.
Siva Prasad
Seema Das
Ranch Hand

Joined: Mar 05, 2001
Posts: 78
Hi Rana,
It looks like the file can take any name. It can be one of the class' name too. I tried following with Name.java and B.java and both ways it works fine.
class A {
int i;
}
class B {
int j;
}
class C {
int k;
}
Thanks
Rana Thakur
Greenhorn

Joined: Feb 26, 2001
Posts: 26
Hi,
Thanks. What was bugging me is that couple of places I read that
"If there is no public class or interface defined within a source code file, then the file must take on a name that is different that its classes and interfaces."
But it doesn't look like that. Guess I must have mixed up.
Thanks a lot to all of you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Source File
 
Similar Threads
What's wrong??
java concepts
source code file
more than one public class in a single file
source file?