Practice Question and Answer
8Q: Define stored procedure. What are its advantages and disadvantages? 1951 05b5cc7dbe4d2b419777515a0
5b5cc7dbe4d2b419777515a0- Show AnswerHide Answer
- Workspace
- SingleChoice
Answer :
Explanation :
A stored procedure is a segment of declarative SQL statements stored inside the database catalog. A stored procedure can be invoked by triggers, other stored procedures or applications such as Java, C#, PHP, etc. Advantages - Typically stored procedures help increase the performance of the applications. Once created, stored procedures are compiled and stored in the database. However MySQL implements the stored procedures slightly different. MySQL stored procedures are compiled on demand. After compiling a stored procedure, MySQL puts it to a cache. And MySQL maintains its own stored procedure cache for every single connection. If an application uses a stored procedure multiple times in a single connection, the compiled version is used, otherwise the stored procedure works like a query. - Stored procedures helps reduce the traffic between application and database server because instead of sending multiple lengthy SQL statements, the application has to send only name and parameters of the stored procedure. - Stored procedures are reusable and transparent to any applications. Stored procedures expose the database interface to all applications so that developers don’t have to develop functions that are already supported in stored procedures. - Stored procedures are secure. Database administrator can grant appropriate permissions to applications that access stored procedures in the database without giving any permission on the underlying database tables. Disadvantages - If you use a lot of stored procedures, the memory usage of every connection that is using those stored procedures will increase substantially. In addition, if you overuse a large number of logical operations inside store procedures, the CPU usage will also increase because database server is not well-designed for logical operations. - A constructs of stored procedures make it more difficult to develop stored procedures that have complicated business logic. - It is difficult to debug stored procedures. Only few database management systems allow you to debug stored procedures. Unfortunately, MySQL does not provide facilities for debugging stored procedures. -It is not easy to develop and maintain stored procedures. Developing and maintaining stored procedures are often required specialized skill set that not all application developers possess. This may lead to problems in both application development and maintenance phases.
Q: Write an algorithm to separate all ones & zeroes in an array. 1782 05b5cc7dbe4d2b4197775159f
5b5cc7dbe4d2b4197775159f- Show AnswerHide Answer
- Workspace
- SingleChoice
Answer :
Explanation :
1. Have two indexes pointing to two ends of array, say i and j. 2. Approach towards each other with a check condition that they dont cross each other. 3. Each iteration of while loop, swap the numbers pointed by two indexes when num[i] index number is not equal to 1. void sort() { int a[]={1,0,0,0,1,1,0,1,0,1,0,0,1,0}; int i=0; int j=13; int temp; while(j>i) { if(a[i]==1) i++; if(a[j]==0) j--; if(a[i]==0) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } for(i=0;i<14;i++) Console.Write(a[i]+", "); } Output: 1,1,1,1,1,1,0,0,0,0,0,0,0
Q: How would you reverse a doubly-linked list? 1409 05b5cc7dbe4d2b4197775159e
5b5cc7dbe4d2b4197775159e- Show AnswerHide Answer
- Workspace
- SingleChoice
Answer :
Explanation :
This problem isn't too hard. You just need to start at the head of the list, and iterate to the end. At each node, swap the values of pNext and pPrev. Finally, set pHead to the last node in the list. Node * pCurrent = pHead, *pTemp; while (pCurrent) { pTemp = pCurrent->pNext; pCurrent->pNext = pCurrent->pPrev; pCurrent->pPrev = temp; pHead = pCurrent; pCurrent = temp; }
Q: Write a method to fill all the spaces in a string with '%20' 858 05b5cc7dbe4d2b4197775159d
5b5cc7dbe4d2b4197775159d- Show AnswerHide Answer
- Workspace
- SingleChoice
Answer :
Explanation :
public class Test { public void replaseSpaces(char[] str, int length) { int spaceCount = 0, newLength = 0, i = 0; for(i = 0; i < length; i++) { if (str[i] == ' ') spaceCount++; } newLength = length + (spaceCount * 2); str[newLength] = '\0'; for(i = length - 1; i >= 0; i--) { if (str[i] == ' ') { str[newLength - 1] = '0'; str[newLength - 2] = '2'; str[newLength - 3] = '%'; newLength = newLength - 3; } else { str[newLength - 1] = str[i]; newLength = newLength - 1; } } System.out.println(str); } public static void main(String[] args) { Test tst = new Test(); char[] ch = {'t', 'h', 'e', ' ', 'd', 'o', 'g', ' ', ' ', ' ', ' ', ' ', ' '}; int length = 6; tst.replaseSpaces(ch, length); } }
Q: Difference between system call and API 1098 05b5cc7dbe4d2b4197775159c
5b5cc7dbe4d2b4197775159c- Show AnswerHide Answer
- Workspace
- SingleChoice
Answer :
Explanation :
A system call is a function.subroutine which interrupts the currently executing program and transfers control to the interrupt routine.The contents of the executing program are saved and after the interrupt routine finishes its function,control is transferred back to the executing program. If we talk in the context of Linux then System calls are called kernel mode. Whereas API (Application Programming Interface) is a function or a set of functions, objects, protocols or data-structures for the support of application development for developers/programmers. It is actually a kind of function definition which specifies how to make available of a specific service of the system/OS to the other program/process or system. Read more at: https://www.queryhome.com/48442/os-what-is-difference-between-system-call-and-api
Q: What is Marshalling? 1834 05b5cc7dbe4d2b4197775159b
5b5cc7dbe4d2b4197775159b- Show AnswerHide Answer
- Workspace
- SingleChoice
Answer :
Explanation :
Marshalling is the process of gathering data from one or more applications or non-contiguous sources in computer storage, putting the data pieces into a message buffer, and organizing or converting the data into a format that is prescribed for a particular receiver or programming interface.
Q: How do you eliminate duplicate values in DB2 SELECT? 1544 05b5cc7dbe4d2b4197775159a
5b5cc7dbe4d2b4197775159a- Show AnswerHide Answer
- Workspace
- SingleChoice
Answer :
Explanation :
Use SELECT DISTINCT ..... in DB2 query The DISTINCT keyword can be used to return only distinct (different) values. Syntax: SELECT DISTINCT column1,column2 FROM table_name;
Q: What is UNION , UNION ALL? 893 05b5cc7dbe4d2b41977751599
5b5cc7dbe4d2b41977751599- Show AnswerHide Answer
- Workspace
- SingleChoice
Answer :
Explanation :
Both these are used to combine the results of different SELECT statements. UNION - Selects only distinct values UNION ALL - Selects duplicate values also Syntax: SELECT column_name(s) FROM table1 UNION / UNION ALL SELECT column_name(s) FROM table2; Notice that each SELECT statement within the UNION must have the same number of columns. The columns must also have similar data types. Also, the columns in each SELECT statement must be in the same order.

