Both Python and Java compile the source files to bytecode. The difference is in how they to run this bytecode. In both languages, the bytecode is basically a binary representation of the textual source code, not an assembly program that can run on a CPU. You have a different program accepts the bytecode and runs it. How does it run it? Python has an interpreter, i.e a program that keeps a "world model" of a Python program (which modules are imported, which variables exist, which objects exist...), and runs the program by loading bytecodes one by one and executing each one separately. This means that a statement such as y = x + 1 is executed as a sequence of operations like "load constant 1", "load x" "add the two values" "store the result in y". Each of these operations is implemented by a function call that does something in C and often reads and updates dictionary structures. This is slow, and it's slower the smaller the operations are. That's why numerical code in Python is slow - numerical operations in Python convert single instructions into multiple function calls, so in this type of code Python can be even 100x slower than other languages. Java compiles the bytecode to machine code. You don't see it because it happens at runtime (referred to as JIT), but it does happen. Since Java also knows that x in y = x + 1 is an integer, it can execute the line using a single CPU instruction. There's actually an implementation of Python that also does JIT compilation. It's called PyPy and it's five times faster than CPython on average, depending what exactly you do with it. It will run all pure Python code, I think, but it still has problems with some libraries. Answer from unruly_mattress on reddit.com
🌐
Reddit
reddit.com › r/python › why python is slower than java?
r/Python on Reddit: Why Python is slower than Java?
January 3, 2024 -

Sorry for the stupid question, I just have strange question.

If CPython interprets Python source code and saves them as byte-code in .pyc and java does similar thing only with compiler, In next request to code, interpreter will not interpret source code ,it will take previously interpreted .pyc files , why python is slower here?

Both PVM and JVM will read previously saved byte code then why JVM executes much faster than PVM?

Sorry for my english , let me know if u don't understand anything. I will try to explain

Top answer
1 of 42
621
Both Python and Java compile the source files to bytecode. The difference is in how they to run this bytecode. In both languages, the bytecode is basically a binary representation of the textual source code, not an assembly program that can run on a CPU. You have a different program accepts the bytecode and runs it. How does it run it? Python has an interpreter, i.e a program that keeps a "world model" of a Python program (which modules are imported, which variables exist, which objects exist...), and runs the program by loading bytecodes one by one and executing each one separately. This means that a statement such as y = x + 1 is executed as a sequence of operations like "load constant 1", "load x" "add the two values" "store the result in y". Each of these operations is implemented by a function call that does something in C and often reads and updates dictionary structures. This is slow, and it's slower the smaller the operations are. That's why numerical code in Python is slow - numerical operations in Python convert single instructions into multiple function calls, so in this type of code Python can be even 100x slower than other languages. Java compiles the bytecode to machine code. You don't see it because it happens at runtime (referred to as JIT), but it does happen. Since Java also knows that x in y = x + 1 is an integer, it can execute the line using a single CPU instruction. There's actually an implementation of Python that also does JIT compilation. It's called PyPy and it's five times faster than CPython on average, depending what exactly you do with it. It will run all pure Python code, I think, but it still has problems with some libraries.
2 of 42
68
There are 2 things that mostly affect this: Language design and Implementation. Python is designed to be higher level and to be more easy to iterate quickly, for example by it's use of duck typing. Java on the other hand, while quite high level when compared to C, forces static type checks at compile time. This means the Java compiler can do optimizations that Python just can't, because it has more information ahead of time (because it forced the programmer to supply that information) Then there is implementation. At least for python I know a handful of language implementations that vary wildly in speed. CPython and PyPy with it'S JIT compiler come to mind. Many of the speed issues are just a matter of optimization. Java has been optimized a lot about 10 years ago I think? I remember sitting in uni and people talking about how Java has finally become fast ^^. Take this with a grain of salt, I don't enjoy java specifically, I might misremember the time. But Python definitely is getting faster by the year. The "normal" python implementation is working hard on optimizations since about 3.9. One of the things holding python back in many applications on modern hardware is the GIL, because it pretty much makes easy and fast multi threading impossible. There are Python versions without a GIL and there are efforts to remove and/or change it for main python as well. These are just some points and examples that came to mind, there is plenty more (Examples as well as details), we only scratched the surface here. I hope it helped though
🌐
Reddit
reddit.com › r/askprogramming › is java faster than python?
r/AskProgramming on Reddit: Is java faster than python?
January 31, 2024 -

Java is said to be much faster than python but there are different ways to run these languages (e.g. pypy for python, maybe dalvik for java). Is there any way python could be made faster than java?

Top answer
1 of 5
17
All things being equal, yes Java is usually faster than Python. That said, there are some pretty important qualifiers to that statement: Much of the "heavy lifting" done by Python is actually implemented in super-optimised C and C++ code which is (again, all other things being equal) faster than Java code, e.g. the Numpy library is a good example of this. Many programmes - e.g. most web apps - are I/O Bound (meaning that their performance is limited by the speed of input/output operations such as sending messages over the network or retrieving information from a database), meaning that, in practice, the speed difference between Java and Python is irrelevant, as the programme spends 99% of its execution time on I/O. Speed of implementation is often more important than speed of language. An inefficient Java implementation will often be orders of magnitude slower than an efficient Python on. Developer time is often relevant. Python advocates often state (rightly or wrongly) that as Python is more concise and "simpler" than Java, meaning that it allows Python developers to be more productive than developers using other languages, which is relevant if CPU cycles are cheaper than engineer wages.
2 of 5
5
Last time I checked, yes, by a huge margin. Java's execution is like reading shorthand (Compiler+JIT), python is like reading Shakespeare (Slow-ass interpreter). While there's good efforts made to make unofficial compilers that can convert Python or Java to Assembly, it's not easy since both languages rely on the VMs that run them to do things like automatic memory management, so the code you have inside your Python/Java program isn't the full story. You also need a garbage collector written in Assembly among other things. This makes it very difficult to turn into native code. That's the efficiency kind of performance. But there's also performance gains from leveraging more hardware that you also need to worry about. Even if you used these unorthodox assembly compilers, the language itself can hamper this performance, like the ability to multithread, which the Python spec lacked for a very long time.
🌐
Reddit
reddit.com › r/python › which language, java or python, can process data faster?
r/Python on Reddit: Which language, Java or Python, can process data faster?
May 31, 2022 - Pure Python is very slow for larger data amounts, therefore specialized libraries like Numpy are used, which are very performant and should out-perform Java (which is compiled, but runs on a VM, which should be slower than code directly compiled ...
🌐
Reddit
reddit.com › r › programming › comments › 24ynh › python_vs_java_an_update_to_a_subjective_speed
r/programming - Python vs. Java: An update to a subjective speed comparison
July 10, 2007 - It doesn't look like it. The code loops a million times, yet Java is only 90x faster than Python. If Java is performing the computation at compile time, it means that variable assignment in Java is 10,000 times slower than loop increment in Python.
🌐
Reddit
reddit.com › r/learnpython › "python vs. java in 2025: which should i focus on?"
r/learnpython on Reddit: "Python vs. Java in 2025: Which Should I Focus On?"
December 10, 2024 -

It's 2025, and I'm at a decision point in my programming journey. I want to dive deep into one language and can't decide between Python and Java.

Here's my context: i am a developer with 10 year experience in java and 5 years in python

  • Python: It's dominating fields like AI/ML, data science, web development, and automation. With its growing libraries and frameworks, it feels like a must-know for cutting-edge tech.

  • Java: Despite being older, it's still a powerhouse for enterprise systems, Android development (with Kotlin in the mix), and large-scale backend solutions. Its stability and performance are undeniable.

Find elsewhere
🌐
Reddit
reddit.com › r/python › why does it seem that python pays more than java (from what little googling i’ve done)? i would assume that since java runs faster and more efficient (and since it’s harder to learn, thus, making it a more scarce skill) that java would be the higher paying language.
r/Python on Reddit: Why does it seem that python pays more than Java (from what little googling I’ve done)? I would assume that since Java runs faster and more efficient (and since it’s harder to learn, thus, making it a more scarce skill) that Java would be the higher paying language.
April 1, 2022 - If you want to head down a dead end road learn Java. ... You need to remember that companies pay for delivering value, not the complexity of the tool you use to do that. You could deliver blazing fast code in assembly but it doesn’t do you any good if it takes you 50x longer to write. ... It can be but if it is the developer wouldn't be using Python. Python gets Chosen for all of its good qualities not for its poor performance...
🌐
Reddit
reddit.com › r/java › java and/vs python (within a business context)
r/java on Reddit: Java and/vs Python (within a business context)
August 14, 2015 -

I've spent the last year working as a software engineer writing a web-app in Python. The interesting part is I'm not actually part of the IT department and they (a year ago) said I could use Python on the understanding I would get no support from them, they were advocating PHP. Due to my own experiences with the two and the project I would be undertaking I picked Python.

Fast forward to today and some other people from IT have performed a code review as the project has been far more successful than they anticipated and people are sitting up and taking notice. The main question they're asking has to do with Python, why am I using it? I've not had a chance to meet the questioners yet but I'm told some of them code in Python themselves and that the main suggestion coming from IT is to use Java instead.

I've had some exposure to Java but not a lot. I understand it's compiled to Byte-code, uses the JVM etc and that it's very popular in more established businesses. What I don't know (beyond what a simple Google search will tell me) is why I would pick one or the other.

I'm not after "Java is better than Python", I'm genuinly curious to hear from people experienced in both which aspects of each make them good for different problems. Is it that Java is a lot better past the 10k loc mark? Is it that Java is so much faster than Python? I think I've covered everything, if not please let me know and I'll answer it.

Top answer
1 of 5
18

I see python like most dynamic languages (compiles at runtime), it's fast to develop in. There are good libraries in it and you can get products going really quickly. But when you start getting to points where you have massive load on the system, python will probably not behave as nicely as Java could.

I see Java being closer to C++ than most of the popular dynamic languages out there (those being PHP, Python, Perl, Ruby, etc...). Java does a lot of compile-time checking for us, specifically around types (static typing). For most small projects, dynamic typing that you get in languages like Python works just fine, but when you start getting a lot of code with a lot of developers working on it, dynamic typing becomes troublesome.

Beyond typing, speed can be a major factor. Java allows you to have some pretty close-to-hardware control over how the language behaves, especially when you are multi-threading.

Java is a good language, but it is a bit more verbose than other languages, and can take more time to prototype out new ideas in. If you are re-writing some existing program to get better performance, Java is definitely a good choice.

(Go-lang would probably be the second language I would look at if speed was an issue).

Edit: To add, everyone has their language preferences. I used to be a Java only fanboy, but since I've picked up a few other languages, I'm starting to see Java's weaknesses. A lot of the time, it is better for a company to choose whatever language the team is comfortable with so there isn't as much training that is required for others to work on the code.

2 of 5
9

Writing a webapp in Java takes a much steeper learning curve, and needs much more experience. Writing it in python is perhaps the faster way. Maintaining the code, that's something different - if further modifications were needed, it might be harder for the python code. Just might be, because a seasoned programmer might develop good enough python programs (he could do that in Basic too if he wants).

But if the application starts to grow, and a lot too, then python runs out of control soon. Several hundreds of thousands of lines of code, that's not for python. Several thousand, it's still fine.

So it all depends, what you are after. Besides, if you are experienced in Python but not so in Java, then the bigger risk is to switch to a new technology.

Each has its own merit, and it depends also on your intentions. If you're going to move to the IT business as a developer, then I'd say Java has a better perspective. But if it was just a hobby project (even if it is useful for others), then I'd say stick with what you know better. One can do most everything with python (and with Java too).

🌐
Reddit
reddit.com › r/python › python vs java in 2020 - what is your opinion?
r/Python on Reddit: Python vs Java in 2020 - What is your opinion?
September 14, 2020 -

Hi all,

As someone who is relatively knew to both Python and Java I'm just now deciding which language I want to explore deeper into.

As far as I can tell from my research the main benefits to Python are that

  1. It is very user friendly, and

  2. There are lots of modules available that are interesting to experiment with.

However, admittedly, I am drawn more to learning Java. As a general consensus it seems to be:

  1. much faster

  2. heavily embedded in the industry

I hear from various sources online that Java seems to be on the way out and Python on the way in but I don't know if that's actually the case? I can't imagine, due to how heavily used Java is, that it is going anywhere anytime soon.

Another thing everyone talks about is dynamically typed vs. statically typed. Perhaps it was just because I started with Java but I feel far more comfortable using a statically typed language over Python. Am I missing out on something here or do other people feel the same?

Also, just in terms of future job possibilities and the use of Python in the industry I would assume that Java or even C / C++ would be more likely to propagate throughout the future just because of the speed? Or am I just over exaggerating how important the speed of the application actually is?

Any opinions you have on this question are greatly appreciated :)

Thanks.

Top answer
1 of 4
4

Hello! I'm a bot!

It looks to me like your post might be better suited for r/learnpython, a sub geared towards questions and learning more about python regardless of how advanced your question might be. That said, I am a bot and it is hard to tell. Please follow the subs rules and guidelines when you do post there, it'll help you get better answers faster.

Show r/learnpython the code you have tried and describe in detail where you are stuck. If you are getting an error message, include the full block of text it spits out. Quality answers take time to write out, and many times other users will need to ask clarifying questions. Be patient and help them help you.

You can also ask this question in the Python discord, a large, friendly community focused around the Python programming language, open to those who wish to learn the language or improve their skills, as well as those looking to help others.


README | FAQ | this bot is written and managed by u/IAmKindOfCreative

This bot is currently under development and experiencing changes to improve its usefulness

2 of 4
3

You are definitely overvaluing speed (and probably exaggerating the speed difference).

Python has been one of the fastest growing languages in terms of job prospects, but it entirely depends on what you want to do. If you want to write GPU drivers, Python isn't the language for you. But if you plan to do data science or full stack web development, then Python may well be the right language.

You seem to be desperately trying to find some justification to choose Java. If you want to choose Java, just do so. You don't need to agonize over static/dynamic typing or other trivialities of the language to justify it. Java isn't going away anytime in the foreseeable future.

🌐
Reddit
reddit.com › r/python › python and/vs java (within a business context)
r/Python on Reddit: Python and/vs Java (within a business context)
December 11, 2012 -

I've spent the last year working as a software engineer writing a web-app in Python (using Pyramid). The interesting part is I'm not actually part of the IT department and they (a year ago) said I could use Python on the understanding I would get no support from them, they were advocating PHP. Due to my own experiences with the two and the project I would be undertaking I picked Python.

Fast forward to today and some other people from IT have performed a code review as the project has been far more successful than they anticipated and people are sitting up and taking notice. The main question they're asking has to do with Python, why am I using it? I've not had a chance to meet the questioners yet but I'm told some of them code in Python themselves and that the main suggestion coming from IT is to use Java instead.

I've had some exposure to Java but not a lot. I understand it's compiled to Byte-code, uses the JVM etc and that it's very popular in more established businesses. What I don't know (beyond what a simple Google search will tell me) is why I would pick one or the other.

I'm not after "Python is better than Java", I'm genuinly curious to hear from people experienced in both which aspects of each make them good for different problems. Is it that Java is a lot better past the 10k loc mark? Is it that Java is so much faster than Python?

I think I've covered everything, if not please let me know and I'll answer it.

Top answer
1 of 5
59
In business context, it will be easier to find a java guy (than a python guy) to replace you, when you'll quit or when you'll be fired ;-) "easier" to maintain.
2 of 5
48
In general it takes a lot more lines of code to do the same thing in java than python. This is only partly down to syntax, but also the design of the standard library plays a part. (A simple example is getting an item from a list, with a default if it's not present). As you'll write less code, there's less to keep in your head + dev is quicker. Also: http://blog.vivekhaldar.com/post/10669678292/size-is-the-best-predictor-of-code-quality The compile/run cycle is fairly handycapping timewise if you go from python to java. It's very frustrating going from python to java, everything you do results in a feeling that it should be a few lines of code, not 5 or 6 classes. You can probably use jython to interface to their existing code. With python there's a lot less syntax - that means more of the code on the screen is expressing what your trying to do, as opposed to boilerplate - since what you can keep in your head is probably measured in screens, that speeds up debugging too. I haven't used java since JSPs, but just hitting refresh to view a django page, rather than building a war file, restarting tomcat is the difference between night and day. Urg, what else. .. the overabundance of xml config in java - xml is for computers not human consumption. At the end though, the java devs will be happy with all of the above, so I don't know if any of those can be distilled into convincing arguments for them. What's good about java... ? For me it was the speed, so when it came to graphical apps + also on android it was all I could use. [edit: typo conventional/convincing]
🌐
Reddit
reddit.com › r/learnprogramming › is python slower or faster than java in 2017?
r/learnprogramming on Reddit: Is Python slower or faster than Java in 2017?
June 3, 2017 -

If you ignore all the other language features and characteristics, and compare them solely on the basis of speed or performance, then which one is better? Python or Java?

In 2010, most were of the opinion that Java is faster (or at least the most optimized Sun Java implementation at that time was faster than the cpython implementation).

Today, we have OpenJDK as standard. So, how do today's OpenJDK compare with today's cpython?

Top answer
1 of 4
4
Java is faster, sometimes significantly faster. (Disclaimer, as always, it depends, but if we are speaking generally). Basically: C and C++ are faster than Java. Other languages that compile to native may be too, but if they have a GC (Go, Swift) they may not be as fast as C and C++. Java is next. Other JVM languages should be comparable. Slower than C and C++, but often significantly faster than all the interpreted languages. Interpreted languages: Python, Ruby, JavaScript, whatever else. These are usually slowest. Again, this all depends on your use case. In some cases you might notice, in others it might be insignificant. Also, when using libraries it might be different. For example, if you use NumPy or SciPy you are basically running native code for the performance heavy parts of your program. So it all depends.
2 of 4
2
The answer to that depends on numerous things. Are you specifically asking about CPython, or do other implementations like PyPy count? What about extension modules? (For example, numerical analysis done with Numpy will often be competitive with native code if written properly, but that's because Numpy is doing all the work in native code.) What about things like Cython or Numba? And so on. There are about a million variables here. If you are strictly referring to only CPython, and only pure Python code, then yes, of course it's slow. Java will win every time (assuming you don't do something ridiculous like include runtime startup costs.) It's really an apples and oranges comparison, since Java has static types whereas Python does not, and that significantly influences how easy it is to make an implementation of a language execute fast. That's not going to change any time soon. Even if CPython grew a JIT it would still be not in the same league.
🌐
Reddit
reddit.com › r/webdev › when to choose python over java or java over python?
r/webdev on Reddit: When to choose python over java or java over python?
May 28, 2021 -

What scenario calls for which language over the other? Both have similar capabilities but which of the two would be superior as far as for a full stack dev to know?

🌐
Imaginary Cloud
imaginarycloud.com › blog › python-vs-java
Python vs Java: Key Differences, Performance, and Use Cases
3 weeks ago - To say that Java offers great software stability does not mean that Python is unstable. In comparison, indeed, big companies, such as Android, Docker, and Airbnb, include Java in their tech stack.
🌐
Medium
medium.com › lets-code-future › python-vs-java-i-used-both-for-5-years-heres-the-real-difference-9da9981d528f
Python vs Java: I Used Both for 5 Years. Here’s the Real Difference
January 2, 2026 - Let me save you from the Reddit rabbit hole you’re about to fall into. ... You’ve been reading comparison articles for three hours. Half say Python is the future. Half say Java runs the world.
🌐
Reddit
reddit.com › r/learnprogramming › which programming language one should focus on for future demand: java or python?
r/learnprogramming on Reddit: Which programming language one should focus on for future demand: Java or Python?
January 25, 2026 -

Hi everyone, I'm trying to decide between java and python based on future job demand and long term career growth. I also want to start learning databases and would like advice on which one to focus on such as PostgreSQL, MySQL, or a NoSQL option like MongoDB. My goal is to build strong job relevant fundamentals.

🌐
Reddit
reddit.com › r/python › what are the main differences between python and java?
r/Python on Reddit: What are the main differences between Python and Java?
November 22, 2016 - Java compiles into BYTECODE and so does Python. But Java JVMs usually also JIT (Just In Time) compile frequently run sections of bytecode into machine language, which runs a LOT faster. Standard "CPython" doesn't do this - but PyPy does - and shows some impressive gains on performance...