Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a small program in Java and a similar one in Python which represents their

ID: 3601984 • Letter: W

Question

Write a small program in Java and a similar one in Python which represents their typing.

Static typed programming languages are those in which variables need not be defined before they are used. This implies that static typing has to do with the explicit declaration (or initialization) of variables before they are employed. Java is an example of a static typed language; C and C++ are also static typed languages.

Dynamic typed (sometimes called untyped or typeless) programming languages are those languages in which variables must be defined before they are used. This implies that dynamic typed languages do not require the explicit declaration of the variables before they’re used. Python is an example of a dynamic typed programming language, and so is PHP.

Explanation / Answer

As said above static type languages need the variables to be declared before. In case of dynamically typed languages there is no need of declaration. variables can be directly initialized and can be used.

Example code in java to calculate sum of two nums is as follows :

---------------------------------------------------------------------------------------------------------------------

/* JAVA PROGRAM TO CALCULATE SUM OF TWO NUMBERS */
puclic class Main{
       public static void main( String args[] ){
       int a = 0;   // a is of type of integer and it is to be declared before using
       int b = 1;   // b is of type of integer and it is to be declared before using
       System.out.println("Sum is : ",a+b);// printing the sum of two numbers
       }
}


------------------------------------------------------------------------------------------------------------------------------

I have commented the code to give you a clear idea of what's happening there.

By declaration we are saying that 'a' is variable that holds an integer data. In the same way 'b' also.

Without that declaration, if use 'a' in the code, it raises an error saying that undeclared variable.

This is called static typed - because this is checked at compile time( static - compile time).

Coming to dynamically typed there is no need of declaration, that is no need to specify what data type it is going to hold. it is decided at run time, (execution time) (dynamic - run time)

Example code in python which does the same functionality as above java code :

---------------------------------------------------------------------------------------------------------------------------------

a = 0

b = 0

print a+b

--------------------------------------------------------------------------------------

/* hope this helps */

/* if any queries please comment */

/* thank you */

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote