What is the difference between java and python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is the difference between java and python?

I have already learnt Java at school, but I feel Python is more useful. It would be really helpful to know the major differences between syntax as well as the basics of Java and Python. I always find comparative studies to be relatively easier.

23rd Mar 2024, 5:41 PM
Saanvi
3 Answers
+ 2
In Java, you have to end each statement with a ; semicolon, and you put code blocks inside {} braces. In Python, the code structure is determined by end of line and by indentation. One of the biggest difference is about types. Java has a static type system, every variable must be declared with a specific type and it cannot ever change its type. On the other hand, Python has dynamic typing, the type of any variable depends on what you assign to it, and it can change within the same program. Java programs are compiled to Java bytecode. To run Java, you need to have the Java Virtual Machine runtime installed, but the same bytecode can usually run on different environments. You can also compile Java to a native executable, for example with GraalVM, then it will not need the JVM at all and it can achieve a tiny size, but loses the platform independence. On the other hand, Python is interpreted from the source code, and you cannot distribute a platform-independent executable.
24th Mar 2024, 4:47 AM
Tibor Santa
Tibor Santa - avatar
+ 4
it's really hard to write all the differences; but they have some in common as well.... few differences: in python you need : (colon) instead of the { } curly brackets in python the white space matters! (for example: indentation in loops) python is an interpreter language, java is compiled language and runs on a java virtual machine (so both are platform independent) in python generally you have to share your source code because of the interpreter; but in java is enough the compiled file in python the variable names can use [azAZ_] in python you can write: x < y < z without any problems, for example: 18 < bmi < 25 (if you are creating a bmi calculator) in python after the dot operator generally you continue with lower case letter (in java not always, but in c# almost never) these are just some of the basics
23rd Mar 2024, 6:50 PM
Mihaly Nyilas
Mihaly Nyilas - avatar
+ 3
Hi, Saanvi ! Here’s some more: 1. Python’s data types are dynamic, enhancing flexibility. 2. Its standard library covers web to data analysis comprehensively. 3. As an interpreted language, Python can be slower than compiled Java. 4. Python supports functional programming with reduce, map, and filter. 5. It excels in machine learning and data analysis ecosystems. 6. Its syntax is user-friendly and promotes readability.
23rd Mar 2024, 8:52 PM
Per Bratthammar
Per Bratthammar - avatar