55
CAMPUS RECRUITMENT TOPICS

Technical Interview

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Technical Interview

CAMPUS RECRUITMENT TOPICS

Page 2: Technical Interview

What to Expect in Interview

In technical interview, interviewer has the liberty to ask any question related to computer science.

Normally they ask for current technologies, some core technologies and most importantly the domain on which company is working.

So before, preparing for interview for any company, check out its profile, areas of interests, domain and other important things.

Interviewer expects that you are fundamentally sound in some basic aspects of computer engineering.

Page 3: Technical Interview

Always prepare one or two subjects completely that you are interested in and want to work on.

But those subjects must be conceptually clear to you, because interviewer will pose difficult questions related to those subjects.

Always be prepared to face the questions regarding project work you’ve done throughout the engineering. ( A good point to score)

Sometimes it is good to have some information about latest technologies and innovations.

Page 4: Technical Interview

Basic Subjects

C Programming language. C++ and Object Oriented Concepts Basics of Data Structure and Algorithms Basics of Analysis of Algorithms Database Management System Operating System Basics of Networks One or more programming Language

(.NET/Java/PHP/HTML/Python/Perl/..)

Page 5: Technical Interview

History of C

C is a general-purpose programming language initially developed by Dennis Ritchie between 1969 and 1973 at Bell Labs.

C is an imperative (procedural) language. It was designed to be compiled using a relatively straightforward compiler, to provide low-level access to memory, to provide language constructs that map efficiently to machine instructions, and to require minimal run-time support.

C was therefore useful for many applications that had formerly been coded in assembly language, such as in system programming.

Page 6: Technical Interview

Basic Concepts of C

A C program, whatever its size, consists of functions and variables. A function contains statements that specify the computing operations to be done, and variables store values used during the computation.

The basic C source character set includes the following characters: Letters: a–z, A–Z, _ Digits: 0–9 Punctuation: ~ ! @ # % ^ & * ( ) - + = : ; " ' < > , . ? |

/ \ { } [ ] Whitespace characters: space, horizontal tab, vertical

tab, form feed, newline

Page 7: Technical Interview

Scope of C variables Block scope : variables are accessible within the block in which they are

declared. Function scope: variables are accessible within the function they are

declared. File scope: A variable with file scope can be accessed by any function or

block within a single file. To declare a file scoped variable, simply declare a variable outside of a block (same as a global variable) but use the static keyword.

Program scope: Variables with program scope are also called global variables, which are visible among different files. These files are the entire source files that make up an executable program.

static int nValue; // file scoped variableFloat fValue; // global variableint main(){double dValue; // local variable}

Page 8: Technical Interview

Type Specifiers of C variables

The auto specifier: The auto specifier indicates that the memory location of a variable is temporary. In other words, a variable's reserved space in the memory can be erased or relocated when the variable is out of its scope.

The static specifier: When a variable within a function is declared with the static specifier, the variable has a permanent duration. In other words, the memory storage allocated for the variable is not destroyed when the scope of the variable is exited, the value of the variable is maintained outside the scope, and if execution ever returns to the scope of the variable, the last value stored in the variable is still there.

The register specifier: Each computer has a certain number of registers to hold data and perform arithmetic or logical calculations. Because registers are located within the CPU (central processing unit) chip, it's much quicker to access a register than a memory location. Therefore, storing variables in registers may help to speed up your program.

Page 9: Technical Interview

The extern specifier: How can a global variable declared in file A, for instance, be seen in file B? In other words, how does the compiler know that the variable used in file B is actually the same variable declared in file A?

The answer is: Use the extern specifier provided by the C language to allude to a global variable defined elsewhere.

The const modifier: If you declare a variable with the const modifier, the content of the variable cannot be changed after it is initialized.

The volatile modifier: If you want to let the compiler know that the value of a variable can be changed without an explicit assignment statement, declare the variable with the volatile modifier so that the compiler will turn off optimizations on expressions involving the variable.

Page 10: Technical Interview

Function parameters

In C, pass by value is the mechanism used to pass parameters into a function. A copy is made of the variable and that copy is used.

Because a copy is used, the function cannot alter variables that are passed in. Parameters only pass values in, not out. This is called Pass by Value.

One way to allow functions to modify the value of argument is by using pass by reference. In pass by reference, we declare the function parameters as references rather than normal variables:

void AddOne(int &y) // y is a reference variable{y = y + 1;}

The above pass by reference concept is valid in C++. So how to pass by reference in C?

Page 11: Technical Interview

Pointers

Pointers "point" to locations in memory. Pointers are just variables that store memory addresses, usually the addresses of other variables.

In order to have a pointer actually point to another variable it is necessary to have the memory address of that variable also. To get the memory address of a variable (its location in memory), put the & sign in front of the variable name.

*p performs the "dereferencing" operation on p; it looks at the address stored in p, and goes to that address and returns the value.

Page 12: Technical Interview

Advantages of Pointers Pointers allow you to implement sharing without copying i.e. pass by

reference v/s pass by copying. This allows a tremendous advantage when you are passing around big arrays as arguments to functions.

Pointers allow us to use dynamic memory allocation. Pointers obviously give us the ability to implement complex data structures

like linked lists, trees, etc. Pointers allow ease of programming, especially when dealing with strings.

This is due to the fact that a pointer increment will move by the size of the pointee i.e. easy coding to increment to the next memory location of an array, without worrying about how many bytes to move for each data type. I.e. a pointer to a char will move the pointer by a byte, pointer to an int, by the size of the int, etc. NOTE that this is important because you do not have to worry about the size of the data types which can vary on different architectures.

Pointers allow us to resize the data structure whenever needed. For example, if you have an array of size 10, it cannot be resized. But, an array created out of malloc and assigned to a pointer can be resized easily by creating a new memory area through malloc and copying the old contents over. This ability is very important in implementing sparse data structures also.

Page 13: Technical Interview

Dynamic memory allocation in C

malloc, calloc, or realloc are the three functions used to manipulate memory.  These commonly used functions are available through the stdlib library so you must include this library in order to use them.

When a program executes, the operating system gives it a stack and a heap to work with. The stack is where global variables, static variables, and functions and their locally defined variables reside. The heap is a free section for the program to use for allocating memory at runtime.

Allocating a Block of Memory : Use the malloc function to allocate a block of memory for a variable. If there is not enough memory available, malloc will return NULL.

The prototype for malloc is: void *malloc(size_t size);

Page 14: Technical Interview

Allocating Multiple Blocks of Memory You can also ask for multiple blocks of memory with the calloc

function: void *calloc(size_t num, size_t size);

Releasing the Used Space All calls to the memory allocating functions discussed here, need to

have the memory explicitly freed when no longer in use to prevent memory leaks. Just remember that for every call to an *alloc function you must have a corresponding call to free.

free(ptr); To Alter the Size of Allocated Memory: We can use realloc

function to alter the size of allocated memory. void *realloc(void *ptr, size_t size);

Pass this function the pointer to the memory you want to resize and the new size you want to resize the allocated memory for the variable you want to resize.

Page 15: Technical Interview

Structures and Union Structures in C are used to encapsulate, or group together different

data into one object. When you define a structure or union, you are creating a custom data type.

struct object {          char id[20];          int xpos;   int ypos;        }; Unions and Structures are identical in all ways, except for one very

important aspect. Only one element in the union may have a value set at any given time. Everything we have shown you for structures will work for unions, except for setting more than one of its members at a time.

Unions are mainly used to conserve memory. While each member within a structure is assigned its own unique storage area, the members that compose a union share the common storage area within the memory.

Unions are useful for application involving multiple members where values are not assigned to all the members at any one time.

Page 16: Technical Interview

Other important things to look at.

Rich operator set of C. (most importantly bitwise operators, logical operators)

Basic instruction set of C (including loops, break, continue, goto, switch, etc.)

Bit of File I/O. (some knowledge of fopen, fclose, fwrite, fread, etc.)

Some knowledge about type casting in C. Bit of command line arguments.

Page 17: Technical Interview

Difference between C and C++

C follows the procedural programming paradigm while C++ is a multi-paradigm language(procedural as well as object oriented)

In case of C, the data is not secured while the data is secured(hidden) in C++

C is a low-level language while C++ is a middle-level language

C++ supports function overloading while C does not We can use functions inside structures in C++ but

not in C. C++ allows the use of reference variables while C

does not

Page 18: Technical Interview

Fundamentals of C++

CLASS A class is an expanded concept of a data structure: instead of

holding only data, it can hold both data and functions. An object is an instantiation of a class. In terms of variables, a

class would be the type, and an object would be the variable. An access specifier is one of the following three keywords:

private, public or protected. These specifiers modify the access rights that the members following them acquire:

private members of a class are accessible only from within other members of the same class or from their friends.

protected members are accessible from members of their same class and from their friends, but also from members of their derived classes.

public members are accessible from anywhere where the object is visible.

Page 19: Technical Interview

Constructor/Destructor in C++

Objects generally need to initialize variables or assign dynamic memory during their process of creation to become operative and to avoid returning unexpected values during their execution.

class can include a special function called constructor, which is automatically called whenever a new object of this class is created. This constructor function must have the same name as the class, and cannot have any return type; not even void.

Constructors cannot be called explicitly as if they were regular member functions. They are only executed when a new object of that class is created.

The destructor fulfils the opposite functionality. It is automatically called when an object is destroyed, either because its scope of existence has finished (for example, if it was defined as a local object within a function and the function ends) or because it is an object dynamically assigned and it is released using the operator delete.

The destructor must have the same name as the class, but preceded with a tilde sign (~) and it must also return no value.

Page 20: Technical Interview

Encapsulation in C++

Encapsulation is the process of combining data and functions into a single unit called class. Using the method of encapsulation, the programmer cannot directly access the data.

Data is only accessible through the functions existing inside the class.

The key strength behind Data Encapsulation in C++ is that the keywords or the access specifiers can be placed in the class declaration as public, protected or private.

Advantages of encapsulation Makes Maintenance of Application Easier Improves the Understandability of the Application Enhanced Security

Page 21: Technical Interview

Overloading in C++

C++ allows you to specify more than one definition for a function name or an operator in the same scope, which is called function overloading and operator overloading respectively.

An overloaded declaration is a declaration that had been declared with the same name as a previously declared declaration in the same scope, except that both declarations have different arguments.

When you call an overloaded function or operator, the compiler determines the most appropriate definition to use by comparing the argument types you used to call the function or operator with the parameter types specified in the definitions.

The process of selecting the most appropriate overloaded function or operator is called overload resolution.

Page 22: Technical Interview

Example of function overloading

#include <iostream> using namespace std; class printData { public: void print(int i) { cout << "Printing int: " << i << endl; } void print(double f) { cout << "Printing float: " << f << endl; } void print(char* c) { cout << "Printing character: " << c << endl; } }; int main(void) { printData pd; // Call print to print integer pd.print(5); // Call print to print float pd.print(500.263); // Call print to print character pd.print("Hello C++"); return 0; }

Page 23: Technical Interview

Example of operator Overloading

#include <iostream> using namespace std; class Box {

double length; // Length of a box double breadth; // Breadth of a box double height; // Height of a box public:

double getVolume(void) { return length * breadth * height; }

void setLength( double len ) { length = len; }

void setBreadth( double bre ) { breadth = bre; }

void setHeight( double hei ) { height = hei; }

Page 24: Technical Interview

// Overload + operator to add two Box objects. Box operator+(const Box& b) {

Box box; box.length = this->length + b.length; box.breadth = this->breadth + b.breadth; box.height = this->height + b.height; return box;

} }; // Add two object as follows:

Box3 = Box1 + Box2;

Page 25: Technical Interview

Polymorphism in C++

The word polymorphism means having many forms. Typically, polymorphism occurs when there is a hierarchy of classes and they are related by inheritance.

C++ polymorphism means that a call to a member function will cause a different function to be executed depending on the type of object that invokes the function.

Page 26: Technical Interview

Virtual members in C++

A member of a class that can be redefined in its derived classes is known as a virtual member. In order to declare a member of a class as virtual, we must precede its declaration with the keyword virtual.

Therefore, what the virtual keyword does is to allow a member of a derived class with the same name as one in the base class to be appropriately called from a pointer, and more precisely when the type of the pointer is a pointer to the base class but is pointing to an object of the derived class, as in the above example.

A class that declares or inherits a virtual function is called a polymorphic class.

Page 27: Technical Interview

Example of virtual member in C++

// virtual members #include <iostream> using namespace std; class CPolygon {

protected: int width, height; public:

void set_values (int a, int b) { width=a; height=b; } virtual int area () { return (0); }

}; class CRectangle: public CPolygon {

public: int area () { return (width * height); }

}; class CTriangle: public CPolygon {

public: int area () { return (width * height / 2); }

};

Page 28: Technical Interview

int main () {

CRectangle rect; CTriangle trgl;

CPolygon poly; CPolygon * ppoly1 = &rect;

CPolygon * ppoly2 = &trgl;CPolygon * ppoly3 = &poly; ppoly1->set_values (4,5);

ppoly2->set_values (4,5); ppoly3->set_values (4,5); cout << ppoly1->area() << endl;

cout << ppoly2->area() << endl; cout << ppoly3->area() << endl;

return 0; }

The use of virtual functions is Dynamic Binding.

Page 29: Technical Interview

Abstract Base Class

Classes that contain at least one pure virtual function are abstract base classes.

To make a pure virtual function, append =0 (equal to zero) to the function declaration. virtual int area () =0;

The main difference between an abstract base class and a regular polymorphic class is that because in abstract base classes at least one of its members lacks implementation we cannot create instances (objects) of it.

However, pointers to this abstract base class can be used to point to objects of derived classes.

Abstract Base Class in C++ concept is similar to concept of interfaces in Java.

Page 30: Technical Interview

Inheritance in C++

Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. This also provides an opportunity to reuse the code functionality and fast implementation time.

When creating a class, instead of writing completely new data members and member functions, the programmer can designate that the new class should inherit the members of an existing class. This existing class is called the base class, and the new class is referred to as the derived class.

Syntax to inherit a class: class derived-class: access-specifier base-class

Page 31: Technical Interview

We can summarize the different access types according to who can access them in the following way:

A derived class inherits all base class methods with the following exceptions:

Constructors, destructors and copy constructors of the base class. Overloaded operators of the base class. The friend functions of the base class.

Access public protected private

Same class yes yes yes

Derived classes yes yes no

Outside classes yes no no

Page 32: Technical Interview

Friend Function in C++

A friend function for a class is used in object-oriented programming to allow access to public, private, or protected data in the class from the outside. Normally, a function that is not a member of a class cannot access such information; neither can an external class.

A friend function is declared by the class that is granting access.

When a function needs to access private data in objects from two different classes. This may be accomplished in two similar ways a function of global or namespace scope may be declared as

friend of both classes a member function of one class may be declared as friend of

another one.

Page 33: Technical Interview

Difference between C++ and Java

C++ Java

Write once, compile anywhere (WOCA).

Write once, run anywhere / everywhere (WORA / WORE).

Allows procedural programming, functional programming, object-oriented programming.

Strongly encourages an object-oriented programming paradigm.

Explicit memory management. Automatic garbage collection (can be triggered manually).

Pointers, references, and pass-by-value are supported.

Primitive and reference data types always passed by value.

Full Multiple inheritance. From classes, only single inheritance is allowed. From Interfaces, Multiple inheritance is also allowed.

Exposes low-level system facilities.

Runs in a virtual machine. Does not always provide full access to the features and performance of the platform on which the software runs.

Page 34: Technical Interview

Some features of Java

Platform Independent Simple Object Oriented Robust Portable Secure Performance Multithreaded Interpreted

Page 35: Technical Interview

Platform Independence in Java

One characteristic of Java is portability, which means that computer programs written in the Java language must run similarly on any hardware/operating-system platform.

This is achieved by compiling the Java language code to an intermediate representation called Java bytecode, instead of directly to platform-specific machine code.

Java bytecode instructions are analogous to machine code, but are intended to be interpreted by a virtual machine (VM) written specifically for the host hardware.

The overhead of interpretation means that interpreted programs almost always run more slowly than programs compiled to native executables would. Just-in-Time (JIT) compilers were introduced from an early stage that compile bytecodes to machine code during runtime.

Page 36: Technical Interview

Robustness in Java

Java has the strong memory allocation and automatic garbage collection mechanism.

It provides powerful exception handling and type checking mechanism as compare to other programming languages.

Compiler checks the program whether there any error and interpreter checks any run time error and makes the system secure from crash.

Java does not use memory pointers explicitly. All the programs in java are run under an area known as the sand box.

Page 37: Technical Interview

Garbage Collection in Java

The JVM's heap stores all objects created by an executing Java program. Objects are created by Java's "new" operator, and memory for new objects is allocated on the heap at run time.

Garbage collection is the process of automatically freeing objects that are no longer referenced by the program.

In the process of freeing unreferenced objects, the garbage collector must run any finalizers of objects being freed.

In Java on calling System.gc() and Runtime.gc(), JVM tries to recycle the unused objects, but there is no guarantee when all the objects will garbage collected.

Page 38: Technical Interview

Multithreading in Java

Multithreading is a technique that allows a program or a process to execute many tasks concurrently (at the same time and parallel). It allows a process to run its tasks in parallel mode on a single processor system.

Advantages of multithreading over multitasking:   Reduces the computation time. Improves performance of an application. Threads share the same address space so it saves the

memory. Context switching between threads is usually less

expensive than between processes.  Cost of communication between threads is relatively low.

Page 39: Technical Interview

Java Collection Framework

The Java collections framework (JCF) is a set of classes and interfaces that implement commonly reusable collection data structures.

There are three main types of collections: Lists: always ordered, may contain duplicates and

can be handled the same way as usual arrays Sets: cannot contain duplicates and provide

random access to their elements Maps: connect unique keys with values, provide

random access to its keys and may host duplicate values

Page 40: Technical Interview

Exception Handling in Java An exception is a problem that arises during the execution of a program. An

exception can occur for many different reasons, including the following: A user has entered invalid data. A file that needs to be opened cannot be found. A network connection has been lost in the middle of communications, or the

JVM has run out of memory. Checked exceptions: A checked exception is an exception that is typically a

user error or a problem that cannot be foreseen by the programmer. For example, if a file is to be opened, but the file cannot be found, an exception occurs. These exceptions cannot simply be ignored at the time of compilation.

Runtime exceptions: A runtime exception is an exception that occurs that probably could have been avoided by the programmer. As opposed to checked exceptions, runtime exceptions are ignored at the time of compilation.

Errors: These are not exceptions at all, but problems that arise beyond the control of the user or the programmer. Errors are typically ignored in your code because you can rarely do anything about an error. For example, if a stack overflow occurs, an error will arise. They are also ignored at the time of compilation.

Page 41: Technical Interview

Some additional features to look for

Java I/O Networking in Java Event Handling in Java Applets and AWT framework Little knowledge about SWING framework Generics in Java

Page 42: Technical Interview

Data Structures

Data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.

Different kinds of data structures are suited to different kinds of applications, and some are highly specialized to specific tasks.

Some Examples: Arrays Structures Stacks Queues Heaps Linked Lists Graphs Trees Hash Tables Tries

Page 43: Technical Interview

Operating System

An operating system (OS) is a collection of software that manages computer hardware resources and provides common services for computer programs.

Page 44: Technical Interview

Topics for Operating System

Kernel Architectures. Memory management. Thread vs. Process. Concurrency Control Mechanism. Cache Memory.

Page 45: Technical Interview

Kernel Architectures

Four broad categories of kernels: Monolithic kernels provide rich and powerful

abstractions of the underlying hardware. Microkernels provide a small set of simple hardware

abstractions and use applications called servers to provide more functionality.

Exokernels provide minimal abstractions, allowing low-level hardware access. In exokernel systems, library operating systems provide the abstractions typically present in monolithic kernels.

Hybrid (modified microkernels) are much like pure microkernels, except that they include some additional code in kernel space to increase performance.

Page 46: Technical Interview

Memory Management

The memory management function keeps track of the status of each memory location, either allocated or free.

It determines how memory is allocated among competing processes, deciding who gets memory, when they receive it, and how much they are allowed.

When memory is allocated it determines which memory locations will be assigned. It tracks when memory is freed or unallocated and updates the status.

Page 47: Technical Interview

Memory management Techniques

Single contiguous allocation: All the computer's memory, usually with the exception of a small portion reserved for the operating system, is available to the single application.

Partitioned allocation: Partitioned allocation divides primary memory into multiple memory partitions, usually contiguous areas of memory. Each partition might contain all the information for a specific job or task. Memory management consists of allocating a partition to a job when it starts and unallocating it when the job ends.

Paged memory management: Paged allocation divides the computer's primary memory into fixed-size units called page frames, and the program's address space into pages of the same size. The hardware memory management unit maps pages to frames.

Segmented memory management: Segments are areas of memory that usually correspond to a logical grouping of information such as a code procedure or a data array.

Virtual Memory

Page 48: Technical Interview

Threads vs. ProcessThreads Process

thread of execution is the smallest unit of processing that can be scheduled by an operating system.

a process is an instance of a computer program that is being executed.

Process can have multiple threads.

Sharing data among threads is trivial because threads share the same memory. (However, great care must be taken to avoid race conditions, as described previously.)

Sharing data among processes requires the use of IPC mechanisms.

Advantage of a multithreaded program allows it to operate faster on computer systems that have multiple CPUs, CPU s with multiple cores, or across a cluster of machines — because the threads of the program naturally lend themselves to truly concurrent execution.

Page 49: Technical Interview

Concurrency Control Mechanisms

Concurrency control ensures that correct results for concurrent operations are generated, while getting those results as quickly as possible.

Techniques of concurrency control in Database Systems: Two Phase Locking Protocol Precedence Graph Timestamp Ordering

Techniques of concurrency control in Operating Systems: Semaphores Monitors

Page 50: Technical Interview

Different type of Memories

Primary storage: Main memory is directly or indirectly connected to the central processing unit via a memory bus.

Secondary storage: The computer usually uses its input/output channels to access secondary storage and transfers the desired data using intermediate area in primary storage.

Cache Memory: The cache is a smaller, faster memory which stores copies of the data from the most frequently used main memory locations.

Page 51: Technical Interview

Behind the Scenes of Compiling a Program

First Step: Create a program in editor. #include<stdio.h>

void main(){

printf(“Hello World”);}

Second Step: Compile the Program (gcc hello.c) When we call compiler, before compiling

preprocessing takes place. So all the preprocessor directives are

expanded.

Page 52: Technical Interview

Continue..

After Preprocessing source code is compiled.

Compilation Process: The front end checks whether the program is

correctly written in terms of the programming language syntax and semantics.

The middle end is where optimization takes place. Typical transformations for optimization are removal of useless or unreachable code.

The back end is responsible for translating the IR from the middle-end into assembly code.

Page 53: Technical Interview

Continue..

Still, the external references to library code is remaining.

Here comes Linking: When a program comprises multiple object

files, the linker combines these files into a unified executable program, resolving the symbols as it goes along.

One or more system libraries are usually linked in by default.

After linking pass, we get an executable which is ready to be executed.

Page 54: Technical Interview

Continue…

Now, to execute that executable it is to be loaded into main memory.

So next comes Loader Loading a program involves reading the

contents of executable file, the file containing the program text, into memory, and then carrying out other required preparatory tasks to prepare the executable for running.

Once loading is complete, the operating system starts the program by passing control to the loaded program code.

Page 55: Technical Interview

BEST OF LUCK Thank You