Python vs Java : Basics

Ganga Siva Krishna Palla
2 min readNov 6, 2019
python

Python is more productive language than Java. Python is an interpreted language with elegant syntax and makes it a very good option for scripting and rapid application development in many areas.

Python is a dynamically typed programming language where there is no necessity of declaring variables whereas java is a statically typed programming language wherein variables are to be explicitly declared.

Python code is much shorter, even though some Java “class shell” is not listed. This might be one reason why Python can be more productive.

1 .How to Run:

Java Program:

Type ‘javac MyFirstJavaProgram.java’ and press enter to compile your code.

Now, type ‘ java MyFirstJavaProgram ‘ to run your program.

Python Program:

type python3 MyFirstPythonProgram.py and press enter

2 .EXAMPLE:

Let us try the most famous first step programming as an example -“The Hello World”

Hello World in Java

HelloWorld.java

Hello World in Python

3 .Variables: How to declare and Use

Java Code:

Python code:

Output:

a value : 10
s value: Var Declaration

4. Data Types

Java Data Types:

Python Data Types:

The data types defined in Python are given below.

  1. Numbers
  2. String
  3. List
  4. Tuple
  5. Dictionary

5. Control Statements

If-else statements:

For python there are no parentheses needed around a condition, but there must be a colon afterward before the indented block. The indentation that is good formatting in Java is REQUIRED in Python.

Java:

Python:

If Else-if Else:

Java:

Python:

Loops:

Java:

Python:

For - Each loop :

java:

python

While Loop:

java:

python:

Loops with If else condition:

java:

python:

7. Functions

java

python

Taking input from the user:

java:

Taking string and number as input from user:

python:

python3: it takes input as string whether it is string or integer

input()

python2: it has two ways to get input from the user

taking string input:

raw_input()

taking integer input:

input()

Have fun, keep learning, and always keep coding.

I hope you liked this content. Thank you

--

--