LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-12-2004, 09:09 AM   #1
jordanGSU
Member
 
Registered: Sep 2004
Distribution: Debian, Slackware, Arch
Posts: 65

Rep: Reputation: 15
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.
 
Old 10-12-2004, 09:28 AM   #2
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
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...

Last edited by Mega Man X; 10-12-2004 at 09:30 AM.
 
Old 10-12-2004, 09:32 AM   #3
jordanGSU
Member
 
Registered: Sep 2004
Distribution: Debian, Slackware, Arch
Posts: 65

Original Poster
Rep: Reputation: 15
Thanks, I have not heard that Gcj converts bytecode into machine language...that should definately speed it up.
 
Old 10-12-2004, 09:35 AM   #4
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
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!
 
Old 10-12-2004, 06:54 PM   #5
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
gcj doesn't HAVE to compile machine code - you can use -C to generate .class files instead.
 
Old 10-12-2004, 07:21 PM   #6
jordanGSU
Member
 
Registered: Sep 2004
Distribution: Debian, Slackware, Arch
Posts: 65

Original Poster
Rep: Reputation: 15
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");
}
}
 
Old 10-12-2004, 07:37 PM   #7
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 97
Cool

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 . 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.
 
Old 10-12-2004, 08:22 PM   #8
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
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
 
Old 10-13-2004, 02:46 AM   #9
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Ubuntu/WSL
Posts: 9,783

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Its interesting to see how the biased Megaman X reply has been proved wrong by a real world experience.
Quote:
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...
Just in time compilers are not a hype but a reality, and have improved themselves enough for java to be competitive with other languages in term of performance. Gcj is not using a just in time compiler, but (without -C) just a plain compiler that has the disadvantage of loosing java classes portability.
 
Old 10-13-2004, 07:12 AM   #10
WhiteChedda
Member
 
Registered: Aug 2003
Location: Florida
Distribution: Mandrake 9.1 for now
Posts: 205

Rep: Reputation: 30
Quote:
Originally posted by Robhogg
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.

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.

Last edited by WhiteChedda; 10-13-2004 at 09:01 AM.
 
Old 10-13-2004, 07:45 AM   #11
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
Red face

Quote:
Originally posted by jlliagre
Its interesting to see how the biased Megaman X reply has been proved wrong by a real world experience.

Just in time compilers are not a hype but a reality, and have improved themselves enough for java to be competitive with other languages in term of performance. Gcj is not using a just in time compiler, but (without -C) just a plain compiler that has the disadvantage of loosing java classes portability.
Don't you just love to when you try to help somebody, in an easy way to understand, as saying "Wine is basically an emulator", so some jack*** jumps in and tries to prove how wrong you were? .

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

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:
Features and Limitations of GCJ

GCJ is not only a compiler. It is intended to be a complete Java environment with features similar to Sun's JDK. If you specify the -C option to gcj it will compile to standard .class files. Specifically, the goal is that gcj -C should be a plugin replacement for Sun's javac command.
so nobody has found the Ultimate Super Combo Finish here... you are all running over other peoples posts without reading it...

Regards!
 
Old 10-13-2004, 08:20 AM   #12
jordanGSU
Member
 
Registered: Sep 2004
Distribution: Debian, Slackware, Arch
Posts: 65

Original Poster
Rep: Reputation: 15
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
 
Old 10-13-2004, 12:56 PM   #13
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Ubuntu/WSL
Posts: 9,783

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
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:
so it will be faster than running inside a virtual machine
which just prove wrong for that particular example, nothing personal.

Just my 2 cents of Sun Java biased opinion
 
Old 10-13-2004, 01:43 PM   #14
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
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!
 
Old 10-13-2004, 08:20 PM   #15
titanium_geek
Senior Member
 
Registered: May 2002
Location: Horsham Australia
Distribution: elementary os 5.1
Posts: 2,479

Rep: Reputation: 50
Quote:
Originally posted by Robhogg
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 . 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.
As a class, we are working through SAMS teach yourself Java in 21 days, one chapter a week. We went for this one instead of the in 24 hours one, because In 24 Hours really skims... just enough to get you started. I was impressed with thier HTML in 24 hours, but not with the Linux in 24 Hours. we are also using the certification book as well, it really helped me flesh out my knowlege of java, even though I failed the exam.

anyway, I have always stuck to javac, I like the portability thing.

titanium_geek
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I configure 'javac' and Using Java on Linux akosombo Linux - General 7 03-13-2005 08:26 AM
How to make javac (java compiler) available on whole system? tisam Linux - Software 11 02-14-2005 09:11 AM
Help php compile javac or java system environment variable antony_csf Programming 1 06-16-2004 01:12 PM
Help php exec, system function for compile javac or java antony_csf Programming 0 06-15-2004 01:45 AM
Can't compile Java Swing Applet with javac chansky Programming 4 09-23-2002 04:50 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration