final vs finally vs finalize in Java

  Рет қаралды 108,586

Naveen AutomationLabs

Naveen AutomationLabs

6 жыл бұрын

final: is a Keyword
1. final can be used to mark a variable "unchangeable".
2. final can also make a method not "overrideable"
3. final can also make a class not "inheritable". i.e. the class can not be subclassed.
finally: is a Block
finally is used in a try/catch statement to execute code "always".
finalize: is a Method
finalize is called when an object is garbage collected. You rarely need to override it.
~~~
Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:
kzfaq.info%20Au...
Follow me on my Facebook Page:
/ naveenqtpexpert
Let's join our Automation community for some amazing knowledge sharing and group discussion:
t.me/joinchat/COJqZQ4enmEt4JA... Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:
kzfaq.info%20Au...
Follow me on my Facebook Page:
/ naveenqtpexpert
Let's join our Automation community for some amazing knowledge sharing and group discussion on Telegram:
t.me/joinchat/COJqZUPB02r5sB7...
Paid courses (Recorded) videos:
Java & Selenium Course: www.naveenautomationlabs.com/p...
API Course: www.naveenautomationlabs.com/p... ➡️Get Our Courses✔️
📗 Get My Paid Courses at
Paid courses (Recorded) videos:
Java & Selenium Course: www.naveenautomationlabs.com/p...
API Course: www.naveenautomationlabs.com/p...
-------------------------------
✔️SOCIAL NETWORKS
Facebook: / naveenqtpexpert
Twitter: / naveenkhunteta
Blog: www.naveenautomationlabs.com
--------------------------------
Support My Channel✔️Or Buy Me A Coffee
Paypal: paypal.me/naveenkhunteta
Google Pay: naveenanimation20@gmail.com
--------------------------------
✔️Thanks for watching!
देखने के लिए धन्यवाद
Благодаря за гледането
感谢您观看
Merci d'avoir regardé
Grazie per la visione
Gracias por ver
شكرا للمشاهدة

Пікірлер: 52
@emalr.dawlatzai3083
@emalr.dawlatzai3083 4 жыл бұрын
Very well explained. You should get the award for using the best teaching methods, specially for someone new to Java.
@tickmedia3977
@tickmedia3977 3 жыл бұрын
Hi Naveen I'm from Afghanistan i follow your Java Tutorial , your explain is so good , thanks
@shwetapatil1362
@shwetapatil1362 5 жыл бұрын
Your videos are helping me a lot!! Thanks, Naveen.
@abhisheksagare
@abhisheksagare 4 жыл бұрын
Perfect explanation and concept clarification.Loved it.Thanks
@malanchakalsa358
@malanchakalsa358 4 жыл бұрын
awsomely explained Naveen , thank you soo much :)
@prithadutta4699
@prithadutta4699 6 жыл бұрын
As usual, Nice explaination...
@srinathsrinath24
@srinathsrinath24 6 жыл бұрын
Superb Explanation with simple way to understand..
@sureshsubramaniyan3201
@sureshsubramaniyan3201 5 жыл бұрын
Thank you very much for your knowledge sharing
@subeshc1426
@subeshc1426 5 жыл бұрын
Very very useful. Please post continuously..
@akshaysarve954
@akshaysarve954 2 жыл бұрын
Thank you so much Naveen... perfect explanation
@himadritanayasahoo4690
@himadritanayasahoo4690 2 жыл бұрын
Thank you so much for an awesome video.. It's really helpful..
@bhargavpinnam733
@bhargavpinnam733 6 жыл бұрын
Thank you Naveen!
@ramyab6961
@ramyab6961 6 жыл бұрын
Thank u so much Naveen.
@khajazakiuddin931
@khajazakiuddin931 5 жыл бұрын
Gud explanation in short duration. Please prepare some videos on SQL.
@sridevireddy1371
@sridevireddy1371 6 жыл бұрын
Thank you Naveen
@ribasoul
@ribasoul Жыл бұрын
Very well explained Naveen
@bharatvarshney2666
@bharatvarshney2666 6 жыл бұрын
nice explanation between of these
@vhvl3888
@vhvl3888 5 жыл бұрын
nice ... explain throw and throws also
@bhavanagyarampalli8983
@bhavanagyarampalli8983 Жыл бұрын
Thanku sir
@lisazhou7776
@lisazhou7776 4 жыл бұрын
very good. thanks.
@emonyousufy5670
@emonyousufy5670 3 жыл бұрын
Thanks Naveen
@ahujabharat19
@ahujabharat19 2 жыл бұрын
Very Well Explain sir
@subhanbasha1
@subhanbasha1 4 жыл бұрын
Hello Naveen Sir. it is very understandable way of teaching of every concept. Thanks for your efforts for all of us. for finalize concept, am getting displayed "Finalize Method" two times in console for ur mentioned code and why?
@naidugaariammai6708
@naidugaariammai6708 Жыл бұрын
nice explanation
@rahulprakash6367
@rahulprakash6367 6 жыл бұрын
very nice
@rajkamalannjoseph8928
@rajkamalannjoseph8928 5 жыл бұрын
If GC clears up all the unused objects, y should we use Finalize method in our code ?
@jayalakshmikrishnan1956
@jayalakshmikrishnan1956 Жыл бұрын
Hi ,Thank you very much for you patient teaching methods. Just one question on finally, i followed you example! For me its not printing the error in sequence, but in your method its coming in sequence ============================================================ public static void Division(){ int i=10; try{ System.out.println("inside try div"); int k = i/0; } catch(NullPointerException e) { System.out.println("Inside AE catch"); } finally { System.out.println("Execute method inspite of exception"); } } ================================================================== My console:- inside try div Execute method inspite of exception Exception in thread "main" java.lang.ArithmeticException: / by zero at JavaBasics.FinallyConcept.Division(FinallyConcept.java:38) at JavaBasics.FinallyConcept.main(FinallyConcept.java:7) ===================================================================================== I think it should 1st display exception and then display Finally comment like this:- inside try div Exception in thread "main" java.lang.ArithmeticException: / by zero at JavaBasics.FinallyConcept.Division(FinallyConcept.java:38) at JavaBasics.FinallyConcept.main(FinallyConcept.java:7) Execute method inspite of exception ===================================================================================== Please Advise ,what could be wrong here!?
@Mr_TravelEatWorship_Official
@Mr_TravelEatWorship_Official 2 жыл бұрын
If you wanna call GC forcefully, finalize() is required 😊
@ujjwalverma7787
@ujjwalverma7787 6 жыл бұрын
when I run finalize concept then its give an error Note: finalizeconcept2.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. please some help me to resolve this error !
@madhankumarkarthikeyan4787
@madhankumarkarthikeyan4787 3 жыл бұрын
Nice video, For the benefit of others, The method finalize is deprecated from Java 8+
@naveenautomationlabs
@naveenautomationlabs 3 жыл бұрын
Ita deprecated from java 9. Now we have cleaner class, replacement of finalize.
@kalyanijoshi6884
@kalyanijoshi6884 6 жыл бұрын
Programs for Prime numbers and Fibonacci series please add
@Aruthewarrior
@Aruthewarrior 6 жыл бұрын
Interview question - 1. Some real time example for Finalize...How you have implemented in your framework 2. What will happen if we use System.exit() in catch block. Does the finally block will execute even though ?
@AshishDubeyash4you
@AshishDubeyash4you 5 жыл бұрын
Yes it will execute finally block if you use System.exit(0) in try block or in Catch block. package finallyy; public class FinallyBlockConcept { public static void main(String[] args) { int a = 9; int b = 0; try { int c = a/b; }catch(Exception E) { System.exit(0); } finally { System.out.println("Execute Finally Block"); } } }
@arunc8342
@arunc8342 5 жыл бұрын
@@AshishDubeyash4you No bro. finally will not be executed. please try running this code itself. it doesnt run. system.exit will terminate the execution fully.
@Shreysanthu
@Shreysanthu 4 жыл бұрын
How to know and verify that finalize is done cleanup processing of the object before garbage collection
@vivekaanand6444
@vivekaanand6444 3 жыл бұрын
Hi Naveen thanks a lot for video , but when i run this program i'm getting the finally block executed first and then the ArithmeticException divide by zero exception is thrown video timing 18:32
@abhishekcardigan3770
@abhishekcardigan3770 3 жыл бұрын
Naveen, for the first example, even if you do not write inside the finally block it will still execute. I am confused, what is the use of finally in this case? package javabasics; public class Finally { public static void main(String[] args) { // TODO Auto-generated method stub try { System.out.println("inside try block"); throw new RuntimeException(); } catch(Exception e) { System.out.println("Exception handled"); } System.out.println("Inside finally block"); } }
@vaibhavsingh3166
@vaibhavsingh3166 Жыл бұрын
yes, it's because you have already handled the exception in catch block if any exception encountered which is not handled in catch block your last print line will not execute without using Finally Block. He just showed for your reference.
@praveenac1092
@praveenac1092 Жыл бұрын
To ellaborate more: The purpose of the finalize() method is to allow an object to perform any necessary cleanup or finalization before it is destroyed. We could use this to release resources such as file handles, network connections, or database connections, as well as performing any other necessary cleanup tasks. Source: OpenAI/ChatGPT 🙃
@satyaranjan2k
@satyaranjan2k 6 жыл бұрын
Hi Naveen, finalize() is getting executed multiple times in my eclipse and it's repeating exactly same nos of times as the nos of objects created. But in your video, though you have 2 objects for the FinalizeConcept concept class, the finalize() is getting executed only once. Below is the code which I have written, Please clarify : package TestCases; public class FinalizeConcept { public void finalize() { System.out.println("finalize method"); } public static void main(String[] args) { FinalizeConcept f1 = new FinalizeConcept(); FinalizeConcept f2 = new FinalizeConcept(); f1 = null; f2 = null; System.gc(); } } O/P : finalize method finalize method
@manikantaraju2592
@manikantaraju2592 5 жыл бұрын
U have created 2objects with 2different reference variable so u are getting output twice. Comment one Object and try to execute it u will get the required output
@jayalakshmikrishnan1956
@jayalakshmikrishnan1956 Жыл бұрын
But example shown in vedio is has 2 objects but still its displaying finalize method only once
@dikshaarora9626
@dikshaarora9626 Жыл бұрын
@@jayalakshmikrishnan1956 Happening same with me too . FinalizeMethod output is coming twice
@ramadeviarikatla9980
@ramadeviarikatla9980 2 жыл бұрын
Hi Naveen, good evening, I tried with finalize method but i got twice finalize method as the output(2 times printed on the console). Please help me out.
@himanshutyagi3280
@himanshutyagi3280 2 жыл бұрын
You must have created two objects
@bihari1422
@bihari1422 2 жыл бұрын
i am a bit confused with the finalize.....if its a keyword then its color should be changed ...System.gc will look any finalize method present in the class and execute it?
@bihari1422
@bihari1422 2 жыл бұрын
Got it only when we are making the ref variable as null then gc will come into picture and it will look for exactly "finalize" method declared before main and will execute it
@seshareddy7254
@seshareddy7254 6 жыл бұрын
Is Catch compulsory for try block..
@AshishDubeyash4you
@AshishDubeyash4you 5 жыл бұрын
No, but if any exception occured & is not caught then JVM will throw error at Runtime.
@kunalchaudhary8221
@kunalchaudhary8221 2 жыл бұрын
garbage collecter guy come😂
@DebunkSensibly
@DebunkSensibly 2 жыл бұрын
Thank you Naveen
This and Super keywords with Constructor Examples In Java
57:03
Naveen AutomationLabs
Рет қаралды 82 М.
Difference between Interface and Absract Class
30:52
Naveen AutomationLabs
Рет қаралды 178 М.
That's how money comes into our family
00:14
Mamasoboliha
Рет қаралды 11 МЛН
Can You Draw A PERFECTLY Dotted Circle?
00:55
Stokes Twins
Рет қаралды 44 МЛН
路飞被小孩吓到了#海贼王#路飞
00:41
路飞与唐舞桐
Рет қаралды 72 МЛН
I Can't Believe We Did This...
00:38
Stokes Twins
Рет қаралды 108 МЛН
Difference between final, finally, finalize ?
10:07
DURGA EDUCATION
Рет қаралды
Difference Between final finally and finalize in Java (Hindi)
11:14
Smart Programming
Рет қаралды 164 М.
Java Custom Exceptions Tutorial - It's Way Easier Than You Think
14:29
Coding with John
Рет қаралды 150 М.
Exception Handling in Java
59:14
Naveen AutomationLabs
Рет қаралды 65 М.
The Flaws of Inheritance
10:01
CodeAesthetic
Рет қаралды 911 М.
Why I Chose Rust Over Zig
33:18
ThePrimeTime
Рет қаралды 19 М.
Samsung Galaxy 🔥 #shorts  #trending #youtubeshorts  #shortvideo ujjawal4u
0:10
Ujjawal4u. 120k Views . 4 hours ago
Рет қаралды 7 МЛН
АЙФОН 20 С ФУНКЦИЕЙ ВИДЕНИЯ ОГНЯ
0:59
КиноХост
Рет қаралды 584 М.
1$ vs 500$ ВИРТУАЛЬНАЯ РЕАЛЬНОСТЬ !
23:20
GoldenBurst
Рет қаралды 1,7 МЛН