What is the singleton class in java?

Answer Posted / naman patidar

A singleton class can never have more then one instance.
Example :

class SingletonClass {
private static SingletonClass singleObject;

public static SingletonClass getInstance() {
if (singleObject == null) {
singleObject = new SingletonClass();
}
return singleObject;
}
}

Is This Answer Correct ?    3 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is gui in java with examples?

678


What are java’s rules regarding tabs, spaces and newline characters?

1206


What's the difference between code-based security and role-based security? Which one is better? : java security

664


Why there are no global variables in java?

701


Do I really have to type in the programs in the book to try them out?

757


Which class is the superclass of every class?

707


What do I need to install netbeans?

706


What's the difference between authentication and authorization? : java security

708


What is an entity in java?

660


What is scrollable resultset in java?

652


What is crud operations in java?

654


In a barber shop there are 2 doors. customer come in 1 door, leave in other. minimum # of chairs. barber spend his life in cutting. always barber can cut 1 customer. few chairs in the shop. if barber busy customer waits, if chairs full, customer leave. if no customer, barber sleeps. treat barber and customer as 2 threads. you can use Semaphore class with arrive and depart and count as parameter.

1885


What's the difference between local, global and universal groups? : java security

673


What are the disadvantages of java sockets?

748


What is jersey in java?

657