Java vs Python - Which Programming Language Should Learn First

Java and Python are two of most popular and powerful programming language of present time. Beginner programmer often get confused, one of the most frequently asked question is should I learn Java or Python, Is Python is good programming language to start with, Which programming language would you recommend for beginners to learn first etc. Since I am a Java developer, my opinion is biased, I will always suggest you to start with Java and then learn Python, but if you ask this question to a Python developer, you might get just opposite answer. I have well documented  my reasons as Why Java is best Programming language and Why a programmer should learn Java. One of the most important reason you would see on that blog post is strong Java community, which will help you though out your Java career.

You can ask some beginner stuff starting from how to set PATH and classpath to advanced stuff about debugging Java program in Eclipse, no matter what kind of question is, there is always some one is Java community, who is ready to answer and help you.

This is one of the reason that StackOverflow is full of Java questions. By the way Python is not spring chicken anymore, it has fully grown and giving strong competition to main stream language like Java and C++. 

When I first come across Python, I thought it's a scripting language, but that is an understatement. You can do object-oriented programming in Python as well.

On beginners point of view, I always suggest pick a language which is easier to learn, powerful to attract you and have strong community support, now both Java and Python fits this bill, and until you do some really good comparative analysis, you can not decide which language to learn from Java vs Python.

Thankfully, we have an infographic, which highlights some important difference between Python and Java, I am sure after taking a look on this Infographic, you will be able to decide which is the right programming language to start with.

Difference between Python and Java - Infographic

Being two different programming languages, Java and Python can be useful tools for modern developers for developing applications. Before learning any of programming language, it is must to know difference between them. It could be hazardous to declare that Java can be less productive compared to Python due to numerous elements. Let’s go through this infographics to know difference.
Infographic source :

From this Infographic, you can easily see that  Java is very verbose than Python. It takes 10 lines of code to read from a file in Java, while it only takes 2 lines of code in Python. this point goes towards Python, because beginner programmer definitely like to write less code. Second point is about static and dynamic type of variable, In my opinion, you need a strict programming language and compiler to detect silly mistakes made by beginners, In Java you can not store integer value in a String variable. So on this point my vote goes to Java. Speed, which is key thing on enterprise level application development, you can see that Java is faster than Python, but do remember that you need to compile and run Java program, while Python doesn't need to be compiled. Python shell can directly interpret python commands, which means easier for programmers. So now Python and Java are both 2 and 2. You can also see that hello world in Java takes more lines than hello world in python.Rest of examples you can analyze by yourself, but all it comes that both Java and Python are equally capable, no one is lesser than other. As a Java developer, I can say from my personal experience that you will not regret learning Java and choosing it as career, of course you can learn Python anytime and it's good for writing small utilities, but Java is Java.

Enjoy your Programming.

Recommended Reading

You can choose Head first Java to start with Java programming and  Head first Python to start with python. I have personally followed Head first series, and in my opinion they are the best resource to start with Java and Python.


Janusz AGH said...

What about concvurrency in Python?
Concyrrencvy, the strong part od Java, one of the most important things in serious corporate programming.

I can't understand why
public static void main(String[] args)
iż always set as prime example for code length in Java?
There is usually one main() method in project but person who doesn't know Javacould think that it is nessary to out main() method Evert time hi wants to write text to console.

Java is owned by Oracle, then it iż obvious, that Google and other "community" do not lukę Java despite the real cobs and pros of Java and Python.

In my humblewd opinion comparing Java and Python is lukę comparing C and Perl and trying replace for ideolgy only with one to another.

Anonymous said...

Your IO comparision is seriously read a file in JAVA one needs no longer than two lines of code as of JDK are writing code as one would do in 1.5...Update yourself mate

Eswar Vandanapu said...

Python code is not doing any automatic resource management. You woild code some thing like this:

with file('/path/to/file','r') as f:

This will make sure file is closed at the end of the with statement.

Unknown said...

Java is a poor language for beginning programmers. Not because python is easier or python programs contain fewer lines of code. Java forces you to program in one way and one way only, a particular form of object oriented programming. When I tell this to people their reaction is often "But object oriented programming is obviously superior to procedural programming!" The fact that they consider the only alternative to java oop to be cobol style procedural programming it's evidence they have been stuck in the java constraints way too long.

Ankit Jain said...
This comment has been removed by the author.
iskorn said...

I honestly cannot consider Python as a _programming_ language, at least a serious one. For me it is just a mess of ad hoc hacks w/o any noticeable consistency behind. In addition its libraries (well, those ones I've looked at) look like they have been created in a rush w/o any design and even taking into account common practice and standards. I do believe that it can be used for quick and dirty scripting but cannot imagine how any serious software can be created with Python. I think that it is a huge step back from Perl which has at least an elegant design. I've heard that PHP is even uglier, but can barely imagine how it can be.


Nice Difference for python and Java
U will Provide a such a good thinks for us..
its Great stuff....!!!!

Indian Minerva said...

I would like to disagree about the speed too. But I would like to admit that my benchmarking has been confined to mere literal operations. for example I tried the below : [sum (2^i) where 0 <= i <= 63] and python has beaten java to dust. Surprised (and encouraged) by that, I tried other similar operations, and guess what?? Python is a clear winner.

N.B. I am a Java developer with 7.5 years of experience and had been introduced to Python only a month or two ago but I am liking Python.

Anonymous said...

So you have learnt Python using 2.x. Then comes 3.x and breaks many things. So you have to learn again. What a great language Python is!

Anonymous said...

After 10 years of C++, I've been doing almost exclusively python for 3 years, and I started to learn java today. On the performance side, python is actually way faster than most people think, because (i) cpu-expensive code is typically written in C (ii) objects don't get copied under the hood. Does java have introspection capabilities? That's one of the very strong advantages of python over C++.

Anonymous said...

java is java. lol

Anonymous said...

haha, java is a pretty bloated language, even if it has more features and abilities than python would have.

Anonymous said...

You can actually read an entire text file to a String in Java in one line:

String text = new Scanner( new File("poem.txt") ).useDelimiter("\\A").next();

Anonymous said...

python is easy compare to java...I was working on java I am working on python....But for a large app java is better.....

Anonymous said...

I have used Python for nearly 9 months and I don't consider it as a serious programming language for the enterprise level applications. It is a nightmare to write large nested blocks of code, since there are no block separators like { } in Python. If one wrong space character could make the whole program logic wrong. It is surprising that Python does not have arithmetic operators like ++ or --. May be the authors of this language intended for only as a scripting language!

rajesh kumar said...

great difference between java and python

Anonymous said...

First, I'm a statistician, and the usual languages in my field are mainly SAS and R (and sometimes VBA). For many tasks related to my job, I prefer Python. I have also used Java in the past (versions 1.3 to 1.5), and tried many other languages. I use Python since around 2002.

To answer one post, a precision : Python has += (and also -= *= ...).

Regarding speed, Python is slow, when relying on "pure" Python features. If you use mostly an underlying C routine, of course it's different. On the other hand, Java has just-in-time compilation, so should be almost as fast as C, unless you rely too much on objects and automatic boxing (but it's quite frequent).

Java is much more verbose than Python. Regarding indentation by space, it's absolutely not a problem, and certainly not worse than indenting with curly brackets. Both are difficult to read if there are too many indentation levels, but it's a problem with the program (and the programmer), not with the language. A too long routine should often be proken into smaller pieces.

Python 3 breaking compatibility with Python 2 ? Sure, but the things that really change, change much less than Java 1.3 (or even 1.5) vs newer versions of Java. It's very easy to port from one version of Python to the other (and there is even an automatic tool for most of the trouble).

Python not a "real" programming language ? What a joke. It has pros and cons, as any other one, and it has proved to be a rather good one. That Python is a good language for your task or not, depends entirely on your task.

I have used both Python and Java quite intensively, and there are a few reasons I now use almost only Python :

- much easier to type : less verbose, no need to declare variables
- Python "philosophy" : often one way to write something, or at least one "good" way, not as in Perl or Ruby for, example
- good data types (list, hash, set), list comprehensions and generators are very usueful (and very easy syntax for generators)
- no trouble with silent integer overflow, there is no integer overflow at all
- very good library for all kind of OS support, plus zillions of other libraries for any need
- speed is not a concern : as design and coding take much longer than running the program in my case (file management, statistics, reporting), I prefer a better readability and easier coding as in Python
- very easy to write modules
- regarding comparison with Java, ability to program in non-OOP style is much appreciated !
- some functionnal programing features, mainly closures
- introspection and ability to produce code at runtime (exec/eval...)

Somes reasons I think Python is not perfect either :
- lack of goto or catch/throw constrcut as in Lisp (which is not the same as exception handling), or at least labeled break/continue. It's annoying in some situations, for example when you want to exit an inner loop. There are workarounds, but I still miss Lisp for this
- syntax for classes is awkward
- lack of a good compiler (pure Python is too slow, compared to Lisp, which is also a dynamic language)

Sure, there are situations where another language would be better (C, C++, why not Java), but there are many cases where Python simply shines.

Anonymous said...

IMHO Python is good for beginners. Java's better for other cases because its usually a bit faster than Python. There is one more reason why many programmer prefer Java since it has good library support, and it's the only native way to do Android.

Anonymous said...

then what the heck was java doing till 1.5 for file io?
dude .. the really power of python comes when everything is dynamic . and for static you can guess .. its kids play . the simple reason java is widely used coz it gained its popularity from sun labs . while guido von rossum was a simple student.

Anonymous said...

It has arithmetic operators like ++ :
In python it is += ,*= ....

Anonymous said...

Python is slower than java??

Anonymous said...

Python is far from perfect...

>>> tup = ('tup')
>>> type(tup)

>>> tup = ('tup',)
>>> type(tup)

Anonymous said...

" In Java you can not store integer value in a String variable ".
In Python either because Python is a strong typed dynamic language. The variables in Python are described by the value that has been assign to. The variable by itself has not any type. Try print(x) and you will get an error. So when you type:
and then
the variable st is assign to int and then to String type.

Anonymous said...

Whenever I see lines such as:
public static int foo() {
I cringe.
No offence to Jave, but Python is my favourite by far. And there are no huge differences between Python 2.x and 3.x syntax-wise, the biggest problem is that many important libraries have not been rewritten yet.

Anonymous said...

python is easy to learn and its fun too...

Zashel said...

Python is slower than JAVA while you don't compile it.

Anonymous said...

Any day, I will choose Java over Python because of just one reason, Java is strongly typed language. A strongly typed languge will catch all your typos at compile time which will only be spotted at runtime in caes of weakly typed language like Python. Of course, you should use proper types instead of just String to represent anything e.g. number, floating point number, employee etc. A strongly typed languge encourage you to use Types to avail full benefit of compiler, then there is enum :)

Anonymous said...

hello world

Anonymous said...

python is python, lol

Anonymous said...

java is love

Robert MacHale said...

Java is an elegant language. And, Microsoft borrows from it in C#. Nobody is suggesting Python style is worth repeating in other languages. RDM

juzraai said...

You can do file reading in one line also in Java.

Anonymous said...

Java is Java - true
Python is Python - true
My vote for Java

Anonymous said...

Do not confuse dynamically typed and statically typed with weakly typed and strongly/strictly typed. Make no mistake, python is strongly typed.

Anonymous said...

Java Is Java...I have started learning Java..., I'm loving it..

Unknown said...

Java is great and Python is great but you compare the two language to Perl then Perl sucks, ugly, and unfashionable..

Кошелев Иван said...

This article is old. JavaScript is number 1 in popularity now (see Stack Overflow and Github). Rightfully so, since it is much faster and more expressive than Python.

Geo Sustainability said...

Yes, Python is a horrible language to learn first. You may able to do a lot in Python with very little in time investment, but the bad habits you will learn by figuring out how to code in a dynamic language will ultimately lead you into a just so-so programmer. You are better off learning how to program in Java or C#, and then move to languages like Python, Ruby, and then on to C when you need speed.

Trust me, bad habits are hard to break and you are better off learning a strict language before you dive into the Wild West.

Post a Comment