What is the use of instanceof keyword | What are Native methods in Java
The java instanceof operator is used to test whether the object is an instance of the specified type (class or subclass or interface).
(I) What is the use of instanceof keyword?
"instanceof" keyword is used to check what is the type of object. For instance in the below code
snippet we are trying to check is "object" of the same type as "object2".
if(object instanceof object2)
(B) What are Native methods in Java?
There may be times when you want to call subroutines which are written in some other language
other than Java like C++, VB6 etc. (B) How do refer to a current instance of object?
You can refer the current instance of object using "this" keyword. For instance if you have class which has "color" property you can refer the current object instance inside any of the method using "this.color".
(I) Explain in depth Garbage collector?
Garbage collection is the process of automatically freeing objects that are no longer referenced by the program, This frees the programmer from having to keep track of when to free allocated memory, thereby preventing many potential bugs. Thus making programmers more productive as they can now put more effort in coding rather than worrying about memory management.
The only disadvantage of garbage collector is it adds overheads. Because the JVM (Java virtual machine)
has to keep a constant track of the objects which are not referenced and then free these unreferenced objects on fly: This whole process has a slight impact on the application performance. But garbage collector has a good algorithm and it runs in its own thread thus having a least impact on the application performance but still, it has some impact.
What are Native methods in Java | What is the use of instanceof keyword
Tags:
Learn Java Programming