Calling method from .class file
Hello!
I have a project I work on and I am interested if it's possible to call a method inside a .class file from another java file (without decompiling the .class file).
Eg:
Inside my.java I call method buildGraph() inside the Graph.class file.
I don't think it's possible, but look at the project's specs:
Graph.class: Working Graph class file. You can use this while you are working on Tasks I/II. My Graph class prints a lot of output to let you see what is happening.
Thank you!
Alex
Re: Calling method from .class file
I think you need to understand how the compiler works, it creates .class files from source files .java, you actually cannot call a method from a .java file, but you can from the compiled file .class.
So to answer your question, yes you can call a method from a class file, just make sure it resides on your classpath so the JVM you are running under can see it.
Incidentally IDE's are effectively looking at the .class files to determine what methods are available, this is obviously hidden from the developer.
Re: Calling method from .class file
I have a question which i think is relevant to this topic. Is there any application that read a .class file and convert it to .java?
Re: Calling method from .class file
Yes, what you want is a Java decompiler.
There are quite a few available if you search for them on the internet.
here is one: "http://java.decompiler.free.fr"
There are some limitations, so you need to check what it can and can't do, for example some may not convert import statements and probably ignore comments. Ok for simple projects but not advisable for complex code in my opinion.
Re: Calling method from .class file
Re: Calling method from .class file
Re: Calling method from .class file
Quote:
Originally Posted by
JavaDaveUK
I think you need to understand how the compiler works, it creates .class files from source files .java, you actually cannot call a method from a .java file, but you can from the compiled file .class.
So to answer your question, yes you can call a method from a class file, just make sure it resides on your classpath so the JVM you are running under can see it.
Incidentally IDE's are effectively looking at the .class files to determine what methods are available, this is obviously hidden from the developer.
:-? This is quite an old thread, but i really would like some help in this matter, with an example, probably? Like, how to the class file method say 'fn1' in class file 'myjava.class' can be called from a method 'fn2' in another java file, say 'mynewjava.java'??
Thanks in advance :)