Skip to main content

Posts

Showing posts from July, 2018

Concurrency, Thread

Definition: Concurrency is when two tasks  overlap  in execution. In programming, these situations are encountered: When two processes are assigned to different cores on a machine by the kernel, and both cores execute the process instructions at the same time. When more connections arrive before earlier connections are finished, and need to be handled immediately. More generally, it’s when we need to handle multiple tasks at about the same time. That’s it. That’s all concurrency is.  Parallel  execution is when two tasks  start  at the same time, making it a special case of concurrent execution. 4 levels of  Concurrency: -- Machine Instruction level -- HLL(High-level language) statement level. -- Unit level -- Program level.  There are two types of Concurrency: 1. Physical Concurrency 2. Logical Concurrency Physical Concurrency :   Several program units from the same program literally execute simultaneously on different processors. Logical Concurrency: S

Different Types of Programming Paradigm

Programming paradigm mainly describes the way in which a particular computer program should be written. According to Wikipedia, it is fundamental style of computer programming. Basically, different programming languages are designed to follow a particular paradigm or may be multiple paradigms. Imperative(procedural) Programming Paradigm:   -- Imperative programming is a programming paradigm that uses statements that change a program's   state.   -- In much the same way that the imperative mood in natural languages expresses commands.   -- An imperative program consists of commands for the computer to perform.   -- Imperative programs describe the details of HOW the results are to be obtained. --  HOW means describing the Inputs and describing how the Outputs are produced.     Examples are: C, C++, Java, PHP, Python, Ruby etc. Popular programming languages are imperative more often than they are any other paradigm . There are two reasons for such popularity: the

Static and Dynamic Polymorphism in OOP

  There are two types of Polymorphism. 1. Static Polymorphism. 2. Dynamic Polymorphism. Static polymorphism is achieved through method overloading. Method overloading means there are several methods present in a class having the same name but different types/order/number of parameters. At compile time, compiler knows which method to invoke by checking the method signatures.  So, this is called compile time polymorphism or static binding. The concept will be clear from the following example: class Adder { static int add ( int a , int b ){ return a + b ; } static int add ( int a , int b , int c ){ return a + b + c ; } } class Main { public static void main ( String [] args ){ System . out . println ( Adder . add ( 11 , 11 ); System . out . println ( Adder . add ( 11 , 11 , 11 ); } } Dynamic Polymorphism: Suppose a sub class overrides a particular method of the sup

Compare Static and Dynamic Binding

 Connecting a method call to the method body is known as binding. There are two types of binding: -static binding (also known as early binding).  -dynamic binding (also known as late binding). Static binding in occurs during compile time while dynamic binding occurs during runtime. private , final and static methods and variables use static binding and are bonded by compiler while virtual methods are bonded during runtime based upon runtime object. Static binding uses Type ( class in Java) information for binding while dynamic binding uses object to resolve binding. Overloaded methods are bonded using static binding while overridden methods are bonded using dynamic binding at runtime. 

Object Oriented Programming Concepts & Questions

1. What is Dynamic Binding?  Binding means the link between procedure call and code to be executed. Dynamic binding means link exists between procedure call and code to be executed at    run time when that procedure is called. It is also known late binding.  It is generally used with polymorphism and inheritance. For example, compiler comes to know at runtime that which function of 'sum' will be called either with two arguments or with three arguments.   2. What is the difference between Dynamic Binding in C++ and Java?  There’s no virtual keyword in Java because all non-static methods always use dynamic binding. In Java, the programmer doesn’t have to decide whether or not to use dynamic binding.  Virtual Function is a function in the base class, which is overridden in the derived class, and which tells the compiler to perform dynamic Binding on this function. The reason virtual exists in C++ is so you can leave it off for a slight increase in effi

Exception Handling & Event Handling

  Q. Define exception , exception handler , and built-in exception.   Exception : An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions. Any unusual event, erroneous or not, that is detectable by either hardware or software and that may require special processing is called exception. Exception Handler: An exception handler processes a raised exception. The exception can be either predefined or user-defined. Predefined exceptions are raised implicitly (automatically) by the run-time system.   Built-in Exception : Built-in exceptions are the exceptions which are available in libraries. These exceptions are suitable to explain certain error situations. Below is the list of important built-in exceptions in Java. Arithmetic Exception ArrayIndexOutOfBoundException ClassNotFoundException FileNotFoundException IOException. Q. What are the advantages of having support for exception handl