Difference between static and dynamic programming languages

Difference between static and dynamic is that before running the program if the data type of each variable is checked and verified then it's static type programming language (e.g:- in case of C++ it's done by the compiler). In Dynamic programming language during runtime, if there is an invalid assignment of a variable that violates its data type then an error is given for that.

Summary- Static type language check any violation before running the program whereas in the dynamic type language the error is given when the program is running and goes to the part were violation has been done.


Static Typing

Static typing means that types are known and checked for correctness before running your program. This is often done by the language's compiler. For example, the following Java method would cause a compile-error, before you run your program:

public void foo() {
    int x = 5;
    boolean b = x;
}

Dynamic Typing

Dynamic typing means that types are only known as your program is running. For example, the following Python (3, if it matters) script can be run without problems:

def erroneous():
    s = 'cat' - 1

print('hi!')

It will indeed output hi!. But if we call erroneous:

def erroneous():
    s = 'cat' - 1

erroneous()
print('hi!')

A TypeError will be raised at run-time when erroneous is called.