+ 1
You can't really make generalisations, even if you consider two programs with the same functionality, written in both languages.
Further it's not clear if you ask about the executable size (storage) or the runtime memory consumption.
A lot of factors can affect this...
- using any external libraries and dependencies
- in Java taking advanced tools like jlink or GraalVM to compress the binary (treeshaking) or compiling to native code
- JVM itself has a memory overhead, in addition to the program, but it does many things to boost performance (JIT optimization, garbage collection) which the Python interpreter cannot, or does differently
- on the other hand Python objects store a lot of extra (arguably unnecessary) details on each object, so complex OOP programs can have a huge memory footprint, as compared to programs that mainly use libraries written in C,such as numpy
- Java has a clear advantage in multithreading apps
https://dev.to/ben/python-vs-java-5lb
+ 1
Yes, you can do machine learning with Java too.
https://www.baeldung.com/java-ai