aspose file tools
The moose likes Java in General and the fly likes Java File Name details Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Meteor in Action this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java File Name details" Watch "Java File Name details" New topic

Java File Name details

Mano haran

Joined: Nov 30, 2006
Posts: 15
what is the internal need for a java filename should have same name as
the class name, which have the main method?.

is there any special reason over there?
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
Originally posted by Mano haran:
..what is the internal need for a java filename should have same name as the class name, which have the main method?.

It just has to do with keeping large projects organized.

Mine is getting very bulky right about now and I need to get straight on package/directory naming conventions.

I see telltales all throughout Java that are the tracks of someone trying to run a large project, Java or otherwise.

"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
prateek chaudhari

Joined: Oct 14, 2006
Posts: 11
Actually In java The Filename should match with the Public class inside that filename, Not with the class which has main method.

This is a requirement of the Java reference compiler released by Sun.

And this is the reason what I found on SDN network, which says

it's in the JLS. Section 7.6:
"When packages are stored in a file system (�7.2.1), the host system may choose to enforce the restriction that it is a compile-time error if a type is not found in a file under a name composed of the type name plus an extension (such as .java or .jav) if either of the following is true:

* The type is referred to by code in other compilation units of the package in which the type is declared.
* The type is declared public (and therefore is potentially accessible from code in other packages).

This restriction implies that there must be at most one such type per compilation unit. This restriction makes it easy for a compiler for the Java programming language or an implementation of the Java virtual machine to find a named class within a package; for example, the source code for a public type wet.sprocket.Toad would be found in a file in the directory wet/sprocket, and the corresponding object code would be found in the file Toad.class in the same directory."
[ June 11, 2007: Message edited by: prateek chaudhari ]

Prateek<br />SCJP 1.5
Pravin Jain
Ranch Hand

Joined: May 20, 2007
Posts: 60
It helps the compiler to locate the dependent java files which
also need to be compiled.

The Zen of Java Programming.
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
Originally posted by prateek chaudhari:
... as posted ...

Since you seem to have this well in hand.

I call my business Belvedere. ( Named after the 1958 Plymouth Belvedere ) My (pet project) is called Alice. The main() class for Alice is now: N:\Alice\ ~ the first line of that file is package Belvedere; "\r" Say I want to move everything over to the ubiquitous   C:\   attachment point. I call the class Alice because it is part of the contract specifications that only baccalaureate grads with field experience will have access to the program, and that they will read the documentation for the program before using it.

Based on my reading, "wet/sprocket" would be appropriate for Toadie the Roadie, but I should create a directory named Alice and change the package names to Alice or or create a directory name Belvedere ( belvedere ?) Belvedere would be a master name that would never be the name of a Program, Class or Java Source File.

The size of N:\Alice\ is 30.5 MB (32,034,152 bytes), so it is well past the point I should have corrected this. There are numerous sub-packages that do various things and I have becomed accustomed (adj. Frequently practiced, used, or experienced; ) to using these package names while writing in Java.
I agree. Here's the link:
subject: Java File Name details