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:
I. Strongly Typed
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:
static int num=10,res=0;
static String s="5";
public static void main(String args)
Integer i=new Integer(s);
System.out.println("The Addition after converting is:"+res);
Output of the program:
The Addition after converting is:15
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.
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.
Posted on: April 17, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles