Forum: JRuby [JRuby] - Java method return empty value from JRuby

02ee2ff9234924331adcb4845754e75e?d=identicon&s=25 Muthu Selvan SR (Guest)
on 2013-06-27 01:43
(Received via mailing list)
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 Selvan SR*
*
*
*
*
*
*
*
*
A8f7c2b66fafa83e9537c1f82348f11d?d=identicon&s=25 Doug Hathaway (Guest)
on 2013-06-27 02:48
(Received via mailing list)
Try this:


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



—
Sent from Mailbox for iPhone

On Wed, Jun 26, 2013 at 7:41 PM, Muthu Selvan SR
<pearl.selvan@gmail.com>
02ee2ff9234924331adcb4845754e75e?d=identicon&s=25 Muthu Selvan SR (Guest)
on 2013-06-27 04:48
(Received via mailing list)
Tried , but this time also ..No output .. any thing should i try ..??
0dae30569556c4f47a5277e8957f1960?d=identicon&s=25 Mark Mandel (Guest)
on 2013-06-27 05:13
(Received via mailing list)
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 Selvan SR
<pearl.selvan@gmail.com>wrote:

>> Sent from Mailbox <https://www.dropbox.com/mailbox> for iPhone
>>>
>>>
>>> }
>>> *The maximum between 5 and 2 is 5*
>>> *
>
--
E: mark.mandel@gmail.com
T: http://www.twitter.com/neurotic
W: www.compoundtheory.com

2 Devs from Down Under Podcast
http://www.2ddu.com/
02ee2ff9234924331adcb4845754e75e?d=identicon&s=25 Muthu Selvan SR (Guest)
on 2013-06-27 06:36
(Received via mailing list)
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 Selvan SR
Caa2df9372ffa0a9e95b2bab1e8fea34?d=identicon&s=25 Karol Bucek (Guest)
on 2013-06-27 08:36
(Received via mailing list)
try `Java::Hi.SayHello()` (instead of `Java::Hello` :) and make sure
Hi.java is 'freshly' compiled ... it should work (Java void method will
return nil in Ruby).
02ee2ff9234924331adcb4845754e75e?d=identicon&s=25 Muthu Selvan SR (Guest)
on 2013-06-27 08:38
(Received via mailing list)
Thanks a lot Karol , its working now ..
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.