Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

retunring value from main()?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a way to get a return value from a java class (e.g. myClass.class) by typing "java myClass" from a commandline?
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Returned . . . to WHAT?
Main is the start of the application, what would catch the value returned??
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can return an integer value from the main thread of a java application by calling System.exit( x ) where x is the integer to return.
 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, yeah, if that is what he means.
 
asako severn
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to write a tiny utility program that gives me back the current time in millisecond, but only thing I can do is to stdout the result ...
public class Clock
{
Clock() {}
public static void main( String p_Argv[] )
{
System.out.println( System.currentTimeMillis() );
}
}
I tried changing return value of main, throwing the value as an exception, but none worked...
My ultimate goal is to calculate the elapsed time in milliseconds in a Perl script, which does not seem to deal with time in less than a second granularity, by making system call to "java Clock" (my little utility program above).
Maybe I'm doing something entirely wrong. Any suggestion to solve the problem will be greatly appreciated. Thank you very much.
 
asako severn
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you Iain!
by the way, asako is a she-name in Japanese.
 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OH - you want to interface with a program written in a different language. For that you need a little JNI (Java Native Interface).
Here is the Sun tutorial http://java.sun.com/docs/books/tutorial/native1.1/concepts/index.html
Actually since you want to use Java from another language (more common is to use another language from within Java) you can skip to this part http://java.sun.com/docs/books/tutorial/native1.1/implementing/index.html
[This message has been edited by Cindy Glass (edited October 15, 2001).]
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic