methods and construtors

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pattanaikhr
    New Member
    • Mar 2007
    • 8

    methods and construtors

    How can we get methods name and costructors name from java class before compilation?Ple ase any body have any idea plaese share with me
  • hirak1984
    Contributor
    • Jan 2007
    • 316

    #2
    [font=Verdana][size=2]question not clear at all.What are you trying to do please explain in details.[/size][/font]
    Originally posted by pattanaikhr
    How can we get methods name and costructors name from java class before compilation?Ple ase any body have any idea plaese share with me

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by pattanaikhr
      How can we get methods name and costructors name from java class before compilation?Ple ase any body have any idea plaese share with me
      Please expalin what you mean by "before compilation".

      Comment

      • pattanaikhr
        New Member
        • Mar 2007
        • 8

        #4
        Hi ,
        I have one java class like test.java

        public class test{


        boolean packFrame = false;

        private int a,b;
        public test() {


        System.out.prin tln("Hi");
        }
        public static final void test45 (int i) {
        int a=0,b=1;
        if(a==b){
        System.out.prin tln("test");
        }
        System.out.prin tln("Hi");
        }

        public static int test123 (int i,String s,int k) {


        System.out.prin tln("Hi");
        return 5;
        }

        public void vee(int i){

        try{
        i +=1;
        sum( a, b);
        }
        catch(Exception e){

        }
        }
        public void sum(int a,int b){




        try {
        int sumab=0;
        sumab= a+b;
        } catch (RuntimeExcepti on e) {

        e.printStackTra ce();
        }
        }

        I want this methods name and constructors name before compile this java class..


        Originally posted by r035198x
        Please expalin what you mean by "before compilation".

        Comment

        • pattanaikhr
          New Member
          • Mar 2007
          • 8

          #5
          output like
          constructor :
          test()
          methods name : test45,test123, sum


          Originally posted by pattanaikhr
          Hi ,
          I have one java class like test.java

          public class test{


          boolean packFrame = false;

          private int a,b;
          public test() {


          System.out.prin tln("Hi");
          }
          public static final void test45 (int i) {
          int a=0,b=1;
          if(a==b){
          System.out.prin tln("test");
          }
          System.out.prin tln("Hi");
          }

          public static int test123 (int i,String s,int k) {


          System.out.prin tln("Hi");
          return 5;
          }

          public void vee(int i){

          try{
          i +=1;
          sum( a, b);
          }
          catch(Exception e){

          }
          }
          public void sum(int a,int b){




          try {
          int sumab=0;
          sumab= a+b;
          } catch (RuntimeExcepti on e) {

          e.printStackTra ce();
          }
          }

          I want this methods name and constructors name before compile this java class..

          Comment

          • hirak1984
            Contributor
            • Jan 2007
            • 316

            #6
            you are confusing us.

            which method name do you want?
            And where is the " main " method in your code?
            where from will the code start to compile or run?
            is this your first java program?just go through some examples of writing a java program first.
            Originally posted by pattanaikhr
            Hi ,
            I have one java class like test.java

            public class test{


            boolean packFrame = false;

            private int a,b;
            public test() {


            System.out.prin tln("Hi");
            }
            public static final void test45 (int i) {
            int a=0,b=1;
            if(a==b){
            System.out.prin tln("test");
            }
            System.out.prin tln("Hi");
            }

            public static int test123 (int i,String s,int k) {


            System.out.prin tln("Hi");
            return 5;
            }

            public void vee(int i){

            try{
            i +=1;
            sum( a, b);
            }
            catch(Exception e){

            }
            }
            public void sum(int a,int b){




            try {
            int sumab=0;
            sumab= a+b;
            } catch (RuntimeExcepti on e) {

            e.printStackTra ce();
            }
            }

            I want this methods name and constructors name before compile this java class..

            Comment

            • pattanaikhr
              New Member
              • Mar 2007
              • 8

              #7
              suppose this test.java class has save in different location , another one xyz.java , which can read test. java , and when we will compile xyz.java , that time it'll give test.java methods name and constructors name like test,test45,tes t123,sum.



              Originally posted by hirak1984
              you are confusing us.

              which method name do you want?
              And where is the " main " method in your code?
              where from will the code start to compile or run?
              is this your first java program?just go through some examples of writing a java program first.

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                I'm not sure what you are trying to do here but you can have a look at the reflection API and see if that's what you want.

                Comment

                • pattanaikhr
                  New Member
                  • Mar 2007
                  • 8

                  #9
                  I know that through reflection it's possible , but this case we need compile first,
                  without compile the java class how can we get method name and constructor name?

                  Originally posted by r035198x
                  I'm not sure what you are trying to do here but you can have a look at the reflection API and see if that's what you want.

                  Comment

                  • r035198x
                    MVP
                    • Sep 2006
                    • 13225

                    #10
                    Originally posted by pattanaikhr
                    I know that through reflection it's possible , but this case we need compile first,
                    without compile the java class how can we get method name and constructor name?
                    Well you should realize then that the jvm won't have anything to do with it until you have created a class file. So you have to manipulate it as you would a text file. You'd have to open it using FileReader or Scanner and try to extract the function names. The constructors are easy to get but the method names require a bit more analysis.

                    Comment

                    • hirak1984
                      Contributor
                      • Jan 2007
                      • 316

                      #11
                      Ya I too cant find any other way.But why do you need to get the names before compilation?Not clear!
                      Originally posted by r035198x
                      Well you should realize then that the jvm won't have anything to do with it until you have created a class file. So you have to manipulate it as you would a text file. You'd have to open it using FileReader or Scanner and try to extract the function names. The constructors are easy to get but the method names require a bit more analysis.

                      Comment

                      • pattanaikhr
                        New Member
                        • Mar 2007
                        • 8

                        #12
                        Yes that is right , but if any method is available in java API which is providing get method and constructors name before compile.Because if we'll think about ur suggestion for generic, then it's too difficult , the different programmer have different coding style. So getting method name is also difficult
                        You told that constructor is get too easy but I'm giving one example here
                        Suppose Test.java is class
                        public class Test{
                        test(){ --------------->constructor
                        System.out.prin tln("Hi");
                        }
                        public void test(){ --------> Method
                        System.out.prin tln("Hi");
                        }

                        Then how can we will differentiate here?


                        Originally posted by r035198x
                        Well you should realize then that the jvm won't have anything to do with it until you have created a class file. So you have to manipulate it as you would a text file. You'd have to open it using FileReader or Scanner and try to extract the function names. The constructors are easy to get but the method names require a bit more analysis.

                        Comment

                        • pattanaikhr
                          New Member
                          • Mar 2007
                          • 8

                          #13
                          Because my requirement like that

                          Originally posted by hirak1984
                          Ya I too cant find any other way.But why do you need to get the names before compilation?Not clear!

                          Comment

                          • r035198x
                            MVP
                            • Sep 2006
                            • 13225

                            #14
                            Originally posted by pattanaikhr
                            Yes that is right , but if any method is available in java API which is providing get method and constructors name before compile.Because if we'll think about ur suggestion for generic, then it's too difficult , the different programmer have different coding style. So getting method name is also difficult
                            You told that constructor is get too easy but I'm giving one example here
                            Suppose Test.java is class
                            public class Test{
                            test(){ --------------->constructor
                            System.out.prin tln("Hi");
                            }
                            public void test(){ --------> Method
                            System.out.prin tln("Hi");
                            }

                            Then how can we will differentiate here?


                            public class Test{
                            test(){ --------------->constructor
                            Wrong!

                            test() is not a constructor. Java is case sensitive.
                            To find the constructor you have to find where the name exactly matches the name of the class and then you would have to see what modifier was used for it e.g

                            Code:
                             public class Test{ 
                            Test(){ --------------->constructor
                            }
                            void Test() {//-------->not a constructor
                            }
                            It is possible to get them including the methods as well if you do your design right but the work required is almost as much as that required to write a compiler.

                            Comment

                            • pattanaikhr
                              New Member
                              • Mar 2007
                              • 8

                              #15
                              Yes that is right java is case sensitive ,

                              ok Test(){---------> constructor
                              }

                              public void Test(){-------->method.

                              }

                              void Test(){------>
                              }
                              then how can we differentiate method and constructor


                              Originally posted by r035198x
                              public class Test{
                              test(){ --------------->constructor
                              Wrong!

                              test() is not a constructor. Java is case sensitive.
                              To find the constructor you have to find where the name exactly matches the name of the class and then you would have to see what modifier was used for it e.g

                              Code:
                               public class Test{ 
                              Test(){ --------------->constructor
                              }
                              void Test() {//-------->not a constructor
                              }
                              It is possible to get them including the methods as well if you do your design right but the work required is almost as much as that required to write a compiler.

                              Comment

                              Working...