wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes why i needed to recomplie ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why i needed to recomplie ??" Watch "why i needed to recomplie ??" New topic
Author

why i needed to recomplie ??

Ammar Salem
Ranch Hand

Joined: Dec 29, 2007
Posts: 60
Greetings Ranchers,I am happy to be here again.Here is the problem, I was compliling and running my programs under Windows,now that I shifted to linux,. I put all the programs in a pin drive and copied them to some folder in linux.To my surprise ! I was not able to run a single program without re-compiling,but doesn't java support "compile once run any where"
I was thinking if the .class file is present, then the program will work without any troubles.Anyway, now that being my question,I would appreciate your comments my dear friends.
Ammar Salem


****************************<br />For Some Dreams.....<br />One Lifetime Is Not Enough.<br />****************************
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3527
    
  15
What happened when you tried to run them without recompiling ?


Joanne
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

hai ammar,

your compiling java file in windows .and try to run in linux.

it will run and it should run utill you specified some property(os related)in that file.

whether you configured class path in linux properly?

without proper reason ,please avoid the negative comments on java

thanks & regards,
seetharaman scjp 1.4
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

In general, yes, your .class files are portable from one machine to another. But most major releases of Java define a new class file version, and so the class files created by default by a newer compiler will not necessarily run on an older JVM. For example, if your Windows machine has the current version of Java, JDK 1.6, and the Linux machine has a JDK 1.5 or older, then you'd have this problem.

You can tell a newer compiler to emit older format class files using the "-source" and "-target" switches; for example

javac -source 1.5 -target 1.5 Foo.java

will create Foo.class that will work on JDK 1.5 and JDK 1.6.


[Jess in Action][AskingGoodQuestions]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: why i needed to recomplie ??