Renaming main method class.

When compiling my java classes, I find that they are always compiled
to a file name of X.class.
If I only ever want to rename one class file, the class file with my main method
inside it, and have
java NewClassName.newExtention
run it as per normal, may I do that, and how do I have it run?
What may I specify in an executable jar file's manifest main-class entry to have this work as well?

I use a free jar wrapper tool, that for reasons I won't go into I'm locked into.
It mentions the main-class manifest entry, and so the main class .class name,
in plain text in the result wrapped file unfortunately.
Which after some research isn't too much of a problem, since
I can't access method or constructor class innards with reflection;
since the default class loader will only get me as far as a class reference.
Correct?
So my only question is...
Java Class Loading.

Similar Messages

  • Adding a class to a project in sunone studio that already has a main method

    i have a frame class and it contains a main method, I can't figure out how to add a class that makes use of the JDialog and call it from the main class. When i try to add a JDialog, it creates its own main method.
    If abc.class is my main method class and dcf.class is my class that makes the dialog GUI, I want abc.class to be able to call it, i can't figure out how to do this in Sun One Studio 5

    Having a main() in the JDialog doesn't hurt. It lets you run the JDialog as a standalone - make sure that it looks good, etc. When you run your other class, the main() won't get called. (And you can delete it when you're all debugged.
    Alternatively, create a new class, then start it by saying
    class MyDialog extends JDialog {
    }S1S will be completely happy if you do it that way.

  • Can users call main method??

    class MainDemo{
    public static void main(String args[]){
    System.out.println("First main method");
    MainDemo.main("hello");
    }Hi all,
    Why is the above code not compiling??

    By adding few lines right after the System.out.println("First main method");.
    class MainDemo
         public static void main(String args[])
              System.out.println("First main method");
              System.out.println("No.of args : " + args.length);
              if (args.length > 0)
                   System.out.println("Passed in : " + args[0]);
              System.out.println();
        static
             String args[] = {"hello"};
             MainDemo.main(args);
    }And the output gives :-
    First main method
    No.of args : 1
    Passed in : hello
    First main method
    No.of args : 0
    Press any key to continue...
    Why is it JVM executes the main() method in the static block instead of the calling the main() method (without argument) directly ?
    Edited by: TKH on Nov 14, 2007 1:08 AM

  • How can i call a main method  from a different class???

    Plzz help...
    i have 2 classes.., T1 and T2.. Tt2 is a class with a main method....i want to call the main method in T2......fromT1..is it possibl..plz help

    T2.main(args);

  • How to add a code TestIfElse(10) to the Main method of the Program.cs class?

    How to add a code  TestIfElse(10) to the Main method of the Program.cs class?
    Here is my code and I have copied from the Wiley book for Microsoft certification page 14,
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    namespace ifelse_Statement
        class Program
            static void Main(string[] args);
            TestIfElse(10);
            public static void TestIfElse(int n);
            if(n < 10)
                     Console.WriteLine("n is less than 10");
             else if(n < 20)
                    Console.WriteLine("n is less than 20");
             else if(n < 30)
                Console. WriteLine("n is greater than or equal to 30");
    Here is the error list I am getting,
    Error 1      Method must have a return type        C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\switch_Statement\Program.cs
    12 13
    switch_Statement
    Error 2
    Type expected C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\switch_Statement\Program.cs
    12 24
    switch_Statement
    Error 3
    Method must have a return type C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    12 9
    ifelse_Statement
    Error 4
    Type expected C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    12 20
    ifelse_Statement
    Error 5
    Invalid token 'if' in class, struct, or interface member declaration
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    16 9
    ifelse_Statement
    Error 6
    Invalid token '10' in class, struct, or interface member declaration
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    16 16
    ifelse_Statement
    Error 7
    Type expected C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    16 16
    ifelse_Statement
    Error 8
    Invalid token '(' in class, struct, or interface member declaration
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    18 35
    ifelse_Statement
    Error 9
    A namespace cannot directly contain members such as fields or methods
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    20 10
    ifelse_Statement
    Error 10
    Type or namespace definition, or end-of-file expected
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    30 1
    ifelse_Statement
    Error 11
    The type or namespace name 'n' could not be found (are you missing a using directive or an assembly reference?)
    c:\users\pvs\documents\visual studio 2013\projects\lesson01\ifelse_statement\program.cs
    16 12
    ifelse_Statement
    Error 12
    'System.Console.WriteLine(string, params object[])' is a 'method' but is used like a 'type'
    c:\users\pvs\documents\visual studio 2013\projects\lesson01\ifelse_statement\program.cs
    18 26
    ifelse_Statement

    static void Main(string[] args){
    TestIfElse(10);
    public static void TestIfElse(int n)
    if (n < 10)
    Console.WriteLine("n is less than 10");
    else if (n < 20)
    Console.WriteLine("n is less than 20");
    else if (n < 30)
    Console.WriteLine("n is greater than or equal to 30");
    Fouad Roumieh

  • Class extending a Frame with main method in it - how do I use the methods?

    Howdy.
    Having a problem.. I want my "main" class, ie. the class with the main method in it to extend a Frame class.. because the main method is static, I can't use Frame's methods.
    What's a trick to get around this ? I am making a deliberate design decision to extend the Frame class, because I thought it was.. well.. better. I could always just create a Frame object and utilise it.. but from little things I've read and seen it's better to extend it.
    When I use Forte to make a Frame program it sets up a constructor/etc. for the main class and then it does something akin to this (the class is called MazeGenerator) :
    public static void main(String args[]) {
    new MazeGenerator().show();
    What does "new MazeGenerator().show();" do when it's not being associated to an object handle ??
    Ta.
    - Scutt.

    Create an instance of the frame in main then the constructor can control it. Or you could add an init method or something:
    class MyFrame extends Frame {
    public static void main (String [] args) {
    MyFrame frame = new MyFrame();
    frame.init();
    You don't necessarily have to have a reference to an Object in order to create one. All the work can be done in the constructor (something I'm not really fond of however)

  • Calling main method in another class using command line arguements

    Hi
    My program need to use 4 strings command line arguments
    entered in Project properties/Run/Application Parameters
    java programming for beginners // arguments
    The program needs to call main in the second class 4 times using argument 1 the first call, argument 2 the second call on so on.
    So the output wil be
    java
    programming
    for
    beginners
    import java.lang.*;
    public class First extends Second{
      public static void main(String[] args) {
        for(int i = 0; i < args.length; i++){
           Second.main(args); // Error I think
    import java.lang.*;
    public class Second {
    public static void main(String[] args){
    System.out.println(args[0]);
    "First.java": Error #: 300 : method main(java.lang.String) not found in class Second at line 6, column 15
    I am only a beginner with little knowledge of java so can the code be as basic as possible

    Your style looks quite bad for starters..... Hows
    this://import java.lang.*; /* NOT NEEDED */
    public class First extends Second{
    public First(String s) {
    super(s);
    public static void main(String[] args) {
    for(int i = 0; i < args.length; i++){
    new First(s);
    public class Second {
    public Second(String s)
    System.out.println(s);
    NOT NEEDED:
    public static void main(String[] args){
    System.out.println(args[0]);
    }My question to you: Do you understand why my code
    works? (does it do what you want?)I think since this is some kind of lesson, the OP have to implement some way to use the main method of the Second class as it is, that is, with String[] args. I think this lesson is interesting exactly because of this requirenment. But, anyway, I don�t know, that is just my assumption...

  • How do you call a java class from the main method in another class?

    Hi all,
    How do you call a java class from the main() method in another class? Assuming the two class are in the same package.
    Thanks
    SI
    Edited by: okun on May 16, 2010 8:40 PM
    Edited by: okun on May 16, 2010 8:41 PM
    Edited by: okun on May 16, 2010 8:47 PM

    georgemc wrote:
    To answer your impending question, either the method you're calling has to be static, or you need an instance of that other class to invoke it against. Prefer the latterAnd to your impending question after that: no, don't use the Singleton pattern.

  • Can we call main method in another class?

    Hi...
    can we call main method in another class?
    If no, please tell me the exact reason why can't we call that....

    ok
    can u give that code for me?
    class A {
    public static void main(String [] args){
    System.out.println("In A");
    class B {
    public static void main(String [] args){
    A.main(null);
    }

  • How to call main method in one class from another class

    Suppose i have a code like this
    class Demo
    public static void main(String args[])
    System.out.println("We are in First class");
    class Demo1
    public static void main(String args[])
    System.out.println("We are in second class");
    In the above program how to call main method in demo calss from Demo1 class......???????

    No, i dont know how to call other than main methods from other classes
    And one more doubt i have i.e. Like in C can we see the execution of the program like how the code is being compiled step by step and how the value of the variable changes from step to step like(Add Watch).........

  • Invoking the main() method of a class within another

    Greetings -
    Can someone tell me what happens when you invoke the main() method of a class from within another class?
    I have a third-party class, designed to be invoked from a command line, that I want to invoke from within a separate class. What appears to be happening is that following the successful execution of the third-party class, the invoking class is terminated as well. That's not the intended behavior I had envisioned. ^_^
    Is there a better way than invoking the main() method? I still need the invoking class to continue executing.
    Thanks!

    Navigate yourself around pitfalls related to the Runtime.exec() method

  • Calling main method of a class

    Hi
    I have to call the Main method of a class in some other class becuass that class is accepting command line aurguments.
    I test it and everything is working fine.
               String[] strings = new String[3];
               strings[0] = "E:/practice.cap";
               strings[1] = "-o";
               strings[2] = "E:/practice.txt";
               Main.main(strings);I now want to know is there any drawback of doing this ?
    BR
    regards

    Muhammad Umer wrote:
    Good Explanation. But my question is not to explain the importance of main method in classes :)As far as the Java language and APIs go, there's nothing wrong with calling main just like any other method, because it is just another method. It's only special to the JVM, and to programmers who assume that it's the entry point to the program.
    As far as Java is concerned, you can call as many mains as you want. The only potential problem arises if some particular main is written in a way that relies on it being the entry point to the whole program. That is, if the author wrote it with the assumption that it would only be called by the JVM at startup time, and would not be called arbitrarily from within your code (EDIT: and if proper behavior relies on that assumption being upheld). However, this is just a particular case of a general issue that we always have to be aware of, namely, make sure you understand how a method is intended to be used, and use it in that fashion, or accept the consequences.
    EDIT: However, having said that, it's unusual to call main explicitly, so if you can, I would suggest pulling the functionality that you want out of that main into a different method, and then both your code and the main can call that method. If you cannot do that, then at the point where you call main, clearly document why you're doing it. Otherwise, whoever reads the code a few months or years from now--maybe somebody else, maybe you--will be wondering if the programmer really knew what he was doing, or if that is a mistake. That kind of second-guessing is the source of a lot of maintenance nightmares.
    Edited by: jverd on Nov 3, 2011 8:43 AM

  • Beginner - class & main method question

    Hello, I am still really new to OOP and Java. I came across an example in the book I am using that threw me for a loop.
    ex.
    class MyClass {
    public static void main(String [] args) {
    int x = 42;
    MyClass y = new MyClass();
    int z = y.go(x);
    int go(int arg) {
    arg = arg * 2;
    return arg;
    what I am confused about is the creation of a new class that contains the main method (MyClass y = new MyClass()), wouldn't this create a new class that also has a main method? Or is this the kind of code I will never encounter outside an example in a book and shouldn't worry about it :-)
    Thanks

    Since the main method is static, it would be invoked through MyClass.main(...). Note that this is not actually creating an object, just calling a static method.
    Creating an object is an entirely different story. MyClass mc = new MyClass(); instantiates a new object of the class MyClass. You couldn't do mc.main(...) because main is static. You can call things such as mc's go() method because they are not static and thus belong to objects of that class, rather than the class itself.
    ...Or something. That all made sense in my head, but if it didn't make sense to you just tell me.

  • Running a main Method from another class??

    Hi,
    I am trying to run a main method from another class, eg the main method is in Class1 and i am trying to run it from class2.
    So I have
    class1 c1 = new class1();
    c1.main();and I get the following compilation error:
    clas2.java:42: main(java.lang.String[]) in class1 cannot be applied to () c1.main();
    any ideas on how to do this correctly
    thanks in advance,
    Donal

    Hi thanks for the replies,
    tried just passing a string earlier and that just gave errors too, I should have been more specific and pass a string array.
    Its working now thanks again.
    Donal

  • Class "adressverwaltung.AdressverwaltungView" does not have a main method

    Hello
    I'm new to Java and also to Netbeans.
    In Netbeans I created a new project as a Java Desktop application. If I will run this application (Run > Run file) I'll get the following error message: Class "adressverwaltung.AdressverwaltungView" does not have a main method.
    What do I have to do to get a main method?
    Thanks in advance.
    Peter

    linux_desktop wrote:
    2: You're right: I have to learn the basics. But the first answer of db didn't help. If I have a site with a lot of chapters, I'm interested in to know which chapter will explain the solution of my problem. Because I'm not interested in to spend a lot of time for nothing.If you're not interested in investing time to learn the basics, then that's your choice.
    However it means that you are highly unlikely to get any good help around here.
    This is not a homework service and we don't usually condone people taking shortcuts, because there aren't any shortcuts that result in actual learning here.
    If you want to do an address management application, then you will need the information contained in the tutorials, there's no way around it.
    And presenting you with "this is how you write a main method" will not help you, because you'll still be missing tons of other stuff.
    3: Only to read is not enough. I have to create an example, learning by doing is it called.As you've been told, you should have looked into the tutorials before discarding them. They do include examples where you should program.

Maybe you are looking for