Java Basics

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rsrinivasan
    New Member
    • Mar 2007
    • 221

    #1

    Java Basics

    Hi,
    Why we are always give the program name same as class name?


    Thanks,
    Srinivasan r
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    this is not compulsory.

    this is for our own convenience.
    actually that depends on ur IDE u r using.

    suppose u r developing an application having thousands of classes.
    if ur IDE allowed to have multiple classes with in a single java file .....then third party having ur packages will take time to analyze the package structure and all the java files.

    so this is not desirable in Software Developement.

    i think u got my point of view.
    This is nothing but programming convenience.

    best of luck.

    kind regards.

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by rsrinivasan
      Hi,
      Why we are always give the program name same as class name?


      Thanks,
      Srinivasan r
      I'm not sure what you mean by program name. If you mean java file name (just a guess) then it's not neccessary to give it the same name as the name of the class(es) that is/are in it. However, if you have a public class in a Java file, then it must be the only public class there and the name of the file must be the same as the name of that public class

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        If you have a public class A that refers to another public class B, javac needs
        the compiled version of class B when it compiles class A. If it can find a B.class
        file (either in the filing system, or a jar) if uses that file to check for correctness
        of class A (which it is compiling). When B.class is outdated, it needs to be
        recompiled. The only way javac can find the source file for class B is by its
        name: B.java. If it finds it it recompiles B.java to check whether or not A.java is
        correct. If class B where allowed to be stored in anything else but B.java, javac
        wouldn't be able to find it.

        The need for class X be stored in a file X.java is purely a compiler technicality.

        kind regards,

        Jos

        Comment

        • mariocb7
          New Member
          • May 2007
          • 1

          #5
          [QUOTE=rsrinivas an]Hi,
          Why we are always give the program name same as class name?


          Thanks,
          Srinivasan r[/QUOTE

          HI my name is brian I am trying to download JDK to window xp platform.

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by mariocb7
            HI my name is brian I am trying to download JDK to window xp platform.
            You do realize that you're hijacking someone else's thread do you? Hijacking
            threads is considered quite rude; start your own thread instead.

            For downloading the JDK visit: the Sun Java Site and download JDK 6u1.

            kind regards,

            Jos

            Comment

            • dmjpro
              Top Contributor
              • Jan 2007
              • 2476

              #7
              JosAH .. again an impressive answer u have ... Thanx

              what do u mean by outdated class?

              Plz answer.
              Kind Regards.

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #8
                Originally posted by dmjpro
                what do u mean by outdated class?
                If a compiled class X.class has a modification time stamp older than the
                modification time stamp of the X.java source file then the X.class file is
                outdated and X.java needs to be recompiled. The javac compiler does that all
                behind your back, i.e. it has a simple 'make' like functionality.

                kind regards,

                Jos

                Comment

                • dmjpro
                  Top Contributor
                  • Jan 2007
                  • 2476

                  #9
                  one more thing JosAH ......

                  i m working with J2EE technolgy for one year.
                  i have confusion right now .... does J2EE framework contain JAVAC?

                  how the web-container compiles a servlet file?
                  so here the javac required.

                  so if i change a .java file then we need not to recompile the java file if my servlet refers to that .java file.
                  but i need to recomile the .java file.

                  now the total thing is mess up.
                  plz help.
                  kind regards.

                  Comment

                  Working...