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.

Similar Messages

  • 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 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.

  • 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.

  • Why does FCP looses its source file reference when files are copied

    Why does FCP looses its source file reference when files are copied from another project??
    i have this happen all the time, I move all my media to another drive and files that originated in another project do not reconnect because they have lost there source?
    Any way to fix this mess? i am in the middle of reconnecting 400 files by hand one at a time!!!
    Thanks, mark

    Because you changed the file path. From one hard drive to another...the hard drive name is no doubt different, and then if you have the files in different folder structures then yeah, it will lose the connection to that media.
    Best thing to do is to clone your media drive, or name the other drive the same name, and keep the exact same file structure (folders in folders) as the original drive. Then you won't need to reconnect.
    Shane

  • FDM, How to replace the value of my source file inside BefFileImport

    Hi all,
    I want to edit some value that will need some validating inside the source file with some condition inside the source file.
    I know the easy way is to build the validation inside import script, but the import script usually will run for each row, if I put the logic inside it will make the performance slow, I assume, because every one row, it will open the file.
    So I try to do one time conversion, so I choose to put my logic inside BefFileImport VBScript, but after my script run, the value was not change, it still stick with old value.
    Need your help for this.
    the below example, I want to do
    Sub BefFileImport(strLoc, strCat, strPer, strFile)
    If InStr(strFile,"test123")>0 Then
    Location="C:\Oracle\FDMApp\SampleApp\Inbox\Batches\OpenBatch\"
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f1 = fso.OpenTextFile(Location & strFile, 1)
    Set str= CreateObject("System.Collections.ArrayList")
    Do Until f1.AtEndOfStream
      str.add f1.ReadLine
    Loop
    Set f1=Nothing
    Set f2 = fso.OpenTextFile(Location & strFile, 2)
    For Each dataLine In str
      tmp = Split(dataLine,";")
      value = valcheck(str,tmp(14),tmp(13), tmp(6), tmp(1))
      If  entityPartner = "" Then
      f2.WriteLine tmp(0) & ";" & tmp(1) & ";" & tmp(2) & ";" & tmp(3) & ";" & tmp(4) & ";" & tmp(14)
      Else
      f2.WriteLine tmp(0) & ";" & tmp(1) & ";" & tmp(2) & ";" & tmp(3) & ";" & tmp(4) & ";"& value
      End If
    Next
    Set f2=Nothing
    Set str=Nothing
    Set fso=Nothing
    End If
    End Sub
    Thanks
    Dedy

    Hi
    You can achieve this with virtual characteristics option. Code the logic in the customer exit program and it would work.
    Thanks & Regards
    8283

  • Whenever i try to download a rather large file i continue to get the "could not read source file" error. Tried new profile, uninstalling and looking for the compreg.dat file to delete nothing is working. Please help

    whenever i try to download a rather large file i continue to get the "could not read source file" error. Tried new profile, uninstalling and looking for the compreg.dat file to delete nothing is working. Please help

    Did you reinstall CS3 after CC?
    For that matter, doing an in-place upgrade on the OS is always a gamble with Adobe programs. Reinstalling all the versions you need, in order, would probably solve your problem.
    And you shouldn't need to save as IDML after opening the .inx in CC.

  • How do we change the name of a sound file once it is in the session?

    how do we change the name of a sound file once it is in the session?
    Thanks
    Steve z

    The only way that you can rename the audio file from within Audition is to do a Save As from the Waveform view AFAIAA. You can rename clips by clicking in the name box at the top of the Properties window or by right clicking on the clip and selecting Rename from the drop down menu (this will automatically open the Properties window if it isn't already open).

  • I am setting up a lab of imacs in a school.  I have successfully bound the imacs to our network and can log in using the windows account.  However, I cannot access my files.  Is there another step?

    I am setting up a lab of imacs in a school.  Our network is windows based using active directoy.  I have successfully bound the imacs to our network and can log in using the windows account.  However, I cannot access my files.  Is there another step?

    If the modem is also a router, either use the modem in bridge and run pppoe client on the TC.. that is assuming ADSL or similar eg vdsl. If it is cable service.. and the modem is a router, then bridge the TC.. go to internet page and select connect by ethernet and below that set connection sharing to bridge.
    Please tell us more about the modem if the above gives you issues.

  • 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>

  • "Windows cannot access the specified device,path, or file.You may not have the appropiate permission

    We subscribe to a service called "Vault" which provies its documents in encrypted PDFs using the etd format. As well as Digitial Editions we have Acrobat Reader 9 installed on our PCs (Windows XP,SP2). When a user tries to download any of the documents they are seeing the following error:
    "Windows cannot access the specified device,path, or file.You may not have the appropiate permissions to access the item."
    However, if they open Digitial Edtions (or have had it open at some point in the past) before they download the document it opens without any problems. We use ZEN works to manage our PCs, and we use something called Dynamic Local User (DLU) which means that when a students logs into a PC the user's local Windows account is created on the fly, and then when they log out it is then deleted. This means that they are effectively using Digitial Edtions for the first time everytime they log into a PC.
    As anyone else seen the above error? Also, is there a way of stopping it? What does Digital Editions do the first time it is opened? Are there registry keys that we can add, which emulates the opening of Digital Editions so it doesn't have to be opened first before we can download the Vault documents?
    Any advice/tips would be most welcome.

    Hi
    Some required information are needed for us to help you.
    Hi NabeelOmer,
    We wonder if you have taken any action such as system restore after this issue occurred.
    You might also try this command to restore your access control list.
    Run this command to navigate to the drive letter, example is D
    D:
    To reset all permissions, run this command
    icacls * /reset /t /c /q
    Visual Studio is a very invasive program and which provides the ability to enumerate projects and solutions for system, user should never try uninstalling it manually without any guidance.
    Visual Studio made changes for your whole system, if the file has been moved or deleted this error would occur.
    Since you mentioned that you get this error almost everywhere even in control panel. We suggest you repair/reinstall your Visual Studio first and check if it could be fixed.
    How to: Repair Visual Studio
    https://msdn.microsoft.com/en-us/library/aa983433%28v=vs.90%29.aspx?f=255&MSPPError=-2147217396
    Regards
    D. Wu

  • Panagon and MGETDOC Application:open a doc, the doc goes to .zip file instead of going to the doc directly

    Application: FileNet content SG (Panagon) and MGETDOC(Web application)
    Issue: when open a doc, the doc goes to .zip file instead of going to the doc directly. Only this issue happens for .xlsx,docs and pptx document.
    Note: On all client machine, we are using office 2007 and IE8 browser
    Cause: On 16<sup>th</sup> July 2013, . Net framework 4.5 is install on all our GI-D desktop machines. There after the issue is started .
    Application Background: Applications built on .net framework 1.1 and it can support up to 4.0 version on client machine to view the documents through panagon and MGETDOC application. Panagon (Filenet content services) is
    not supported in .net framework 4.5 and above.
    Work around: After I had troubleshooting and tested with one of our  system which has .net framework 4.5, IE8 does not support with HTML5 and tested with IE9 and Chrome, documents were able to open successfully.
    I had removed .Net framework 4.5 uninstalled and able to open the documents w/o any issue. And also we had give the work around as if the doc goes to zip file, they open the doc by removing the . zip extension and they can save it as .xlsx or docx file and
    they can able to open file.
    Please let us know if you there is a fix to export the files through framework 4.5 and do contact us if you need further details, we shall discuss on the same. Thank you for your support. Request you to email @
    [email protected]/[email protected]
    Candida

    Presumably you're using Safari?
    You can change that in Safari Preferences (at least in 5.0.3, might be different in 5.1.x)
    The checkbox at the bottom will do that for you. However! I strongly advise against permitting that; there have been, and no doubt will be again, malware that uses that to bypass authentication.
    Just select Desktop as the default download location so you don't have to dig for the files.

  • Hi, never used support before - here goes! My Mac G4 MDD no longer shows the start up hard drive icon. The one with all my files on! It shows the other 3 hard drive icons and boots up OK. Has my start up hard drive failed? Can it be fixed? Thanks.

    Hi, never used support before - here goes!
    My Mac G4 MDD no longer shows the start up hard drive icon. The one with all my files on!
    It shows the other 3 hard drive icons and boots up OK.
    Has my start up hard drive failed? Can it be fixed?
    Thanks.
    Machine Name: Power Mac G4
      Machine Model: PowerMac3,6
      CPU Type: PowerPC G4  (3.2)
      Number Of CPUs: 2
      CPU Speed: 1.25 GHz
      L2 Cache (per CPU): 256 KB
      L3 Cache (per CPU): 1 MB
      Memory: 2 GB
      Bus Speed: 167 MHz
      Boot ROM Version: 4.5.7f1

    Doesn't sound like any hard drive failure to me - more a Finder preference.
    Finder -> Preferences -> General -> Show these items on the desktop -> Hard disks
    The startup disk is sometimes treated differently from other disks (such as external and network disks) and I'm guessing this is a simple preference setting, although I might be wrong.

  • I've reinstalled OS X 10.7.5 using the Apple servers but my files were not erased, has the HD been reformatted and 10.7.5 reinstalled?

    I've reinstalled OS X 10.7.5 using the Apple servers but my files were not erased, has the HD been reformatted and 10.7.5 reinstalled?

    Reinstalling OS X does not erase your files.
    Compare
    OS X Lion: Reinstall Mac OS X
    and
    OS X Lion: Erase and reinstall Mac OS X - Apple Support

  • D750 Nikon are the camera raw or DNG file ready to work in the Raw format in Lightroom?

    D750 Nikon are the camera raw or DNG file ready to work in the Raw format in Lightroom?

    Crazy idea - do a site search for "D750"...

Maybe you are looking for