OK now let's look at the essentials demo specifically look at the asset statement itself and we will 2
also look at the flaks the year flag under the Firaaq year for enabling officer issuance NBA for disabling 3
officers. 4
It's unreal. 5
Specifically look at the year flag. 6
The enabling flag at book Class unpackaged level under the flag only at a colossal event and we will 7
also look at the year flag applied. 8
But it's that. 9
Without that without any restrictions at class or package of it. 10
So here for this demo I created a new snapback package within exceptions called assertions and there 11
are four classes which I've created a B C and D and A B and D going inside the assertions package on 12
assertions also has a package quite Beaven on seed or July is placed inside be one. 13
Now the main class is the Class 8 which means that it has a main method and within all four classes 14
there is a best method. 15
You can see it here in B B and C and within each element there has only one parameter in all the four 16
classes on their stuff. 17
It's a barometer. 18
I am the first statement in all of the methods in each of the classes is an absurd statement. 19
For example here in 8 or Java it is answered and it is simply checking. 20
F I is greater than zero if it is greater than zero. 21
We know that it is good. 22
I can go with the next statement but if it is less than or equal to zero it means that our position 23
is wrong and this message will be passed on to the as shown error which should be generated as a result 24
of this failure. 25
OK so in this case it is invalid. 26
I in a test so similarly in beat or Jawa X is invalid. 27
I n b dark dust and indeed are Java X's. 28
In reality I indeed are dust and we have the similar statement and the class now. 29
So Class C is inside the package be run here. 30
OK just an ER doc and here in Class A. 31
After the statement we are simply creating an instance of be an instance of C an instance of d n NBT 32
are invoking the best matter that an argument minus one. 33
I can beat or Java just has only the so its statement and seed Argile also just has only that sort of 34
statement. 35
Indeed our Java has no such statement but it is also creating an instance of B and is invoking that 36
method that value minus one. 37
So we will see why we are doing that. 38
So let's just go ahead and run this. 39
So by default it is disabled. 40
All associates are disabled. 41
So all these statements do not have any effect so far on it. 42
So there is there is nothing happening just this Klaas's is running and this method is getting in work 43
on all of these instances of getting created under US methods of getting in work. 44
But those statements are disabled on Wednesday or not do you want to exit your date. 45
So let's go ahead now and do the first test which is going to run us undrawn configurations. 46
So we are going to enable it only for the Klasky. 47
OK so let's go into arguments here. 48
So this is for. 49
This is for the Class A. 50
OK we have done it right click on that and we have come here so we need to enable that only for class 51
. 52
So it would be hyphen. 53
And this is the assertions doc a guess what we are enabling it for a. 54
So when we run it we are passing minus one here and the method is getting invoked. 55
And since it is less than or equal to zero it's printing the message invalid in a test. 56
OK on your string assertion error not it's possible one here instead of minus one. 57
Now we don't have such an error because this is true. 58
Now this condition is true and we are going into the next statement. 59
But assertions are unable and only for class A. 60
So for that reason as assertions in any of these classes like B C and B are not executed. 61
OK so now. 62
So that's the first test. 63
No let's just go ahead and label it for the package itself. 64
Assertions. 65
Package Berengar on as. 66
So this is what we are doing it on class. 67
Because that has the main matter. 68
Once again let's pass the arguments the VM arguments here. 69
Now here instead of a we are going to say since it's a package label. 70
Is it docked three dots right. 71
So that's for the package Acme applied here and it's run it. 72
And now the associate set up Blyde. 73
You can see that it's failing here for the test method in class B because we are passing a minus one 74
understeering and associate error and the program is basically terminated in 1991 going to exit could 75
any of these statements. 76
So let's make this one SILVERDOCS SOTA statement and Glasby will work OK. 77
But it is failing in class C. 78
Ok that doesn't matter in class C because we are passing minus one. 79
So the important thing to note here is the flag. 80
The package level house specified it as assertions. 81
But even though C is inside some baggage office notions that particular flag is still working. 82
OK so the assertions have been unable for seed Argile also even doing it is part of a snapback edge 83
. 84
OK so the package level when we enable it at back is no wonder it would apply to both. 85
All all the classes in that package and also any classes and sub packages. 86
OK so that such package was not discussed earlier in the lesson so it would also apply for all packages 87
. 88
So let's also make this one now. 89
Now everything is fine. 90
It's only that in the class B there is an assertion outer and how. 91
Because we are passing minus one. 92
So that's the second best. 93
Now let's just go ahead and disable it only for class D. 94
So B stands for disabling. 95
You can think that way. 96
So it is going to aid our Java like going to run configurations here get into arguments and that's enabling 97
. 98
Now let's say discipling. 99
It's Haifaa NBA 100
needs to be D. 101
K so let's apply. 102
Sure on and on. 103
As you can see now how does this it will be back within that dust method. 104
Off D we are creating an instance off beat. 105
So this statement is working fine because it's true. 106
On the contrary comes here goes into best mentor and we are passing it minus one here. 107
OK so since this is an instance of B so since we are passing minus one controller comes here on this 108
phase underspending printing done invalid I indeed our best and you can see that back stack trace also 109
says beat. 110
Best indeed are best because it is invoking B and DS in don't invoke from a. 111
And you can see the actress. 112
So that's the third Test. 113
Now let's just use only only that you like. 114
OK so let's remove the package here. 115
This will not make any difference in the output. 116
So we are passing only EAF like to class A. 117
So you are running a real running class A and we are passing on the flag. 118
But we are also disabling only the class D. 119
So we just go how to apply this. 120
So once again it's the same output. 121
So it means that the assertions are an amber since it's applied on a. 122
It's a blight. 123
It's an enabler for all classes that are being accessed from a. 124
Which means except for B C and B. 125
But in this case we have disabled it for beat. 126
OK so it's disembody for me. 127
So assertion is disabler here. 128
But then since D is also invoking B cert it is also applied for B. 129
So it is basically applied for a any unidentified object tree that is that gets created from Iran where 130
it's ok including an object that is getting created somewhere inside. 131
So that is we are in working creating an instance of B and within be an instance another instance of 132
B is created and an assertion is also applied for that also. 133
OK this one. 134
So that's about it. 135
That's how you were unable undecidable assertions and just all the discord is in the resources section 136
. 137
So you can go ahead and download and play with it and that's it. 138
Thank you and happy coding