Many Unix programs let you put in a "#! " that state what should be used to run the program. for example,
tell Unix that the file should be run using the perl interpreter found in that path.
Is there something equivalent for Java? I think the idea is that for most other programs/scripts, the user doesn't need to know what the command is to run the program, they can just type "myScript.pl" and Unix knows to use Perl.
Can you do the same thing for java programs?
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Yeah, but those are scripting languages, they run text files. Java is a compiled language, and you cannot prepend "#! java" to a binary. Your choise are create a shell script to run the java app (this is done by most software) or write a C shell to load the JVM and Java app (check out the JNI docs for how to do this).
You can also configure your file manager to execute JAR files using java so that when you double-click them the Java app runs. Of course, the JAR needs to specify the starting class in the manifest.
One other thought - Groovy is a scripting language. And I think that somewhere in the Groovy docs is a way to add the "#! " to the start of the groovy script. And since Groovy is an extension of Java, that could help you accomplish your goal.
but you can run a compiled 'c' program by simply typing it's name.
Yes, that is because the C compiler and linker generate binary files, with a very specific layout, containing machine code. Such binary files contain a hex marker (0x7F454C46) in the first several bytes that identifies the file as a "binary executable" and Linux knows how to load and run such a file.
You could always modify the app loader of the Linux kernel (or whatever code handles this in Linux) to recognize the binary marker for a class file (0xCAFEBABE) as a Java file and have it launch the file with Java. Of course you would have to deal with the classpath somehow.
Doing the same for JARs would be trickier because they use the same binary marker as ZIP files (0x504B) but not all ZIP files are "runnable".
There is a way to do this in Linux. Maybe it's even enabled by default on Ubuntu. Sorry, I don't know any details, but there is a way to configure different kinds of executables, and you can specify with which programs they should be started. Look around in the /etc directory if you can find anything that has to do with this. (I don't have a working Ubuntu at hand to check it out...).