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!?
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?
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 No bro. finally will not be executed. please try running this code itself. it doesnt run. system.exit will terminate the execution fully.
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(); }
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.
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();
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
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?
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
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 🙃
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
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.
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 !
Very well explained. You should get the award for using the best teaching methods, specially for someone new to Java.
Hi Naveen I'm from Afghanistan i follow your Java Tutorial , your explain is so good , thanks
Thank you so much Naveen... perfect explanation
Perfect explanation and concept clarification.Loved it.Thanks
Your videos are helping me a lot!! Thanks, Naveen.
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!?
Superb Explanation with simple way to understand..
awsomely explained Naveen , thank you soo much :)
Very well explained Naveen
Very very useful. Please post continuously..
Thank you so much for an awesome video.. It's really helpful..
Thank you very much for your knowledge sharing
Gud explanation in short duration. Please prepare some videos on SQL.
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?
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 ?
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");
}
}
}
@@AshishDubeyash4you No bro. finally will not be executed. please try running this code itself. it doesnt run. system.exit will terminate the execution fully.
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");
}
}
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.
Nice video, For the benefit of others, The method finalize is deprecated from Java 8+
Ita deprecated from java 9. Now we have cleaner class, replacement of finalize.
As usual, Nice explaination...
If you wanna call GC forcefully, finalize() is required 😊
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
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
But example shown in vedio is has 2 objects but still its displaying finalize method only once
@@jayalakshmikrishnan1956 Happening same with me too . FinalizeMethod output is coming twice
Very Well Explain sir
Thank you Naveen
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?
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
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 🙃
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
Programs for Prime numbers and Fibonacci series please add
How to know and verify that finalize is done cleanup processing of the object before garbage collection
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.
You must have created two objects
nice explanation
nice ...
explain throw and throws also
Thank u so much Naveen.
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 !
nice explanation between of these
Thanku sir
Is Catch compulsory for try block..
No, but if any exception occured & is not caught then JVM will throw error at Runtime.
Thank you Naveen!
Thanks Naveen
very good. thanks.
very nice
garbage collecter guy come😂
Thank you Naveen