If you want to compile for JDK 1.4 using a JDK 1.5 compiler, you need to use the -target option when you use javac. The class file format has changed slightly with most majore releases, including 1.5, which means that the class file needs to have a field which specifies which format it's using. If you use the standard 1.5 format, a 1.4 compiler obviously cannot be guaranteed to understand it correctly (even if it could probably understand most of the file correctly), because 1.5 was unknown when 1.4 was created. If you want the class file to be usable by a 1.4 JVM, you need to specify this at compile time.
The main thread calls t.start() once. From that moment on, there are two threads which may be active, and we don't know for sure which will happen first. The main thread may remain active, and call t.start() again, which should result in an IllegalStateException being thrown. This has no effect on the new thread though, which would then proceed to run. So the output would be:
Exception Inside Run
Alternately, after t.start() is called the first time, the new thread may run immediately. After it completes, the main thread may resume and call t.start(0 a second time, which will again result in error. The output in this case would be:
Inside Run Exception
Either of these is possible, and we have no way of knowing which will happen.
[Jay]: This is a bug in j2sdk1.4 and has been fixed in tiger release.
Mmm, I think you're thinking of the fact that previous JDKs did not correctly throw IllegalThreadStateException, as documented here. On older JDKs you might see only
However this was definitely a bug, and has been fixed now. And it wouldn't really account for the output Rathi is asking about.
However, in the real world, if you use JDK 1.3 or 1.4, you may see output
because JDK 1.3 and 1.4 had a bug which resulted in incorrect behavior. This incorrect behavior will never, ever be on the exam; I only mentioned it because Jay mentioned a bug in 1.4.2, and I think this is what he meant.