![]() |
Java vs Python and C++
I am looking at Java and Python and like to know if Java is an interpreted language. What are its benefits over a language like C++?
|
Java is a strongly typed, compiled language. Learn C++ or Java before Python. Google C++ vs. Java for more information about their differences.
|
The ostensible benefit to Java (aside from language-utility issues) is that it compiles to byte-code. Machines which have a JVM (java virtual machine) then map the byte code to the appropriate machine instructions. This supposedly provides a "write once, run anywhere" capability, no porting issues. All JVMs are not created equal. As Grumpy has said, it sometimes results in a "write once, debug everywhere" situation. MS's C#/VB ala .NET entree (I'll take Eggs Benedict, thank you) is supposed to capitalize on the same approach (distributable byte code or whatever name is the flavor of the day) and it would be great for El Bill if he could succeed well enough to make substantial inroads on the Java market.
|
Another benefit of Java over C++ (specifically) is that while they're both C-derived object oriented languages, Java is a bit neater and simpler. C++ has been accused of being a bag on the side of C - i.e. a big lump of irrelevant extra features - and while this isn't necessarily fair, it's certainly not as neat and 'pretty' (for want of a better word) as Java.
C++ is a bit of an industrial strength language. I suppose Neal Stephenson might call it the "Hole Hawg" of programming languages. Java is a bit like a cute, cut-down C++, lacking features like operator overloading and multiple inheritance. The absence of these features could be good or bad - depending on who you ask - but there's no denying it's simpler and therefore ought to be easier to learn. As a beginner's language, I'd recommend Java over C++. Both are commercially and practically reasonable first choices, and Java's simplicity and essential similarity to C++ make it the better of the two in my opinion. Even little things like having a universal, standard abstract windowing toolkit (for creating GUI applications) rather than a whole horde of competing ones makes it more appealing to a newcomer. |
Thank you very much for the nice answers! I am still a little confused.
I know that C++ code compiles and then links to give an executable file (.exe). Python compiles to a byte code and is then interpreted. Is Java more like Python or more like C++? |
It's more like C++ in my mind, but i wouldn't trust my mind.
|
Quote:
|
Quote:
This makes it faster than interpretted languages, since it only reads through the user's code once. After that, it uses the intermediate object code to determine what to do. Java, on the other hand compiles into low level bytecode, rather than higher level object code, and this probably gives it a benefit in speed. Correct me if I'm wrong, but I believe Java can also be compiled to native machine code using gcj. Once that's done, the JVM isn't needed (although the Java SDK is needed for compilation). Python, on the other hand, can only currently be turned into an exe via a wrapper, such as py2exe. And that's not exactly a neat and tidy process :( Quote:
Python, on the other hand, has more in common with ABC and Modula 3, at least according to this diagram. As a language, Python has a more advanced syntax than Java, but tends to be slower to execute. ( Programming Languages are something of an interest of mine :) ) |
Quote:
Thanks for the info and the GCJ link. |
Java (like any language, actually) can be compiled to native machine code if someone puts in the effort to write a suitable compiler. In practice, Java is usually compiled to java bytecodes, which implies a need for a JVM to interpret them.
Strictly speaking, Java can be dynamically compiled (just look up topics like JIT [Just In Time] compilation). Like Pyton, it blurs the distinction between an interpreted language and a completely compiled one. I would say that Java has little in common with C++ although, syntactically, it looks rather similar. It does well in some niche areas (eg rapid prototyping, applications that can run in a web browser), but those areas are rarely targetted by C++ programmers. It also forces programming in particular styles, regardless of what one is trying to do, which tends to rub experienced C++ programmers the wrong way. Java is significantly simpler than C++ (which is either an advantage or a disadvantage, depending on what you're trying to do). The reliance on garbage collection makes life easier for the programmer for some types of work (eg without gc, it would be very difficult to write non-trivial web applets), but makes it much harder in other ways (eg unpredictable performance hit makes Java less suitable for hard real time or mission critical applications, even if the RT java extensions are employed). |
| All times are GMT -5. The time now is 8:37 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC