Win a copy of Rust Web Development this week in the Other Languages forum!

Adhir Gupte

Greenhorn
+ Follow
since Dec 28, 2006
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Adhir Gupte

Hi,

Serialization is a very important concept. This proves a bliss in java when we are transferring data over network. Object serialization helps us when we need to transfer a file to a remote location. A serialize object is converted to a Byte Stream say a ByteArray[] then the recieving end converts the byte array to an object by deserializing the same.

adhir.
15 years ago
Hi,

A singleton pattern allows you to create only one instance of a class at one time. This helps you that the class wont have multiple instances created for it. The only one instance becomes the global point of access to it. Live example is a print spooler where at a time only one instance of the job is needed. For creating the same:

public class DemoSingleton {
private static DemoSingleton instance = null;
protected DemoSingleton () {
// Exists only to defeat instantiation.
}
public static DemoSingleton getInstance() {
if(instance == null) {
instance = new DemoSingleton();
}
return instance;
}
}


call it using:

public class SingletonInstantiator {
public SingletonInstantiator() {
DemoSingleton instance = DemoSingleton.getInstance();
DemoSingleton anotherInstance =
new DemoSingleton();
...
}
}

The above create only one instance if it does not exists, otherwise will return the same instance every time.
I hope that it solves
15 years ago
Hi,

If a finally clause is included, it's statements are executed after all other try-catch processing is complete.
The finally clause executes whether or not an exception is thrown or a break or continue are encountered

The finally(if used) is always executed when there is a try catch block. The only fail condition for this is if you write a System.exit() in a catch block which will fail finally to execute.
15 years ago