Friday, 28 June 2013

Technical Interview Questions

Java Basics - Interview Questions and Answers




Java Example questions

1. What is the difference between a constructor and a method?
A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator.
A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator.

2. What is the purpose of garbage collection in Java, and when is it used?
The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused.
A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used.

3. Describe synchronization in respect to multithreading.
With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources.
Without synchonization, it is possible for one thread to modify a shared variable while another thread is in the process of using or updating same shared variable. This usually leads to significant errors.

4. What is an abstract class?
Abstract class must be extended/subclassed (to be useful). It serves as a template. A class that is abstract may not be instantiated (ie. you may not call its constructor), abstract class may contain static data.
Any class with an abstract method is automatically abstract itself, and must be declared as such. A class may be declared abstract even if it has no abstract methods. This prevents it from being instantiated.

5. What is the difference between an Interface and an Abstract class?
An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract.
An interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.), but has some abstract methods.

6. Explain different way of using thread?
The thread could be implemented by using runnable interface or by inheriting from the Thread class. The former is more advantageous, 'cause when you are going for multiple inheritance, the only interface can help.
 
 

The C Language Basics - C Interview Questions and Answers

 
 
 
 1. What is a local block?
A local block is any portion of a C program that is enclosed by the left brace ({) and the right brace (}). A C function contains left and right braces, and therefore anything between the two braces is contained in a local block. An if statement or a switch statement can also contain braces, so the portion of code between these two braces would be considered a local block.
Additionally, you might want to create your own local block without the aid of a C function or keyword construct. This is perfectly legal. Variables can be declared within local blocks, but they must be declared only at the beginning of a local block. Variables declared in this manner are visible only within the local block. Duplicate variable names declared within a local block take precedence over variables with the same name declared outside the local block. Here is an example of a program that uses local blocks:


#include <stdio.h>
void main(void);
void main()
{
     /* Begin local block for function main() */
     int test_var = 10;
     printf("Test variable before the if statement: %d\n", test_var);
     if (test_var > 5)
     {
          /* Begin local block for "if" statement */
          int test_var = 5;
          printf("Test variable within the if statement: %d\n",
                 test_var);
          {
               /* Begin independent local block (not tied to
                  any function or keyword) */
               int test_var = 0;
               printf(
               "Test variable within the independent local block:%d\n",
               test_var);
          }
          /* End independent local block */
     }
     /* End local block for "if" statement */
     printf("Test variable after the if statement: %d\n", test_var);
}
/* End local block for function main() */

This example program produces the following output:
Test variable before the if statement: 10
Test variable within the if statement: 5
Test variable within the independent local block: 0
Test variable after the if statement: 10
Notice that as each test_var was defined, it took precedence over the previously defined test_var. Also notice that when the if statement local block had ended, the program had reentered the scope of the original test_var, and its value was 10.

2. Should variables be stored in local blocks?
The use of local blocks for storing variables is unusual and therefore should be avoided, with only rare exceptions. One of these exceptions would be for debugging purposes, when you might want to declare a local instance of a global variable to test within your function. You also might want to use a local block when you want to make your program more readable in the current context.
Sometimes having the variable declared closer to where it is used makes your program more readable. However, well-written programs usually do not have to resort to declaring variables in this manner, and you should avoid using local blocks.

3. When is a switch statement better than multiple if statements?
A switch statement is generally best to use when you have more than two conditional expressions based on a single variable of numeric type. For instance, rather than the code

if (x == 1)
     printf("x is equal to one.\n");
else if (x == 2)
     printf("x is equal to two.\n");
else if (x == 3)
     printf("x is equal to three.\n");
else
     printf("x is not equal to one, two, or three.\n");

the following code is easier to read and maintain:

switch (x)
{
     case 1:   printf("x is equal to one.\n");
                    break;
     case 2:   printf("x is equal to two.\n");
                    break;
     case 3:   printf("x is equal to three.\n");
                    break;
     default:  printf("x is not equal to one, two, or three.\n");
                    break;
}

Notice that for this method to work, the conditional expression must be based on a variable of numeric type in order to use the switch statement. Also, the conditional expression must be based on a single variable. For instance, even though the following if statement contains more than two conditions, it is not a candidate for using a switch statement because it is based on string comparisons and not numeric comparisons:

char* name = "Lupto";
if (!stricmp(name, "Isaac"))
     printf("Your name means 'Laughter'.\n");
else if (!stricmp(name, "Amy"))
     printf("Your name means 'Beloved'.\n ");
else if (!stricmp(name, "Lloyd"))
     printf("Your name means 'Mysterious'.\n ");
else
     printf("I haven't a clue as to what your name means.\n");


4. Is a default case necessary in a switch statement?
No, but it is not a bad idea to put default statements in switch statements for error- or logic-checking purposes. For instance, the following switch statement is perfectly normal:

switch (char_code)
{
     case 'Y':
     case 'y': printf("You answered YES!\n");
               break;
     case 'N':
     case 'n': printf("You answered NO!\n");
               break;
}

Consider, however, what would happen if an unknown character code were passed to this switch statement. The program would not print anything. It would be a good idea, therefore, to insert a default case where this condition would be taken care of:

...
     default:  printf("Unknown response: %d\n", char_code);
               break;
...

Additionally, default cases come in handy for logic checking. For instance, if your switch statement handled a fixed number of conditions and you considered any value outside those conditions to be a logic error, you could insert a default case which would flag that condition. Consider the following example:

void move_cursor(int direction)
{
     switch (direction)
     {
          case UP:     cursor_up();
                       break;
          case DOWN:   cursor_down();
                       break;
          case LEFT:   cursor_left();
                       break;
          case RIGHT:  cursor_right();
                       break;
          default:     printf("Logic error on line number %ld!!!\n",
                               __LINE__);
                       break;
     }
}
 
 
 

 

Operating Systems - Interview Questions and Answers

 
 
 
 
 
 


1. Explain the concept of Reentrancy?
It is a useful, memory-saving technique for multiprogrammed timesharing systems. A Reentrant Procedure is one in which multiple users can share a single copy of a program during the same period. Reentrancy has 2 key aspects: The program code cannot modify itself, and the local data for each user process must be stored separately. Thus, the permanent part is the code, and the temporary part is the pointer back to the calling program and local variables used by that program. Each execution instance is called activation. It executes the code in the permanent part, but has its own copy of local variables/parameters.

2. Explain Belady's Anomaly?
Also called FIFO anomaly. Usually, on increasing the number of frames allocated to a process virtual memory, the process execution is faster, because fewer page faults occur. Sometimes, the reverse happens, i.e., the execution time increases even when more frames are allocated to the process. This is Belady's Anomaly. This is true for certain page reference patterns.
3. What is a binary semaphore? What is its use?
A binary semaphore is one, which takes only 0 and 1 as values. They are used to implement mutual exclusion and synchronize concurrent processes.
4. What is thrashing?
It is a phenomenon in virtual memory schemes when the processor spends most of its time swapping pages, rather than executing instructions. This is due to an inordinate number of page faults.
5. List the Coffman's conditions that lead to a deadlock.
  1. Mutual Exclusion: Only one process may use a critical resource at a time.
  2. Hold & Wait: A process may be allocated some resources while waiting for others.
  3. No Pre-emption: No resource can be forcible removed from a process holding it.
  4. Circular Wait: A closed chain of processes exist such that each process holds at least one resource needed by another process in the chain.
6. What are short, long and medium-term scheduling?
Long term scheduler determines which programs are admitted to the system for processing. It controls the degree of multiprogramming. Once admitted, a job becomes a process.
Medium term scheduling is part of the swapping function. This relates to processes that are in a blocked or suspended state. They are swapped out of real-memory until they are ready to execute. The swapping-in decision is based on memory-management criteria.
Short term scheduler, also know as a dispatcher executes most frequently, and makes the finest-grained decision of which process should execute next. This scheduler is invoked whenever an event occurs. It may lead to interruption of one process by preemption.
UNIX File Management - Interview Questions and Answers
1. How are devices represented in UNIX?
All devices are represented by files called special files that are located in /dev directory. Thus, device files and other files are named and accessed in the same way. A 'regular file' is just an ordinary data file in the disk. A 'block special file' represents a device with characteristics similar to a disk (data transfer in terms of blocks). A 'character special file' represents a device with characteristics similar to a keyboard (data transfer is by stream of bits in sequential order).
2. What is 'inode'?
All UNIX files have its description stored in a structure called 'inode'. The inode contains info about the file-size, its location, time of last access, time of last modification, permission and so on. Directories are also represented as files and have an associated inode. In addition to descriptions about the file, the inode contains pointers to the data blocks of the file. If the file is large, inode has indirect pointer to a block of pointers to additional data blocks (this further aggregates for larger files). A block is typically 8k.
Inode consists of the following fields:
  1. File owner identifier
  2. File type
  3. File access permissions
  4. File access times
  5. Number of links
  6. File size
  7. Location of the file data
 
 

 

UNIX File Management - Interview Questions and Answers

 
1. How are devices represented in UNIX?
All devices are represented by files called special files that are located in /dev directory. Thus, device files and other files are named and accessed in the same way.
    chmod
    2. What are links and symbolic links in UNIX file system?
    A link is a second name (not a file) for a file. Links can be used to assign more than one name to a file, but cannot be used to assign a directory more than one name or link filenames on different computers.
    Symbolic link 'is' a file that only contains the name of another file.Operation on the symbolic link is directed to the file pointed by the it.Both the limitations of links are eliminated in symbolic links
3. Brief about the directory representation in UNIX.
A Unix directory is a file containing a correspondence between filenames and inodes. A directory is a special file that the kernel maintains. Only kernel modifies directories, but processes can read directories. The contents of a directory are a list of filename and inode number pairs. When new directories are created, kernel makes two entries named '.' (refers to the directory itself) and '..' (refers to parent directory). System call for creating directory is mkdir (pathname, mode).
4. What are the Unix system calls for I/O?
  1. open(pathname,flag,mode) - open file
  2. creat(pathname,mode) - create file
  3. close(filedes) - close an open file
  4. read(filedes,buffer,bytes) - read data from an open file
  5. write(filedes,buffer,bytes) - write data to an open file
  6. lseek(filedes,offset,from) - position an open file
  7. dup(filedes) - duplicate an existing file descriptor
  8. dup2(oldfd,newfd) - duplicate to a desired file descriptor
  9. fcntl(filedes,cmd,arg) - change properties of an open file
  10. ioctl(filedes,request,arg) - change the behaviour of an open file
  11. The difference between fcntl anf ioctl is that the former is intended for any open file, while the latter is for device-specific operations.
5. How do you change File Access Permissions?
Every file has following attributes:
  1. owner's user ID ( 16 bit integer )
  2. owner's group ID ( 16 bit integer )
  3. File access mode word
(r w x) - (r w x) - (r w x) (user permission) - (group permission) - (others permission) To change the access mode, we use chmod(filename,mode).


Travel Link Exchange Directory
Free link exchange and link building service for travel themed websites. Hunting Tips On Kynigi.org
Arthra, reviews kai alla! Ask The Guru!
Programming questions and answers Greek Jokes!
Ola ta anekdota edo! Franchise De Menage Nettoyage Entretien Menager Montreal Laval
Franchise d'entretien menager et femme de menage montreal laval longueuil services de menage et nettoyage laval, montreal Filme Online, Filme Hd Online, Filme Hd, Hd Film, Filme 2013, Filme Online 2013 , Filme Online 2012
Filme hd online gratuite, filme premiate, hd film, filme 2013 online, filme hd online gratuite, filme noi hd, filme 2012, seriale online gratuite, trailere filme Nettoyage- M�nage-montr�al
Nettoyage-m�nage-montr�al m�nage-poly�- service de nettoyage, entretien m�nager, femme de m�nage recherch�? Confiez nous la corv�e de votre m�nage. Estimation Get Infinity | Get8 | Get 8 | Get8.biz | Get8 Biz | Get 8 Biz
Get infinity, www. Get8. Biz, get 8biz, get biz, get8 biz, get8 bz, gget8 biz, geet8 biz, gett8 biz, get8 bbiz, get8 biiz, get8 bizz, egt8 biz, gte8 biz, ge8t biz, get 8biz, get8 ibz, get8 bzi, get8biz, et 8 biz, gt 8 biz, ge 8 biz, get biz, get8biz Online Shopping
Discount online shopping with the worlds most popular shopping malls, boutiques, shops, warehouses, dropshipping and outlets, it is all about good shopping Electronic, Computer & Medical Equipment World
Progress electronics, computers and medical equipment must be achieved by all the people of indonesia and the world. Therefore this website is dedicated to provide information related to it. Live Scores And Results
Live scores and live results service for football, tennis, basketball, ice hockey, american football, baseball and handball. Results from all over the world on all leagues as well as tables and stats on every game. Home Based Opportunities
Home based opportunities Ask The Guru!
Programming questions and answers

No comments:

Post a Comment

Free Movie Download
Get free movies, i can't give you the latest movie, but i can give you copies of the original tv series movie, the lone ranger. You can download them right here on my site 100% free and 100% legal.