Java Vs Python
Java Vs Python
Difference?
Python has become more popular than Java. Google Trends shows
Python’s fame rose above Java in 2017:
(Source)
Python overview
Python was first released in 1991. It is an
interpreted, high-level, general purpose
programming language. It is Object-Oriented.
1. New programmers
2. Getting ideas down fast
3. Sharing code with others
Java overview
Java is old. Java is a general-purpose programming language
that utilizes classes and, like Python, is object-oriented.
With its ties to Sun Microsystems, Java was the most widely
used server-side language. Though no longer the case, Java
reigned for a long while and garnered a large community, so it
continues to have a lot of support.
Syntax
Because Python is an interpreted language, its syntax is more
concise than Java, making getting started easier and testing
programs on the fly quick and easy. You can enter lines right
in the terminal, where Java needs to compile the whole program
in order to run.
Type python and then 3+2 and the computer responds with 5.
python
3+2
5
Consider doing this with Java. Java has no command line
interpreter (CLI), so, to print 5 like we did above, we have
to write a complete program and then compile it. Here is
Print5.java:
java Print5
3+2=5
def main():
print('3+2=', 3+2)
if __name__== "__main__":
main()
Classes
Python code runs top to bottom—unless you tell it where to
start. But you can also make classes, like possible with Java,
like this:
Python Class
class Number:
def __init__(self, left, right):
self.left = left
self.right = right
number = Number(3, 2)
The class, Number, has two member variables left and right.
The default constructor is __init__. We instantiate the object
by calling the constructor number = Number(3, 2). We can then
refer to the variables in the class as number.left and
number.right. Referring to variables directly like this is
frowned upon in Java. Instead, getter and setter functions are
used as shown below.
Here is how you would do that same thing In Java. As you can
see it is wordy, which is the main complaint people have with
Java. Below we explain some of this code.
class PrintNumber {
int left;
int right;
On the other hand, Java has strict type checking. This helps
avoid runtime errors. Below we declare an array of Strings
called args.
String[] args
You usually put each Java class in its own file. But here we
put two classes in one file to make compiling and running the
code simpler. We have:
class PrintNumber {
int left;
int right;
}
That class has two member variables left and right. In Python,
we did not need to declare them first. We just did that on-
the-fly using the self object.
Related reading
BMC DevOps Blog
Using Python for Big Data & Analytics
Java Developer Roles and Responsibilities
10 Must-Read Books for Java Developers
Top Programming & Software Dev Conferences of 2020
Java vs Go: What’s The Difference?