Java Native Compilation Examined
An Anonymous Coward writes: "DeveloperWorks has an interesting article about compiling Java apps to run as native appplications on the target machine without the need for a JVM."
← Back to Stories (view on slashdot.org)
What's the point of taking a language that jumps through hoops to be "cross-platform" and cutting it's legs off?
I was waiting for this to happen. The two things between Java and me are non-native code and some OOP problems (no operator overloads, etc). It's good to see new work being done on the VM side of things. Now I have to consider JSP as a possibility -- good good good!
Mike.
http://www.yourmothernaked.com
...people are finally admitting that Java isn't too speedy?
- A.P.
"Remember when the U.S. had a drug problem, and then we declared a War On Drugs, and now you can't buy drugs anymore?"
The JVM essentially gets embedded into the final executable. While there are some areas that will benefit by being compiled to native code, other bits will necessarily need to remain at a level that a VM will be able to get at.
It's a pretty cool idea, but CPUs don't supply some features that make Java (and other interpreted languages) so cool.
Runtime bounds checking, typecast checking, etc... do those get included in the native executable as well (and if so, then wouldn't the performance hit negate the advantages gained thru native compilation?), and if not, then it could be dangerous.
There's 10 types of people in this world, those who understand binary and those who don't.
This happened today at school. Annoyer: Java rocks! Me: Java is too slow. C++ is faster. Annoyer: Java rocks with JIT compiler! Me: You idiot.
PayPal $$ if you sign up for free offers (eBay, cred cards, e
On the AS400 you can run your jars through a compilation process. Whenever the jar is referenced by the system the compiled code is picked up and run. We haven't seen particularly performance improvements from this, but I guess it depends on the sort of work your code is doing...
This would solve my greatest beef with Java - that messy JVM which piles into the processor when it compiles bytecode. Of course, the idea of running Java natively seems to defeat the purpose of Java entirely: runs the same on any computer. Interesting idea, though...
political_news.c: warning: comparison is always true due to limited range of data type
If the code is in native binary form and not bytecode, I guess it would make it harder to reverse engineer. I don't have to run those obfuscation-wares everytime I build. Saves time (both in building and running)
Lets see TowerJ has been out since when ? 1999. Having tried my hand at this I have some reservations. The project I was on ... a large dinosaur of a thing which will remain nameless had 12,000 classes which TowerJ turned into C files which were then compiled by GCC. Resulted in 50 megabyte executables on a Sun. Didn't really solve the problem which wasn't really about speed but throughput. The solution was a better design using servlets and Java Webserver ... result DRAMATICALLY faster without any need for native compilation.
Mind you I noticed in the IBM article that the memory footprint was much smaller. That might be nice.
Bitter and proud of it.
Most notably, there is very little support for AWT, making GCJ unsuitable for GUI applications.
That's the real shame of the matter. Java shines most in its ease-of-use for creating complex GUIs -- unfortunately that's also where the worst memory/performance problems appear. For instance, Swing is good for client apps if you can ship with minimum RAM requirements of 64+ mb (and even that's cutting it close). Performance is most important in the UI, where the user notices any lack of responsiveness. Hopefully some Java native compilers will help out here.
Different compilers support differing levels of class library; Excelsior JET is one compiler that claims to completely support AWT and Swing.
Maybe there's hope yet!
The program used in the benchmarks was very simplistic .. I would rather have seen a program creating and destroying many objects of various sizes. In the nativly compiled version, how does garbage collection work? Is it possible to write AWT apps? Swing?
"Java is nice in the fact that you can do pretty much anything with it. However, while you're doing pretty much everything, you might want to look at other languages, which'll do specific instances of everything *better*."
This is built into the .NET Framework. Run ngen.exe on any .NET .exe or .dll and the MSIL is precompiled into an optimized native binary. In fact, setups for .NET apps can do this on the assemblies they install. Indeed, the .NET Framework actually precompiles its managed shared .dlls on install time.
The big advantage of GCJ isn't speed, it's the vastly better interface to C++ code (CNI vs. JNI). Of course, using that really does make your code non-portable.
Those were supposed to run the bytecode natively in hardware, for blazing speed. Why haven't we heard anything more about them?
I, personally, *resort* to Java only when I'm looking for a level platform-independence that can't be accomplished with Tcl. Is it really worth the hassle to not use an alternative langauge that is more efficient if we're targeting a single platform?
Good progress is being made in native compiler for Palm OS. See http://sourceforge.net/projects/jump/
and also http://www.superwaba.org for info on the related JVM for PDAs that it replaces.
Good stuff.
Beta only seems to work for Google. Such a shame.
I always thought Java was very interesting with it's cross-platform compatibility and whatnot. But as everyone has noted, it's painfully slow. I always wondered why people hadn't implemented a native-code compiler for it. Sure, with bounds-checking and garbage collection, natively compiled Java will still be slower than natively compiled C++.
The point is, Java is really just another programming language. What's wrong with allowing developers the opportunity to write their natively compiled software in a solid, object-oriented language that doesn't have all the backwards-compatability issues that C/C++ has?
Whether this will be useful, I dunno. But it opens up options, and that's always a good thing.
Learn to Play Go
I hope you're not using university bandwidth to post racist messages. I don't think they'd like that.
I don't have to run those obfuscation-wares everytime I build.
Obscurity != security. For every piece of obfuscation-wares, there's an equal and opposite piece of de-obfuscation-warez. Besides, what do you have to hide?
Will I retire or break 10K?
Seems to me the problem with Java is that it waits until memory is full to garbage collect. In C++ Code, if you allocate and free a lot of memory, eventually you are going to fragment your memory to the point where you may not be able to allocate large enough memory blocks for your purpose. GC is supposed to get around that. But if C++ doesn't GC, how can a C++ app run indefinitely. I would really appreciate someone who understands the subtle nuances to explain. If there are better memory allocation schemes, couldn't you use them until you were forced to use GC?
Open Source Identity Management: FreeIPA.org
I was a little disappointed in the selection of the the JVM's they selected for their example. Especially now that PDAs/CellPhones are now powerful enough to run real applications on the client. I have yet to see a StrongArm device ship with the Sun, IBM, or KaffeJVM, why, because they are slow. The JVMs listed in the subject line run 10-200x faster on devices. Soon we will see EJB and other J2EE compents on PDAs. As a developer of client java applications/applets I would never distribute a device specific application, it would be a nightmare to have 160 diiferent compiled versions of the same application. The good JVMs already have done that, and my code I compiled years ago works on the newest PDAs...So there
"Get them before they get....
That isn't to say garbage collection is necessarily a bad thing -- it's good for security and portability (the two things Java really aims for) since it eliminates the need for all those nasty pointers. But it's the main reason C++ code can runs circles around similar Java code. And doing native compilation won't help the situation any.
Garbage collection is not by definition slow and is generally the same as new/malloc -- although lots of people seem to think it is alot slower. For non-gui code and if your doing pure Java code (i.e. no JNI) the performence is rougly comparable to C++ (assuming you have a good JVM).
I am not a number! I am a man! And don't you
This has been happening for quite some time. Native code compilation of java is nothing new!.
Derek Greene
when it's set to produce bytecode? If it produces slow bytecode, then it wouldn't be that surprising for it to produce slow native code as well. This could just mean that it's immature and not well optimized. The article would've been more useful if he'd tried out more than the one native compiler, as well, since he lists eight of them.
I'm not going to try to champion Java, JITs, or native compilation, I'm just going to point out what's wrong with this "study".
This has to be the third or fourth weak study of Java performance I've seen over several years. Issues such as whether or not all Java features are in place in the native compilations (e.g. array bound checking, but note that GCJ turns this on by default) or what sort of optimizations are performed by the native compiler and JVMs are completely ignored. The author also suggests that compiling from bytecode to native code is the natural route when it's quite possible that gains could be made by compiling directly from source to native. While GCJ accepts either Java source or bytecode, it's not clear from the documentation I've read whether or not it first translates source to bytecode or goes straight from source to native.
When comparing disk space, the author comments that an installed JVM can be up to 50 MB vs. 3 MB or so for libgcj. This is a ridiculous comparison since those directories probably include all of the tools, examples and libraries, and as far as I know, libgcj doesn't include the whole J2SE API set, so it's nowhere near a fair comparison. It's a pretty limited set of benchmarks for making these judgements too.
I played around with native compilation of Java a few years ago. At one point (probably around 1996/7?) native compilers could offer noticable gains over Sun's JVM on a numerically intensive application (neural network stuff). However, after the initial versions of HotSpot and IBM's JIT, I couldn't find a native compiler that gave competitive performance on similar apps. I think this is largely due to underdeveloped native compilers with poor optimization (HotSpot is quite insane in its runtime optimizations).
Anyway, I sure hope IBM doesn't pay too generously for studies this poor. Its final message is essentially "who knows?" - not terribly useful.
Alea
As I understand it, the performance gains are probably marginal. Native code compilation is not too different from JIT compilation, I would think. You do need something to do garbage collection, RTTI, etc. That doesn't go away, and is probably the majority of the performance hit.
As a Java developer, I think this is great, and it might allow Java to be able to compete better with C#. In any case, it's certainly not a bad thing. If you want to generate classfiles, it's just an intermediate step for any native compiler, so WORA won't go away.
And to he who made the comment wrt operator overloading -- it's a damned maintenance headache, that's why it's not included in Java.
Taking a quick glance at the benchmarks, it looks native compilation is not all it's cracked up to be.
With the renewed interest in beos thanks to the leaked 5.1/dano release, developers for beos should seriously consider trying for a native compiler since the various jvm projects arent going anywhere fast. If beos could run java apps, I could see this renewed interest continue to grow at amazing rates..
"...compiling Java apps to run as native appplications on the target machine without the need for a JVM."
In other news, they have also decided on a name for this wonderful new technology: C.
Simpli - Your source for San Jose dedicated servers and colocation!
People think of the VM as an interpreter that executes the bytecodes. That's a particular implementation of a VM. And not a very good one -- which is why no production VM works that way.
The simplest optimization is to use a JIT. This gives you native execution speed once the class files are loaded -- but loading is slower, because it includes compiling the byte codes. You can end up wasting a lot of time compiling code you'll only execute once -- most programs spend 90% of their time in 10% of their code. Depending on the application, you can end up wasting more time on unnecessary compilation than you save by running native code.
Intuition suggests that the most efficient thing to do is to "get rid" of the VM by compiling everything to native code before you distribute your app. But that doesn't get rid of the VM -- it just converts it to a different form. There are some VM features you can't compile away, such as garbage collection. Some experts claim (not me, I get dizzy when I even read benchmarks) that "pure" nativeness is illusory and not that efficient. Plus you lose a lot of the features of the Java platform when you run the program that way. Might as well stick with C++.
Some VM implementations use a sophisticated comprimize between interpreters and JIT compilers. If you can identify the small part of the program that does most of the actual work, you know what parts of the program really need to be compiled. How do you do this? You wait until the program actually starts running!
Advocates of this approach claim that it has the potential to be faster than C++ and other native-code languages. A traditional optimizing compiler can only make decisions based on general predictions as to how the program will behave at run time. But if you watch the program's behavior, you have specific knowledge of what needs to be optimized.
Computer science breakthrough, or illogical fantasy? Don't ask me, I'm just a spectator.
The engineers I picked this stuff up were very contemptuous of "microbenchmarks" like those described in the developerWorks article. Nothing to do with the real world.
Actually, the first gives 111 and the second 795.
First, I have to identify that we (my company) do use the JET byte->native compiler by Excelsior. Good product, I've recommended it to others and they've had success with it too. In our case, it produced a 10-15% speed increase, some in-memory size savings, and it had one huge advantage missing from the byte code: SECURITY!
After experimentation, I'm pretty convinced that the decompilers on the market that work on obfuscated byte code KICK THE CRAP OUT OF THE OBFUSCATORS. The long and the short of it is the decompiled code is pretty decipherable.
If you want to protect your IP (Intellectual Property), that's not a good thing. In fact, that might be (if you are in a competitive arena) a VeryBadThing(TM). The native code (especially optimized native code) is far harder to effectively decompile into something usefully readable which crackers and script kiddies can abuse or which competitors can peruse. This benefit alone makes it worth going this route if you can.
One of the other things the article missed:
It didn't devote much thought to the settings and optimizations these compilers provide. The Excelsior compiler (by example, I looked at Bullet Train and some others before we picked Excelsior) provides ways to disable certain safety checks (like array bounds checks) for extra speed. If you're in a fairly aggressive environment with some pretty significant timing issues (I won't say hard realtime, because anyone doing hard realtime should be using something like QNX), you will find that even these small gains may be useful (and the risks they introduce acceptible). But the article didn't even hint at these possibilities.
So, if you want to build something that is less likely to be cracked or examined, this type of tool is the way to go. Excelsior, for example, is fairly easy to setup. I did get some help from their guys, but only because our product includes OpenGL, QuickTime, a bunch of XML parser stuff, DirectX, sound support, UI, etc. - a whole pile of external dependencies. The buddy I recommended it to had his project up in going in half an hour or so, with a more modest project (but still a useful, full fledged app with GUI).
Undoubtedly, these won't solve all your ills and they may introduce some new difficulties in bug hunting (though some of the new debuggers coming out with these products are very neat also). So you will want to look at what you need, what your concerns are (security, speed, cross platform deployment, etc) and decide accordingly.
-- Mal: "Well they tell you: never hit a man with a closed fist. But it is, on occasion, hilarious."
eat my ass, fuckmonkey. the trolls are the only reason i come to this site.
browse at 0.
thank you.
--
the strongest word is still the word "free"
The aphorism "you can't tell a book by its cover" originated in the times when books were sold in plain cardboard covers, to be bound by each purchaser according to his own taste. In those days, you couldn't tell a book by its cover. But publishing has advanced since then: present-day publishers work hard to make the cover something you can tell a book by.
I spend a lot of time in bookshops and I feel as if I have by now learned to understand everything publishers mean to tell me about a book, and perhaps a bit more. The time I haven't spent in bookshops I've spent mostly in front of computers, and I feel as if I've learned, to some degree, to judge technology by its cover as well. It may be just luck, but I've saved myself from a few technologies that turned out to be real stinkers.
So far, Java seems like a stinker to me. I've never written a Java program, never more than glanced over reference books about it, but I have a hunch that it won't be a very successful language. I may turn out to be mistaken; making predictions about technology is a dangerous business. But for what it's worth, as a sort of time capsule, here's why I don't like the look of Java:
1. It has been so energetically hyped. Real standards don't have to be promoted. No one had to promote C, or Unix, or HTML. A real standard tends to be already established by the time most people hear about it. On the hacker radar screen, Perl is as big as Java, or bigger, just on the strength of its own merits.
2. It's aimed low. In the original Java white paper, Gosling explicitly says Java was designed not to be too difficult for programmers used to C. It was designed to be another C++: C plus a few ideas taken from more advanced languages. Like the creators of sitcoms or junk food or package tours, Java's designers were consciously designing a product for people not as smart as them. Historically, languages designed for other people to use have been bad: Cobol, PL/I, Pascal, Ada, C++. The good languages have been those that were designed for their own creators: C, Perl, Smalltalk, Lisp.
3. It has ulterior motives. Someone once said that the world would be a better place if people only wrote books because they had something to say, rather than because they wanted to write a book. Likewise, the reason we hear about Java all the time is not because it has something to say about programming languages. We hear about Java as part of a plan by Sun to undermine Microsoft.
4. No one loves it. C, Perl, Python, Smalltalk, and Lisp programmers love their languages. I've never heard anyone say that they loved Java.
5. People are forced to use it. A lot of the people I know using Java are using it because they feel they have to. Either it's something they felt they had to do to get funded, or something they thought customers would want, or something they were told to do by management. These are smart people; if the technology was good, they'd have used it voluntarily.
6. It has too many cooks. The best programming languages have been developed by small groups. Java seems to be run by a committee. If it turns out to be a good language, it will be the first time in history that a committee has designed a good language.
7. It's bureaucratic. From what little I know about Java, there seem to be a lot of protocols for doing things. Really good languages aren't like that. They let you do what you want and get out of the way.
8. It's pseudo-hip. Sun now pretends that Java is a grassroots, open-source language effort like Perl or Python. This one just happens to be controlled by a giant company. So the language is likely to have the same drab clunkiness as anything else that comes out of a big company.
9. It's designed for large organizations. Large organizations have different aims from hackers. They want languages that are (believed to be) suitable for use by large teams of mediocre programmers-- languages with features that, like the speed limiters in U-Haul trucks, prevent fools from doing too much damage. Hackers don't like a language that talks down to them. Hackers just want power. Historically, languages designed for large organizations (PL/I, Ada) have lost, while hacker languages (C, Perl) have won. The reason: today's teenage hacker is tomorrow's CTO.
10. The wrong people like it. The programmers I admire most are not, on the whole, captivated by Java. Who does like Java? Suits, who don't know one language from another, but know that they keep hearing about Java in the press; programmers at big companies, who are amazed to find that there is something even better than C++; and plug-and-chug undergrads, who are ready to like anything that might get them a job (will this be on the test?). These people's opinions change with every wind.
11. Its daddy is in a pinch. Sun's business model is being undermined on two fronts. Cheap Intel processors, of the same type used in desktop machines, are now more than fast enough for servers. And FreeBSD seems to be at least as good an OS for servers as Solaris. Sun's advertising implies that you need Sun servers for industrial strength applications. If this were true, Yahoo would be first in line to buy Suns; but when I worked there, the servers were all Intel boxes running FreeBSD. This bodes ill for Sun's future. If Sun runs into trouble, they could drag Java down with them.
12. The DoD likes it. The Defense Department is encouraging developers to use Java. This seems to me the most damning sign of all. The Defense Department does a fine (though expensive) job of defending the country, but they love plans and procedures and protocols. Their culture is the opposite of hacker culture; on questions of software they will tend to bet wrong. The last time the DoD really liked a programming language, it was Ada.
Bear in mind, this is not a critique of Java, but a critique of its cover. I don't know Java well enough to like it or dislike it. This is just an explanation of why I don't find that I'm eager to learn it.
It may seem cavalier to dismiss a language before you've even tried writing programs in it. But this is something all programmers have to do. There are too many technologies out there to learn them all. You have to learn to judge by outward signs which will be worth your time. I have likewise cavalierly dismissed Cobol, Ada, Visual Basic, the IBM AS400, VRML, ISO 9000, the SET protocol, VMS, Novell Netware, and CORBA, among others. They just smelled wrong.
It could be that in Java's case I'm mistaken. It could be that a language promoted by one big company to undermine another, designed by a committee for a "mainstream" audience, hyped to the skies, and beloved of the DoD, happens nonetheless to be a clean, beautiful, powerful language that I would love programming in. It could be, but it seems very unlikely.
by Paul Graham
it should be noted that this is the first time i've been modded down.
if feels so good to be so bad.
--
the strongest word is still the word "free"
Another Thing About The Article:
1995 called. They want their story back, pronto.
If you celebrate Xmas, befriend me (538
You know, I would be a lot more impressed with Jawa bytecode. The label "utinni" would stand for any register- let the computer worry about it. If it was English it would be like saying "move 0x203 over there".
graspee
s/if/it, but you knew that already.
and you fuckwit mods better get on the ball, I'm looking for some negative karma here.
--
the strongest word is still the word "free"
Is it just me or does this article seem like a shameless plug for IBM's JRE? It seems to wil all but two of the tests (and those are regarding memory usage, not so much performance). I'm betting they picked the tests that the IBM JRE would score well on to push their own product, while letting native compilation come in second a lot of the time so it could still be somewhat of a winner. I wouldn't make decisions by these numbers in any case.
Brian
I also realized that native compilation would destroy the cross-platform capabilities of Java. So I always thought it would be cool to distribute Java apps with both native compiled code for a specific platform and Java bytecode too. That way if you happened to be running the target platform you could get the speedup. If not you could still run the app, and maybe even compile the bytecode to a native app for your platform. This is similar to the fat-binary idea that Macs used when they switched from 68k chips to PPC, allowing a binary to run on either platform.
Lasers Controlled Games!
A while back, there was this thing called "C" which already does this. Some say it is faster too, but that's an entirely different dead horse needing little beating.
I've always thought AS/400's native compilation was very cool. The bytecode hangs around for compatibility purposes, and there's a hidden staticly compiled object that the system links to it. You probably haven't noticed a lot of performance benefit from it because you're already using compilation without knowing it (your default optimization level is 30 or higher) or you're using the JIT, which is also screaming these days. Try using optimization level *interpret and you'll see what I mean.
AS/400 can also use WPO (Whole Program Optimization) when creating the program objects... something you can't get in a JIT. However, a good JIT will selectively optimize heavily used pieces of code... something not even the best native compiler can do. However, A native compile with WPO would be hard to beat with almost any program.
I found it interesting that this author, an IBM researcher, chose to only test a single java-to-native compiler, the GCJ (GNU product). This is an immature open-source package that I would not expect much performance from. His paper rehashes a lot of really basic info, then gives some performance results which show IBM's JVM spanking Sun, Kaffe, and GCJ. This is no great surprise; IBM is tooting it's own horn - fine, they deserve to IMHO. But as an exercise in "the state of native compilation" it's useless. What would actually be really useful is a comparison that also included at least a half-dozen other major players in the java native compiler market. I suspect you'd see some different results.
As an aside; I see people call Java "painfully slow," but in my experience it's not that painful post 1.3. I'm not giving you benchmarks, and anti-Java people will just "no" me, but these are my experiences after a few hundred thousand lines of Java code over the past few years. Anyway, it's a good exercise to ask naysayers what _their_ basis is; they often have none.
Also, as other posters have pointed out, the speed loss must be seen in the runtime safety context, as bounds checking and garbage collection yield stability and security dividends and, at the end of the day, we almost always want those things and are willing to wait the extra few ms for the guarantees.
All these complaints about speed are especially ironic given how many massive wasters there are in the modern computer, _especially_ in Windows NT/2k/XP.
But the biggest flaw in this Java vs. C debate is that often you don't get a choice between writing code in Java vs. C/C++, since you don't have the extra 50% in your time budget to do C/C++, and your real choice is between Java and VBScript...
All the people shouting "I can write C++ 10 times as fast as you can write Java, loser" please form a line in an orderly fashion, you will be spanked in the order you arrive...
We're on the road to Tycho.
These kinds of articles raise more questions than they answer. I have to ask what does Java native compilation gain me? Martyn writes in the article that performance and memory consumption were basically a wash on the more complex app, so what are the other considerations that might drive me to use a native compiler?
Native compilers have been here for a long time and they haven't really taken off. They either need to offer something absolutely necessary that I can't get via regular Java compilation and runtime, or they need to offer performance improvements that are orders of magnitude better than what we already have. If the vendors can do that, then I want to talk to them. Otherwise it's just another experiment in an already too busy world. Stph
I know nobody wants to hear it, but this is sort of similar to how .NET works, except you don't have to sacrifice anything. You still would distribute your program in the platform's bytecode (or IL, whatever) but you have the option of natively compiling this bytecode to native at any point. In .NET, this occurs automatically when an assembly is executed. It's generated native code is subsequently cached and used for future execution until the assembly file is replaced by a newer version. You also have the option to natively compile the assembly immediately where it will be stored in a cache called ZAP where it will always remain. Since .NET is always JIT compiled, the resultant performance boost isn't THAT great except for initial load times.
Hate MS all you want, this is not a bad idea.
So, in other words, you're a fucking moron who doesnt understand the stories, and goes for (mostly) retarded humor?
Wouldn't a native compiler defeat the whole purpose of Java?
I mean C is fairly portable in the sense that any console mode app will virtually build anywhere.
If they are moving Java to a "machine code" type system how would it improve on C [in ways that C++ didn't?]
Personally I'm a huge C fan, I can appreciate C++ and Java too. But this going full circle crap is just stupid.
Tom
Someday, I'll have a real sig.
Mister AC & SweetAndSourJesus, I love you both. Really, we're probably like Musketeers or triplets or some such shit. I'd love to See a FreeBSD/Scoop site side-by-side compared to any shit-pit running Linux/Slash.
My first two programming languages were both assembly,
:-D
so you know I am a performance freak by nature.
When I first tried java, the only two things that came
between me and it were run time and compile time
speed.
The later has been solved by native compilers, and GHz
speeds.
The first is yet to be solved.
For an edit-compile-run-debug programming language like
java, I need the least time between edit and debug.
The "one public class per file" policy forces some
code modularity, and with an incremental compiler,
speeds things up.
But the java compiler itself is SLOOW. My energy
is exhausted waiting to test the effect of a one line change. Turbo C did thrice that work, on my
286, under an operating system that didn't see more
than 640K bytes, thank you very much.
I am much more productive, evaluating my expressions
immediately in an emacs buffer, and running CLISP
as an inferrior
Lots of experts here.
Some experts who have never used Java want to tell me that it's no good, and will never be any good--why? They don't know, but they know!
And some experts who want to tell me all about why Java's compilation, why it is hard or easy even though they really don't know anything about a compiler.
And some experts on Java's market share who really don't know anything about who uses Java.
And some experts who sat in a room where Java was... gosh gee... being implemented, telling me... well I don't quite know what, but gosh!
So many experts here--I must be reading slashdot!
There's a thread about this article over at the gcj's mailing list: here.
The author chimes in, BTW.
Core dumps.
Don't be so sure - Java is still quite slow. However, I really don't know why the gcj results in the article were so slow considering no objects were created (no heap to contend with) and this was a purely CPU bound benchmark. Gcj uses the same compiler back end as gcc which delivers 3X the speed of java:
./prime
$ cat prime.cpp
#include <stdio.h>
inline int isPrime(long i)
{
for (long test = 2; test < i; test++)
if(i%test == 0)
return 0;
return 1;
}
main()
{
long n_loops = 50000;
long n_primes = 0;
for (long i = 0; i < n_loops; i++)
if (isPrime(i))
n_primes++;
printf("%d primes found\n", n_primes);
}
$ gcc -O3 -o prime prime.cpp
$ time
5135 primes found
real 0m17.885s
user 0m17.785s
sys m0.070s
Using JDK 1.3 (JIT) on the same machine:
$ time java prime
5135 primes found
Time taken = 59886
real 1m0.497s
user 0m0.030s
sys m0.050s
$ time java -server prime
5135 primes found
Time taken = 60387
real 1m1.228s
user 0m0.050s
sys m0.050s
The C++ version of the code takes 17.8 seconds versus 60 seconds for the equivalent Java code.
The memory consumption in the C++ program was less than a third of the Java program.
-
for
(long test=2; test < i; test++)
If the compiler generates slow code for that, something is very wrong in the compiler.{ if (i%test == 0) { return false; }
}
On the safety front, subscript checking is almost free if done right. Subscript checking can usually be hoisted out of loops. Old studies on Pascal optimization showed that 95% of subscript checks can be optimized out at compile time without loss of safety. GCC, though, being a C compiler at heart, isn't likely to know how to do that. Merely putting a Java front end on it doesn't make it a Java compiler deep inside.
Java, in the form of EJBs and servlets, is becoming fairly common on "big iron". One reason is indeed the cross-platformability of it. But, frankly, most often a change in platform accompanies a change in framework. For example, a switch from UNIX servers to a mainframe may accompany a switch from CGIs to an application server (such as Websphere). The dramatic switch here is probably not from UNIX to OS/390 (after all, OS/390 has a POSIX layer), but from CGIs to Websphere. So, as you said, it's not really cross-platformability which is driving Java in the server realm. I think the principal reason is that Java provides (at least some semblance of :) a language-level security model. By security, I don't mean crypto and virii and external attacks. I mean an application is secure from itself, and its (all too human) programmers.
It's being done by IBM, anyone would think it's biased? :)
:)
:/ (We call Kaffe 'MS' JDK'2, not just for humor, but it's really the case. ^_^)
:D
:)
Don't get me wrong, I'm a big fan of IBM, and IBM has really, really made a JDK multi-times out-performing SUN's JDK.
However, I'd believe the selection of 'opponents' are simily..unfair.
Kaffe is surely an easy-pick. Yes it's the only GPL JDK out there but many people(at least Java developers here) would avoid kaffe as it has a fatal security flaws that kaffe team doesn't seem to want to solve it.
Even the GNU people know gcj is slow, even GNU guys know it; but speed is not a real issue for gcj, it's basically a starting point for all implementation - or reference implementation as we like to call it. We would pick a commercial java compiler if we need it.
SUN's JDK, well...you know what I think it just what you think - IT'S SLOW! Yes, we all know that.
Nevertheless I think developer's work is doing a great job here, it confirms something everybody know - that IBM's JDK is fast, and that's it. I don't see it could conclude the performance of native compiled java programs. Unless they include all other commercial java compilers into testing, I wouldn't think we have reached a conclusion yet.
I have been a java developer for about 5 years. When I first heard of GCJ, I decided to try some informal benchmarking. One area which has sucked with java is IO performance. Sun is addressing this with jdk 1.4, but in a real world business environment, jdk 1.5 will probably been in production before anyone is switching. Anyway... My benchmark consisted of creating a text file of arbitrary length (1024 bytes was the default I think), and I found that IO performance with GCJ was even slower than java IO with the sun jdk. This was about 6-12 months ago, so GCJ may be better now, but at the time, all I could do was laugh. Take something which sucks, and make it suckier is not a way to gain market acceptance. ;)
What he should have said was, "without the need for an additional external JVM." But if it does not run in a JVM, it is not Java because that is part of the language specification. Native compilation is basically "statically linking" to the JVM. It does not make much sense to me. Its only forced because M$ does not put a quality JVM in with their OS so every java app decides to include their own. Its stoopid because the java app should just install the default JVM if its not there, not have 10 different apps each with a statically linked copy of the same JVM within them wasting 20MB... I have YET TO SEE a real native compiled java code. Sure if its non graphical and does not use swing. But you can not just take the whole java library and compile it to true native form. It just aint java no more, not that that is a problem, long as it works. But if your strip Java of most its benefits, why use it?
Most of the programs I write are small, text-based, unix-like applications.
I'd like to use Java because of its garbage collector, string, and exception support. The explicit memory allocation required by C/C++ is annoying (even more so without elegant error handling), and string manipulations are tedious in C.
The problem is that the VM is too bloated for small programs like this. What? I have to load a several megabyte (or more) VM into memory to run a program that's less than 100 KB?
And what if I want to distribute these programs? What? I have to ask users to download and install a several megabyte (or more) VM to use a program that's less than 100 KB?
And then there's the joy of dealing with different VM versions. What fun. Is there any kind of guarantee that future VMs and future libraries will behave the same way as the current ones? If so, backwards compatibility makes them even bigger.
As far as cross-platform issues go, I really don't care. I'd rather cross-compile if necessary, and as long as the source code is portable, that's good enough for me.
On the otherhand, companies buy Sun hardware not for pure speed, but for reliability, redundancy and proven scalability. The one thing all these benchmarks fail to address is "how important is speed over reliability and scalability?" A good programmer can take out lots of security, memory management and allocation checks to make it run really fast, but how stable will it be? Will it be solid enough to run 24/7 with 1% downtime? With the way CPU speeds are increasing, who cares about speed. Lets talk about the real issues, ease of development, maintainability of the code, built in document creation, wide selection of prebuilt libraries, consistent and solid security model and portability between platforms. My personal experience, large companies use a variety of platforms, so a windows only solution is not an option. A solution that allows multiple developers on different platforms to build their pieces and integrate is what many large projects require. Doing so with C can be done, but how many people feel C code is easy to maintain? I don't know that question, since I've never coded in C. Those I know who use C joke about how unreadable C becomes. Bottom line, each tool has it's strengths and weaknesses. It's about which problems you want to live with.
One of the best articles on native compilation is this performance report
Also see on Javalobby the The "native compilation" myth and RFEs for JDK1.5 threads which discuss native compilation.
Yes, there are some companies like Jet and Jove (and GCJ) making native compilers, but I'd like to see a company of the clout of Sun (or IBM) make native Java compiling more accessable by having a "javac -native" option with their JDK and a smaller standardized runtime (instead of the full JRE) specifically for native compiled apps. The most likely target for native compiled apps running w/o a JVM would probably for the client/desktop side which don't have the resources of server boxes. Remember... it would be an OPTION in the JDK... the old bytecode compiling for VM/JIT would still be there.
It's arguable whether the runtime performance of a native compiled app would be substantially better than JIT compiled (if some of the Hotspot tricks were moved upstream into the JDK compiler?), but there are also other advantages, such as a faster startup time (no need to startup a VM processes and JIT compile) better memory usage (no need for VM process as well as the meta data and bytecode which must be held in memeory). There would also be some drivespace savings as the full JRE wouldn't be needed (though at this time, a developer can't include a partial runtime, Sun wants the full thing if they include one... Sun needs a change of heart and make a standardized smaller runtime for native apps). Also, with native binaries an obfuscator (used for btyecode classes) isn't needed for commercial apps for those who want to keep their code proprietary.
There are lots of suggestions going around for the VM/JIT issues such as loading the VM at bootime, a singular shared VM, and JIT caching. These workarounds aren't neccesary with JVM-less native compiled apps.
Of course, there are WORA extremists who don't like this idea of native compilation because it goes against the dogma of only needing to compile ONCE and run on any OS with a JVM. IMO, as long as the source stays the same, compiling natively for different OS's is still pretty near to the WORA ideals. The Java language is VERY tweaked for portability as-is. It's the OPTION of native compiling that should be available in the Sun or IBM JDK.
NO.
Java sucks, and so do all derivatives of Visual Basic(VBA, VBs, etc). Whoever designed that pile of shit deserves to die.
The more you program in these languages, the more stupid you get. no joke. You'll notice such ppl instantly when they say, "Well, why don't u use java to write a kernel?". OMG. The end of time is approaching.
Once again with feeling (sorry I forgot, under deadline):
Jump Project
SuperWaba
Beta only seems to work for Google. Such a shame.
You simply can't run most Java programs without either a JVM or a bundled compiler. The reason for this is dynamic class loading. You can load classes by arbitrary name, from urls, from byte codes you've created on the fly in memory, etc, etc. These classes cannot be precompiled. So you either need a JVM to interpret them, a compiler to compile them, or both in the form of a jitted JVM.
Why do people complain about the size of the JVM? Every scripting language has to have the equivalent in the form of an interpreter. The *base* perl installation on Linux is 21MB. That's without docs and a UI toolkit (Java includes both). I don't hear complaints about the size of Perl's interpreter or the heft of the Tk or Gtk toolkit libraries.
Would people like Java more if it didn't have byte codes? If we had a Java shell like Perl, Tcl and Python? Skip the byte codes and let it be tokenized each and every time? Or is it just the cross-platform talk that rankles everyone? Maybe it's Sun's stupid open/not-open antics. Or perhaps it's just language l33t1sm.
http://java.sun.com/docs/books/performance/
-Steve
I am not a Java programmer and am by no means an expert at all, however I have a question that perhaps the experts can answer (this is not a flame nor flamebait -- it is a valid question that I have always had, asked many times, read a lot about and still can't find a good answer to). What are the merits of using Java? Why is Java so special? I have asked this question to many Java developers and I never get a good answer.
.this article about native Java code is just this. . .
The answers I typically get are not related to the programming *language* at all, but the organization and "java culture":
1) "Java classes are well-organized and well-documented and all-in-one-place." Not a language mertit! You can learn C++ classes as well.
2) "Java stops you from your own stupidity by not allowing pointers and has garbage collection." If you REALLY hated pointers that much you could write C++ code without pointers and write your own garbage collector (not to mention that LISP does garbage collection too -- nothing new).
3) "Java is cross-platform." I haven't seen too many implementations when cross-platform is needed at run-time. The browser cross-platform stuff seems to have died in the browser wars and Java incompatibilities in browser implementations, thus most Java developers that I know are making JSPs. You know the platform of your server (it won't randomly change without you knowing) so why not write in a higher-level language such as C++ and skip all the platform-dependant code (or do ifdefs) and have it run natively faster? If your platform changes you just re-compile. .
4) "Java has a cross-platform GUI". So is GTK and QT.
5) "Java is easy to learn". I'll skip that.
6) "Java has javabeans, etc". Not a language merit!
Other then the "java culture" and the fact that it's libraries are well organized, what are the real-world (not theoretical) merits to Java? Why program in Java when you can achieve the same result faster in another language? This is a serious question that has plagued me for years and I would love a good answer if anyone has one. It is a little off-topic however it does relate to the article because the article promotes killing one of the valid merits that I know of for Java (cross-platform).
Just distribute the bytecode, and let customers run a bytecode-to-native compiler when they install the app...
It took forever to compile, but once it was done, I had a (large) executable for my native platform, windows.
It ran about 30% slower than the JDK. There are a number of things that are still pretty slow in java, but in general, it's a pretty fast language these days. JIT compilers and hotspot to a good job. It can never be as fast as C++ due to things such as GC, but the performance tends to be close for most applications.
This is indeed interesting, but I think it is entirely irrelevant. Speed of execution is usually about 7th on the list of important-stuff-im-thinking-about when choosing a language and starting a project. There are so many more important things, such as maintainability, scalability, code reusability, code robustness (the number of stuff you get so easy compared to C++ just leaves you wondering how you could ever program in C++ again), you know the stuff. These things are often far more of an issue than raw performance. Look at Slashdot, it's written in perl, presumably because they thought it was easier to write the website in, not because it was the fastest thing around.
dominionrd.blogspot.com - Restaurants on
I agree. As much as I love Java, Swing is definately shit. Well, some of it anyways. Like JTree and JTable... They are very tedious and complex to use. The Tree and Table implementation in C# is much more logical and easier to use. And why is all of java pretty much synchronous, but the image processing stuff asynchronous? That's stupid. They recommend queueing up repaints every 100ms while you draw to the graphics object. But repaint calls update, which clears the graphics object. That means you have to draw the whole damn thing over again. And even if you fix that, what if you are painting in layers. Its screws everything up. So to solve that you use a MediaTracker and paint after the image is done loading. I've seen lots of other people's code, and they do the same... So with that being done, the whole thing might as well have been synchronous, and stick it on a different thread or something, and make it like almost everything else in Java.
And someone earlier said Java network classes are nice... Java network classes suck even more than Swing does. What if I don't want to spawn a thread for fscking everything? What if I want to have access to lower level things that Berkely gives you? Tho, 1.4 may fix that. But what's up with the static cache in the InetAddress.GetByName???? That makes it absolutely worthless, as if you call it to get the IP before you dial-up (for example), then no matter what you do, it will always return 127.0.0.1, likewise if you do it after, then no matter how many times you hang-up re-dial, and get a new IP, it will return the same IP. Or if you are using wireless, and you go out of range and come back, etc etc. Of course, there are undocumented APIs, but relying on those is stupid.
Anyways, I'm done ranting for now...
Why is everything inconsistent?
With Sun's latest JDK, behavior is different between Linux and Windows, despite it being the same version and from the same vendor.
Example:
Under windows: Component gets both Key and Mouse events, as well as repaints.
Under linux: Component gets key event, but frame traps mouse event. And frame traps repaint as well.
You would think they would have the same behavior... This really makes for write once, debug everywhere.
The biggest speed issues in Java are not from the JVM being an interpreter or JIT, they are from the API and the very high level of safety guarantees provided by Java.
Java code can be very fast, but you have to take the API and the nature of Java into account in your design. If you want to do nothing but sling strings around, you're going to pay a massive penalty for doing it in Java, because all of the Java API's (at least in 1.3 and prior) require String objects for any string activity, and String objects are non-mutable due to a concern for thread safe API calls. If you want to change the third character in a String, you get to either create a new String with that change in place, or you get to create a StringBuffer class that will spew non-mutable String copies for each time you want to use the characters in your StringBuffer.
A C program would never ever do things this way, and so you get insanely better performance. But if you write a C++ program that does do things this way, you'll actually get performance that is very close to Java's, except you have no guarantees as to the integrity of any of your objects because some random piece of code can scribble all over anything it wants to. Plus no universal set of exception classes that everything knows about, no portable thread synchronization primitives, etc., etc., etc.
- jon
Ganymede, a GPL'ed metadirectory for UNIX
I've used both C++ and Java extensively (although I haven't used garbage collected C++).
For ease of coding, I find that Java simply outshines C++ because it doesn't leave me dealing with low level stuff, like pointers.
An occasional big time-killer with C++ is trying to debug something that corrupts memory.This doesn't happen with Java (although you can muck up the synchronization with threading and get unpredictable results which is just about as bad).
On the other hand, if I want performance (such as writing image processing software), I'll go with C++ (or assembler), as there is no way that Java can compete on speed for low level stuff.
And even the awful C++ templates are better than no templates at all.
No JVM for this baby.
A feeling of having made the same mistake before: Deja Foobar
I would rather listen to a series of speeches by Fidel Castro, Mulmar Quadaffi and Osama bin Laden than inhale that crap that passes as serious discussion on Javalobby. Typical Javalobby "discussion": "There (sic) gonna hurt Java!" or my favorite "How are we gonna get back at Microsoft for C#?".
That would be browsing at "+3" or more.
Whoops, the truth gets modded down again.
The richness of a language's vocabulary is what lets its speakers express themselves in powerful ways distinct from what other language speakers can do. French has a number of terms and concepts that don't have direct translations in English, and in fact, a huge amount of common English vocabulary comes from French.
A programming language's libraries are equivalent to a natural language's vocabulary. And this is exactly where Java shines the most from an application development point of view. (It shines for other reasons on other fronts, like for embedded programming.)
Sure, you can go out and develop a C++ app without using pointers, but that's just one app. The next one probably will use pointers. Even if I become a C++ programmer and refuse to use pointers in all my applications, I will have to work with someone who does, or use a library that requires them (is there one that doesn't?). And, eventually, I'll have to maintain someone's code that uses pointers. In the end, there's no getting away from it. Java eliminates the vulnerability pointers represent unilaterally, for better or worse.And similarly, you can go grab a library for doing garbage collection, but which one? You have nearly infinite choices, and every app will make a different choice. It's exactly the consistency of features that make Java superior in this regard. And when I say superior, I mean cheaper, and not just in terms of money, but in terms of resources. The support engineer trying to fix a bug in a Java program won't have any questions about the subtleties of a garbage collection API he's never seen, nor wonder what's in this odd little pointer that seems to keep causing a production crash. These are real advantages, even if they are hard to quantify.
That's just the limit of your experience then. My experience is exactly the opposite. The advantage here is the fact that you maintain a single codebase--the same source files--for all platforms, and they do work as advertised minus any VM bugs (which are fairly rare compared to application bugs).Let me tell you a story. I used to work for one of the real success stories of the dot-com era. My company implemented different pieces of its product using Java and C++, and these pieces used CORBA to interoperate. As far as any one distributed object was concerned, the object on the other end could be any language; it was only a difference of implementation.
Anyway, the support and maintenance costs for the Java portion of the product were dramatically lower than for the C++ portions. They both used the same infrastructure, but one was cheaper and faster to develop in, easier to fix and enhance for the next version, easier to debug both in-house and in the field, and more stable to boot. Add to this the fact that you only had one copy of the source files for the Java portions, versus the several versions for all the different platforms we supported in C++. In the end, if you work on large, complex software systems, Java is vastly easier to maintain, and vastly cheaper to support. Ask any of the product engineers and they would say the same thing: Java is just more pleasant and productive to work in, and they prefer Java over C++. They all hated the C++ portions of the product, and regretted ever putting them in.
And, sadly, most programmers out there aren't that good. With C++, you give them a loaded weapon and tell them to be careful. As often as not, they inadvertantly shoot you or themselves. At least with Java, poor programmers have to load the gun before they can shoot anyone. Sorry for the extended analogy.
Ugh, so much to say here. The problem is that what you are suggesting is a myth; it does not represent the real world of enterprise application development. You don't know your platform, it is not a constant in the equation. You want to provide for all platforms if you're a software vendor. Once you can sell to one, using Java, you can sell to all others without any significant extra effort. Furthermore, bugs fixed in one version of your code are fixed in all versions--support costs go down dramatically.If you're a client, you may find that you are grossly unsatisified with vendor X's hardware/support/performance and want to switch to using a solution by vendor Y (and this happens all the time in the corporate environment). What do you do now? Just because you know things are changing doesn't make the cost of changing any less. However, the fact that you wrote your application in Java does make the cost less--it makes it nil, because the same code runs on HP, Solaris, Intel, Windows, Linux, MacOS, AS/400, etc. The ability to move code effortlessly between platforms allows you as a company to save costs if it makes sense to switch hardware platforms, or mix and match platforms.
Yes, but the application code your GUI fronts is also cross-platform. Not so with the others. And again, there's the benefit of the single binary versus a binary per platform. That's fine, but it really is. Try it. The limited complexity of the language lets programmers focus on the task at hand far more easily in my experience, and it's much easier to do OO in Java than in C++. This means all the benefits of OO are more easily achievable (and if you don't think OO is a good thing, don't bother talking to me.) If you can, great, but I haven't found that language yet. It might be Smalltalk, or Perl, or COBOL, but nothing so far has taken all the great ideas from all of these languages and made them so eminently useful and practical. For example, Smalltalk is probably the most elegant, most forward-thinking languages around (even today), with tons of powerful features. However, it doesn't have the network orientation that Java does, or the C/C++ like syntax that makes it easy for developers to learn. It doesn't have the ability to be pared down and run inside a DIMM-sized computer, or be as dynamic as Java.I'm not advocating Java over other languages if those languages are more suited to the job. I'm not going to write a device driver in Java. I'm suggesting that a task that can be equally accomplished in Java and some other language will be more maintainable, cost less to support, and completed more quickly, when written in Java. The real-world merits of Java are that it reduces resource costs for anyone using it, end of story.
The only certainty is entropy.
"runtime" ? You mean "compiled VB6 apps" are native 386 executables?
...
A few days ago, I had a little problem with this vb6 thing.
I wrote an expression like this :
IF i>=0 AND x(i)7 THEN
The trick here is that the second term is not evaluatable at all if the first one is false (typical C/C++/Java/C# code).
Guess what? Your nice vb6 "runtime" evaluates the whole expression! Exactly like EXCEL or any programmable calculator! It took me more than a hour to find the problem in my code!
This is typical of an INTERPRETER that keeps an expression as a tree of terms in memory, and has no choice but evaluate the whole thing. Real compilation leads to generate code that computes the expression, so that a branch of it can be skipped, like in the above example. Even Java does this right.
How come C# and "vbnet" have no such problems? Is it a real "runtime" now at last?
Sun pushed *binary* compatibility so hard because Java's claim to fame was taking what loaded into your browser from static content to full executable apps -- making the underlying OS irrelevant in the process. "Death to Windows!"
It didn't work out. Client side Java is essentially dead. "Death to Java applets!" C#/.Net will become what Java only dreamed it could be -- but, sadly, only on Windows.
In the meantime, Java hit pay dirt on the server, because the language is so easy and productive to work in and the result is so portable.
Source portability would have been sufficient on the server, though. I can't prove it, but I strongly suspect they could have created a better server-side programming language if they had designed for 100% *source* portability, then instead of constraining themselves to binary portability and security sufficient for running *anybody's* binaries on *anybody's* client, had instead optimized for high performance plus ease of rapid, bug-free development -- more like Eiffel.
"Those who have never entered upon scientific pursuits know not a tithe of the poetry by which they are surrounded."
For example in C/Java I have:
if (FixedLess(FixedAdd(FixedCreate(1.0), foo), FixedMult(FixedCreate(2.5), bar))
which in C++ would be
if (1+foo Fixed(2.5)*bar)
which is much easier to write and understand. If you sausage your code by calling things stupid names then what do you expect?
Well, maybe if you programmed safely you wouldn't have these problems.
I mean - why the hell are you programming in VB6 if you dont know what you're doing ?
It reminds me of that oldsaying.... something about a shoddy craftsman blaming his tools...
Some VM implementations use a sophisticated comprimize between interpreters and JIT compilers [sun.com]. If you can identify the small part of the program that does most of the actual work, you know what parts of the program really need to be compiled. How do you do this? You wait until the program actually starts running!
Advocates of this approach claim that it has the potential to be faster than C++ and other native-code languages. A traditional optimizing compiler can only make decisions based on general predictions as to how the program will behave at run time. But if you watch the program's behavior, you have specific knowledge of what needs to be optimized.
Err - but you can do that with C++. Ever heard of Feedback Directed Program Restructuring (FDPR)? You run your code under whatever load you feel like optimizing and use the FDPR tools to rebuild the code, changing the ordering and ensuring that cache misses are minimized as much as possible. Try taking a look here for some more details.
Cheers,
Toby Haynes
Anything I post is strictly my own thoughts and doesn't necessarily have anything to do with the opinions of IBM.
Why doesn't HotSpot have a bin dump of its 'insanely' optimized native code? This way, you have a small and fast native app, and a smaller 'JVM' footprint that supplies the rest of the stuff you don't want natively compiled (like GC thread etc.) Unless I miss something, I'm sure this is technologically achievable on Sun's part, but they're not doing it for political reasons. Do people remember the days of JavaOS and Java chip? When the JVM is part of the OS, you can't call it 'virtual' anymore, and this subtle difference has a psychological effect on people so they will stop complaining about the JRE footprint etc: the JVM process is officially now part of the group of system kernel processes. So then JavaOS becomes a platform by itself and who knows if it will be compatible with any other platforms out there, especially if it starts to gain a significant market share. Just face it: IT business is 99% about market share and locking users in.
www.rexguo.com - Technologist + Designer
. :-(
:-)
Sorry but, I would like NOT TO touch this vb6 thing!!! Unfortunately, I *have* to touch it from time to time in my job ("programming" is a word I would personnaly never use when refering to vb6) when our local VB expert is on holydays!
Besides, my remark was not about my personal problems or my dangerous coding style! It was about whether or not VB*DLL contained an interpreter, or a modern Virtual Machine ("runtime").
I think my little incident with interpreted expression evaluation was perfectly demonstrative about that. There must be millions of other details like this one, that I obviously don't know (and don't want to) regarding what vb6 was and was not.
And, please, start thanking MS Management for giving you the net/sharp Virtual Machine, so that dangerous people like me can stop blaming their tool !
So why aren't you switching? Rates go up as the number of practitioners in the field drops - usually as a result of reduced demand. The last man standing in the C++ practioner market will be a happy camper, but this doesn't indicate a success for the language.
A comparison with C/C++ compiled by gcc. At least for the prime factorization, changing the code from java to C would have been trivial, and would also show any discrepancies between natively-compile java vs. compiled C.
My server
> If your programming mucks up, the wrong people
> DIE. If you don't have standards that are
> _rigorously_ abided by, our soldiers DIE.
Ah, a convincing argument for Windows deployment
by the US military. And so eloquently put!
Bah. My beef with java is and always has been that it is slow, buggy, and produces a reliably ugly GUI when you need to create one. It really doesn't matter which platform, either. Apple used to do this advertising (you will laugh) which said "See java run - quickly!" Guess which OS? If you guessed X, you're right. The fact is that for whatever reason (I admit ignorance - I don't know!), Java is slower than other languages. I have been watching this thread, and it is interesting to see the arguments re: automatic garbage collection versus manual cleanup.
My >guess is that the reason most Java apps run so slowly is because the language is structured in such a way that it is easy to write sloppy code. For example, why bother figuring out which specific library to call up when you can just call java.lang.* in your file. In that sense, I guess I am guilty as charged. The second biggest reason most people poo poo Visual Basic is that it lets people get awaw with writing shitty code. Same with Java.
political_news.c: warning: comparison is always true due to limited range of data type
Obviously Java has not turned out to be the universal solution that it was supposed to be. Of course there are non-Java solutions for some problems that are objectively better, or at least preferrable to the developers that employ them.
The purpose of my rant was not to advocate Java in general, or any particular approach to it. (In point of fact, I haven't worked with Java for over 3 years. As I said, I'm no expert, and it doesn't suprise me that people find flaws in my summary of the VM issue.) I was merely pointing out that the naiveness of the VM-versus-Native dichotomy.
Then perhaps you should learn how to use C++.
Not to flame you -- I'm usually the first person to use the right-tools-right-job argument -- but one of the best books to teach C++ doesn't even mention pointers or builtin arrays until chapter 10. They teach C++, not C features that happen to show up in C++.
After having used C++ quite heavily for a decade, even I found parts of this book refreshing. I highly recommend it, both to beginning programmers, and crusty veterans like us.
You cannot apply a technological solution to a sociological problem. (Edwards' Law)
For example, why bother figuring out which specific library to call up when you can just call java.lang.* in your file
erm, you're a dumbass, get a life and stop trolling and go gain some education, every _normal_ programmer knows that importing a whole library doesn't change a thing, when it's compiled, it always has absolute class references.
IMO, Perl is the one that allows to write sloppy code with undeclared variables and cryptic syntax
"when it's compiled"
And I suppose the compiler doesn't need any resources to run? So who's the dumbass? BTW, post with your logon if you want to namecall.
political_news.c: warning: comparison is always true due to limited range of data type
Python (and eLisp too, for that matter) both have bytecode compilers. Don't know nothin' 'bout perl.
I tend to sympathize with the write-once-run-anywhere (WORA) advocates.
I haven't seen single cross-platform programming language that didn't have some platform-specific idiosyncrasies. You either have to avoid those areas completely, or try to code around them.
If you need those features, then you have to fix things for the specific platform at either compile-time or run-time. Compile-time means some kind of hack like the C pre-processor. Run-time means dynamically loading the correct version of some class. Either way, I say: "Ugh." That's not to say that either approach won't work, but it isn't as pleasant.
It keeps things simplier and saner when you're just targeting the same VM and standard libraries. You still have to have a bunch of conformance tests to make sure the particular JVM is compliant, but that's easier to maintain than platform-specific code in every application you write.
I've been doing mostly Java programming for the last couple months, and while there are a number of features in the language that annoy me, the overall development process is more pleasant than in other environments.
Seems to me that native Java would be virtually indistinguishable from native C++.
I can't believe how much Java has backed away from its cross-platform emphasis. Oh ok, let's make Jini for when you want to use Jave but need it in this special platform. And why not let you comile to a native binary? Sheesh... not much Java left.
You can do the same thing with C or C++. Or ANY language that you can compile. If Java compiled separately for each different platform is 'cross-platform' then so is C++. This DOES eliminate cross-platform as a benefit. And confirms the point that if you have a large, slow Java application where the speed is a serious problem, you should have written it in C++ in the first place.
PS - Your definition of "toy code" applies to anything other than an operating system....
If your fridge asks the printer to print something, then status messages for that print job will be returned to the requester automatically. If the fridge has any message display mechanism, it can decide to display the messages. Or it can ignore them. What the fridge does with its messages isn't the printer's concern.
.Net to become more successful at this than Java due to MS's dominance of this type of client.
The printer and the fridge have no need to reprogram each other. They just need to send messages in standard formats appropriate for the class of device: a printer or a fridge.
Java was designed to run on general-purpose clients, and it's only there that the idea of sending executable code makes more sense than sending remote API calls. I think that will mostly mean clients with browsers, and I expect
"Those who have never entered upon scientific pursuits know not a tithe of the poetry by which they are surrounded."
Actually, you've hit the nail on the head without realizing it. Java, like Perl, is a wonderful scripting langauge, and things like Perl are exactly the kinds of things it should be compared with. It's talk as if Java were in the same category as C or C++ that rankles everyone. If Sun wants to push Java as a much better alternative to Perl, I think people would be less rankled than when Sun acts like Java is the C++ killer or some such nonsense...
"Convictions are more dangerous enemies of truth than lies."
<sigh> Like it took me two minutes to type that... (silly slashcode...)
"Convictions are more dangerous enemies of truth than lies."
runtimes and interpreters are not virtual machines. A virtual machine includes pseudo-registers, a stack pointer, etc. This is as opposed to runtime libraries, which are not interpreters, but binary code your app can be linked against, and which you can call the various functions.
Squishing an interpreter and its' script into an 'exectuable' is an old trick:
dBase executables, dbFast executables, vb executables, etc. Their idea of 'linking' is not the same as a true compiled language.
The idea of pcode was actually started a couple of decades ago with pascal pseudo-compilers, which compiled down to byte-code which could be interpreted by the run-time quicker. Now, of course, pascal compiles to object code (and you can do the same w. basic - remember Turbo Basic). The true test is if other languages can link against your object files.
Just a bit of history, for what it's Wirth (pun intended) (re Nicholas Wirth, so I don't get fl*med for spelling).
is still a language that's much easier/quicker to code in than C++,
and that has all the portability of the old Java, in addition to this (still vaporware) extra feature.
When in doubt, have a man come through a door with a gun in his hand.
64-bit add, subtract, and multiply work fine if the numbers fit in integers. Overflows on conversion back to integer cause an invalid-arithmetic-operand FPU exception, which Java can use but C has no idea what to do with. So that's fine.
Divide and mod are tougher to do as integer operations in the FPU, because fractional results appear in the FPU registers, but it's possible if the rounding modes are set to "round down". Note that the benchmark used "%", and it's possible that GCC doesn't try to do 64-bit "%" (which, after all, isn't used much) in the FPU.
Thank you all for the informed replies and the anecdotes. I have a better outlook on Java now and understand better where it is best suited.
:).
I think most of my 'questioning' Java has come from people who try to 'sell' Java as a panacea -- aka 'putting Java in light bulbs', "re-writing OS kernels in Java', etc.
What you mantioned is the clearest and best answer that I've hear for the reasons to use Java thus far -- aka you *can* do it in another language, but the support costs and development time for Java is a lot smaller. That makes sense and in that case the main costs to weigh when choosing Java over another language is what it will cost in developer/support time versus the performance losses.
Thank you for your answers, even though my question did get modded into oblivion