+ Start a Discussion
KIRONKUMARKKIRONKUMARK 

APEX IS STRONGLY TYPED LANGUAGE - What does it mean?

APEX IS STRONGLY TYPED LANGUAGE - What does it mean?

 

 

Thanks

Kiran

Best Answer chosen by Admin (Salesforce Developers) 
JitendraJitendra

Strong typed language means while declaring variable you have to declare with datatype.

 

Example:

 

Loose typed language:

PHP :

$var1 = 10;

$var2 = '10';

 

Java Script:

var c = 10;

 

Strong Typed language : 

while declaring variable specify its data type:

Example :

Java:

int a = 10;

 

 

 

All Answers

JitendraJitendra

Strong typed language means while declaring variable you have to declare with datatype.

 

Example:

 

Loose typed language:

PHP :

$var1 = 10;

$var2 = '10';

 

Java Script:

var c = 10;

 

Strong Typed language : 

while declaring variable specify its data type:

Example :

Java:

int a = 10;

 

 

 

This was selected as the best answer
EL HITARY FaroukEL HITARY Farouk

This might be a very old Question but i'm clarifying things for all the visitors who might read this from now on since this post is easily reachable to junior developers.
 

The response provided by Jitendra is not right nor wrong, but can be misleading because some people might end up conflicting this with Static vs Dynamic languages,


A strongly typed language is a language that disallow convertion between unrelated data types, where a weakly typed language allows implicit convertions between unrelated data types,
An implicit convertion are simply convertions between data types that are done by the compiler automatically depending on the data types involved withing an instruction.

examples :

C# (strongly typed):

int number = 1;
number = 1 + 'a'; (ERROR)

C (weakly typed):
int number = 1;
number = 1 + 'a'; (C implicitly converts 'a' to its equivalent integer acsii 97 and adds that to 1 wich results to 98)


There is also Static vs Dynamic languages, this refers to the type checking and data type assignment to the corresponding variables.

 

Static is language that performs type checking during the Compile time, where Dynamic language performs type checking during runtime.

 

C (Static):

int number = 1; (Data type must be specified);

Python (Dynamic):

number = 1; (Data type is not required, the compiler assigns the corresponding data type to the variable number)


A side note from StackOverFlow:


Static/Dynamic vs Strong/Weak
The point here is that the static/dynamic axis is independent of the strong/weak axis. People confuse them probably in part because strong vs weak typing is not only less clearly defined, there is no real consensus on exactly what is meant by strong and weak. For this reason strong/weak typing is far more of a shade of grey rather than black or white.
So to answer your question: another way to look at this that's mostly correct is to say that static typing is compile-time type safety and strong typing is runtime type safety.
The reason for this is that variables in a statically typed language have a type that must be declared and can be checked at compile time. A strongly-typed language has values that have a type at run time, and it's difficult for the programmer to subvert the type system without a dynamic check.
But it's important to understand that a language can be Static/Strong, Static/Weak, Dynamic/Strong or Dynamic/Weak.