• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java File Name details

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
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?
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 Toad.java 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 ]
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It helps the compiler to locate the dependent java files which
also need to be compiled.
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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\Alice.java ~ 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\Alice.java 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic