views:

58

answers:

2

How would I find and run the default calculator in java without making my program platform dependent. I could just hard-code all the paths for each major OS, and then find the OS the person is using and then use that OS's respective path. But, see I don't want to do it like that, is there anyway to do it without hard-coding the paths in?

+3  A: 

I don't think there is really a concept of the "default calculator" in an OS. Sure, Windows offers a calculator application, but it's not registered in any way as the calculator, it's just an application you can run.

David M
Hmm didn't know that, always thought there was some type of "default calculator" setting in your OS.
Gnarly
It's "/usr/bin/bc" on Unix :-)
Brian Agnew
Same on Mac OS X, but `open -a Calculator` works, too. :-)
trashgod
+2  A: 

You could hard-code what you know to be standard calculators on a few platforms (e.g. calc.exe on Windows), then in your application, make a best effort to open the calc for the OS you're on. If you application cannot find the calc where you think it should be, prompt the user to browse for their calc application, then save the path they enter somewhere where your app can use it again in the future.

Andy White
Hmm alright, I guess that could be done easily. Thanks.
Gnarly
+1 for letting the user choose.
ZoogieZork