public void foo() {
String [] args = new String[2];
args[0] = "hello";
args[1] = "every";
System.out.println("Output: " + args[0] + args[1]);
// etc... the usage of 'args' here and in the main method is identical
}
/* Get the application's main method */
mainID = (*env)->GetStaticMethodID(env, mainClass, "main",
"([Ljava/lang/String;)V");
...
{ /* Make sure the main method is public */
...
mods = (*env)->CallIntMethod(env, obj, mid);
if ((mods & 1) == 0) { /* if (!Modifier.isPublic(mods)) ... */
message = "Main method not public.";
messageDest = JNI_TRUE;
goto leave;
...
// one class needs to have a main() method
public class HelloWorld
{
// arguments are passed using the text field below this editor
public static void main(String[] parameter)
{
System.out.println(parameter[0] + parameter[1]); // Output is 11
//Comment out below code in case of String
System.out.println(Integer.parseInt(parameter[0]) + Integer.parseInt(parameter[1])); //Output is 2
System.out.println(Float.parseFloat(parameter[0]) + Float.parseFloat(parameter[1])); //Output is 2.0
System.out.println(Long.parseLong(parameter[0]) + Long.parseLong(parameter[1])); //Output is 2
System.out.println(Double.parseDouble(parameter[0]) + Double.parseDouble(parameter[1])); //Output is 2.0
}
}