how can we get the class name

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sravan008
    New Member
    • Feb 2010
    • 10

    how can we get the class name

    hie every one ,here is my actually Question ..

    Q:
    how can we know the "Main "method class name ??is there any method to know the class name of the main method ??

    my project is struck here

    actually i am having 10 classes in my java program after i complied i got 10 different classes names ,in run time i have to know the class name of the main method ,then only i can accomplish my task .


    my project :a simple java editor


    when any one click on the compile button it searches class name of the main method , i am tried to get the class name of the main method but every time i am failed :( , so please help how can we know the class name of the main method ..
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    I suggest googling "Java Manifest". You specify the main classes in there.

    Comment

    • karthickkuchanur
      New Member
      • Dec 2007
      • 156

      #3
      see the java.lang.refle ct in java from u can get the classes and methods

      Comment

      • sravan008
        New Member
        • Feb 2010
        • 10

        #4
        @karthickkuchan ur


        bro i didn't get u .. can U tel me in a clear way please ..

        Comment

        • karthickkuchanur
          New Member
          • Dec 2007
          • 156

          #5
          Run the code

          Code:
          import java.lang.reflect.*;
          import java.net.InetAddress;
          public class reflexion {
          	public void add() {
          		
          	}
                
              public static void main(String args[])
              {
                 try {
                   Class cls = Class.forName("com.echain.SQLTrace.reflexion");
                    Method methlist[] 
                      = cls.getDeclaredMethods();
                    for (int i = 0; i < methlist.length;i++) {  
                       Method m = methlist[i];
                       System.out.println("name  = " + m.getName());
                       System.out.println("decl class = " +
                                      m.getDeclaringClass());
                      
                    }
                 }
                 catch (Throwable e) {
                    System.err.println(e);
                 }
              }
           }

          Comment

          • sravan008
            New Member
            • Feb 2010
            • 10

            #6
            Thanks dood .. Let me try once , and i will get back to u soon ..

            Comment

            Working...