Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Java (http://www.programmingforums.org/forum17.html)
-   -   Java vs Python and C++ (http://www.programmingforums.org/showthread.php?t=5421)

Dietrich Aug 16th, 2005 9:57 AM

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++?

skuinders Aug 16th, 2005 10:12 AM

Java is a strongly typed, compiled language. Learn C++ or Java before Python. Google C++ vs. Java for more information about their differences.

DaWei Aug 16th, 2005 10:58 AM

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.

mackenga Aug 18th, 2005 6:38 PM

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.

Dietrich Aug 19th, 2005 5:52 PM

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++?

Pizentios Aug 19th, 2005 5:54 PM

It's more like C++ in my mind, but i wouldn't trust my mind.

OpenLoop Aug 19th, 2005 8:29 PM

Quote:

Originally Posted by Dietrich
Python compiles to a byte code and is then interpreted. Is Java more like Python or more like C++?

Python interprets on the fly I believe, no compilation. Java on the other hand, compiles the source code to byte code which can be run on any machine with the Java Virtual Machine installed (linux, MacOS, or Windows). Usually, java executables end with .class or .jar. However, it can be wrapped into an exe but it still needs the JVM.

Arevos Aug 20th, 2005 7:58 PM

Quote:

Originally Posted by OpenLoop
Python interprets on the fly I believe, no compilation. Java on the other hand, compiles the source code to byte code which can be run on any machine with the Java Virtual Machine installed (linux, MacOS, or Windows). Usually, java executables end with .class or .jar. However, it can be wrapped into an exe but it still needs the JVM.

Close. If I may be needlessly pedantic, Python is a dynamically compiled language, rather than an interpretted language (such as QBasic). When Python executes a script, it first compiles the program into object code, which it caches as a .pyc file. It then uses this object code to run the program.

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:

Originally Posted by Pizentios
It's more like C++ in my mind, but i wouldn't trust my mind.

Java is very much like C++. I believe it was designed that way, in order to attract C++ programmers to the language, since C++ was the most popular Object Orientated language at that time (and might still be).

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 :) )

OpenLoop Aug 20th, 2005 10:21 PM

Quote:

Originally Posted by Arevos
Close. If I may be needlessly pedantic, Python is a dynamically compiled language, rather than an interpretted language (such as QBasic). When Python executes a script, it first compiles the program into object code, which it caches as a .pyc file. It then uses this object code to run the program.

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).

Didn't know that Python compiles, but it still slow compared to Java and too slow compared to C++. See my thread where i made a small comparison
Thanks for the info and the GCJ link.

grumpy Aug 21st, 2005 12:49 AM

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