Re: [Tutor] Differnce between java and python (fwd)
[Keeping tutor@python.org in CC. Ok, so now we know that Shivayogi already has Java experience. Shivayogi might also be a little annoyed that he has to learn a new language. We have to tread more carefully in making claims like "Python is easier than Java", because for anyone starting on another language, the language we already know is obviously easier than the one we are trying to learn. *grin*] Hi Shivayogi, There are a few nice things about Python that make common tasks easier to do. We can go through a few examples, and if you have questions on them or would like to see more examples, please ask and folks on the list will be happy to talk with you. (Please make sure to keep tutor@python.org in CC by using your email client's "Reply to All" feature.) For example, Java has an "iterator" protocol, but until Java 1.5, it didn't have much syntactic support. As an example, writing loops to go across iterators involved manually next()ing the iterable and calling hasNext(): /*** Java ***/ import java.util.*; // ... within some method body List words = Arrays.asList(new String[] {"hello", "world", "this", "is", "a", "test"}); for (Iterator iter = words.iterator(); iter.hasNext(); ) { String word = (String) iter.next(); System.out.println(word.toUpperCase()); } /**/ Python's for loop, on the other hand, natively works across iterables: the 'for' loop itself is responsible for doing things like 'next()': ### Python ### words = ["hello", "world", "this", "is", "a", "test"] for word in words: print word.upper() ## I understand that Java's for loop finally has iterator support, but from the examples I've seen, it looks a bit syntactically heavyweight. Another casual example where Python and Java differ is the treatment of common types. Python doesn't have a notion of "primitive" types, whereas in Java, we sometimes have to think about 'int' vs. Integer. For example, we know that the Java method: /**/ int double(int x) { return x * 2; } /**/ breaks on large input because the declared types are primitive ints. To make this really work, we have to use BigIntegers: /**/ BigInteger double(BigInteger x) { return x.multiply(new BigInteger("2")); } /**/ On the other hand, Python integers also automatically promote themselves to bignums rather than overflow, so the function: ## def double(x): return x * 2 ## just works. Does this make sense so far? Please feel free to ask more questions. There's also a book by Bruce Tate called "Beyond Java" that talks about these issues. Best of wishes! -- Forwarded message -- Date: Thu, 22 Dec 2005 10:40:13 +0530 From: shivayogi kumbar <[EMAIL PROTECTED]> To: Danny Yoo <[EMAIL PROTECTED]> Subject: Re: [Tutor] Differnce between java and python Sir, I hve done my MSc(c.s).I did my project on Java.Know I have joined the company where they work on Python.So It has forced to me learn PYthon.SoI have approaced you people.What are the advntages of Python over java. Thank you On 12/22/05, Danny Yoo <[EMAIL PROTECTED]> wrote: > > > > On Wed, 21 Dec 2005, shivayogi kumbar wrote: > > > sir plz tell me the main differnces between java and python? And What > > are the advantages of python? > > Hi Shivayogi, > > When you post on a mailing list that's dedicated to help teach programming > with Python, you do anticipate what kind of answers you're going to get > here, right? *grin* > > Are you a beginner programmer? Do you have any previous experience with > programming? I'd really like us to turn the discussion toward what you > really want to learn. Advocacy and cheerleading is fun, of course, but > let's see if we can help you too. What are you trying to do? > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Differnce between java and python
[Putting this back on the list so others get the context info] - Original Message - From: "shivayogi kumbar" <[EMAIL PROTECTED]> Subject: Re: [Tutor] Differnce between java and python Sir I have completed my Msc(c.s).I have worked on java and also done my project on javaa using swings ,RMI technology.The thing is now I have joined the company is working on the Python.So I would ike to know the difference between Java and Python -- In that case since you have a good knowledge of Python we can focus on a feature comparison with Java. Python has much in common with Java in that both work by compiling to byte code, however Java does so in a traditional comipile first manner whereas Python compiles at first run. Python is dynamically typed and uses protocol based polymorphism rather than inheritance based(so called Duck typing). Python is a much higher level language than Java, I'd guess the ratio of lines of code per function point is around 3:1. Python is often called 'executable pseudo code'. Python has a much more elegant syntax, it is much less based on C (Although some C-isms do show through in places) Python is more object oriented than Java which is predominantly class based. By that I mean there are lots of objects around in Python where you never see the class. Similarly there are relatively few class methods (static in Java). You can't use Java wthout without seeing at least one class statement. Python has much better support for higher order programming, functional programming and, more debateably, meta-programming. There's lots more but that should e enough for now. Check the refeences others have sent. Also check out Jython which combines the best of both worlds with remarkably few compromises. Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Differnce between java and python
>>Another example is that Python supports "Duck Typing", that is >>its type checking is protocol based. > > I see your point, but duck typing seems awfully implicit and > behind-the-scenes. When you first encounter it it is. I came from a C++ and Pascal background where strict typing was the rule, Python seemed very lax. But I had the advantage of having worked in Lisp and Smalltalk too so I kind of relaxed fairly quickly. > Seems like if I expect a protocol, and you provide something that claims > to > implement said protocol, there ought to be some contract that ensures > we're > dealing with the same protocol. I ought not to be able to pass my car and > my nose to the same function, just because the both run(). It depends. Obviously in this example its likely that the behaviour would result in boizarre results but on the other hand if the function was race(obj1, obj2) then both car and nose could be appropriate, but in the latter case with rather horrible connotations... But seriously, Duck Typing allows for a far more expreessive and powerful use of objects. When you are no longer bound by the limitations of inheritance heirarchies you can start to build much more powerful funcions. The downside is that there is an onus on the client to sanity check the usage of the function - will it really do what I expect? Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Differnce between java and python
On Wed, 21 Dec 2005, shivayogi kumbar wrote: > sir plz tell me the main differnces between java and python? And What > are the advantages of python? Hi Shivayogi, When you post on a mailing list that's dedicated to help teach programming with Python, you do anticipate what kind of answers you're going to get here, right? *grin* Are you a beginner programmer? Do you have any previous experience with programming? I'd really like us to turn the discussion toward what you really want to learn. Advocacy and cheerleading is fun, of course, but let's see if we can help you too. What are you trying to do? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Differnce between java and python
Alan Gauld wrote: >>>Python is more forgiving >> >>Could you elaborate on this feature? > > > Python allows you to do things, without complaining, that Java just > won't allow. Another way to put it is, Java is way more picky than Python. Much of this is a consequence of Python's dynamic typing - you never declare the type of anything in Python. This alone saves a ton of (finger) typing. Also exceptions in Python don't have to be declared, like unchecked exceptions in Java. It's a matter of some debate whether the extra strictness of Java provides enough safety to be worth the cost. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Differnce between java and python
Alan, thanks for the response. >Python allows you to do things, without complaining, that Java just >won't allow. Checked exceptions are a pain, but at least there's no ambiguity about what f(x) is gonna throw (unless it throws a RuntimeException). Nevertheless, I agree: checked exceptions are probably a misfeature. >Another example is that Python supports "Duck Typing", that is >its type checking is protocol based. I see your point, but duck typing seems awfully implicit and behind-the-scenes. Seems like if I expect a protocol, and you provide something that claims to implement said protocol, there ought to be some contract that ensures we're dealing with the same protocol. I ought not to be able to pass my car and my nose to the same function, just because the both run(). Despite all of this, I still prefer python! (when given the choice). I learned java first, so I probably rely on its compiler crutches. --PETE ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Differnce between java and python
>>Python is more forgiving > > Could you elaborate on this feature? Python allows you to do things, without complaining, that Java just won't allow. As one example: you create a Java module M containing a class C with a method F that throws exception E. Now to use that in your code, say called by function g() you must import the module and also ensure that the function g() is either defined to throw E - or to handle the exception E. The compiler complains otherwise. In Python you simply import the module and call the function. If the exeception is thrown it will generate a stack trace exactly as if you had thrown it inside your code. Of course you might want to handle it locally, but you don't have to be explicit about it. Another example is that Python supports "Duck Typing", that is its type checking is protocol based. So if I declare a function def f(aNumber): ... I can pass in anything that acts like a number, provided it can respond to the subset of numeric operations that I use I can pass in anything. If I nor define a Java funtion/method void f(int n){} I can only pass in an integer or something that can be typecast as an integer. Very often that's far too strict a limitation. Now the strictness is there for a reason and it encourages good design, but it does require much more thought up front about exactly what will be passed where and which exceptions will be thrown where etc. If you are just learning, or want to get a quick job done then Java's approach is frustrating rather than helpful. That's what I mean by Pyython being more forgiving, or tolerant, than Java. HTH, Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Differnce between java and python
Mr Gauld wrote: >Python is more forgiving Could you elaborate on this feature? Thanks, Pete ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Differnce between java and python
A good point is that Python is fun to program with. But the jobs point is important too. In my country 80% of the jobs for informatic´s area is to C#, VB, Delphi and Java(50% of the 80%) programmers. So, having a job with Python is hard. :( Cheers! =]On 12/21/05, Alan Gauld <[EMAIL PROTECTED]> wrote: > sir plz tell me the main differnces between java and python?What kind of information do you want? Differences in syntax?,architecture? resource usage? They are completely differentprogramming languages. Do you have a programming background? If so which languages do you know? That way we can comparewith what you do know.If you don't have a programming background forget Java and learnPython. You can learn Java later if you like but it will be easier to start from a knowledge of Python.> And What are the advantages of python?Python is easier to learnPython produces more functionality for fewer lines of codePython is more forgivingAnd dont you want to know the advantages of Java? Java is slightly faster (nowadays, it didn't use to be)Java is easier to deploy because the JVM tends to be everywhereThere are more jobs for Java programmersThats a start...Alan GAuthor of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld___Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor-- O_oMurtog ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Differnce between java and python
> sir plz tell me the main differnces between java and python? What kind of information do you want? Differences in syntax?, architecture? resource usage? They are completely different programming languages. Do you have a programming background? If so which languages do you know? That way we can compare with what you do know. If you don't have a programming background forget Java and learn Python. You can learn Java later if you like but it will be easier to start from a knowledge of Python. > And What are the advantages of python? Python is easier to learn Python produces more functionality for fewer lines of code Python is more forgiving And dont you want to know the advantages of Java? Java is slightly faster (nowadays, it didn't use to be) Java is easier to deploy because the JVM tends to be everywhere There are more jobs for Java programmers Thats a start... Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Differnce between java and python
Pujo Aji wrote: > Hi, > > you can check this website: > http://www.ferg.org/projects/python_java_side-by-side.html Don't miss the links on that site, either. Compared to Java, Python is compact, expressive and lightweight. It is dynamically typed with first-class functions and far better built-in support for simple data structures, introspection and metaprogramming. After writing Python for a while, Java seems full of unneccessary restrictions and artificial limitations. In comparison, Python stays out of the way. Here are a few more links: My own comparison with some details: http://www.pycs.net/users/323/stories/18.html Python is not Java: http://dirtsimple.org/2004/12/python-is-not-java.html Java is not Python, either: http://dirtsimple.org/2004/12/java-is-not-python-either.html Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Differnce between java and python
Hi,you can check this website:http://www.ferg.org/projects/python_java_side-by-side.htmlabove all.python is very compact, clear language. I did some code using C# for 1 year, and when I move to python I can rewrite it even more in about 3 months.My code becomes clearer than ever beforeCheers,pujo On 12/21/05, shivayogi kumbar <[EMAIL PROTECTED]> wrote: sir plz tell me the main differnces between java and python?And What are the advantages of python? ___Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Differnce between java and python
sir plz tell me the main differnces between java and python?And What are the advantages of python? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor