[JRuby] - Java method return empty value from JRuby

Hi All ,

I am trying to call below java method : max from TestMax Class from
jruby …but its not returning any value …but No error also

Note : if i running java program separately its returning values

// Java Code for returning MAX values *
public class TestMax {
/
* Main method */
public static void main(String[] args) {
int i = 5;
int j = 2;
int k = max(i, j);
System.out.println("The maximum between " + i +
" and " + j + " is " + k);
}

/** Return the max between two numbers */
public static int max(int num1, int num2) {
int result;
if (num1 > num2)
result = num1;
else
result = num2;

  return result;

}
}

*// Ruby Code : *
//call_Java.rb
import ‘TestMax’
Java::TestMax::max(5,3)

*JRuby OUTPUT : Its empty …No error *
*
*
JAVE OUTPUT : $java TestMax
The maximum between 5 and 2 is 5
*
*
Please let me know what should i do to return max value from TestMax
java
class

*
*
Thanks ,
Muthu S. SR
*
*
*
*
*
*
*
*

Tried , but this time also …No output … any thing should i try …??

Try this:

​ Java::TestMax.max(5,3)


Sent from Mailbox for iPhone

On Wed, Jun 26, 2013 at 7:41 PM, Muthu S. SR
[email protected]

Are you actually doing a ‘puts’ anywhere to output the result? I’m not
seeing it anywhere in your code.

Mark

On Thu, Jun 27, 2013 at 12:46 PM, Muthu S. SR
[email protected]wrote:

Sent from Mailbox https://www.dropbox.com/mailbox for iPhone

}
The maximum between 5 and 2 is 5
*


E: [email protected]
T: http://www.twitter.com/neurotic
W: www.compoundtheory.com

2 Devs from Down Under Podcast
http://www.2ddu.com/

Thanks mark , after puts statement its working fine …

Please confirm this , Java should have return the values then only we
can
call from jruby ?

I want to call the method which will not return any values …

# This is java Code *
mselv2m1:ruby_Code mselv2$ cat Hi.java
class Hi
{
public static void main(String[] args)
{
System.out.println(“Hello”);
}
public static void SayHello() #
I want call this method from jruby*
{
System.out.println(“Hello”);
}
}

*# This ruby code *
mselv2m1:ruby_Code mselv2$ cat Hi.rb
import ‘Hi’
Java::Hello.SayHello()

*ERROR : *
mselv2m1:ruby_Code mselv2$ jruby Hi.rb
NoMethodError: undefined method `SayHello’ for
Java::Default::Hello:Class
(root) at Hi.rb:2

Thanks ,
Muthu S. SR

Thanks a lot Karol , its working now …

try Java::Hi.SayHello() (instead of Java::Hello :slight_smile: and make sure
Hi.java is ‘freshly’ compiled … it should work (Java void method will
return nil in Ruby).