Branch Target buffer

Problem What is a Branch Target buffer? Explain how it can be used in reducing bubble cycles in cases of branch misprediction. Solution Branch misprediction occurs when the CPU mispredicts the next instruction to be executed. The CPU uses pipelining which allows several instructions to be processed simultaneously. But during a conditional jump, the next instruction to be executed depends on the result of the condition. Branch Prediction tries to guess the next instruction. [Read More]

Virtual memory, page fault and thrashing

Problem Explain the following terms: virtual memory, page fault, thrashing. Solution In short: Virtual memory is a technique that uses hard disk pages as main memory. Page fault is the error occurred when transferring pages. Thrashing - When paging occurs very very frequently, causing performance degradation. Now lets go in details: Virtual Memory Virtual memory is a computer system technique which gives an application program the impression that it has contiguous working memory (an address space), while in fact it may be physically fragmented and may even overflow on to disk storage. [Read More]

ER diagram for a database of company

Thanks this info was really helpful! I used a webs… Unknown - Jun 2, 2014Thanks this info was really helpful! I used a website called Lucidchart to find er diagram examples and it was really easy to understand. If you use diagrams often you should check it out! Yes its a good and online option. For offline (and online) option, we can also use Microsoft Visio, which is equally good. [Read More]

ER diagram for a database of company

Problem Draw an entity-relationship diagram for a database with companies, people, and professionals (people who work for companies). Solution Entities: Company: companyID, companyName, companyLocation, ect People: peopleID, name, gender, age, etc Professional: professionalID , FK to People, degree, work experience Relations: People ISA Professionl: 1:1 Professional WORKS Company: N:1 People who work for companies are Professionals. So there is an ISA (is a) relationship between People and Professionals (or we could say that a Professional is derived from People). [Read More]

What is denormalization?

Problem What is denormalization? Explain the pros and cons Solution We have already studied normalization here, but now just study opposite of it. Denormalization is the process of attempting to optimize the performance of a database by adding redundant data or by grouping data. Denormalization is generally used to either : Avoid a certain number of queries Remove some joins Lets take an example. Suppose you are working in a team, which is client facing (say in some investment bank), that serves the trade data to the client. [Read More]

Count the number of calls of put() and get() for a map in Java

Problem Suppose you are using a map in your program, how would you count the number of times the program calls the put() and get() functions? Solution Method 1 - Implement the map interface with static count field One simple solution is to put count variables for get() and put() methods and, whenever they are called, increment the count. We can also achieve this by extending the existing library map and overriding the get() and put() functions. [Read More]

Object reflection in Java

Problem Explain what object reflection is in Java and why it is useful. Solution The name reflection is used to describe code which is able to inspect other code in the same system (or itself). For example, say you have an object of an unknown type in Java, and you would like to call a ‘doSomething’ method on it if one exists. Java’s static typing system isn’t really designed to support this unless the object conforms to a known interface, but using reflection, your code can look at the object and find out if it has a method called ‘doSomething’ and then call it if you want to. [Read More]

final, finally and finalize in Java

Problem What is the difference between final, finally, and finalize? Solution The keyword “final” means constant. A final variable is a constant variable. A final method cannot be overridden. A final class cannot be extended. The keyword “finally” is for catching exceptions. When all the specified type of exceptions have been caught, the finally block will be executed to handle the rest unspecified exceptions. The keyword “finalize” is for user-defined garbage collection. [Read More]

Finally block and return statement

Problem In Java, does the finally block gets executed if we insert a return statement inside the try block of a try-catch-finally? Solution The answer is yes, both in java and c#. In java, the only time a finally block will not be executed is when you call exit() OR for some reason JVM crashes, before finally is reached. The exit() call will shutdown the JVM, so no subsequent line of code will be run. [Read More]