use gcc or javac for java compile?
Trying to see which is best.
1) gcc can be compiled with java support. 2) javac is the compiler that comes from SUN. Which one do you use--and why? I have not tried either in Linux, but under windows I use javac. |
Gcj converts java byte code into machine language, so it will be faster then running inside a virtual machine. It's a great attempt of the called "Just in time compilers", a hype that appeared about the same time when Java started to be widely used outside web-applets...
gcj really is neat, but it's quite limited when it comes down to AWT and Swing classics (java's graphical Interfaces for buttons, frames, windows, etc). At the end, it's all up to you: Do you need to use AWT or Swing for your applications and/or are following a book about Java? Or maybe portability? Because if you use gcj to convert Java byte code into machine language you can kiss you platform independent code good bye... If so is the case, then stick with Java2 from Sun, otherwise it's worthy to take a look into gcj which, unlike Sun's compiler, it's open source... |
Thanks, I have not heard that Gcj converts bytecode into machine language...that should definately speed it up.
|
Cool, no problems :). I've found an interesting link for you:
http://www.linuxjournal.com/article.php?sid=4860 I believe that Slackware ships with both Sun's Java2 SDK and gcc/gcj, so you could try it right away and see the performance differences ;). Good luck! |
gcj doesn't HAVE to compile machine code - you can use -C to generate .class files instead.
|
kinda interesting...
I was trying out gcj...expecting to see an improvement in performance. What I actually found was that a .class file seems to execute faster than machine-code, or at least in the one case that I tested. I'm thinking that this is probably a fluke...has anyone had similar experiences?
Tests: --machine code-- giro@slackbox:~/java$ ./test done...execution took: 9523 milliseconds giro@slackbox:~/java$ ./test done...execution took: 9243 milliseconds giro@slackbox:~/java$ ./test done...execution took: 9486 milliseconds --byte code-- giro@slackbox:~/java$ java test done...execution took: 2974 milliseconds giro@slackbox:~/java$ java test done...execution took: 2942 milliseconds giro@slackbox:~/java$ java test done...execution took: 2940 milliseconds Heres how I compiled: --to compile to machine-code: gcj -c -g -O test.java gcj --main=test -o test test.o --to compile to byte-code: javac test.java Source Code: public class test { public static void main(String []args) { long start=System.currentTimeMillis(); double poo=1; for(int i=0;i<1000000;i++) for(int j=0;j<10;j++) { poo=Math.random(); poo=poo*2; poo=Math.random(); poo=poo*2; } long stop=System.currentTimeMillis(); long result=stop-start; System.out.println("done...execution took: "+result+" milliseconds"); } } |
I'm sticking with using javac at the moment, for two main reasons: It's the way described in the book I'm learning from, and I can use it on My Mac and in Windows as well as in Linux.
Incidentally, any opinions on introductory books? I feel that the one I started off with ("teach yourself Java" by Chris Wright) is a bit lacking in explanation. I think I would have been making more progress with a book that had told me, for instance, the implications of declaring a method to be static :rolleyes:. i'm considering trying the Java book in SAMS' "Teach Yourself... in 24 Hours" series, as I've been impressed with their other books that I've looked at. |
I think I'd blame gcj's optimization versus Hotspot's. The Hotspot compiler also compiles native versions of the Math.Random functions, while gcj's assembler output doesn't appear to contain it, so it's probably calling a less efficient version.
If you want to see the java version run much slower, add -Xint to the command line to force it to interpreted mode ;) |
Its interesting to see how the biased Megaman X reply has been proved wrong by a real world experience.
Quote:
|
Quote:
GCC works those 3 platforms and more, just FYI. http://gcc.gnu.org/install/specific.html Mac OSX is built on BSD, which like linux is a unix variant. Pretty much anything that runs on a unix platform can be found for OSX. |
Quote:
Please note that I said a hype that "were". Just in time compilers do, exist today but they did not when Java came out. I also never said that it was not possible to compile Java to byte code with gcj, did I? Not sure what is going on in this forum lately... looks like peoples always try to prove you wrong or reply to an already answered question to increase post numbers or something :rolleyes: To make it clear, I never said you could not compile Java code to byte code (.class) with gcj, nor did I said that JITC _are_ a hype, but _were_... If anybody had actually read the link I've posted, it's clearly quoted: Quote:
Regards! |
hey...no flame wars :)
Everyone's opinion is important to me, although I do like to hear conflicting ideas because they give me something to investigate...lets not bash anyone. thanks |
Hi Megaman X, sorry for the way my posting was perceived, it went beyond what I wanted to express.
I was just pointing at your definitive sentence: Quote:
Just my 2 cents of Sun Java biased opinion ;) |
No problems jlliagre!. I was to strong on you. Been having one of the worst weeks ever for reasons that I won't botter you with, but includes from racism to trains being canceled in the butt place I live in Sweden for some 16 years old kids who wants attention.
I apologize. Really sorry mate. I won't post anything more here until I'm back on the tracks. I'm very un-social lately. Oh my, I so have to move away from here... Regards! |
Quote:
anyway, I have always stuck to javac, I like the portability thing. titanium_geek |
All times are GMT -5. The time now is 03:12 PM. |