Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Java or Python

  1. Apr 13, 2005 #1
    I am a physics student. I am very much intrested in computers.I have already studied C++. I would like to study Java also. But some friends told me that Python is far better than Java. Can u please help me to choose one of them?
     
  2. jcsd
  3. Apr 13, 2005 #2

    dduardo

    User Avatar
    Staff Emeritus

    I come from a C/C++ background and i've tried java a couple of times but never found it compelling enough to learn. Its very clunky and consumes lots of memory (8-16MB min). Python on the other hand is a very nice language. It has very clean syntax and programs can be developed quickly. It also has a small memory foot print and you can include C/C++ modules in your code to speed up execution.
     
  4. Apr 13, 2005 #3
    I'm avoiding discussing about which of them is the best to learn, but you should know that moving from C++ to Java is much easier (may take just weeks) than moving from C++ to Python. So you can learn a few additional things about Java (especially multithreading) and go on with Python.
     
  5. Apr 13, 2005 #4

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    dduardo,

    Python often has a memory footprint similar to Java, and Python is usually quite a bit slower. Compared to C++, Java is a resource hog, but Python really has little advantage, if any, on resource consumption.

    The advantage of Python is that it's a very elegant, simple language.

    I would advise learning Python over Java for one simple reason: You will learn more about computer programming in general by learning a language distinctly different from the one you already know. Syntactically and conceptually, Java is similar enough to C++ that I consider them related languages. Python, on the other hand, is radically different (and better) than both in many ways.

    Go with Python.

    - Warren
     
  6. Apr 14, 2005 #5
    Thank you for your answers. But I wan'ts to know which is beneficial for future than which is easy. Can you help me please.
     
  7. Apr 14, 2005 #6

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    The future is not known. I would venture that Python has a wider scope of applicability, though, and it's growing fast.

    It doesn't really matter, though -- once you learn a couple of languages, it only takes days or weeks to pick up another. You're not going to limit yourself by picking either.

    - Warren
     
  8. Apr 15, 2005 #7

    JasonRox

    User Avatar
    Homework Helper
    Gold Member

    I just started programming and I just did simple programs so far, like graph functions and search for things and what not, but it's all cool stuff anyways.

    Using the same algorithm for finding primes, I found Java is much faster than Visual Basics .NET.

    My question is... is C or C++ much more faster than Java?

    That would just be sick if that was the case.

    Once I get a good algorithm going, I'll buy a computer that will simply run all day finding a nice ordered collection of primes that can be useful for encryption/decryption.

    Also, I will use the computer for other things, but I have to keep that project secret. :D

    I have never heard of Python, but I seem pretty content with Java and Visual Basics .NET. I prefer Java, but will most likely move onto C or C++ just for fun. Some programs may have advantages of others. For example, Visual Basics is good for a quick "bing badaboom bada bing" program. :)
     
  9. Apr 15, 2005 #8

    robphy

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    Here's why I learned Python: http://www.vpython.org
    ...It's the quickest way for me to produce animated visualizations for physics.
    (A few years back, I was frustrated with Java+VRML and Java3D. Then, I found VPython.)
     
  10. Apr 15, 2005 #9

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    For algorithms (searches, sorts, etc.) no, it's roughly the same speed as C++. For windowing and graphics, there are much faster C++ implementations.
    http://www.python.org

    I suggest a book like "Programming Python" from O'Reilly to really learn the language.

    I strongly suggest you give up on Visual Basic, and try Python. Visual Basic and Python are both aimed at rapid prototyping, but Python is suprisingly even easier than VB.NET, and it's portable everywhere.

    - Warren
     
  11. Apr 15, 2005 #10
    I say learn them both Python and Java. Having to do with C++ it's a pity not to learn a few things about Java, as the latter combines most of the features of today's modern languages (the event handling model, the exception model, streams, multithreading, easy networking with sockets, serialization, built-in libraries and data structures, portability, pure object-orientation, interfaces, huge support for security, applets, high-level, interpreted, and so on, and so on). You will learn both a language and a set of important concepts that you will surely need in the future. After all it won't take you that long to learn this language.
     
  12. Apr 15, 2005 #11
    I'll go out on a limb and recommend Lisp.

    I'll also add that if you allready know C++, continuing with Java doesn't make sense to me. They are to similar, and will not really widen your horizon. Learning Java will mostly just teach you new syntax.

    Guess it depends on what your goals are. Knowing Lisp will probably not land you that job with company X. It will however teach you a radically different way of approaching programming.
     
  13. Apr 16, 2005 #12
    Thanks for your advice
     
  14. Apr 21, 2005 #13
    LISP and its popular implementation Scheme are very powerful languages for introducing certain algorithms, and modelling purely theoretical problems in computer science. You can do alot of really neat things in Scheme in LISP in one line that would take you 20 lines in C++ or Java. Unfortunately they do not have the API support for things like graphics, database connectivity, etc. that Java and even Python do. Recursion, which functional programming languages are heavily dependent on, is pretty inefficient unless its made properly tail recursive and the compiler optimizes functions who satisfy this property. The automatic garbage collection and extremely weak typing system also makes them pretty unwieldy for production use, although Phillip Greenspun would have you believe otherwise. Self-modifying code also is alot more difficult to debug, and by extension alot more difficult to make secure.
     
  15. Apr 21, 2005 #14

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Your points are good, so-crates, but they all have obvious refutations:

    1) Yes, Lisp is well suited for a number of algorithms of mainly academic interest, including aritificial intelligence, natural language processing, and so on. The lack of API support or inter-language interfacing makes them unsuitable for probably 90% of the projects done in the real world.

    2) Recursion is one of the most difficult constructs for programmers to write (and maintain) properly, so most programmers advocate never using recursion except in very simple cases. Strong software-engineering methodologies like Cleanroom also discourage recursive coding. There are only a small class of algorithms that require recursion; the rest would be better coded with other techniques.

    3) It's an outdated belief that strongly typed languages result in less-buggy code. The idea was that strong typing finds errors at compile-time, while weak typing lets the errors stand until they are detected at run-time. The problem with this logic is that a large majority of bugs in strongly-typed language occur in code that converts data from one type to another. It turns out to be better to build type conversion into the interpreter/executive/virtual machine than to force every programmer to ad lib it each time it's needed.

    There is a great deal of academic and commercial evidence, growing daily, that Python programs are less buggy than equivalent C programs. In addition, Python programs are much easier to read, maintain, refactor, and update.

    And, you know, I've never once seen any self-modifying code in a production environment. Have you?

    - Warren
     
    Last edited: Apr 21, 2005
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Java or Python
  1. Learning Python (Replies: 4)

  2. Java problem. (Replies: 4)

Loading...