<< < 1 2 3 4 5 6 7 8 > >>   Sort: Rank

If I write return at the end of the try block, will the finally block still execute?
If I write return at the end of the try block, will the finally block still execute? Yes even if you write return as the last statement in the try block and no exception occurs, the finally block will execute. The finally block will execute and then the control return.
2013-06-04, 2147👍, 0💬

Is it necessary that each try block must be followed by a catch block?
Is it necessary that each try block must be followed by a catch block? It is not necessary that each try block must be followed by a catch block. It should be followed by either a catch block OR a finally block. And whatever exceptions are likely to be thrown should be declared in the throws clause ...
2013-06-03, 3226👍, 0💬

What is the basic difference between the 2 approaches to exception handling.
520. What is the basic difference between the 2 approaches to exception handling. 1. try catch block and 2. specifying the candidate exceptions in the throws clause? When should you use which approach? In the first approach as a programmer of the method, you urself are dealing with the exception. Th...
2013-06-03, 1790👍, 0💬

What are the different ways to handle exceptions?
What are the different ways to handle exceptions? There are two ways to handle exceptions, 1. By wrapping the desired code in a try block followed by a catch block to catch the exceptions. and 2. List the desired exceptions in the throws clause of the method and let the caller of the method hadle th...
2013-05-31, 1842👍, 0💬

How does an exception permeate through the code?
How does an exception permeate through the code? An unhandled exception moves up the method stack in search of a matching When an exception is thrown from a code which is wrapped in a try block followed by one or more catch blocks, a search is made for matching catch block. If a matching type is fou...
2013-05-31, 1788👍, 0💬

If my class already extends from some other class what should I do if I want an instance of my class to be thrown as an exceptio
If my class already extends from some other class what should I do if I want an instance of my class to be thrown as an exception object? One can not do anytihng in this scenarion. Because Java does not allow multiple inheritance and does not provide any exception interface as well.
2013-05-30, 1991👍, 0💬

If I want an object of my class to be thrown as an exception object, what should I do?
If I want an object of my class to be thrown as an exception object, what should I do? The class should extend from Exception class. Or you can extend your class from some more precise exception type also.
2013-05-30, 1815👍, 0💬

How to create custom exceptions?
How to create custom exceptions? Your class should extend class Exception, or some more specific type thereof.
2013-05-29, 1888👍, 0💬

What is the difference between error and an exception?
What is the difference between error and an exception? An error is an irrecoverable condition occurring at runtime. Such as OutOfMemory error. These JVM errors and you can not repair them at runtime. While exceptions are conditions that occur because of bad input etc. e.g. FileNotFoundException will...
2013-05-29, 1807👍, 0💬

What are runtime exceptions?
What are runtime exceptions? Runtime exceptions are those exceptions that are thrown at runtime because of either wrong input data or because of wrong business logic etc. These are not checked by the compiler at compile time.
2013-05-28, 1791👍, 0💬

What are checked exceptions?
What are checked exceptions? Checked exception are those which the Java compiler forces you to catch. e.g. IOException are checked Exceptions.
2013-05-28, 1757👍, 0💬

Why do we need wrapper classes?
Why do we need wrapper classes? It is sometimes easier to deal with primitives as objects. Moreover most of the collection classes store objects and not primitive data types. And also the wrapper classes provide many utility methods also. Because of these resons we need wrapper classes. And since we...
2013-05-27, 1816👍, 0💬

What are wrapper classes?
What are wrapper classes? Java provides specialized classes corresponding to each of the primitive data types. These are called wrapper classes. They are e.g. Integer, Character, Double etc.
2013-05-27, 1811👍, 0💬

Give a simplest way to find out the time a method takes for execution without using any profiling tool?
Give a simplest way to find out the time a method takes for execution without using any profiling tool? 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 co...
2013-05-24, 1781👍, 0💬

Does Java provide any construct to find out the size of an object?
Does Java provide any construct to find out the size of an object? No there is not sizeof operator in Java. So there is not direct way to determine the size of an object directly in Java.
2013-05-24, 1774👍, 0💬

What happens to the static fields of a class during serialization?
What happens to the static fields of a class during serialization? 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 on...
2013-05-23, 1783👍, 0💬

What one should take care of while serializing the object?
What one should take care of while serializing the object? One should make sure that all the included objects are also serializable. If any of the objects is not serializable then it throws a NotSerializableException.
2013-05-23, 1811👍, 0💬

When you serialize an object, what happens to the object references included in the object?
When you serialize an object, what happens to the object references included in the object? The serialization mechanism generates an object graph for serialization. Thus it determines whether the included object references are serializable or not. This is a recursive process. Thus when an object is ...
2013-05-22, 1768👍, 0💬

What is Externalizable interface?
What is Externalizable interface? Externalizable is an interface which contains two methods readExternal and writeExternal. These methods give you a control over the serialization mechanism. Thus if your class implements this interface, you can customize the serialization process by implementing the...
2013-05-22, 1775👍, 0💬

What is the common usage of serialization?
What is the common usage of serialization? Whenever an object is to be sent over the network, objects need to be serialized. Moreover if the state of an object is to be saved, objects need to be serilazed.
2013-05-21, 1819👍, 0💬

How can I customize the seralization process? i.e. how can one have a control over the serialization process?
How can I customize the seralization process? i.e. how can one have a control over the serialization process? 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....
2013-05-21, 1848👍, 0💬

Which methods of Serializable interface should I implement?
Which methods of Serializable interface should I implement? The serializable interface is an empty interface, it does not contain any methods. So we do not implement any methods.
2013-05-20, 1740👍, 0💬

How do I serialize an object to a file?
How do I serialize an object to a file? 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.
2013-05-20, 1755👍, 0💬

What is serialization?
What is serialization? Serialization is a mechanism by which you can save the state of an object by converting it to a byte stream.
2013-05-17, 1885👍, 0💬

<< < 1 2 3 4 5 6 7 8 > >>   Sort: Rank