This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why i needed to recomplie ??" Watch "why i needed to recomplie ??" New topic

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

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

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

Joined: Jul 08, 2003
Posts: 24183

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

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

[Jess in Action][AskingGoodQuestions]
wood burning stoves
subject: why i needed to recomplie ??
Similar Threads
class 1
Updated my Eclipse with HibernateSynchrnoizer
Not able to run the successfully compiled programs in cmd, even after adding the "."
import problem
Compiling Java Programs