Java and C Programming Quiz
Test your knowledge of Java and C programming languages including collections, threading, networking, pointers, memory management, and synchronization.
Questions
Which of the following statements are true about synchronization? choose two
- Static methods cannot be synchronized
- Synchronized methods cannot make calls to non-synchronized methods
- A synchronized method can be overridden to be non-synchronized and vice versa
- When a thread is executing a synchronized method, other threads can freely access non-synchronized methods of the same object
char * Name[] = { "Ritesh", "Kumar" "Singh", "Happy", "Bittoo" "Roshan", "Go", }; How many elements does the array dwarves (declared above) contain?
- 4
- 5
- 6
- 7
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?
- n = n->next; free( n );
- struct node m = n; n = n->next; free( m );
- free( n ); n = n->next;
- struct node m = n; free( m ); n = n->next;
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
- 2
- 4
- 6
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?
- p = realloc( ptr, 10 * sizeof( struct ritesh));
- realloc( ptr, 9 * sizeof( struct ritesh) );
- p+= malloc( 9 * sizeof( struct ritesh) );
- p = realloc( ptr, 9 * sizeof( struct ritesh) );
Which one of the following will declare a pointer to an integer at address 0x100 in memory?
- int *p; *p = 0x200;
- int *p = &0x200;
- int *p = *0x200;
- int *p = 0x200;
Sockets provide an interface for programming networks in which layer?
- Application
- Network
- Transport
- Physical
Socket – based communication is programming language independent.
- True
- False
Using which class,A server can be implemented?
- Server in java.net package
- ServerSocket in java.util.package
- Server in java.util package
- ServerSocket in java.net package
If a client is run, when the server is not up
- Null Pointer Exception at client side
- Client will receive warning message
- ConnectException is thrown
- Compilation Error
The assigned port at the server can be obtained in the client side by
- getLocalPort() method
- getActivePort() method
- By pinging the server
- By giving value 0 as port number
Which one of the following is not marker interface?
- Serializable
- Remote
- Cloneable
- List
Which algorithm is used in thread scheduling?
- Fixed Priority
- Round Robin
- Discrete Optimization
- None of the above
Which modifier tells JVM to avoid object persistence during serialization?
- final
- transient
- public
- private
What is the super class of Hashtable?
- Map
- HashMap
- Dictionary
- Vector
Main is the only thread that runs when a Java program is started?
- True
- False
Which of the following does not guarantee the order of data storage will be constant over a period of time?
- HashMap
- ArrayList
- Stack
- Queue
Iterator for a collection will update along with the collection, when it is modified and give the updated one while traversing.
- True
- False
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); } }
- Prints "hello123"
- Prints "HELLO123"
- Compiler error
- IllegalFormatException
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));
- Prints "truetruetrue"
- Prints "falsefalsetrue"
- Prints "falsefalsefalse"
- Compiler error on line 5
- Compiler error on line 7
- None