Python is not java

How Similar are Java, C#, and Python? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.

Community Wiki means «there’s no one right answer». Please edit your question, and check the «Community Wiki» box. Otherwise, someone’s probably going to vote to close your question. (On the downside, you will not earn reputation points for responses to a community wiki post.)

It doesn’t really help to tell the OP to wiki the question after 5 answers have already been submitted. Just flag it for moderator attention or vote to close if you have the rep.

10 Answers 10

  • Require some form of runtime on your system (JVM/.net/Python runtime)
  • All can probably be compiled to executables without the runtime (this is iffy and situational, none of them are designed to work this way)
  • Are good languages
  • All have specific areas where they are much more appropriate than the other two
  • Tries very hard to be Cross Platform—generally succeeds
  • Little access to platform features that are not in the SDK
  • Slowest of the three to change and does not contain features common to the other two such as closures
  • Very backwards compatible (partly because of the previous point)
  • FAST (about 2x slower than C, quite a few x faster than python)
  • Probably has the most library support of the three
  • Strong multi-platform server systems already deployed using J2EE
  • Scales down to embedded (I’ve worked on 2 different embedded java projects—coming soon to a cable box near you)
  • Static
  • Quicker to add new features
  • Windows only—Mono is cross platform but does not have the library support.
  • Started very similar to Java but has many more language features now.
  • Much better access to windows APIs
  • Not sure about speed—I think it’s similar to Java.
  • Very good library support
  • The only one of the three that you have to pay for (it’s free for «entry level»)
  • Static
  • Language is cross platform. Not sure about non-language platform access (such as drag-and-drop)—anyone know?
  • Probably an easier language to learn
  • The only one of the three that does not use c-like syntax
  • Slowest of the three, but still pretty darn fast compared to other dynamic languages.
  • Dynamic

+1 excellent answer. I’d also point out that both Python and C# have better support for functional-style programming and lazy evaluation than Java has (e.g., both Python and C# have yield , and both have lambda functions and closures, although the implementations are different).

Good point—added a little text indicating that Java does not include closures (trying not to bloat the list even more).

Читайте также:  Как получить содержимое html jquery

Python is a dynamic language where Java and C# are really not. It is totally different than the other two. There are ways to accomplishing things in Python that do not translate well to the others and vice versa.

Java and C# look the same, but they have differences between the two under the sheets. Being an expert in one, does not make you an expert in the other by any stretch of the imagination. The syntax is similar and libraries are too, so it would be easier to get up to speed in one or the other, but there are subtleties that can trip you up.

C# and Java have almost identical syntax and very similar libraries. There are differences that you have to be aware of (Type Erasure in Java, for example).

Python is a completely different animal. It is a dynamic language (where the other two aren’t). Python winds up being closer in style to something like Ruby.

Java and C# are statically typed languages, while Python is a dynamically typed language. That’s a huge difference.

The syntax of Java and C# is similar (but I would not call it «almost identical» as Justin Niessner says).

Java and c# are pretty similar in terms of syntax and are mostly strongly typed (C# is getting more dynamic with every version), Python is a dynamic language

Strong and static typing are not the same thing (or rather, using those terms to mean the same thing leads to confusion). For example, read this: artima.com/weblogs/viewpost.jsp?thread=7590

C# is a statically typed language, but it can use type inference with auto and dynamic typing with dynamic. Python is a dynamically typed language, but you can add annotations and use mypy to check your annotations statically. Some Python IDEs/linters support some form of «type inference», but its not «complete».

Java and C# are very similar and are syntactically similar to C/C++. They also use braces to mark code blocks.

Python is completely different. Although imperative like Java and C#, Python uses indentation to define blocks of code.

Java and C# are also compiled languages, whereas Python is interpreted and dynamic.

Python, Ruby, and Groovy are somewhat similar languages.

BTW most modern dynamic languages are compiled as they are being interpreted so they run on bytecode. However, Python’s dynamic compiler (JIT) is pretty bad right now although its getting better with the pypy project.

C# and Java are easy to move between, although I don’t know many people who are experts in both. C#’s syntax is based off of Java, so they read very, very similarly. They both run cross-platform; Java on the JVM, C# on .NET or Mono. They’re both OOP, and widely used for web development. I’d use whichever the team was more familiar with.

Python’s off to the side there. It’s also used frequently as a scripting language. It can use classes and object orientation, but isn’t forced to. It’s not as well supported for web work. I’d use this for a different set of tasks than C#/Java.

Читайте также:  HTML фон

Technically, C#’s syntax is based off of C/C++. It just so happens that Java’s syntax has the same basis.

@JAB: JAB is correct, my bad for being a bit off. Java and C# are based on C++, and C# took a few lessons learned from Java along the way.

Python is OOP even if you don’t use classes as functions are objects, strings are objects, etc. OOP and classes aren’t the same thing, the word «OOP» was invented by Alan Kay and he didn’t mean C#/Java when he thought of OOP. Although its not taught in schools, plain nested functions can capture variables from their environment(scope) and act like objects(called closures), but they are much simpler to use. This new style of programming was unavailable to C++/C#/Java until recently, but its actually in many ways better than class based OOP for objects with only one or two methods.

C# and Java are the two languages you listed that are most similar. Python has a very different syntax, and uses a slightly different programming model. Both C# and Java are Object Oriented languages at their core, with increasing nods to Dynamic Typing. Python began as a Dynamically Typed scripting language and has been picking up more and more Object Oriented features over the years.

The C# class library (.NET Framework) is theoretically multi-platform, though it’s heavily weighted towards the Windows platform, and any other OS compatibility is largely an afterthought. The .NET framework currently has two «official» frameworks for building windowed applications (Windows Forms, and WPF) and two «official» frameworks for building web applications (ASP.NET, and ASP.NET MVC). Windows Forms is similar to Java Swing, but the other four frameworks are very different from much of what is found in the Java or Python worlds. There are many language features in C# that are different or lacking in Java, such as Delegates.

The Java class library is pretty solidly multi-platform. It’s officially supported desktop and web frameworks (Swing and J2EE) are generally regarded as slow, and difficult to use. However, there is a very lively open source community which has built several competing frameworks that are very powerful and versatile. Java as a language is very slow to introduce new language features, though it is runtime-compatible with several other languages that run on the Java platform (Groovy, Jython, Scala, etc..). Java is the language which has has the most run-time optimizations put into it, so an application written in Java is almost certainly going to be faster than an application written in C# or Python.

Python is an interpreted language (in general), and is pretty solidly multi-platform. Python has no «official» desktop or web frameworks, though desktop applications can be written using GTK or Qt support, both of which are multi-platform. Django has become a de-facto standard for Python web development, and is regarded as a very powerful and expressive framework. Python is at this point fully Object Oriented, and is notable for it’s powerful tools for working with collections/arrays/lists. As an interpreted language, Python will be significantly slower than either C# or Java.

Читайте также:  Example class loader in java

Источник

Java -> Python?

Besides the dynamic nature of Python (and the syntax), what are some of the major features of the Python language that Java doesn’t have, and vice versa?

5 Answers 5

  1. List comprehensions. I often find myself filtering/mapping lists, and being able to say [line.replace(«spam»,»eggs») for line in open(«somefile.txt») if line.startswith(«nee»)] is really nice.
  2. Functions are first class objects. They can be passed as parameters to other functions, defined inside other function, and have lexical scope. This makes it really easy to say things like people.sort(key=lambda p: p.age) and thus sort a bunch of people on their age without having to define a custom comparator class or something equally verbose.
  3. Everything is an object. Java has basic types which aren’t objects, which is why many classes in the standard library define 9 different versions of functions (for boolean, byte, char, double, float, int, long, Object, short). Array.sort is a good example. Autoboxing helps, although it makes things awkward when something turns out to be null.
  4. Properties. Python lets you create classes with read-only fields, lazily-generated fields, as well as fields which are checked upon assignment to make sure they’re never 0 or null or whatever you want to guard against, etc.’
  5. Default and keyword arguments. In Java if you want a constructor that can take up to 5 optional arguments, you must define 6 different versions of that constructor. And there’s no way at all to say Student(name=»Eli», age=25)
  6. Functions can only return 1 thing. In Python you have tuple assignment, so you can say spam, eggs = nee() but in Java you’d need to either resort to mutable out parameters or have a custom class with 2 fields and then have two additional lines of code to extract those fields.
  7. Built-in syntax for lists and dictionaries.
  8. Operator Overloading.
  9. Generally better designed libraries. For example, to parse an XML document in Java, you say
    Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(«test.xml»);
    and in Python you say
    doc = parse(«test.xml»)

Anyway, I could go on and on with further examples, but Python is just overall a much more flexible and expressive language. It’s also dynamically typed, which I really like, but which comes with some disadvantages.

Java has much better performance than Python and has way better tool support. Sometimes those things matter a lot and Java is the better language than Python for a task; I continue to use Java for some new projects despite liking Python a lot more. But as a language I think Python is superior for most things I find myself needing to accomplish.

Источник

Оцените статью