• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why i needed to recomplie ??

 
Ammar Salem
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happened when you tried to run them without recompiling ?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic