Subjects
PRICING
COURSES
SIGN IN
Start Free Trial
Ankit S.
Software Developer
Tutor Satisfaction Guarantee
Java Programming
TutorMe
Question:

Consider a scenario, in which a student A made a singleton class. He did everything for making it singleton, i.e: > He made constructor private > Created a private final static class object,and > Provided a getInstance() method which ensures only one object is returned. Now, another student B goes to the student A and made a singleton object of the class he made, say, singletonObj. And he wrote the below: singletonObj.clone(); And yes, a copy of singletonObj was made, Now student A was left with 2 objects of the same sibgleton class he made. Now, student B asks A, your singleton principle is violated. Can you help student A answer the violation addressed by student B ?or, is student B correct ?

Ankit S.
Answer:

Well, yes student B said it correctly that on cloning singleton class's object , I have 2 copies of same singleton class. Yes its a violation of singleton principle and to address it, we override a clone method in Singleton class that would throw cloneNotSupported exception if cloning is made on singleton class's object. public Object clone() throws CloneNotSupportedException { } Add this function to Singleton Class student A made by implementing Cloneable marker interface. The singleton principle is thus preserved.

Computer Science (General)
TutorMe
Question:

Suppose we have a rapid incoming stream of data at high rate from ClientA and suppose we need to send it to ClientB, that has a very low data acceptance speed. We need to send data from Client A to B. Client A can send data continuously, in chunks or whenever it wants. Answer the below questions: 1. How it can be achieved ? 2. Suppose Client B goes down. How can we prevent data loss ?

Ankit S.
Answer:

Lets answer it point-wise. 1. So the concept is called "Throttling" in Computer Science. In such cases, we built a Throttle based system. Considering this scenario, Allow Client to send data with its own speed, whenever it wants. What we will do, is that, We will built a middleware (in any programming language) that would accept data at Client A rate and save it to database or any storage type. Next, create a batching process that would pick the data from the storage / Database and will send it to Client B with ClientB's rate. 2. In case B's is down, throttle the system to process 0 traffic to B, in that case data would get stored in Database but will not be processed to Client B. Now, when Client B is up, again throttle the system to process traffic to Client B. I this case data loss won't be there.

C Programming
TutorMe
Question:

How can you "call a function before main( )" in C ?

Ankit S.
Answer:

So, Though main( ) is the entry point for the compiler to start executing the program, but there exists some directives called "#pragma" which are generally used to turn on/off features. By using #pragma directive , one can include a method execution before and after main(). Please find below a sample code: void funcA(); #pragma startup funcA main() { printf("\nMAIN"); } void funcA() { printf("\n Executing funcA before main"); } Now , above program would first execute "funcA()" before main() . TIP: One can use same directive #pragma to call a function after main() method executes. (i.e, at the end of the main) Use: #pragma exit funcB(); // This would make funcB() execute after main()

Send a message explaining your
needs and Ankit will reply soon.
Contact Ankit
Ready now? Request a lesson.
Start Session
FAQs
What is a lesson?
A lesson is virtual lesson space on our platform where you and a tutor can communicate. You'll have the option to communicate using video/audio as well as text chat. You can also upload documents, edit papers in real time and use our cutting-edge virtual whiteboard.
How do I begin a lesson?
If the tutor is currently online, you can click the "Start Session" button above. If they are offline, you can always send them a message to schedule a lesson.
Who are TutorMe tutors?
Many of our tutors are current college students or recent graduates of top-tier universities like MIT, Harvard and USC. TutorMe has thousands of top-quality tutors available to work with you.