Java Vs Python Tried and true Vs "modern and new"
“A programming language changes the world”
According to Wikipedia, Python was released in 1991 as a high-level language for general-purpose programming. But it actually dates back to 1989.
The interest around Python began to rise only around 2000, and today Python is loved for its highly readable code. That is why many programmers believe it's the easiest language to get started with.
Why is that? Well, the story starts decades ago.
In the 90s, if you wanted a managed, Object Oriented language, there was surprisingly little choice. C# and Java didn't exist, nor did Ruby. We had a sloppy Perl and TCL that had OOP only as an extra feature. Above all, lots of languages were Windows-only like Delphi or Visual Basic.
In the meantime, C++ was frightening to beginners, and Smalltalk always felt like a nice idea, but not something you actually wrote software with. And here we go, Python seemed better than everything else what was out there. Java was around since 1995, but it seemed too 'corporate'. In 2000 C# was coming out, but it was, again, Windows only.
Today Python is one of the most important and popular languages in the world and is still gaining our attention.
“Java is arguably the most popular programming language as 90% of the Fortune 500 companies heavily use it. Its famous slogan “write once, run anywhere” captures one of the keys that makes Java so valuable — its powerful Java Virtual Machine (JVM), which makes it cross-platform compatible.”
Alexander Petkov, Medium.freecodecamp.org
It was 1995 and C++ was the language of choice for building large-scale software systems. It was a powerful object-oriented language, the successor of widely used C. But not only was C++ powerful, it was also quite complicated. Here’s the point where Java was released.
Java is a high-level object-oriented language. Initially conceived and developed in 1991 under the name OAK, it was designed for handheld devices and set-top boxes, but due to some circumstances the name was changed to Java and modified the target to the then evolving World Wide Web.
So, at the moment, Java is one of the most widely-used languages for developing and delivering content on the web plus developing enterprises applications and Android apps.
An estimated 9 million developers use it and more than 3 billion mobile phones run it.
#1: History: long ride vs short bite
Both languages were developed relatively at the same time, in 1991. But started to draw attention in quite different periods: Java wasn’t really itself back then, and Python just started to open his little pixel-eyes.
Nevertheless, they both are actively engaged in making improvements and perfecting the current results:
Python. Since the popularity reached a peak, it had given rise to long discussions.
15 most popular languages according to GitHub in 2017.
So the answer to “How did Python transform itself into one of the most popular languages?” is still in demand. A few things had happened that shifted the attitude towards Python and made it more viable as a web development language:
- FastCGI came, and then WSGI (before that, you had to run Python scripts as ordinary Common Gateway Interface, which wasn’t fast enough). So instead of creating a new process for each request, FastCGI uses permanent processes to handle a series of requests. It increases the speed of implementation and reduces time on development.
- Prominent universities began using Python in their curriculum, teaching algorithm and other classes (e.g. University of Oxford, Harvard, Binghamton University, Carnegie Mellon University, New York University Polytechnic School of Engineering etc.).
- Visible developers and standards developers, such as Joe Gregorio and Mark Pilgrim were both using Python to implement the prototypes of the Atom protocol. During that time, Python was stable and has implemented features such as Unicode support, a new Garbage Collector, generators and functional methods, etc.
- A huge step was applying the Django framework - it’s fast, secure and makes the code clean and easy to write.
- And Google, of course. It was the main reason why Python had risen so tremendously in literally several years. Google adopted Python back in 2006. They’ve used it as a top-tier implementation language for many platforms and applications since. By reinvesting in development of the language they perfected it and built up the trust.
“Java code may never dominate all computers or all platforms, but it is as close to a lingua franca as there is.”
Java is the one that always has been there. It was developed at Sun Microsystems in 1991, and released in 1995.
The first ten years were packed with intensive adoption and explosive growth. The developers managed to create something simpler than C++ which equals its performance capabilities.
- Over time, Sun has released three major versions of Java: 1.0, 1.1 and 1.2. Version 1.2 seems to finally bring Java into the prime time, in particular where user interface tools are concerned.
- A couple of years later J2SE 1.3 added something new, including the Hotspot JVM, a new version of the Java Virtual Machine (JVM), the sound API and improved debugging.
Java core was simple and powerful compared to what they had back there. JVM broke the limitations of that time and significantly drew attention to the Sun’s flagship.
- Then there were libraries. A huge impact was made, just because from now on developers shifted their focus from struggles with the infrastructure to the application itself. This aspect made Java even more popular than it used to be.
Source: StackOverflow Survey 2018
- In 2002, version 1.4 added new tools in the language. And then in 2004, J2SE 5.0 was released, known internally as 1.5. From this point forward Java would be known as Java 5, Java 6, Java 7, and Java 8 and so on.
Unfortunately, several years ago Sun Microsystems had ceased to exist being swallowed by the Oracle on January 27, 2010.
In the end, Java’s still expected to be everywhere, whether it is a web, desktop or mobile devices. It’s gradually expanding the influence on the whole of modern programming industry.
The main idea here is when the types of variables are checked.
Statically typed languages define the type of a variable at compile time. In short, types are checked before run-time. For some languages, this means that the programmer must specify what type each variable is (Java, C, C++).
The main advantage here is that all kinds of checking can be done by the compiler, and therefore a lot of trivial bugs are caught at a very early stage.
Dynamically typed languages are checking types on the fly, during execution. This means that a programmer writes a little quicker because he does not have to specify types every time. Languages that support this type are Perl, Ruby, and Python.
Most scripting languages have this feature as there is no compiler to do static type-checking anyway, but you may find yourself searching for a bug that is due to the interpreter misinterpreting the type of a variable.
Static typing Dynamic typing
Supporting dynamic typing is an important reason why programmers can be more productive with Python. They simply don’t have to deal with the overhead of Java’s static typing.
In the meantime, BECAUSE it is dynamic, there are many design restrictions that are reported by some Python developers and the need to search for bugs every time the code has an error (in static typing the compiler makes it for you). It also requires more testing time, and the errors show up when the applications are finally run.
The visible difference looks like that:
Python is an interpreted language. In an interpreted language most of its implementations execute the code directly and freely, without previously compiling a program into machine-language instructions.
So, while a compiled language after the implementation has ready-to-go instructions for the device you use, in the interpreted language an interpreter interprets the original code every time the program runs.
Java, C/C++, Assembler, COBOL and many others are translated by running the source code through a compiler. This results in very efficient code that can be executed any number of times. The overhead for the translation is incurred just once when the source is compiled; thereafter, it need only be loaded and executed.
Interpreted languages, in contrast, must be parsed, interpreted, and executed each time the program runs, thereby greatly adding to the cost of running the program.
- Good when it comes to the projects with time restrictions on development
- Ease of future changes to the program
- Are generally more suited to ad hoc requests, rather than predefined (fixing, editing happens on-the-go)
- Easier to use (errors are immediately displayed and corrected by a user until the program is able to be executed)
- Smaller executable package size comparing with a compiled source code
- Higher execution costs - more time required for the implementation
- The interpreted program must be translated every time it is executed
- Less efficient than compiled programs
- Interpreters can be 2 to 10 times slower than compilers (they have to translate the same statements over and over again)
- Optimized for the target hardware
- Fast execution
- Optimizing compilers may increase speed and decrease the size of a file.
- Compilers ensure that static variables can be created so that providing less probability of runtime errors
- Security (the compiled version of a code is not clear and cannot be read this makes application hard for reverse engineering).
- Require a compiler (developers need to spend the time to install additional software before they start working on a project)
- Editing + deploying the code is sometimes much slower than interpreters
Python executes with the help of an interpreter instead of the compiler, which causes it to slow down because compilation and execution help it to work normally. On the other hand, it can be seen that it is fast for many web applications too.
The full benchmark of Python vs Java fastest programs (and some more languages) is available here.
The speed isn’t Python strong suit. In contrast, Java is faster - high-level languages are expected to act on a high velocity and be genuinely effective, as represented in the graph below:
As you can see, the program written in different languages runs consuming a different amount of time. E.g. Python handled this test for 694 secs, comparing to Java that required only 6 seconds.
“Python was so friendly and versatile to begin with that it became viral.”
By Toni Alatalo on Quora.com
The most basic use case for Python is as a scripting and automation language. Python isn’t just a replacement for shell scripts or batch files; it is also used to automate interactions with web browsers or application GUIs (Graphical User Interface).
Python is also used for system operations, web development, machine learning, server and administrative tools, deployment, scientific modeling and much more.
But, surprisingly, many developers don’t pick up Python as their primary language. Because it’s so easy to use and learn, they choose it as a second or third language.
Java is a cross-platform language that is applied in many fields including:
- Transportation, etc.
Moreover, Java is highly portable as it must be executed through a cross-platform compatible Java Virtual Machine (JVM). That is why it’ is easily applied on a wide range of hardware devices like television sets, VCRs, toasters and many other devices.
Java was, is and will be successfully applied in many domains including, first of all, enterprise and Android applications, experimental stuff, web development and desktop. It won’t be first forever, but shining in its element.
#4: Ease of use
The other school believes in minimalism, in keeping the language small, simple, easy to learn, and easy to use. Examples include Smalltalk, Scheme, Forth, Go, Pascal, and Oberon.
Python allows programmers to code faster with less effort. Above all, due to its simplicity and usability, Python is a great language to learn first.
But, here comes a disadvantage: while Python lovers become so accustomed to its features and its extensive libraries, they face problem in learning or working on other programming languages. Python experts may see even the requirements of adding curly braces or semicolons as an onerous task.
Java’s simplicity, comparing to its predecessors, also explains the position of Java as one of the most popular programming languages in the world. Add a huge ecosystem packed with libraries and frameworks, a super-optimized JVM runtime, and you have the formula for a killer language.
Anyways, nobody refers to Java as the most simple language that is readable for kids. See the example below:
“Hello world” written in Java and Python:
Null in both languages:
Working with files in Java and Python:
Java can’t be classified as one of the complex and difficult ones. However, this language is not a piece of cake so you’ve got to make an effort to become totally comfortable with it.
The famous guy who created C++ said once:
“There are only two kinds of programming languages: those people always b*tch about and those nobody uses.”
Today, Python is popular because it's easy to get started with, has a lot of libraries and frameworks available, and if you're OK with dynamic types, it's a decent enough language.
On the other hand, we have Java. A top-notch language that is applied literally everywhere. A unique set of standard libraries doesn’t concede in any place. The virtual machine that performs greatly on any platform, sturdy garbage collection and the overall ecosystem itself define Java as a beautiful creation that will be in the forefront for a long time.
Make your choice that is based on your specific experience and remember, that both Python and Java are worthy to be on top.
So, do these programming languages really need to fight? Well, the thing is, they were created for particular purposes and can be successfully implemented in different domains showing unique performance.