Posts

Showing posts from May, 2012

Operating System Question and Answers

What are the basic functions of an operating system ?  - Operating system controls and coordinates the use of the hardware among the various applications programs for various uses. Operating system acts as resource allocator and manager. Since there are many possibly conflicting requests for resources the operating system must decide which requests are allocated resources to operating the computer system efficiently and fairly. Also operating system is control program which controls the user programs to prevent errors and improper use of the computer. It is especially concerned with the operation and control of I/O devices. Why paging is used?  - Paging is solution to external fragmentation problem which is to permit the logical address space of a process to be noncontiguous, thus allowing a process to be allocating physical memory wherever the latter is available. While running DOS on a PC, which command would be used to duplicate the entire diskette?  diskcopy What r...

Difference Between Interface and Abstract Class

Difference Between Interface and Abstract Class Interface:   Java Interfaces are equivalent to protocols. They basically represent an agreed-upon behavior to facilitate interaction between unrelated objects. For example, the buttons on a Remote Controller form the interface for outside world to interact with TV. How this interface is implemented by different vendors is not specified and you’re hardly aware of or bothered about how these buttons have been implemented to work internally. Interface is plainly a contract between the producer and the consumer. How the producer implements the exposed behavior is normally not cared by the consumer. In Java, an Interface is normally a group of methods with empty bodies. You can have constant declarations in a Java Interface as well. A class that implements the interface agrees to the exposed behavior by implementing all the methods of the interface. interface TVRemoteController{ void power(); void setChannel(int channelNumber); void upCh...

Difference between Android Service,Thread,IntentService and AsyncTask

Service Thread IntentService AsyncTask When to use ? Task with no UI, but shouldn't be too long. Use threads within service for long tasks. - Long task in general. - For tasks in parallel use Multiple threads (traditional mechanisms) - Long task   usually   with no communication to main thread. (Update) - If communication is required, can use main thread handler or broadcast intents - When callbacks are needed (Intent triggered tasks).  - Long task having to communicate with main thread. - For tasks in parallel use multiple instances OR Executor   Trigger Call to method onStartService() Thread start() method Intent Call to method execute() Triggered From (thread) Any thread Any Thread Main Thread (Intent is received on main thread and then worker thread is spawed) Main Thread Runs On (thread) Main Thread Its own thread Separate worker thread Worker thread. However, Main thread methods may be invoked in between to publish progress. Limitations / Drawb...

Does Java pass by reference or pass by value?

Image
Q: If Java uses the pass-by reference , why won't a swap function work? Your question demonstrates a common error made by Java language newcomers. Indeed, even seasoned veterans find it difficult to keep the terms straight. Java does manipulate objects by reference, and all object variables are references. However, Java doesn't pass method arguments by reference; it passes them by value. Take the badSwap() method for example: public void badSwap(int var1, int var2) { int temp = var1; var1 = var2; var2 = temp; } When badSwap() returns, the variables passed as arguments will still hold their original values. The method will also fail if we change the arguments type from int to Object , since Java passes object references by value as well. Now, here is where it gets tricky: public void tricky(Point arg1, Point arg2) { arg1.x = 100; arg1.y = 100; Point temp = arg1; arg1 = arg2; arg2 = temp; } public static void main(String [] args) { Point pnt1 = new P...