File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Type safe language Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Type safe language" Watch "Type safe language" New topic

Type safe language

Hari babu
Ranch Hand

Joined: Jun 25, 2001
Posts: 208
Hi All,
What do we mean by type safe language ?
Leslie Chaim
Ranch Hand

Joined: May 22, 2002
Posts: 336
Type-safe refers to a language's built-in checking for type compatibility. For example Java will not allow assignments of a variable with wider width to a variable with a shallower width.
For example, the following Java code fails to compile:

But the following C code does compile:

Type safety goes much further in Java when it comes to reference checking but you get the idea.
[ October 16, 2002: Message edited by: Leslie Chaim ]

Normal is in the eye of the beholder
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
In fact, there are two forms of type safety:
There are weakly versus strongly typed languages. Java and Smalltalk are strongly typed languages - they will give you an error if you try to use an object as an inapropriate type (for example by throwing a ClassCastException). C++ is a weakly typed language - you can cast any object to any type, the program will just try to interpret the bytes at the memory location accordingly (with sometimes devastating results...).
Then there are dynamically versus statically typed languages. In statically typed languages like Java and C++, the validity of calling a method is determined at compile time - polymorphism is bound to the inheritance hierarchy. In dynamically typed languages like Smalltalk, method calls are verified at runtime, based solely on method signatures - polymorphism and inheritance are totally orthogonal in these languages.
Does that help?

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I agree. Here's the link:
subject: Type safe language
It's not a secret anymore!