Programming Languages and Threading Concepts

Test your knowledge of programming languages by identifying code snippets and understanding threading concepts in Java.

20 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

program helloworld(output); var I: Integer; begin WriteLn('Hello, World!'); for I := 1 to 10 do WriteLn(I); end

  1. C
  2. PASCAL
  3. ADA
  4. LISP
Question 2 Multiple Choice (Single Answer)

000100 IDENTIFICATION DIVISION. 000200 PROGRAM-ID. HELLOWORLD. 000300 000400* 000500 ENVIRONMENT DIVISION. 000600 CONFIGURATION SECTION. 000700 SOURCE-COMPUTER. RM-COBOL. 000800 OBJECT-COMPUTER. RM-COBOL. 000900 001000 DATA DIVISION. 001100 FILE SECTION. 001200 100000 PROCEDURE DIVISION. 100100 100200 MAIN-LOGIC SECTION. 100300 BEGIN. 100400 DISPLAY " " LINE 1 POSITION 1 ERASE EOS. 100500 DISPLAY "Hello world!" LINE 15 POSITION 10. 100600 STOP RUN. 100700 MAIN-LOGIC-EXIT. 100800 EXIT.

  1. COBOL
  2. LISP
  3. FORTRAN
  4. BASIC
Question 3 Multiple Choice (Single Answer)

with Text_To; use Text_To procedure hello is begin put("Hello World"); end hello

  1. LISP
  2. PROLOG
  3. ADA
  4. BASIC
Question 4 Multiple Choice (Single Answer)

hello_world :- write('Hello World!').

  1. PROLOG
  2. PYTHON
  3. PASCAL
  4. PERL
Question 5 Multiple Choice (Single Answer)

C++ main() { cout << "Hello World!"; return 0; }

  1. C
  2. JAVA
  3. C#
  4. C++
Question 6 Multiple Choice (Single Answer)

JAVA class myfirstprog { public static void main(String args[]) { System.out.println("Hello World!"); } }

  1. JAVA
  2. Visual BASIC
  3. C++
  4. C#
Question 7 Multiple Choice (Single Answer)

Identify the programming language

  1. PERL
  2. LISP
  3. FORMAC
  4. LOGO
Question 8 Multiple Choice (Single Answer)

int main() { printf("hello, world"); return 0; }

  1. C++
  2. C-
  3. C
  4. C#
Question 9 Multiple Choice (Single Answer)

10 PRINT "Hello World!" 20 GOTO 10

  1. PYTHON
  2. Z
  3. CSP
  4. BASIC
Question 10 Multiple Choice (Single Answer)

PROGRAM HELLO WRITE(,) 'Hello World' END PROGRAM

  1. ALGOL
  2. FORTRAN
  3. COBRA
  4. IDL
Question 11 Multiple Choice (Single Answer)

main() { cout << "Hello World!"; return 0; }

  1. C#
  2. C++
  3. JAVA
  4. C
Question 12 Multiple Choice (Single Answer)

class myfirstprog { public static void main(String args[]) { System.out.println("Hello World!"); } }

  1. JAVA
  2. C#
  3. JavaScript
  4. PYTHON
Question 13 Multiple Choice (Single Answer)

Find a character in a string. Choose the correct one.

  1. substr
  2. find_first_of
  3. find_last_of
  4. compare
Question 14 Multiple Choice (Single Answer)

Find character in string from the end. Choose the correct one.

  1. find_last_of
  2. find_first_not_of
  3. data
  4. find
Question 15 Multiple Choice (Single Answer)

Append character to string

  1. erase
  2. copy
  3. push_back
  4. swap
Question 16 Multiple Choice (Single Answer)

Return size of allocated storage

  1. length
  2. size
  3. max_size
  4. capacity
Question 17 Multiple Choice (Single Answer)

Which of the following statements regarding threads is true?

  1. A thread dies as soon as the execution of the start() method ends.
  2. A thread's priority can be specified as an argument to its constructor
  3. A sleeping thread can be made runnable by invoking notify().
  4. A thread can call notify() on an object only if it holds the lock on that object.
Question 18 Multiple Choice (Single Answer)

You have created a TimeOut class as an extension of Thread, the purpose being to print a "Time's Up" message if the Thread is not interrupted within 10 seconds of being started. Here is the run method that you have coded. 1. public void run() 2. { 3. System.out.println("Start!"); 4. try 5. { 6. Thread.sleep(10000); 7. System.out.println("Time's Up!"); 8. } 9. catch(InterruptedException e) 10. { 11. System.out.println("Interrupted!"); 12. } 13. } Given that a program creates and starts a TimeOut object, which of the following statements is true?

  1. Exactly 10 seconds after the start method is called, "Time's Up!" will be printed.
  2. Exactly 10 seconds after "Start!" is printed, "Time's Up!" will be printed.
  3. The delay between "Start!" being printed and "Time's Up!" will be 10 seconds plus or minus one tick of the system clock.
  4. If "Time's Up!" is printed you can be sure that at least 10 seconds have elapsed since "Start!" was printed.
Question 19 Multiple Choice (Single Answer)

There are 10 threads waiting for the lock of an object. How will you bring the 5th thread myThread out of the waiting state?

  1. By calling notify(5)
  2. By calling notifyAll()
  3. By calling myThread.notify()
  4. By calling notify(myThread)
  5. None of these
Question 20 Multiple Choice (Multiple Answers)

Which of the following statements regarding the wait() method are correct? choose three

  1. It is an instance method of Object class.
  2. It is a static method of the Object class
  3. It is an instance method of Thread class.
  4. The Thread must have a lock on the object on which the wait() method is to be invoked
  5. An object can have only one Thread in a waiting state at a time
  6. It must be called in a synchronized code