rama ilango wrote:using shell script, how to call the test.sample() method and get the return value.
You cannot call the method directly. The shell cannot interpret Java by itself, you must first start a JVM executing your code (i.e. with the "java" command). This will always call the main() method (which may do anything you like). So in order to invoke sample(), you need to invoke it from main(), then have your shell script run "java test". You cannot call Java methods directly from the shell. If you want to capture the output, either of these would do it in Bash (storing result in "out"):
Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / AmazonAmazon UK )
'Not working' is a poor error description. What didn't work? Did you get an error message? Which? How did you experience that it didn't work? What result did you expect, what did you get?
Sorry for that vague reply.
I meant the solution did not workout.
I did not get any error message. I did not get the returned value in the variable in my script.
I expect a string to be returned from the class and that is not happening.
Backticks are deprecated (Ommm, Ommm) because you can't nest them easily. Since classes should wear uppercase initials, you call `java Test`, not `java test`.
The example i have quoted here has class name starting will small letters, but when I am trying here locally my class name is proper.
should be public
* named with capital T
* main method is empty - so nothing happens
* sample-method returns a String, but does no output.
The other thing you should try is to just run the Java program from the command line and confirm it is working - don't try to capture the output at this stage, just get confirmation that your application is working as expected first.
One of the things that might be an issue is that you might be running your application as root, and on many systems you will get classpath issues if you run as root. This can be quickly discounted if you run the program from the command line without trying to capture the output as a first step.