Jaw Why is referred to as it type safe language. 2
And in this lesson we'll see what that means. 3
The reason we are not looking at this concept of type safety is because it is relevant to what we saw 4
in casting objects specifically. 5
We encounter a few compile time and runtime errors on those are due to the result of applying typesafe 6
needles. 7
So let's go ahead and see what biosafety means. 8
According to Wikipedia bike safety is the extent to which a programming language prevents something 9
called pipefitters. 10
So let's see what bipedally means. 11
Type errors are certain bot kind of errors that could lead to undesirable program behavior. 12
Let's look at a couple of examples. 13
One example could be in Wilkin nonexisting method on an object in our history. 14
The class stuff does not include a Proview mattered. 15
So we should not be able to invoke this method on a staff object. 16
We already know that Java's compiler will not allow us to do this but some languages that are not safe 17
could allow this and it could lead to some undesirable behavior. 18
Second example is related to memory safety on one specific example is buffer overflow which is usually 19
associated with languages like C and C++. 20
Let's consider this example declaration in C language where a catenary is initialized with the string 21
hello and this will get co-presenter in memory as shown here after hello. 22
We have a null character indicating that I need a string after null character in the adjacent memory 23
location. 24
We have some data from some other variable and this gives the character a non Nazi. 25
We want to insert the katak to be in the very next position 6. 26
However it would be invalid as it is outside the RSA range but in a pipe unsafe language this could 27
override that data in the next memory location. 28
So you can see that he has got over it done with chiropody. 29
So basically what happened was data got corrupted undocks an undesirable behavior. 30
So these are kind of pipe errors that are typesafe language. 31
We're trying to avoid some languages trying to put two in pipefitters at compile time. 32
Some do it only a runtime while some others do that but compile time and run time and what does it both 33
compile time as well as runtime types if checks that are done at compile time is also referred to as 34
a static type checking one of checks done at runtime. 35
Is your footrests dynamic like chicken. 36
C and Pascal are examples of languages that use only static type checking. 37
While Ruby and Python are examples of languages that use only dynamic electrican not let's look at couple 38
of stocktake by picking examples in Java. 39
We know that in Java they get a compiler error when we do this. 40
That is we cannot assign a larger type with a smaller type. 41
So here we are trying to assign a double literal to an incredible and we also know that the solution 42
for this is to insert an explicit cast and we also know that we cannot work on non-existing matter here 43
the reference type stuff does not include the proof review method on compiler promptly the parser solution 44
once again is to insert an explicit cast. 45
Finally genetics is all about types of beat at compile time. 46
Before generics many of the errors were only caught at runtime but with the introduction of generics 47
and Jollof I knew many of those errors at compile time access. 48
And that is what is before. 49
You would want to detect as many errors as possible at compile time itself. 50
So when we get to generics you will see me using the phrase type safety. 51
Quite a big Nona's checkout to a couple of examples on how GBM uses dynamic type checking to prevent 52
some of the pipe errors. 53
We saw this example when discussing object winds are going to cost promising the compiler that variable 54
S will always reference either an editor object or one of its subtypes but render the method with a 55
stop object. 56
We get a runtime error art class class exception indicating that the Stav object could not be Castner 57
to Ed.. 58
We know that this is because stuff can be an editor but it can also be something else like an email 59
address. 60
So people who enter type for JVM destroying this runtime error thus avoiding any undesirable behavior 61
. 62
And this example demonstrates prevention of buffer overflow type error here Qaderi is first initialized 63
with the characters hello and then we are trying to access element index location file which is altered 64
off I responded. 65
So the get runtime error card again. 66
This sort of bonnes exception as you can see the name of the error does the story so we can see the 67
dynamic by checking Crozon in order to avoid any undesirable behavior. 68
Basically Java static budgeting is enforced to prevent as many type errors as possible at compile time 69
itself. 70
However it is impossible to prevent all of that by bettors only at compile time. 71
So the ones that cannot be prevented at compile time are they can get off at runtime using dynamic type 72
checking. 73
So John Law uses both static and dynamic type checking and response doesn't typesafe language. 74
Also note that since toxically type languages do all the chicks at compile time itself and do not need 75
any additional checks at runtime they can still be faster than dynamically typed languages which have 76
to do all of the checks at runtime. 77
No sometimes people incorrectly use terms like strongly typed system to refer to static typing on Veeck 78
type system to refer to dynamic typing. 79
Unfortunately there is no standard definition for strong or weak type systems. 80
But let's look at some acceptable views for these two items. 81
Strong typing generally means that there are no loopholes in that type system. 82
That is a pipe system of a language gives certain guarantees. 83
If the language is strongly typed. 84
You cannot go out and undo something but in reality it does not and is on the other hand Veeck typing 85
means that the type system has some loopholes and hence can be subverted. 86
Invalidating any guarantees and in this respect July is considered as a strongly typed language. 87
Some experts say that C is a Beagley type language as it seems to have several loopholes so that support 88
type safety on July is considered as a type safe language. 89
It is very strict about type safety and uses both static and dynamic typing. 90
I'm also including some relevant pointers in the supplementary notes. 91
If you're interested you can check them out. 92
Thank you