Saturday 22 January 2011

c programming examples

Example 1 - C hello world program
/* A very simple c program printing a string on screen*/

#include<stdio.h>
 
main()
{
    printf("Hello World\n");
    return 0;
}

Output of above program:
"Hello World" Example 2 - c program to take input from user using scanf

#include<stdio.h>
 
main()
{
   int number;
 
   printf("Enter a number\n");
   scanf("%d",&number);
 
   printf("Number entered by you is %d\n", number);
 
   return 0;
}

Output:
Enter a number
5
Number entered by you is 5 Example 3 - using if else control instructions

#include<stdio.h>
 
main()
{
   int x = 1;
 
   if ( x == 1 )
      printf("x is equal to one.\n");
   else
      printf("For comparison use == as = is the assignment operator.\n");
 
   return 0;
}

Output:
x is equal to one. Example 4 - loop example
#include<stdio.h>
 
main()
{
   int value = 1;
 
   while(value<=3)
   {
      printf("Value is %d\n", value);
      value++;
   }
 
   return 0;
}
Output:
Value is 1
Value is 2
Value is 3
Example 5 - c program for prime number

#include<stdio.h>
 
main()
{
   int n, c;
 
   printf("Enter a number\n");
   scanf("%d", &n);
 
   if ( n == 2 )
      printf("Prime number.\n");
   else
   {
       for ( c = 3 ; c <= n - 1 ; c++ )
       {
           if ( n % c == 0 )
              break;
       }
       if ( c != n )
          printf("Not prime.\n");
       else
          printf("Prime number.\n");
   }
   return 0;
}
Example 6 - command line arguments

#include<stdio.h>
 
main(int argc, char *argv[])
{
   int c;
 
   printf("Number of command line arguments passed: %d\n", argc);
 
   for ( c = 0 ; c < argc ; c++)
      printf("%d. Command line argument passed is %s\n", c+1, argv[c]);
 
   return 0;
}

Above c program prints the number and all arguments which are passed to it. Example 7 - Array program

#include<stdio.h>
 
main() 
{
    int array[100], n, c;
 
    printf("Enter the number of elements in array\n");
    scanf("%d", &n);
 
    printf("Enter %d elements\n", n);
 
    for ( c = 0 ; c < n ; c++ ) 
        scanf("%d", &array[c]);
 
    printf("Array elements entered bu you are:\n");
 
    for ( c = 0 ; c < n ; c++ ) 
        printf("array[%d] = %d\n", c, array[c]);
 
    return 0;
}
Example 8 - function program

#include<stdio.h>
 
void my_function();
 
main()
{
   printf("Main function.\n");
 
   my_function();
 
   printf("Back in function main.\n");
 
   return 0;
}
 
void my_function()
{
   printf("Welcome to my function. Feel at home.\n");
}
Example 9 - Using comments in a program

#include<stdio.h>
 
main()
{
   // Single line comment in c source code
 
   printf("Writing comments is very useful.\n");
 
   /*
    * Multiline comment syntax
    * Comments help us to understand code later easily.
    * Will you write comments while developing programs ?
    */
 
   printf("Good luck\n"); 
 
   return 0;
}
Example 10 - using structures in c programming

#include<stdio.h>
 
struct programming
{
    float constant;
    char *pointer;
};
 
main()
{
   struct programming variable;
   char string[] = "Programming in Software Development.";
 
 
   variable.constant = 1.23;
   variable.pointer = string;
 
   printf("%f\n", variable.constant);
   printf("%s\n", variable.pointer);
 
   return 0;
}
Example 11 - c program for fibonacci series

#include<stdio.h>
#include<conio.h>
 
main()
{
   int n, first = 0, second = 1, next, c;
 
   printf("Enter the number of terms ");
   scanf("%d",&n);
 
   printf("First %d terms of fibonacci series are :-\n",n);
 
   for ( c = 0 ; c < n ; c++ )
   {
      if ( c <= 1 )
         next = c;
      else
      {
         next = first + second;
         first = second;
         second = next;
      }
      printf("%d\n",next);
   }
 
   getch();
   return 0;
}
Example 12 - c graphics programming

#include <graphics.h>
#include<conio.h>
 
main()
{
    int gd = DETECT, gm;
 
    initgraph(&gd, &gm,"C:\\TC\\BGI");
 
    outtextxy(10,20, "Graphics source code example.");
 
    circle(200, 200, 50);
 
    setcolor(BLUE);
 
    line(350, 250, 450, 50);
 
    getch();
    closegraph( );
    return 0;
}

For gcc compiler users

If you are using gcc compiler on linux operating system then you need to modify programs. For example consider the following programs which prints first ten natural numbers
#include<stdio.h>
#include<conio.h>
 
main()
{
    int c;
 
    for ( c = 1 ; c <= 10 ; c++ )
        printf("%d\n", c);
 
    getch();
    return 0;
}
Above source code includes a header file <conio.h> and uses function getch, but this file is Borland specific so it works in turbo c compiler but not in gcc. So the code for gcc should be like
#include<stdio.h>
 
main()
{
    int c;
 
    /* for loop */
 
    for ( c = 1 ; c <= 10 ; c++ )
        printf("%d\n", c);
 
    return 0;
}
If using gcc compiler save the code in a file say numbers.c, to compile the program open the terminal and enter command gcc numbers.c, this will compile the program and to execute the program enter command ./a.out .

Monday 17 January 2011

Telecommunications interview questions

A well-known telecommunications company uses this pop quiz for oral and written examinations of applicants for engineering positions.
1. A 2MB PCM(pulse code modulation) has…
a) 32 channels
b) 30 voice channels & 1 signaling channel.
c) 31 voice channels & 1 signaling channel.
d) 32 channels out of which 30 voice channels, 1 signaling channel, & 1 synchronization channel.
Ans: c

2. Time taken for 1 satellite hop in voice communication is…
a) 1/2 second
b) 1 seconds
c) 4 seconds
d) 2 seconds
Ans: (a)
3. Max number of satellite hops allowed in voice communication is:
a) only one
b) more han one
c) two hops
d) four hops
Ans: (c)
4. What is the maximal decimal number that can be accommodated in a byte?
a) 128
b) 256
c) 255
d) 512
Ans: (c)
5. Conditional results after execution of an instruction in a micro processor is stored in…
a) register
b) accumulator
c) flag register
d) flag register part of PSW(Program Status Word)
Ans: (d)
6. Frequency at which VOICE is sampled is…
a) 4 KHz
b) 8 KHz
c) 16 KHz
d) 64 KHz
Ans: (a)
7. Line of sight is…
a) Straight Line
b) Parabolic
c) Tx & Rx should be visible to each other
d) none of the above
Ans: (c)
8. Purpose of PC(Program Counter) in a MicroProcessor is…
a) To store address of TOS(Top Of Stack)
b) To store address of next instruction to be executed.
c) count the number of instructions.
d) to store base address of the stack.
Ans: (b)
9. What action is taken when the processor under execution is interrupted by a non-maskable interrupt?
a) Processor serves the interrupt request after completing the execution of the current instruction.
b) Processor serves the interrupt request after completing the current task.
c) Processor serves the interrupt request immediately.
d) Processor serving the interrupt request depends upon the priority of the current task under execution.
Ans: (a)
10. The status of the Kernel is…
a) task
b) process
c) not defined.
d) none of the above.
Ans: (b)
11. What is the nominal voltage required in subscriber loop connected to local exchange?
a) +48 volts
b) -48 volts
c) 230 volts
d) 110 volts
12. To send a data packet using datagram , connection will be established…
a) before data transmission.
b) connection is not established before data transmission.
c) no connection is required.
d) none of the above.
Ans: (c)
13. Word alignment is…
a) aligning the address to the next word boundary of the machine.
b) aligning to an even boundary.
c) aligning to a word boundary.
d) none of the above.
Ans: (a)
14. When a C function call is made, the order in which parameters passed to the function are pushed into the stack is…
a) left to right
b) right to left
c) bigger variables are moved first than the smaller variales.
d) smaller variables are moved first than the bigger ones.
e) none of the above.
Ans: (b)
15. What is the type of signaling used between two exchanges?
a) inband
b) common channel signaling
c) any of the above
d) none of the above.
Ans: (a)
16. Buffering is…
a) the process of temporarily storing the data to allow for small variation in device speeds
b) a method to reduce cross talks
c) storage of data within transmitting medium until the receiver is ready to receive.
d) a method to reduce routing overhead.
Ans: (a)
17. Memory allocation of variables declared in a program is…
a) allocated in RAM.
b) allocated in ROM.
c) allocated on stack.
d) assigned to registers.
Ans: (c)
18. A software that allows a personal computer to pretend as a computer terminal is …
a) terminal adapter
b) bulletin board
c) modem
d) terminal emulation
Ans: (d)

Friday 7 January 2011

General Java Servlet questions

  1. What is the servlet?
  2. What are the JSP atrributes?
  3. What is the need of super.init(config) in servlets?
  4. How to know whether we have to use jsp or servlet in our project?
  5. Can we call destroy() method on servlets from service method?
  6. What is the Servlet Interface?
  7. What is the difference between GenericServlet and HttpServlet?
  8. How we can check in particular page the session will be alive or not?
  9. What is the importance of deployment descriptor in servlet?
  10. When we increase the buffer size in our project using page directive attribute ‘buffer’ what changes we observe?
  11. What is the difference between ServetConfig and ServletContext..?
  12. When a servlet accepts a call from a client, it receives two objects. What are they?
  13. What are the differences between GET and POST service methods?
  14. In which conditions we have to use the ServletContext?
  15. What methods will be called in which order?((i.e)service(),doget(),dopost())
  16. Servlet is Java class. Then why there is no constructor in Servlet? Can we write the constructor in Servlet
  17. What is the use of ServletConfig and ServletContext..?
  18. What information that the ServletRequest interface allows the servlet access to?
  19. What is the difference between ServletContext and ServletConfig?
  20. When do you have action=get?
  21. What is a Singleton class. How do you write it?
  22. What is difference between sendRedirect() and forward()..? Which one is faster then other and which works on server?
  23. What information that the ServletResponse interface gives the servlet methods for replying to the client?
  24. Can I invoke a JSP error page from a servlet?
  25. Can a init(ServletConfig config) method be overrided in servlets?
  26. How many ServletConfig and servlet context objects are present in one application?
  27. Do we have a constructor in servlet? can we explictly provide a constructor in servlet programme as in java program?
  28. What are the uses of Servlets?
  29. Can I just abort processing a JSP?
  30. Is servlet is used to create a dynamic webpage or Static webpage or both?
  31. If you want a servlet to take the same action for both GET and POST request, what should you do?
  32. What is the difference between JSP and SERVLETS?
  33. What are the advantages using servlets than using CGI?
  34. What is a better approach for enabling thread-safe servlets and JSPs? SingleThreadModel Interface or synchronization?
  35. We have two applications in that we have two servlets each.How they(servlets) communicate with each other?
  36. How the server will know (i.e) when it can invoke init, service,destroy methods of servlet life cycle?
  37. How to communicate between two servlets?
  38. What is the difference between servlets and applets?
  39. How will u pass the argument from one servlet to another servlet?
  40. What method used to add a jsp to the servlet?
  41. How HTTP Servlet handles client requests?
  42. How to get one Servlet’s Context Information in another Servlet?
  43. Difference between single thread and multi thread model servlet
  44. What is the super class of All servlets?
  45. How are Servlet Applet communication achieved?
  46. What is servlet context and what it takes actually as parameters?
  47. What is the servlet life cycle?
  48. Types of Servlets?
  49. Why is that we deploy servlets in a webserver.What exactly is a webserver?
  50. Which code line must be set before any of the lines that use the PrintWriter?

Monday 3 January 2011

10 questions on MySQL speed-up and optimizations

Jay Pipes, author of Pro MySQL, on his blog posts 10 questions and answers dealing with MySQL speed optimizations.
  1. Which will be faster out of these two queries - one with OR or one with IN?
  2. Where does MyISAM cache table records?
  3. Which will be faster out of queries with explicit INNER JOIN and implicit one?
  4. Is InnoDB faster/better than MyISAM?
  5. Is CHAR faster than VARCHAR?
  6. Is VARCHAR(80) faster than VARCHAR(255)?
  7. Are there performance issues when joining tables from different storage engines?
  8. If I change a derived table to a view, will performance increase?
  9. If I see Using temporary; Using filesort” in the Extra column of EXPLAIN output, does that mean a temporary table is created on disk?
  10. Is it possible to do a FULL OUTER JOIN in MySQL?

Saturday 1 January 2011

Simple Java questions

  1. Meaning - Abstract classes, abstract methods
  2. Difference - Java,C++
  3. Difference between == and equals method
  4. Explain Java security model
  5. Explain working of Java Virtual Machine (JVM)
  6. Difference: Java Beans, Servlets
  7. Difference: AWT, Swing
  8. Disadvantages of Java
  9. What is BYTE Code ?
  10. What gives java it’s “write once and run anywhere” nature?
  11. Does Java have “goto”?
  12. What is the meaning of “final” keyword?
  13. Can I create final executable from Java?
  14. Explain Garbage collection mechanism in Java
  15. Why Java is not 100% pure object oriented language?
  16. What are interfaces? or How to support multiple inhertance in Java?
  17. How to use C++ code in Java Program?
  18. Difference between “APPLET” and “APPLICATION”

Search here for "Freshers Jobs"