Programming Languages and Threading Concepts
Test your knowledge of programming languages by identifying code snippets and understanding threading concepts in Java.
Questions
program helloworld(output); var I: Integer; begin WriteLn('Hello, World!'); for I := 1 to 10 do WriteLn(I); end
- C
- PASCAL
- ADA
- LISP
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.
- COBOL
- LISP
- FORTRAN
- BASIC
with Text_To; use Text_To procedure hello is begin put("Hello World"); end hello
- LISP
- PROLOG
- ADA
- BASIC
hello_world :- write('Hello World!').
- PROLOG
- PYTHON
- PASCAL
- PERL
C++ main() { cout << "Hello World!"; return 0; }
- C
- JAVA
- C#
- C++
JAVA class myfirstprog { public static void main(String args[]) { System.out.println("Hello World!"); } }
- JAVA
- Visual BASIC
- C++
- C#
Identify the programming language
- PERL
- LISP
- FORMAC
- LOGO
int main() { printf("hello, world"); return 0; }
- C++
- C-
- C
- C#
10 PRINT "Hello World!" 20 GOTO 10
- PYTHON
- Z
- CSP
- BASIC
PROGRAM HELLO WRITE(,) 'Hello World' END PROGRAM
- ALGOL
- FORTRAN
- COBRA
- IDL
main() { cout << "Hello World!"; return 0; }
- C#
- C++
- JAVA
- C
class myfirstprog { public static void main(String args[]) { System.out.println("Hello World!"); } }
- JAVA
- C#
- JavaScript
- PYTHON
Find a character in a string. Choose the correct one.
- substr
- find_first_of
- find_last_of
- compare
Find character in string from the end. Choose the correct one.
- find_last_of
- find_first_not_of
- data
- find
Append character to string
- erase
- copy
- push_back
- swap
Return size of allocated storage
- length
- size
- max_size
- capacity
Which of the following statements regarding threads is true?
- A thread dies as soon as the execution of the start() method ends.
- A thread's priority can be specified as an argument to its constructor
- A sleeping thread can be made runnable by invoking notify().
- A thread can call notify() on an object only if it holds the lock on that object.
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?
- Exactly 10 seconds after the start method is called, "Time's Up!" will be printed.
- Exactly 10 seconds after "Start!" is printed, "Time's Up!" will be printed.
- The delay between "Start!" being printed and "Time's Up!" will be 10 seconds plus or minus one tick of the system clock.
- If "Time's Up!" is printed you can be sure that at least 10 seconds have elapsed since "Start!" was printed.
There are 10 threads waiting for the lock of an object. How will you bring the 5th thread myThread out of the waiting state?
- By calling notify(5)
- By calling notifyAll()
- By calling myThread.notify()
- By calling notify(myThread)
- None of these
Which of the following statements regarding the wait() method are correct? choose three
- It is an instance method of Object class.
- It is a static method of the Object class
- It is an instance method of Thread class.
- The Thread must have a lock on the object on which the wait() method is to be invoked
- An object can have only one Thread in a waiting state at a time
- It must be called in a synchronized code