Strongly Typed Programming Languages

Strong typing in computing are used when a programmer has to put more than once restrictions in a programme in any operation, which are to be executed on different declared data types with different values. In strongly typed languages, every variable defined in a code has been be well defined and assigned with data type.

Strongly Typed Programming Languages

Strong typing in computing are used when a programmer has to put more than once restrictions in a programme in any operation, which are to be executed on different declared data types with different values. In strongly typed languages, every variable defined in a code has been be well defined and assigned with data type.

Strong Typing,Java Training Courses,Java Training delhi,Online Java Training,Online Java Tutor,Free

Strong Typing

     

In computer science, a typed system defines how a programming language classifies values and expressions into data types. In computer programming a type of data indicates a set of values that have the same sort of generic meaning or intended purpose. So the process of verifying the data types in a program is called type checking which may occur either at compile time or runtime.

The programming languages can be categorized in following types:

  • Strongly Typed 
  • Weakly Typed 

I. Strongly Typed Languages:

In computer programming  languages the term strong typing is used to describe those situations where the programming  language specifies one or more restrictions on the operations that are to be performed on the different declared data types holding different values. This type of language forces the programmer to make his program in a proper behavior explicitly. The Java programming language is a strongly typed language, which means that every variable which is defined in any line code of programming has to be properly well defined and assigned with a data type i.e. every variable has its own type and a value that an expression can produce, determining the meaning of operations at compile time. 

This technique helps programmer in detecting the errors at compile time.  For example if you want to add a number and a string in your program then the specified code must convert the string into a number to be used of an addition operator and produce an error free result. This makes your code easier to understand and  more verbose.

Lets see, how this example converts a string into a number explicitly:

import java.util.*;

class StrongType
{
  static int num=10,res=0;
  static String s="5";
  public static void main(String[] args) 
   {
  Integer i=new Integer(s);
  res=num+i;
   System.out.println("The Addition after converting is:"+res);
  }
}

Output of the program:

C:\Roseindia>javac StrongType.java

C:\Roseindia>java StrongType

The Addition after converting is:15

Download this program

II. Weakly Typed Languages: 

In weakly Typed languages, you can simply declare a variable without assigning it a data type. Once you have declared a variable of  that type, it will  only accept the values that are of the same type and will remain of that type indefinitely. In such languages the type checking is performed at runtime. The JavaScript language is such type of  language where the data conversion is not required explicitly , and all the conversion are handled implicitly.  
For example, If we pass a string to the addition operator then it will be interpreted as a number or cause an error if the contents of the string are not  converted into a number automatically. However the code written in this language is not easier to understand because a lot of its behaviors are hidden in implicit type conversions.

Strongly vs. weakly typing is comparable with static vs. dynamic typing
In a statically typed language, type checking is performed at compile time. On the other hand, In a dynamically typed language, type checking is performed at runtime. In practice, weakly typed languages are usually referred as dynamically typed language. And strongly typed languages are referred as statically typed language.