C++ Interview Question Implement itoa


Implementing itoa function is a popular interview question. Here’s one implementation from SAP.
char *itoa(int value)
{
int count, /* number of characters in string */
i, /* loop control variable */
sign; /* determine if the value is negative */
char *ptr, /* temporary pointer, index into string */
*string, /* return value */
*temp; /* temporary string array */
 
count = 0;
if ((sign = value) < 0) /* assign value to sign, if negative */
{ /* keep track and invert value */
value = -value;
count++; /* increment count */
}
 
/* allocate INTSIZE plus 2 bytes (sign and NULL) */
temp = (char *) malloc(INTSIZE + 2);
if (temp == NULL)
{
return(NULL);
}
memset(temp,'\0', INTSIZE + 2);
 
string = (char *) malloc(INTSIZE + 2);
if (string == NULL)
{
return(NULL);
}
memset(string,'\0', INTSIZE + 2);
ptr = string; /* set temporary ptr to string */
 
/*------------------------------------------------------------------–+
| NOTE: This process reverses the order of an integer, ie: |
| value = -1234 equates to: char [4321-] |
| Reorder the values using for {} loop below |
+------------------------------------------------------------------–*/
do {
*temp++ = value % 10 + '0'; /* obtain modulus and or with '0' */
count++; /* increment count, track iterations*/
} while (( value /= 10) >0);
 
if (sign < 0) /* add '-' when sign is negative */
*temp++ = '-';
 
*temp-- = '\0'; /* ensure null terminated and point */
/* to last char in array */
 
/*------------------------------------------------------------------–+
| reorder the resulting char *string: |
| temp - points to the last char in the temporary array |
| ptr - points to the first element in the string array |
+------------------------------------------------------------------–*/
for (i = 0; i < count; i++, temp--, ptr++)
{
memcpy(ptr,temp,sizeof(char));
}
 
return(string);
}

x86 interview questions

These interview questions test the knowledge of x86 Intel architecture and 8086 microprocessor specifically.

1. 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.
2. Give examples for 8 / 16 / 32 bit Microprocessor? - 8-bit Processor - 8085 / Z80 / 6800; 16-bit Processor - 8086 / 68000 / Z8000; 32-bit Processor - 80386 / 80486.
3. Why 8085 processor is called an 8 bit processor? - Because 8085 processor has 8 bit ALU (Arithmetic Logic Review). Similarly 8086 processor has 16 bit ALU.
4. 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.
5. Define HCMOS? - High-density n- type Complimentary Metal Oxide Silicon field effect transistor.
6. What does microprocessor speed depend on? - The processing speed depends on DATA BUS WIDTH.
7. Is the address bus unidirectional? - The address bus is unidirectional because the address information is always given by the Micro Processor to address a memory location of an input / output devices.
8. Is the data bus is Bi-directional? - The data bus is Bi-directional because the same bus is used for transfer of data between Micro Processor and memory or input / output devices in both the direction.
9. What is the disadvantage of microprocessor? - It has limitations on the size of data. Most Microprocessor does not support floating-point operations.
10. What is the difference between microprocessor and microcontroller? - In Microprocessor more op-codes, few bit handling instructions. But in Microcontroller: fewer op-codes, more bit handling Instructions, and also it is defined as a device that includes micro processor, memory, & input / output signal lines on a single chip.
11. What is meant by LATCH? - Latch is a D- type flip-flop used as a temporary storage device controlled by a timing signal, which can store 0 or 1. The primary function of a Latch is data storage. It is used in output devices such as LED, to hold the data for display.
12. Why does microprocessor contain ROM chips? - Microprocessor contain ROM chip because it contain instructions to execute data.
13. What is the difference between primary & secondary storage device? - In primary storage device the storage capacity is limited. It has a volatile memory. In secondary storage device the storage capacity is larger. It is a nonvolatile memory. Primary devices are: RAM / ROM. Secondary devices are: Floppy disc / Hard disk.
14. Difference between static and dynamic RAM? - Static RAM: No refreshing, 6 to 8 MOS transistors are required to form one memory cell, Information stored as voltage level in a flip flop. Dynamic RAM: Refreshed periodically, 3 to 4 transistors are required to form one memory cell, Information is stored as a charge in the gate to substrate capacitance.
15. What is interrupt? - Interrupt is a signal send by external device to the processor so as to request the processor to perform a particular work.
16. What is cache memory? - Cache memory is a small high-speed memory. It is used for temporary storage of data & information between the main memory and the CPU(center processing unit). The cache memory is only in RAM.
17. What is called .Scratch pad of computer.? - Cache Memory is scratch pad of computer.
18. Which transistor is used in each cell of EPROM? - Floating .gate Avalanche Injection MOS (FAMOS) transistor is used in each cell of EPROM.
19. Differentiate between RAM and ROM? - RAM: Read / Write memory, High Speed, Volatile Memory. ROM: Read only memory, Low Speed, Non Voliate Memory.
20. What is a Compiler? - Compiler is used to translate the high-level language program into machine code at a time. It doesn.t require special instruction to store in a memory, it stores automatically. The Execution time is less compared to Interpreter.
21. Which processor structure is pipelined? - All x86 processors have pipelined structure.
22. What is flag? - Flag is a flip-flop used to store the information about the status of a processor and the status of the instruction executed most recently
23. What is stack? - Stack is a portion of RAM used for saving the content of Program Counter and general purpose registers.
24. Can ROM be used as stack? - ROM cannot be used as stack because it is not possible to write to ROM.
25. What is NV-RAM? - Nonvolatile Read Write Memory, also called Flash memory. It is also know as shadow RAM.

Embedded systems interview questions

The Following are Embedded systems interview questions, Please do go through them, if you have answers do reply:

1. Can structures be passed to the functions by value?
2. Why cannot arrays be passed by values to functions?
3. Advantages and disadvantages of using macro and inline functions?
4. What happens when recursion functions are declared inline?
5. Scope of static variables?
6. Difference between object oriented and object based languages?
7. Multiple inheritance - objects contain how many multiply inherited ancestor?
8. What are the 4 different types of inheritance relationship?
9. How would you find out the no of instance of a class?
10. Is java a pure object oriented language? Why?
11. Order of constructor and destructor call in case of multiple inheritance?
12. Can u have inline virtual functions in a class?
13. When you inherit a class using private keyword which members of base class are visible to the derived class?
14. What is the output of printf(”\nab\bcd\ref”); -> ef
15. #define cat(x,y) x##y concatenates x to y. But cat(cat(1,2),3) does not expand but gives preprocessor warning. Why?
16. Can you have constant volatile variable? Yes, you can have a volatile pointer?
17. ++*ip increments what? it increments what ip points to
18. Operations involving unsigned and signed — unsigned will be converted to signed
19. a+++b -> (a++)+b
20. malloc(sizeof(0)) will return — valid pointer
21. main() {fork();fork();fork();printf(”hello world”); } — will print 8 times.
22. Array of pts to functions — void (*fptr[10])()
23. Which way of writing infinite loops is more efficient than others? there are 3ways.
24. # error — what it does?
25. How is function itoa() written?
26. Who to know whether system ses big endian or little endian format and how to convert among them?
27. What is interrupt latency?
28. What is forward reference w.r.t. pointers in c?
29. How is generic list manipulation function written which accepts elements of any kind?
30. What is the difference between hard real-time and soft real-time OS?
31. What is interrupt latency? How can you reduce it?
32. What is the difference between embedded systems and the system in which rtos is running?
33. How can you define a structure with bit field members?
34. What are the features different in pSOS and vxWorks?
35. How do you write a function which takes 2 arguments - a byte and a field in the byte and returns the value of the field in that byte?
36. What are the different storage classes in C?
37. What are the different qualifiers in C?
38. What are the different BSD and SVR4 communication mechanisms

Java/J2EE Interview Questions


The Following are Java/J2EE Interview Questions

1. What is Jakarta Struts Framework? - Jakarta Struts is open source implementation of MVC (Model-View-Controller) pattern for the development of web based applications. Jakarta Struts is robust architecture and can be used for the development of applicationof any size. Struts framework makes it much easier to design scalable, reliable Web applications with Java.
2. What is ActionServlet? - The class org.apache.struts.action.ActionServletis the called the ActionServlet. In the the Jakarta Struts Framework this class plays the role of controller. All the requests to the server goes through the controller. Controller is responsible for handling all the requests.
3. How you will make available any Message Resources Definitions file to the Struts Framework Environment? - Message Resources Definitions file are simple .properties files and these files contains the messages that can be used in the struts project. Message Resources Definitions files can be added to the struts-config.xml file throughtag.
Example:

4. What is Action Class? - The Action Class is part of the Model and is a wrapper around the business logic. The purpose of Action Class is to translate the HttpServletRequest to the business logic. To use the Action, we need to Subclass and overwrite the execute() method. In the Action Class all the database/business processing are done. It is advisable to perform all the database related stuffs in the Action Class. The ActionServlet (commad) passes the parameterized class to Action Form using the execute() method. The return type of the execute method is ActionForward which is used by the Struts Framework to forward the request to the file as per the value of the returned ActionForward object.
5. Write code of any Action Class? - Here is the code of Action Class that returns the ActionForward object.

       import javax.servlet.http.HttpServletRequest;
       import javax.servlet.http.HttpServletResponse;
       import org.apache.struts.action.Action;
       import org.apache.struts.action.ActionForm;
       import org.apache.struts.action.ActionForward;
       import org.apache.struts.action.ActionMapping;
        
      public class TestAction extends Action
      {
         public ActionForward execute(
           ActionMapping mapping,
           ActionForm form,
           HttpServletRequest request,
           HttpServletResponse response) throws Exception
        {
               return mapping.findForward(\"testAction\");
        }
       }

6. What is ActionForm? - An ActionForm is a JavaBean that extendsorg.apache.struts.action.ActionForm. ActionForm maintains the session state for web application and the ActionForm object is automatically populated on the server side with data entered from a form on the client side.
7. What is Struts Validator Framework? - Struts Framework provides the functionality to validate the form data. It can be use to validate the data on the users browser as well as on the server side. Struts Framework emits the java scripts and it can be used validate the form data on the client browser. Server side validation of form can be accomplished by sub classing your From Bean with DynaValidatorForm class. The Validator framework was developed by David Winterfeldt as third-party add-on to Struts. Now the Validator framework is a part of Jakarta Commons project and it can be used with or without Struts. The Validator framework comes integrated with the Struts Framework and can be used without doing any extra settings.
8. Give the Details of XML files used in Validator Framework? - The Validator Framework uses two XML configuration files validator-rules.xml and validation.xml. The validator-rules.xml defines the standard validation routines, these are reusable and used in validation.xml. to define the form specific validations. The validation.xml defines the validations applied to a form bean.
9. How you will display validation fail errors on jsp page? - The following tag displays all the errors:

10. How you will enable front-end validation based on the xml in validation.xml? - The  tag to allow front-end validation based on the xml in validation.xml. For example the code:  generates the client side java script for the form “logonForm” as defined in the validation.xml file. The when added in the jsp file generates the client site validation script.

Java Web development interview questions


Following are some Java Web development interview questions:

1. Can we use the constructor, instead of init(), to initialize servlet? - Yes , of course you can use the constructor instead of init(). There’s nothing to stop you. But you shouldn’t. The original reason for init() was that ancient versions of Java couldn’t dynamically invoke constructors with arguments, so there was no way to give the constructur a ServletConfig. That no longer applies, but servlet containers still will only call your no-arg constructor. So you won’t have access to a ServletConfig or ServletContext.
2. How can a servlet refresh automatically if some new data has entered the database? - You can use a client-side Refresh or Server Push.
3. The code in a finally clause will never fail to execute, right? - Using System.exit(1); in try block will not allow finally code to execute.
4. How many messaging models do JMS provide for and what are they? - JMS provide for two messaging models, publish-and-subscribe and point-to-point queuing.
5. What information is needed to create a TCP Socket? - The Local System?s IP Address and Port Number. And the Remote System’s IPAddress and Port Number.
6. What Class.forName will do while loading drivers? - It is used to create an instance of a driver and register it with the DriverManager. When you have loaded a driver, it is available for making a connection with a DBMS.
7. How to Retrieve Warnings? - SQLWarning objects are a subclass of SQLException that deal with database access warnings. Warnings do not stop the execution of an application, as exceptions do; they simply alert the user that something did not happen as planned. A warning can be reported on a Connection object, a Statement object (including PreparedStatement and CallableStatement objects), or a ResultSet object. Each of these classes has a getWarnings method, which you must invoke in order to see the first warning reported on the calling object
        SQLWarning warning = stmt.getWarnings();
        if (warning != null)
        {
          while (warning != null)
          {
            System.out.println(\"Message: \" + warning.getMessage());
            System.out.println(\"SQLState: \" + warning.getSQLState());
            System.out.print(\"Vendor error code: \");
            System.out.println(warning.getErrorCode());
            warning = warning.getNextWarning();
          }
        }

8. How many JSP scripting elements are there and what are they? - There are threescripting language elements: declarations, scriptlets, expressions.
9. In the Servlet 2.4 specification SingleThreadModel has been deprecated, why? - Because it is not practical to have such model. Whether you set isThreadSafe to true or false, you should take care of concurrent client requests to the JSP page by synchronizing access to any shared objects defined at the page level.
10. What are stored procedures? How is it useful? - A stored procedure is a set of statements/commands which reside in the database. The stored procedure is pre-compiled and saves the database the effort of parsing and compiling sql statements everytime a query is run. Each database has its own stored procedure language, usually a variant of C with a SQL preproceesor. Newer versions of db’s support writing stored procedures in Java and Perl too. Before the advent of 3-tier/n-tier architecture it was pretty common for stored procs to implement the business logic( A lot of systems still do it). The biggest advantage is of course speed. Also certain kind of data manipulations are not achieved in SQL. Stored procs provide a mechanism to do these manipulations. Stored procs are also useful when you want to do Batch updates/exports/houseKeeping kind of stuff on the db. The overhead of a JDBC Connection may be significant in these cases.
11. How do I include static files within a JSP page? - Static resources should always be included using the JSP include directive. This way, the inclusion is performed just once during the translation phase. Do note that you should always supply a relative URL for the file attribute. Although you can also include static resources using the action, this is not advisable as the inclusion is then performed for each and every request.
12. Why does JComponent have add() and remove() methods but Component does not? - because JComponent is a subclass of Container, and can contain other components and jcomponents.
13. How can I implement a thread-safe JSP page? - You can make your JSPs thread-safe by having them implement the SingleThreadModel interface. This is done by adding the directive <%@ page isThreadSafe="false" % > within your JSP page.