Statically Vs Dynamically Typed Languages

Search for a command to run...

No comments yet. Be the first to comment.
In my other series, I write my personal note as a blog so when I mention some things I add references inside blogs so I created this series to write the details.
Variable Variables are for storing data values. In Golang there are available data types for variables are string, int, boolean, and float32. There are 2 ways to declare the variable First way is to declare a variable using the var keyword Second ...

A go file has the following parts: Package declaration Import packages main() function Example: package main import "fmt" func main() { fmt.Println("Hello World!") } package keyword defines the package name because every program is a part of t...

Content Security Policy ( CSP ) CSP is a layer that helps to prevent certain types of attacks including Cross-Site Scripting ( XSS ) and data injection attacks. These types of attacks are used to deface websites and steal data. CSP is designed to be ...

Go language statically typed language, compiled programming language designed at Google. Infrastructure has changed a lot in years with cloud and multi-core processors. As it said the infrastructure is scalable & distributed, and dynamic has more cap...

Statically typed language needs to define variable data type before compiling the program Because the compiler doesn’t understand the type of variable value whether it’s string or integer.
Example:
public class Main
{
public static void main(String[] args) {
// datatype variableName = value
String variableName = "Hello World!";
System.out.println(variableName);
// Output: Hello World!
}
}
As there is a String data type assigned this is why it’s not showing any error but when there will be no data type the compiler will return an error.
Example:
public class Main
{
public static void main(String[] args) {
// no datatype assigned
variableName = "Hello World!";
System.out.println(variableName);
}
}
Output:
Main.java:12: error: cannot find symbol
variableName = "Hello Worlds";
^
symbol: variable variableName
location: class Main
Main.java:13: error: cannot find symbol
System.out.println(variableName);
^
symbol: variable variableName
location: class Main
2 errors
It will return can’t find symbol error due to not defined data type, There are a few languages that are statically typed languages such as C, C++, C#, and Java.
Dynamically typed languages don’t need to define variable data type before compiling the program, Compiler or Interpreter automatically identifies the value’s data type and returns the output.
Example:
#!/bin/python
variable_name = "Hello World!"
variable_name_2 = 10
print(f"{variable_name} : {type(variable_name)}\n\n{variable_name_2} : {type(variable_name_2)}")
# Output:
"""
Hello World! : <class 'str'>
10 : <class 'int'>
"""