I need to execute a method in .java
or .class
but this class doesn't have a main
function (I can't use main
function because it has no return value) I must execute this method in cmd , Is there any way to resolve this problem ?
Asked
Active
Viewed 213 times
0
-
What kind of problem you are trying to solve? For what do you need to call direct class method? I think, that you may call your method from `main()` and print result to `cmd` with `System.out.println()`. – ar4ers Jun 17 '15 at 11:01
-
other program (edit with Python) will execute this method and in this method I`ll do something then I should return a value tell the caller if this method goes wrong – Wangbo Jun 17 '15 at 11:06
2 Answers
3
First of all: Java has methods, not functions.
Up until Java 7, it was possible to run Java without a main method using the static block, but this was removed as of Java 7, because the static block was not supposed to use this way.
If you want to run it: add a main method.

Stultuske
- 9,296
- 1
- 25
- 37
-
Oh,thanks, I will corrected my syntex (In mounts of Chinese`s option function is method and method is function ) the most difficult is I need to run this class file and it must give me a return value how can I do this ? – Wangbo Jun 17 '15 at 11:24
-
Function and method here are not english or chinese notions, they are programming terms (independent on languages). There are differences between them. To where do you want a value to be returned? To the main method? You want the main method to return a value? This is not possible. You can call any other method by another program, and the method it calls can return a value, though this may not be the main method, or any other method with return type void. – Stultuske Jun 24 '15 at 06:16
0
If you want to call Java class from Python and get result from it, then you should use something like JPype
or Pyjnius
.