Q:)What is meant by Checked Exception and Unchecked Exception?
A:
CHECKED EXCEPTION:Checked Exception are exception which was raised by the compiler by compilation time.EX:Servelt Exception and IO Exception.
UNCHECKED EXCEPTION:Unchecked Exception are the exception which were raised by JVM at runtime .EX:Runtime Exceptions.
Q:)What is difference between Partial Checked Exception and Fully Checked Exception?
A:
PARTIAL CHECKED EXCEPTION:This are the Exception if and only if some of it's child classes are Checked partially.
FULL CHECKED EXCEPTION:This are the Exception if and only if all it's child classes are FULL Checked.
Q:What is Overriding?
A:When a class defines a method using the same name, return type, and arguments as a method in its superclass,
the method in the class overrides the method in the superclass.When the method is invoked for an object of the class,
it is the new definition of the method that is called, and not the method definition from superclass.
Methods may be overridden to be more public, not more private..
Q:What type of parameter passing does Java support?
A:In Java the arguments are always passed by value .
Q: | Can a top level class be private or protected? |
A: | No. A top level class can not be private or protected. It can have either "public" or no modifier. If it does not have a modifier it is supposed to have a default access.If a top level class is declared as private the compiler will complain that the "modifier private is not allowed here". This means that a top level class can not be private. Same is the case with protected. | | | | | |
Q:How do I serialize an object to a file?
A:The class whose instances are to be serialized should implement an interface Serializable.
Then you pass the instance to the ObjectOutputStream which is connected to a fileoutputstream.
This will save the object to a file.
Q: | Which methods of Serializable interface should I implement? |
A: | The serializable interface is an empty interface, it does not contain any methods. So we do not implement any methods. |
Q:How can I customize the seralization process? i.e. how can one have a control over the serialization process?
A:Yes it is possible to have control over serialization process. The class should implement Externalizable interface.
This interface contains two methods namely readExternal and writeExternal.
You should implement these methods and write the logic for customizing the serialization process.
Q:What happens to the static fields of a class during serialization?
A:There are three exceptions in which serialization doesnot necessarily read and write to the stream. These are
1. Serialization ignores static fields, because they are not part of ay particular state state.
2. Base class fields are only handled if the base class itself is serializable.
3. Transient fields.
Q:Does Java provide any construct to find out the size of an object?
A:No there is not sizeof operator in Java. So there is not direct way to determine the size of an object directly in Java.
Q:Give a simplest way to find out the time a method takes for execution without using any profiling tool?
A:Read the system time just before the method is invoked and immediately after method returns.
Take the time difference, which will give you the time taken by a method for execution.
To put it in code...
long start = System.currentTimeMillis ();
method ();
long end = System.currentTimeMillis ();
System.out.println ("Time taken for execution is " + (end - start));
Remember that if the time taken for execution is too small, it might show that it is taking zero milliseconds for execution. Try it on a method which is big enough, in the sense the one which is doing considerable amout of processing.
Read more...