Java and C Programming Quiz

Test your knowledge of Java and C programming languages including collections, threading, networking, pointers, memory management, and synchronization.

20 Questions Published

Questions

Question 1 Multiple Choice (Multiple Answers)

Which of the following statements are true about synchronization? choose two

  1. Static methods cannot be synchronized
  2. Synchronized methods cannot make calls to non-synchronized methods
  3. A synchronized method can be overridden to be non-synchronized and vice versa
  4. When a thread is executing a synchronized method, other threads can freely access non-synchronized methods of the same object
Question 2 Multiple Choice (Single Answer)

char * Name[] = { "Ritesh", "Kumar" "Singh", "Happy", "Bittoo" "Roshan", "Go", }; How many elements does the array dwarves (declared above) contain?

  1. 4
  2. 5
  3. 6
  4. 7
Question 3 Multiple Choice (Single Answer)

void Free( struct node *ptr ) { while( ptr) { ???? } } Which one of the following can replace the ???? for the function above to release the memory allocated to a linked list?

  1. n = n->next; free( n );
  2. struct node m = n; n = n->next; free( m );
  3. free( n ); n = n->next;
  4. struct node m = n; free( m ); n = n->next;
Question 4 Multiple Choice (Single Answer)

int n = 0; for ( ; ; ) { if (n++ == 5) break; continue; } printf("x=%d\n", x); What will be printed when the sample code above is executed?

  1. 1
  2. 2
  3. 4
  4. 6
Question 5 Multiple Choice (Single Answer)

struct customer *p= malloc( sizeof( struct customer ) ); Given the sample allocation for the pointer "p" found above, which one of the following statements is used to reallocate ptr to be an array of 10 elements?

  1. p = realloc( ptr, 10 * sizeof( struct ritesh));
  2. realloc( ptr, 9 * sizeof( struct ritesh) );
  3. p+= malloc( 9 * sizeof( struct ritesh) );
  4. p = realloc( ptr, 9 * sizeof( struct ritesh) );
Question 6 Multiple Choice (Multiple Answers)

Which one of the following will declare a pointer to an integer at address 0x100 in memory?

  1. int *p; *p = 0x200;
  2. int *p = &0x200;
  3. int *p = *0x200;
  4. int *p = 0x200;
Question 7 Multiple Choice (Single Answer)

Sockets provide an interface for programming networks in which layer?

  1. Application
  2. Network
  3. Transport
  4. Physical
Question 8 True/False

Socket – based communication is programming language independent.

  1. True
  2. False
Question 9 Multiple Choice (Single Answer)

Using which class,A server can be implemented?

  1. Server in java.net package
  2. ServerSocket in java.util.package
  3. Server in java.util package
  4. ServerSocket in java.net package
Question 10 Multiple Choice (Single Answer)

If a client is run, when the server is not up

  1. Null Pointer Exception at client side
  2. Client will receive warning message
  3. ConnectException is thrown
  4. Compilation Error
Question 11 Multiple Choice (Single Answer)

The assigned port at the server can be obtained in the client side by

  1. getLocalPort() method
  2. getActivePort() method
  3. By pinging the server
  4. By giving value 0 as port number
Question 12 Multiple Choice (Single Answer)

Which one of the following is not marker interface?

  1. Serializable
  2. Remote
  3. Cloneable
  4. List
Question 13 Multiple Choice (Single Answer)

Which algorithm is used in thread scheduling?

  1. Fixed Priority
  2. Round Robin
  3. Discrete Optimization
  4. None of the above
Question 14 Multiple Choice (Single Answer)

Which modifier tells JVM to avoid object persistence during serialization?

  1. final
  2. transient
  3. public
  4. private
Question 15 Multiple Choice (Single Answer)

What is the super class of Hashtable?

  1. Map
  2. HashMap
  3. Dictionary
  4. Vector
Question 16 True/False

Main is the only thread that runs when a Java program is started?

  1. True
  2. False
Question 17 Multiple Choice (Single Answer)

Which of the following does not guarantee the order of data storage will be constant over a period of time?

  1. HashMap
  2. ArrayList
  3. Stack
  4. Queue
Question 18 True/False

Iterator for a collection will update along with the collection, when it is modified and give the updated one while traversing.

  1. True
  2. False
Question 19 Multiple Choice (Single Answer)

What is the result of compiling and running the following program? import java.util.Formatter; class Format2 { public static void main(String[] args) { String s="hello123"; Formatter f=new Formatter(); f.format("%S",s); System.out.println(f); } }

  1. Prints "hello123"
  2. Prints "HELLO123"
  3. Compiler error
  4. IllegalFormatException
Question 20 Multiple Choice (Single Answer)

What is the result of compiling and running the following code ? 1. StringBuffer s1=new StringBuffer("hello"); 2. StringBuffer s2=new StringBuffer("hello"); 3. Float f1=9.0F; 4. Double f2=9.0; 5. System.out.print(f1.equals(f2)); 6. System.out.print(s1==s2); 7. System.out.print(s1.equals(s2));

  1. Prints "truetruetrue"
  2. Prints "falsefalsetrue"
  3. Prints "falsefalsefalse"
  4. Compiler error on line 5
  5. Compiler error on line 7
  6. None