What is the difference between final and finally key words? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the difference between final and finally key words?

26th Apr 2018, 1:29 PM
DN HAMSAVENI
DN HAMSAVENI - avatar
4 Answers
+ 11
well final and finally both came in Java. final keyword can be used along with variable, method and Class in Java. If you make a variable final, you can not change it's value, it will act like a constant. final variables are initialized at the time of creation except in case of blank final variable which is initialized in Constructor. If you make a method final in Java, you can not overrideit in sub class . If you make a class final means it can not be sub classed. Making a class final automatically makes all its method final and this is sometime required due to security reason, This is one of the reason Why String is final in Java.  and finally is used in exception handling with try and catch block finally block has special advantage over catch that its guaranteed to be executed despite whether Exception is thrown or not, this makes it, an ideal place to close system resource 
26th Apr 2018, 1:44 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 11
it's not compulsory in exception handling but it generally used with exception handling but finally block will execute compulsory in any place it used refer this code and if you have any query then asked again
26th Apr 2018, 1:56 PM
GAWEN STEASY
GAWEN STEASY - avatar
0
finally block is really compulsory in exception handling?
26th Apr 2018, 1:50 PM
DN HAMSAVENI
DN HAMSAVENI - avatar
0
Mllnono.zzz mm 6% 6966!9.6%?9?36966633533055865?.9⃣ 51686?969666.696393?356
30th Apr 2018, 6:20 PM
Nilson Adiel Grazt Salamanca
Nilson Adiel Grazt Salamanca - avatar