Tuesday, 26 April 2011

unix interview questions



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:


File owner identifier
File type
File access permissions
File access times
Number of links
File size
Location of the file data


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?
- Open: to open a file. Syntax: open (pathname, flag, and mode).
- Create: To create a file. Syntax: create (pathname, mode).
- Close: To close a file. Syntax: close (filedes).
- Read: To read data from a file that is opened. Syntax: read (filedes, buffer, bytes)
- Write: To write data to a file that is opened. Syntax: write (filedes, buffer, bytes)
- Lseek: To position the file pointer at given location in the file.
Syntax: lseek (filedes, offset, from).
- Dup: To make a duplicate copy of an existing file descriptor. Syntax: dup (filedes).
- Fcntl: To make the changes to the properties of an open file.
Syntax: fcntl (filedes, cmd, arg).


5.  What is a FIFO? 
FIFO are otherwise called as 'named pipes'. FIFO (first-in-first-out) is a special file which is said to be data transient. Once data is read from named pipe, it cannot be read again. Also, data can be read only in the order written. It is used in interprocess communication where a process writes to one end of the pipe (producer) and the other reads from the other end (consumer).


6.  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.
Commands for linking files are:
Link ln filename1 filename2
Symbolic link ln -s filename1 filename2


7.  How do you create special files like named pipes and device files? 
The system call mknod creates special files in the following sequence.
1. kernel assigns new inode,
2. sets the file type to indicate that the file is a pipe, directory or special file,
3. If it is a device file, it makes the other entries like major, minor device numbers.
For example:
If the device is a disk, major device number refers to the disk controller and minor device number is the disk.


8. What is the difference between internal and external commands?


Internal commands are commands that are already loaded in the system. They can be executed any time and are independent. On the other hand, external commands are loaded when the user requests for them. Internal commands don’t require a separate process to execute them. External commands will have an individual process. Internal commands are a part of the shell while external commands require a Path. If the files for the command are not present in the path, the external command won’t execute.



9. What is difference between ps -ef and ps -auxwww?


This is indeed a good Unix Interview Command Question and I have faced this issue while ago where one culprit process was not visible by execute ps –ef command and we are wondering which process is holding the file.
ps -ef will omit process with very long command line while ps -auxwww will list those process as well.


10. How do you find how many cpu are in your system and there details?


By looking into file /etc/cpuinfo for example you can use below command:
cat /proc/cpuinfo


11. What is difference between HardLink and SoftLink in UNIX?


I have discussed this Unix Command Interview questions  in my blog post difference between Soft link and Hard link in Unix


12. What is Zombie process in UNIX? How do you find Zombie process in UNIX?


 When a program forks and the child finishes before the parent, the kernel still keeps some of its information about the child in case the parent might need it - for example, the parent may need to check the child's exit status. To be able to get this information, the parent calls 'wait()'; In the interval between the child terminating and the parent calling 'wait()', the child is said to be a 'zombie' (If you do 'ps', the child will have a 'Z' in its status field to indicate this.)
Zombie : The process is dead but have not been removed from the process table.




13. There is a file some where in your system which contains word "UnixCommandInterviewQuestions” How will find that file in Unix?


 By using find command in UNIX for details see here 10 example of using find command in Unix


14. In a file word UNIX is appearing many times? How will you count number?
  grep -c "Unix" filename


15. How do you set environment variable which will be accessible form sub shell?


 By using export   for example export count=1 will be available on all sub shell.



Monday, 25 April 2011

java interview questions

What is garbage collection? What is the process that is responsible for doing that in java?  
Reclaiming the unused memory by the invalid objects. Garbage collector is responsible for this process
What kind of thread is the Garbage collector thread? 
 It is a daemon thread.
What is a daemon thread? 
These are the threads which can run without user intervention. The JVM can exit when there are daemon thread by killing them abruptly.
How will you invoke any external process in Java? 
Runtime.getRuntime().exec(….)
What is the finalize method do? 
Before the invalid objects get garbage collected, the JVM give the user a chance to clean up some resources before it got garbage collected.
What is mutable object and immutable object? 
If a object value is changeable then we can call it as Mutable object. (Ex., StringBuffer, …) If you are not allowed to change the value of an object, it is immutable object. (Ex., String, Integer, Float, …)
What is the basic difference between string and stringbuffer object? 
String is an immutable object. StringBuffer is a mutable object.
What is the purpose of Void class? 
The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the primitive Java type void.
What is reflection? 
Reflection allows programmatic access to information about the fields, methods and constructors of loaded classes, and the use reflected fields, methods, and constructors to operate on their underlying counterparts on objects, within security restrictions.
What is the base class for Error and Exception? 
 Throwable
What is the byte range? 
128 to 127
What is the implementation of destroy method in java.. is it native or java code? 
 This method is not implemented.
What is a package? 
 To group set of classes into a single unit is known as packaging. Packages provides wide namespace ability.
What are the approaches that you will follow for making a program very efficient? 
By avoiding too much of static methods avoiding the excessive and unnecessary use of synchronized methods Selection of related classes based on the application (meaning synchronized classes for multiuser and non-synchronized classes for single user) Usage of appropriate design patterns Using cache methodologies for remote invocations Avoiding creation of variables within a loop and lot more.
What is a DatabaseMetaData? 
 Comprehensive information about the database as a whole.
What is Locale? 
A Locale object represents a specific geographical, political, or cultural region
How will you load a specific locale? 
 Using ResourceBundle.getBundle(…);
What is JIT and its use? 
Really, just a very fast compiler… In this incarnation, pretty much a one-pass compiler — no offline computations. So you can’t look at the whole method, rank the expressions according to which ones are re-used the most, and then generate code. In theory terms, it’s an on-line problem.
Is JVM a compiler or an interpreter? 
 Interpreter
When you think about optimization, what is the best way to findout the time/memory consuming process? 
 Using profiler


 What is immutable object? Can you write immutable object?

You need to make class final and all its member final so that once objects gets crated no one can modify its state. You can achieve same functionality by making member as non final but private and not modifying them except in constructor.


 Does all property of immutable object needs to be final?
Not necessary as stated above you can achieve same functionality by making member as non final but private and not modifying them except in constructor.


What is the difference between creating String as new () and literal?
When we create string with new () it’s created in heap and not added into string pool while String created using literal are created in String pool itself which exists in Perm area of heap.


How does substring () inside String works?
Another good question, I think answer is not sufficient but here it is “Substring creates new object out of string by taking a portion of original string”.


 How do you handle error condition while writing stored procedure or accessing stored procedure from java?
Open for all, my friend didn't know the answer so he didn't mind telling me.


What is difference between Executor.submit() and Executer.execute() method ? 
(Former returns an object of Future which can be used to find result from worker thread)


What is the difference between factory and abstract factory pattern?
Open for all, he explains about factory pattern and how factory pattern saves maintenance time by encapsulating logic of object creation but didn't know exact answer


What is Singleton? is it better to make whole method synchronized or only critical section synchronized ?
see my article 10 Interview questions on Singleton Pattern in Java




Can you write code for iterating over hashmap in Java 4and Java 5 ?
Tricky one but he managed to write using while and for loop.


When do you override hashcode and equals() ?
Whenever necessary especially if you want to do equality check or want to use your object as key in HashMap.


Is it better to synchronize critical section of getInstance() method or whole getInstance() method ?
Answer is critical section because if we lock whole method than every time some one call this method will have to wait even though we are not creating any object)


 What is the difference when String is gets created using literal or new() operator ?
When we create string with new() its created in heap and not added into string pool while String created using literal are created in String pool itself which exists in Perm area of heap.


Does not overriding hashcode() method has any performance implication ?
This is a good question and open to all , as per my knowledge a poor hashcode function will result in frequent collision in HashMap which eventually increase time for adding an object into Hash Map.

C++ INTERVIEW QUESTIONS


What is the diffrence between c# and c+?

c is procedure oriented language&c++is object oriented language.
 

Read the following program carefully and write the output of the program. Explain each line of code according to given numbering. #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <errno.h> 1……………… int main (void) { pid_t pid; 2………………………… pid = fork(); 3…………………………. if (pid > 0) { int i; 4………………………… for (i = 0; i < 5; i++) { 5………………… …………… printf(" I AM VU : %d\n", i); 6………………… …………… sleep(1); } exit(0); } 7………………… ……… else if (pid == 0) { int j; for (j = 0; j < 5; j++) { 8……………………………… printf(" I have no child: %d\n", j); sleep(1); } _exit(0); } else { 9………………………………fprintf(stderr, "can't fork, error %d\n", errno); 10……………… … ………… exit (EXIT_FAILURE); } ?

1 int main (void) Starts the main function 
2 pid = fork ( ); The fork ( ) method will call and store 
the integer value in the pid variable. In case of Child “0” 
value returned while the parent will store the “process id” 
of the child. In case when fork fails it will be 
initialized by -1 
3 if (pid > 0) This condition will be only true when fork 
failed. 
4 for (i = 0; i < 5; i++) Limmitations of for loop are 
declared and the loop starts 
5 printf(" I AM VU : %d\n", i); 
Prints I AM VU and the value of I message on screen 
6 sleep(1); Process sleeps 
7 else if (pid == 0) Now this blok of code executes in 
parent process since fork returns the ID to the parent 
process from child. which is not 0. 
8 printf(" I have no child: %d\n", j); 
“I have no child” is printed on the screen 
9 fprintf(stderr, "can't fork, error %d\n", errno); 
If the given conditions are not true then this error 
message is send 
10 exit (EXIT_FAILURE); system call will terminate the 
process abnormally as it fails.

1 1 2 1 2 3 1 2 3 4 1 2 3 1 2 1 generate this output using for loop?

#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,k,l;
for(i=1;i<=4;i++)
{
 for(k=i;k<=4;k++)
 {
  printf(" ");
 }
 for(j=1;j<=i;j++)
 {
  printf(" %d",j);
 }
printf("\n");
}
for(i=3;i>0;i--)
 {
 for(l=i;l<=3;l++)
  {
  printf(" ");
  }
 for(j=1;j<=i;j++)
  {
  printf(" %d",j);
  }
 printf("\n");
 }
getch();

What’s the advantage of using System.Text.StringBuilder over System.String? 
StringBuilder is more efficient in the cases, where a lot of manipulation is done to the text. Strings are immutable, so each time it’s being operated on, a new instance is created.
Can you store multiple data types in System.Array?
 No.
What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?
 The first one performs a deep copy of the array, the second one is shallow.
How can you sort the elements of the array in descending order? 
By calling Sort() and then Reverse() methods.
What’s the .NET datatype that allows the retrieval of data by a unique key?
 HashTable.
What’s class SortedList underneath? 
A sorted HashTable.
Will finally block get executed if the exception had not occurred? 
Yes.
What’s the C# equivalent of C++ catch (…), which was a catch-all statement for any possible exception?
 A catch block that catches the exception of type System.Exception. You can also omit the parameter data type in this case and just write catch {}.
Can multiple catch blocks be executed? 
No, once the proper catch code fires off, the control is transferred to the finally block (if there are any), and then whatever follows the finally block.
Why is it a bad idea to throw your own exceptions? 
Well, if at that point you know that an error has occurred, then why not write the proper code to handle that error instead of passing a new Exception object to the catch block? Throwing your own exceptions signifies some design flaws in the project.
What’s a delegate? 
A delegate object encapsulates a reference to a method. In C++ they were referred to as function pointers.
What’s a multicast delegate? 
It’s a delegate that points to and eventually fires off several methods.
How’s the DLL Hell problem solved in .NET? 
Assembly versioning allows the application to specify not only the library it needs to run (which was available under Win32), but also the version of the assembly

What are the ways to deploy an assembly? 
An MSI installer, a CAB archive, and XCOPY command.
 
 

civils interview questions and answers



Tell me something interesting about yourself?

Don’t be embarrassed or mention that you collect beer mats. Take this opportunity to make some positive statements. In particular your relevant strengths, qualities, achievements and recent experience could all be described. Equally, if you possess a particular distinction it should be mentioned here. An example could be a sporting achievement of significance, a local honor for helpfulness or bravery or anything else that will help the interviewer single you out in their mind: as long as it is positive and commendable of course. 


You may be asked about something you have mentioned in your application. In which case you will be expected to be reasonably knowledgeable and interested in the topic. Be prepared! 


Why compression strenth of concrete is tested with a cube of size 150x150x150 mm ?


Because as per IS standard the compressive strength is 
taken as per these specimen.


What is the diffrence between FE 415 & FE 500 TMT BARS?


Yield stress of the steel for Fe 415 is 415 n/mm2 and for Fe
500 is 500n/mm2.


What is stub column ?


A stub column is column which does no have any base  which provided only for stiffness purpose of the member.


How many quantity of water use in 1cu.m. concrete?


Depending upon grade of concrete and water cement ratio. it will be about 180litres/cum.



What would your present employer say about your suitability for the Civil Service?


Bearing in mind that the Board has plenty of references from your previous employers you need to be careful here. Be confident, but also be honest. Just pick on a few issues to start with and see if the discussion goes any deeper. There may be a reason for the Board to be checking something out that a previous employer of yours has said about you. This could be either positive or negative. 


Alternatively it could just be a conventional and routine question. It is best to be prepared and perhaps check with your referees before attending the Selection Board. 



How to find motors H.P. whout any rating?(only give you a motor and multimeter)


If there is provision to apply load on it ,the HP can be ascertained from the circle diagram of the motor.



 Explain what you will bring to the fast stream should you be successful?


A straightforward question asking you to outline your strengths and qualities. At least that is the way you should look at it. You should ideally consider the key requirements made of fast stream applicants from the information the selection board provided you with and reflect this back to the board. 


You should certainly consider mentioning some or all of the following:


Desire/ambition to succeed
Interests in taking a lead role
Willingness to work flexibly and as required
A profound interest in researching and preparing policy documents
An interest in and aptitude for team work
Ability to take decisions
Ability to priorities activities etc,












Saturday, 23 April 2011

digital logic design interview questions



1) Explain about setup time and hold time, what will happen if there is setup time and hold tine violation, how to overcome this?


Set up time is the amount of time before the clock edge that the input signal needs to be stable to guarantee it is accepted properly on the clock edge.
Hold time is the amount of time after the clock edge that same input signal has to be held before changing it to make sure it is sensed properly at the clock edge.
Whenever there are setup and hold time violations in any flip-flop, it enters a state where its output is unpredictable: this state is known as metastable state (quasi stable state); at the end of metastable state, the flip-flop settles down to either '1' or '0'. This whole process is known as metastability.


2) What is skew, what are problems associated with it and how to minimize it?


In circuit design, clock skew is a phenomenon in synchronous circuits in which the clock signal (sent from the clock circuit) arrives at different components at different times.
This is typically due to two causes. The first is a material flaw, which causes a signal to travel faster or slower than expected. The second is distance: if the signal has to travel the entire length of a circuit, it will likely (depending on the circuit's size) arrive at different parts of the circuit at different times. Clock skew can cause harm in two ways. Suppose that a logic path travels through combinational logic from a source flip-flop to a destination flip-flop. If the destination flip-flop receives the clock tick later than the source flip-flop, and if the logic path delay is short enough, then the data signal might arrive at the destination flip-flop before the clock tick, destroying there the previous data that should have been clocked through. This is called a hold violation because the previous data is not held long enough at the destination flip-flop to be properly clocked through. If the destination flip-flop receives the clock tick earlier than the source flip-flop, then the data signal has that much less time to reach the destination flip-flop before the next clock tick. If it fails to do so, a setup violation occurs, so-called because the new data was not set up and stable before the next clock tick arrived. A hold violation is more serious than a setup violation because it cannot be fixed by increasing the clock period.
Clock skew, if done right, can also benefit a circuit. It can be intentionally introduced to decrease the clock period at which the circuit will operate correctly, and/or to increase the setup or hold safety margins. The optimal set of clock delays is determined by a linear program, in which a setup and a hold constraint appears for each logic path. In this linear program, zero clock skew is merely a feasible point.
Clock skew can be minimized by proper routing of clock signal (clock distribution tree) or putting variable delay buffer so that all clock inputs arrive at the same time


3. How do you convert a XOR gate into a buffer and a inverter (Use only one XOR gate for each)


4.Implement an 2-input AND gate using a 2x1 mux.

5.what is a multiplexer? 
A Multiplexer  is a combinational  circut which selects one of many input signals and directs to the only              out put.



microprocessor interview questions, answers



What is a Microprocessor?
Microprocessor is a program-controlled device, which fetches the instructions from memory, decodes and executes the instructions. Most Micro Processor are single- chip devices.
What are the flags in 8086?
In 8086 Carry flag, Parity flag, Auxiliary carry flag, Zero flag, Overflow flag, Trace flag, Interrupt flag, Direction flag, and Sign flag.
Why crystal is a preferred clock source?
Because of high stability, large Q (Quality Factor) & the frequency that doesn?t drift with aging. Crystal is used as a clock source most of the times.
In 8085 which is called as High order / Low order Register?
Flag is called as Low order register & Accumulator is called as High order Register.
What is Tri-state logic?
Three Logic Levels are used and they are High, Low, High impedance state. The high and low are normal logic levels & high impedance state is electrical open circuit conditions. Tri-state logic has a third line called enable line.
What happens when HLT instruction is executed in processor?
The Micro Processor enters into Halt-State and the buses are tri-stated.
Which Stack is used in 8085?
LIFO (Last In First Out) stack is used in 8085.In this type of Stack the last stored information can be retrieved first
What is Program counter?
Program counter holds the address of either the first byte of the next instruction to be fetched for execution or the address of the next byte of a multi byte instruction, which has not been completely fetched. In both the cases it gets incremented automatically one by one as the instruction bytes get fetched. Also Program register keeps the address of the next instruction.
What are the various registers in 8085?
Accumulator register, Temporary register, Instruction register, Stack Pointer, Program Counter are the various registers in 8085
What is 1st / 2nd / 3rd / 4th generation processor?
The processor made of PMOS / NMOS / HMOS / HCMOS technology is called 1st / 2nd / 3rd / 4th generation processor, and it is made up of 4 / 8 / 16 / 32 bits.
Name the processor lines of two major manufacturers?
High-end: Intel - Pentium (II, III, 4), AMD - Athlon. Low-end: Intel - Celeron, AMD - Duron. 64-bit: Intel - Itanium 2, AMD - Opteron.
What?s the speed and device maximum specs for Firewire?
IEEE 1394 (Firewire) supports the maximum of 63 connected devices with speeds up to 400 Mbps. Where?s MBR located on the disk? Main Boot Record is located in sector 0, track 0, head 0, cylinder 0 of the primary active partition.
Where does CPU Enhanced mode originate from?
Intel?s 80386 was the first 32-bit processor, and since the company had to backward-support the 8086. All the modern Intel-based processors run in the Enhanced mode, capable of switching between Real mode (just like the real 8086) and Protected mode, which is the current mode of operation.
How many bit combinations are there in a byte?
Byte contains 8 combinations of bits.
Have you studied buses? What types?
There are three types of buses.
Address bus: This is used to carry the Address to the memory to fetch either Instruction or Data.
Data bus : This is used to carry the Data from the memory.
Control bus : This is used to carry the Control signals like RD/WR, Select etc.
What is the Maximum clock frequency in 8086?
5 Mhz is the Maximum clock frequency in 8086.
What is meant by Maskable interrupts?
An interrupt that can be turned off by the programmer is known as Maskable interrupt.
What is Non-Maskable interrupts?
An interrupt which can be never be turned off (ie. disabled) is known as Non-Maskable interrupt
What are the different functional units in 8086?
Bus Interface Unit and Execution unit, are the two different functional units in 8086.
What are the various segment registers in 8086?
Code, Data, Stack, Extra Segment registers in 8086.
What does EU do?
Execution Unit receives program instruction codes and data from BIU, executes these instructions and store the result in general registers.
Which Stack is used in 8086? k is used in 8086?
FIFO (First In First Out) stack is used in 8086.In this type of Stack the first stored information is retrieved first.
What are the flags in 8086?
In 8086 Carry flag, Parity flag, Auxiliary carry flag, Zero flag, Overflow flag, Trace flag, Interrupt flag, Direction flag, and Sign flag.
What is SIM and RIM instructions?
SIM is Set Interrupt Mask. Used to mask the hardware interrupts.
RIM is Read Interrupt Mask. Used to check whether the interrupt is Masked or not.
What is the difference between 8086 and 8088?
The BIU in 8088 is 8-bit data bus & 16- bit in 8086.Instruction queue is 4 byte long in 8088and 6 byte in 8086.
Give example for Non-Maskable interrupts?
Trap is known as Non-Maskable interrupts, which is used in emergency condition.
Give examples for Micro controller?
Z80, Intel MSC51 &96, Motorola are the best examples of Microcontroller.
What are the various interrupts in 8086?
Maskable interrupts, Non-Maskable interrupts.
What is meant by Maskable interrupts?
An interrupt that can be turned off by the programmer is known as Maskable interrupt.
What is Non-Maskable interrupts?
 An interrupt which can be never be turned off (ie.disabled) is known as Non-Maskable interrupt.