Why File Name is Same Name as The Public Class Name

Hi Friends,
What is the reason for Naming the File Name is puvlic class name??
thanks in advance.

konstkaras wrote:
What could be reason to give it other name?
It's as much better as we have less distinct names.
When I was a schoolboy, I programmed Turbo Pascal. Each program there had a name (declared in file's beginning). The name was never used, but: it has no such restriction of length (as MS-DOS file names had) and it could clash with other identifiers described in code.
So why those names should be distinct?Java was invented after MSDOS was obsolete, so 8.3 limits were not a consideration.
Java is designed for larger programs than were attempted in the MSDOS era, so supports compilation of programs which are created from many source files. Turbo Pascal 4 also supported separate compilation units, and did use the name you mention for exactly that purpose, but I can't remember how it dealt with dependencies between compilation units.
Having the public class' name and package as component in the source file path and the class file path simplifies the dependency problem between the compilation units - all the compiler has to do to determine whether the foo.bar.Baz class needs updating is to look whether foo/bar/Baz.class exists, and if it is less recently modified than foo/bar/Baz.java.

Similar Messages

  • Why the name of our source file should be same as the 'public class'  name

    Hi all,
    I am very new in java and have a question in my mind.
    I read somewhere , our souce file name should be same as public class in that file.
    but i don't know the reason for this.
    Can anybody help me out with this .
    Thanks,

    HMRPanchal wrote:
    Thanks,
    Can you give me some link or documents from where I can go through this article.
    because I am not clear with what you are saying( makefiles , automatic recompilation etc).
    I am a new in Java .The fact that you don't have to worry about those things is what makes it A Good Thing.

  • Public class name same as file name

    Why should the public class name be same as the file name in which it is written?
    http://forum.java.sun.com/thread.jspa?threadID=198585&messageID=657978
    The above thread says it is because it makes the compilation faster. is that the only reason?
    Thank you.

    That's specified in the JLS. See � 7.6, Top Level Type Declarations.
    <i>
    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. <b>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.</b>
    When packages are stored in a database (�7.2.2), the host system must not
    impose such restrictions.
    </i>

  • Why public class name should be same as the java file name

    Hi,
    I would like to know, why public class name should be same as the its java file name. Iam in the process of finding the answer to this question. Can someone help me out in finding the explanation.
    Thanks in advance,
    Manoj

    This is a requirement of the Java reference compiler released by Sun. I have used compilers that did not require this, but most seem to follow the reference compiler (which is a very good idea). I am NOT sure if this is specified in the Java Language Specification. Some of the other regulars who are more familiar with the JLS than I may be able to tell you.
    ? {?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Why it is necessary that public class name should  same as filename in java

    hi,
    why it is necessary that public class name should same as filename in java.
    As I know that it is a convention, but I want the information why this convention is made.
    thanx.

    user13445117 wrote:
    but suppose if i am creating a java file with default access modifire then we do not need to save the file name as a class name.So, your question is "Why does the rule about top-level classes being in a file of the same name apply +only+ to public classes"?
    If it were applied to all classes, then we could never have two top-level classes in the same file. Doing that is generally not a good idea, but it might be useful from time to time. EJP already told you why it applies to public classes, and, since these are the most common by far, it's a fair compromise that it apply to them but not to other classes.
    Was this the reason the original designers did it that way 15 or so years ago? Don't know, don't care, but it's one plausible explanation. Maybe it was just a balance between simplicity and clarity on the one hand, and flexibility on the other.
    It's certainly not something I can see caring that much about, unless you're doing an in-depth history on Java, or writing an in-depth treatise on computer language and compiler theory.

  • I had renamed my user login name and assumed that there will be no change in the settings and files. When I login with the new profile name everything is gone. How can I get back all my files and settings?

    I had renamed my user login name and assumed that there will be no change in the settings and files. When I login with the new profile name everything is gone. How can I get back all my files and settings? Please help. Thanks.

    You should have asked this before you tried: Changing username or short name- User Account and Short Name- OS X- How to change user account name or home directory name.

  • Public class name same as filename

    Every book I've read stated that if you have a public class declared in the source file, then you have to name the file the same as the class name. However, none of the book explain why, can anyone tell me about this?

    Not all public classes need to have the same name as the file that contains them -- only top-level public classes. Public nested classes can have a name that's different from the filename.
    Also, not only do top-level public classes need to have the same name as the file that contains them, but the names of the package and the directory structure must match as well.
    This is done simply so that if you see a class named com.mycompany.mypackage.MyClass referred to somewhere, you know that the source code is in the file com/mycompany/mypackage/MyClass.java. Isn't that helpful? ;-)

  • How to get the current class name in static method?

    Hi,
    I'd like to get the current class name in a static method. This class is intended to be extended. So I would expect that the subclass need not to override this method and at the runtime, the method can get the subclass name.
    getClass() doesn't work, because it is not a static method.
    I would suggest Java to make getClass() static. It makes sense.
    But in the mean time, does anybody give an idea to work around it?
    Thank you,
    Bill

    Why not create an instance in a static method and use getClass() of the instance?
    public class Test {
       public static Class getClassName() {
          return new Test().getClass();

  • Is it possible to get the main class name in a Thread context ?

    for example, i want to get the main class name (the first entry of the program).
    public class Test implements Runnable {
         public Test() {}
         public static void main(String[] args) {
              new Thread(new Test()).start();
         public void run() {
              try {
                   //Want to get the main class name (not the current class name)
                   throw new Throwable();
              } catch (Throwable e) {
                   e.printStackTrace();
    }

    Acutally, i wanna make clear about the concept of a "Thread"
    Is it true that ..
    the main() method is a thread , once I create another thread in the program , both of (or all of them) will contains it owns stack exception information ?
    My english is poor, please try to understand it. Thx

  • Finding the standard class name using methods

    hi experts,
                     How to find out the standard class if you have methods.for example i know a method name, so i want to know its class name.How to achieve that??

    Hi ,
    Go to transaction SE84. Repository Info system.
    CLASS LIBRARY -> METHODS .  Search as you like.

  • What's the WMI class name to get Client Approval status

    What's the WMI class name to get Client Approval status.
    Unfortunately the below example with class "SMS_R_System" does not have the approval status
    Get-WmiObject -Namespace "root\sms\site_LAB" -Class SMS_R_System | fl *
    I listed all the available classes and... yeah It's going to take along time to go though all the possibilities.
    Note: I'm running this in powershell on the primary first
    If anyone knows it... I'd appreciate your help

    This is all still in the testing phase so I'm not sure this is the best solution... but here's my problem and idea to resolve it.
    Currently in our environment OSD can only be run against unknown computers and approved clients.
    I currently automatically approve all clients in a trusted domain. So all systems that succeed OSD and auto join the domain are approved and I can always run OSD against those machines in the future.
    Problem is with the systems that fail OSD for any reason and therefore do not automatically join the domain. They end up getting a SCCM record by the name of "Unknown" and therefore cannot run OSD again until the "Unknown" record
    is deleted. "Unknown" records happen too frequently to manually delete and I'm not too comfortable with just deleting ALL of them on a scheduled basis.
    Additionally there are way too many OU's in my environment to automatically join our OSD'd systems to the domain. So I have a script that checks using a prestart command to see if the system is already in AD, and if so then OSD continues and simply
    joins the machine to the domain in it's current OU. If not the tech is given a nasty error message telling them to add the computer object in AD in the proper OU first.
    I intend to check , with a Prestart Command if the current system already has a record in SCCM and delete it if found AND is not approved yet. This should resolve the "There are no task sequences available" error I get with
    systems that have an "Unknown" SCCM record.
    In this way the system will be essentially approved if the system was already prestaged in AD manually by a technician and any "unknown" record for that system will simply be deleted at the point of OSD.
    Note: Although I can easily use the new SCCM Powershell cmdlettts and get the "Approved" status, I need to do all of this in WinPE without the cmdletts. If this property is not available via WMI, then I'm guessing this will not work.

  • How to change the public display name?

    How to change the public display name since the last person left the job and I am not new person take it.

    Hello,
    The TechNet Wiki Forum is a place for the TechNet Wiki Community to engage, question, organize, debate, help, influence and foster the TechNet Wiki content, platform and Community.
    Please note that this forum exists to discuss TechNet Wiki as a technology/application.
    As it's off-topic here, I am moving the question to the
    MSDN and TechNet Profile and Recognition System forum.
    Karl
    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
    My Blog: Unlock PowerShell
    My Book:
    Windows PowerShell 2.0 Bible
    My E-mail: -join ('6F6C646B61726C406F75746C6F6F6B2E636F6D'-split'(?<=\G.{2})'|%{if($_){[char][int]"0x$_"}})

  • Hi, I have the DPS Single Edition is but the Folio Producer public when the folio I alone was deprived. Why? How do I publish for the public? Thank You

    Hi, I have the DPS Single Edition is but the Folio Producer public when the folio I alone was deprived. Why? How do I publish for the public? Thank You

    You should look at our Single Edition publishing guide. You don't use Folio Producer with Single Edition. http://help.adobe.com/en_US/ppcompdoc/Step_by_step_guide_to_dps_se.pdf
    Note that support for Single Edition in Creative Cloud ends on May 1st. Make sure you get your app completed and approved by Apple before then.
    Neil

  • Why a public class name and file name same?

    All of us know that, a public class should be declared in a file which has the same name of that class. What is the underlying concept behind this..Can someone give a clear explanation?
    Thanx..
    Sandeep Joseph
    Paragon Solutions
    [email protected]

    Another issue, it was said that the file must be named
    after the class to find the class's code when
    compiling dependent classes. Doesn't this apply to
    non-public classes too (with the dependent class being
    located in the same package)?This applies to all top-level classes ...
    You can define multiple classes in one file though:
    class A {
    class B {
    }It's perfectly valid to have both classes defined in the same file (named A.java if A is the first class to be defined in that file).
    You will get a compiler warning as soon as you reference a non-top-level class from a class that is defined in another file, though.

  • How to force my Wiki Page Title to get the same value as the wiki page Name

    I am working on an enterprise wiki site collection, and currently each wiki Page will have two properties that seems confusing; Name & Title.
    While the default edit form allow to edit the Wiki Page Name only , it does not provide a way to edit the Title.
    So my question is about how I can update the Wiki Page title to be always equal to the Wiki Page name that the user enters?
    For example when I first create a wiki page I miss-spell the word “Bookmark”, so I wrote the following for the wiki page name:-
    Add Bokkmarks Within a Wiki Page.
    Then I edit the page and I change the name to have a correct spelling, so currently I got the following , where the title is still having the wrong spelling:-
    So that why I am want to find a way to always update the page title to be equal to the page name? can anyone advice on this please?
    Thanks

    Hi
    You can add custom event handlers for doing the same
    The details can be referred in the links
    http://www.c-sharpcorner.com/uploadfile/Chandresh.P/implementing-event-handler-in-sharepoint/
    http://blogs.msdn.com/b/brianwilson/archive/2007/03/05/part-1-event-handlers-everything-you-need-to-know-about-microsoft-office-sharepoint-portal-server-moss-event-handlers.aspx
    Thanks
    Girish
    so is there an option in sharepoint that allow me to set the value of a site column to be equal to another value ,, without having to write code ?

Maybe you are looking for