What is singleton class?

Answer Posted / abhijith thette nagarajan

As per the definition,Singleton class in one such class
which will have only one instance of it at any given point
of time...

But,it is allowed to any number of instances,not
necessarily be one..

Generally its contructor will have "protected" key work,no
problem also if we have private also,but if it is
private,we need to have a getter method to create an

Is This Answer Correct ?    34 Yes 20 No

Post New Answer       View All Answers

Please Help Members By Posting Answers For Below Questions

How listener identify that the event came from a particular object?


who can i handle multiple client in RMI


placement papaers of spring computing technology


what is the role of xml in core java?? and how we can use it?? can somebody give a sample program with explanation and from where i can read more about xml?????


when a request is generated from apache tomcat 5.5 and goes to oracle 10g or mysql,,, how the oracle or mysql reads the request as apache is a web server and oracle 10g is application server? when the oracle 10g provides response, how the apche tomcat reads it???


What methods are used in Servlet?Applet communication?


Is it possible to declare abstract class as final?What happens if we do so?


os is developed in c no java is more secured then c na why dont the os developed is developed using java


what is object slice?


Tell me about your ability to work under pressure


Addition to previous section relative word 5th one was Putrid ans: rotten, also there was prob. in 1st section on bucket weight ans:10kg, also there was a prob. on train speed to find bridge length ans:800 mtrs.


Highest level event class of the event-delegation model?


Where will it be used?


The following program reads data (details of students) from a file named students.txt and converts it into e-mail addresses. The results are written to a file named studentemail.txt. students.txt consists of a number of lines, each containing the data of a student in colon delimited format: Last Name:First Name:Student Number Each input record is converted to an e-mail address and written to studentemail.txt in the following format: the first character of the last name + the first character of the first name + the last four digits of the student number + “@myunisa.ac.za” import java.io.*; public class EmailConverter { public static void main(String[] args) throws IOException { BufferedReader input = new BufferedReader(new FileReader ("students.txt")); PrintWriter output = new PrintWriter(new FileWriter ("studentemail.txt")); String line = input.readLine(); while (line != null) { // Extract the information for each student String[] items = line.split(":"); // Generate the email address String email = "" + items[0].charAt(0) + items[1].charAt(0) + items[2].substring(4,8) + "@myunisa.ac.za"; email = email.toLowerCase(); // Output output.println(email); line = input.readLine(); } input.close(); output.close(); } } Rewrite the class so that it handles possible errors that may occur. In particular, it should do the following: • It should catch at least three appropriate exceptions that might occur, and display suitable messages. • At this stage, the program will not run correctly if there is an empty line in the input file. Change the program so that if an empty line is encountered, an exception is thrown and the empty line is ignored. This exception should be handled with the display of a suitable error message. • Before the e-mail address is added to the output file, check if the student number has 8 digits. If not, throw an InvalidFormatException (which the program should not handle itself)


3.2 Consider the following class: public class Point { protected int x, y; public Point(int xx, int yy) { x = xx; y = yy; } public Point() { this(0, 0); } public int getx() { return x; } public int gety() { return y; } public String toString() { return "("+x+", "+y+")"; } } Say you wanted to define a rectangle class that stored its top left corner and its height and width as fields. 3.2.1 Why would it be wrong to make Rectangle inherit from Point (where in fact it would inherit the x and y coordinates for its top left corner and you could just add the height and width as additional fields)? (1) 8 Now consider the following skeleton of the Rectangle class: public class Rectangle { private Point topLeft; private int height, width; public Rectangle(Point tl, int h, int w) { topLeft = tl; height = h; width = w; } public Rectangle() { this(new Point(), 0, 0); } // methods come here } 3.2.2 Explain the no-argument constructor of the Rectangle class given above. 3.2.3 Write methods for the Rectangle class to do the following: • a toString() method that returns a string of the format "top left = (x, y); height = h; width = w " where x, y, h and w are the appropriate integer values. • an above() method that tests whether one rectangle is completely above another (i.e. all y values of the one rectangle are greater than all y values of the other). For example, with the following declarations Rectangle r1 = new Rectangle(); Rectangle r2 = new Rectangle(new Point(2,2), 1, 4); the expression r2.above(r1) should give true, and r2.above (r2) should give false. (You can assume that the height of a rectangle is never negative.) (2) (5)