View Full Version : Is Java worth it?

12-01-01, 03:30 PM
I'm currently expanding my knowledge on C/C++ (I'm just makin' stupid little useless proggies) and want to know if I really have to learn Java.
I'm not gonna make java applets anyways.
Is Java any better than C or what?

12-04-01, 05:40 PM
Java and C++ are very similar. Much of the syntax is the same. There are some difference conceptually, for instance Java has a strict adherence to to OO methodology, in that classes can only inherit from one parent--whereas C++ allows multiple inheritance. But, for the most part, they are the same. The basic difference is the level at which they support portability. C++, assuming it's written ANSI/ISO compliant, is only portable at a pre-compiled level (you have to compile it for each architecture you wish it to run on). Java, on the other hand, compiles to bytecode which is then interpretted by the Java Virtual Machine that resides on the architecture that you run it on (you compile it for the virtual machine, and the virtual machine knows how to interact with the hardware and operating system on the system it is run on).

Most of the arguments I've heard against Java, from those of us who are C++ enthusiasts, deal with execution speed. Since there is an additional layer between the bytecode and the hardware and operating system, Java runs slower than native C++. However, this is only a factor when you are using large amounts of memory. For instance, if you are using a DOM XML parser to interact with a XML document that has a million entities, then Java will be noticably slower than a C++ version of that same program. But, by and large, there is a very small difference in execution speed.

The biggest difference between Java and C++, that I've seen, is that Java (javax) has tons of things built into it that C++ doesn't. This is because Sun Microsystems (the creators and maintainers of Java) have worked with many other companies to come up with open standards for different technologies. Which makes it very easy to introduce and replace different features.

For instance, you interact with a messaging server using the same classes, methods, and parameters, regardless of the vendor of the messaging server (there are some small things to change in the code, but nothing significant). This means, if a better messaging server comes out on the market, you can replace yours with very little work. As of yet, C++ doesn't have anything in place like this. So, you end up using vendor-specific APIs to interact with the same messaging server--meaning that replacing the current messaging server is a lot of work. However, many vendors are extending the Java open standards to their C/C++ APIs. So, this advantage should disappear in the future.

In addition, Java integrated the graphical user interface (GUI) right into the language. Thus, it does not rely on the operating system or third party toolkits to render a user-friendly environment.

Another difference, is that Java doesn't let you "be dangerous". It has put in place a fairly well thought out strategy for not allowing the programmer to do things that could harm the environment it is run in. In effect, the virtual machine controls the enviroment, not the programmer. In C/C++, the programmer must be mindful of the environment, as it allows you much more freedom than Java does.

Both languages have their strengths and weaknesses. Whether one is better than the other is entirely dependent on the application that you are applying the language to and the amount of portability you desire. If, for instance, you are writing an operating system, C/C++ would probably be a better choice (assuming you had to choose between only Java and C/C++). If you are writing a server-side web application that interacts with a database, but you aren't sure what operating system or database you will be using a year from now (or if it will be used on multiple operating systems or multiple databases from different vendors), then Java might be the better choice. You pick the best tool for the job at hand.

12-05-01, 02:56 AM
wow. I've read the work of a genuis.

12-05-01, 01:02 PM
That is the best (and longest) explanation and reply to any of my posts. It really helps out, Stu, I honor you :)