Monday 18 March 2013

What is final, finalize() and finally?


What is final, finalize() and finally?  
final : final keyword can be used for class, method and variables. A final class cannot be subclassed and it prevents other programmers from subclassing a secure class to invoke insecure methods. A final method can’t be overridden. A final variable can’t change from its initialized value. finalize() : finalize() method is used just before an object is destroyed and can be called just prior to garbage collection. finally : finally, a key word used in exception handling, creates a block of code that will be executed after a try/catch block has completed and before the code following the try/catch block. The finally block will execute whether or not an exception is thrown. For example, if a method opens a file upon exit, then you will not want the code that closes the file to be bypassed by the exception-handling mechanism. This finally keyword is designed to address this contingency.

Blog Author: Vijay Kumar


What is UNICODE?


What is UNICODE?  
Unicode is used for internal representation of characters and strings and it uses 16 bits to represent each other.



Blog Author: Vijay Kumar

What is Garbage Collection and how to call it explicitly?


What is Garbage Collection and how to call it explicitly?  
When an object is no longer referred to by any variable, java automatically reclaims memory used by object. This is known as garbage collection. System.gc() method may be used to call it explicitly.

Blog Author: Vijay Kumar


What is finalize() method?


What is finalize() method?  
finalize () method is used just before an object is destroyed and can be called just prior to garbage collection.

Blog Author: Vijay Kumar


What is method overloading and method overriding?



What is method overloading and method overriding?  
Method overloading: When a method in a class having the same method name with different arguments is said to be method overloading. Method overriding : When a method in a class having the same method name with same arguments is said to be method overriding.


Blog Author: Vijay Kumar

What is difference between overloading and overriding?


What is difference between overloading and overriding?  
a) In overloading, there is a relationship between methods available in the same class whereas in overriding, there is relationship between a superclass method and subclass method. b) Overloading does not block inheritance from the superclass whereas overriding blocks inheritance from the superclass. c) In overloading, separate methods share the same name whereas in overriding, subclass method replaces the superclass. d) Overloading must have different method signatures whereas overriding must have same signature.

Blog Author: Vijay Kumar


What is meant by Inheritance and what are its advantages?



What is meant by Inheritance and what are its advantages?  
Inheritance is the process of inheriting all the features from a class. The advantages of inheritance are reusability of code and accessibility of variables and methods of the super class by subclasses.


Blog Author: Vijay Kumar

What is the difference between this() and super()?


What is the difference between this() and super()?  
this() can be used to invoke a constructor of the same class whereas super() can be used to invoke a super class constructor.

Blog Author: Vijay Kumar


What is the difference between super class and subclass?


What is the difference between super class and subclass?
A super class is a class that is inherited whereas sub class is a class that does the inheriting.

Blog Author: Vijay Kumar


What modifiers may be used with top-level class?


What modifiers may be used with top-level class? 
public, abstract and final can be used for top-level class.

Blog Author: Vijay Kumar