Which of the following is a standard library in Python for mathematical functions?
A stdio
B os
C math
D file
In Python, the math module provides various mathematical functions like trigonometric operations, logarithms, and constants like pi. It is part of Python’s standard library, making it easy to perform complex mathematical operations.
Which of these functions is used to initialize a thread in Python’s threading module?
A start()
B run()
C execute()
D begin()
In Python’s threading module, the start() function is used to begin the execution of a thread. It calls the run() method internally, which contains the code to be executed by the thread.
In Java, which package is used for handling I/O operations?
A java.text
B java.util
C java.io
D java.lang
In Java, the java.io package provides classes for system input and output, including reading from and writing to files. Classes like FileReader, BufferedReader, and FileWriter are part of this package.
What is the role of the threading module in Python?
A To manage files
B To handle exceptions
C To perform string operations
D To enable multithreading
In Python, the threading module allows you to create and manage multiple threads, enabling concurrent execution. It is used to perform tasks concurrently without blocking the main program execution.
What does the print() function in Python do?
A Prints text to the screen
B Returns output
C Reads user input
D Handles errors
The print() function in Python is used to display the output to the console or terminal. It prints text, variables, or any other data type to the standard output.
Which of the following is a tool used for debugging in C?
A printf()
B log()
C debug()
D gdb
gdb (GNU Debugger) is a powerful tool used in C for debugging. It allows developers to examine and control the execution of their program, helping to identify and fix bugs in the code.
Which of these is used to create a file in Python?
A fcreate()
B open()
C file()
D newfile()
In Python, the open() function is used to create and open files. You can specify the mode (e.g., read, write) and interact with the file content using methods like read(), write(), and close().
What is the default mode of opening a file in Python?
A Write mode
B Append mode
C Read mode
D Binary mode
By default, Python opens files in read mode (r). This allows you to read the file content. To write or append to a file, you would need to specify w or a modes, respectively.
In Java, how do you create a new thread?
A By using new Thread()
B By extending Thread
C Both A and B
D By implementing Runnable
In Java, a new thread can be created either by extending the Thread class and overriding its run() method or by implementing the Runnable interface and passing it to a Thread object.
Which of these is the correct way to handle an exception in Java?
A try {catch}
B throw (Exception e)
C catch (Exception e)
D finally (Exception e)
In Java, exceptions are handled using the try-catch block. The catch (Exception e) part catches exceptions of the specified type and allows you to handle them appropriately, ensuring the program doesn’t crash.
Which of these is a method used to stop a thread in Python?
A join()
B terminate()
C end()
D stop()
In Python, the join() method is used to wait for a thread to finish execution. While it doesn’t directly stop a thread, it ensures that the program waits for the thread to complete before continuing.
In C, which function is used to free dynamically allocated memory?
A malloc()
B free()
C alloc()
D delete()
In C, free() is used to deallocate memory that was previously allocated using malloc() or calloc(). This is important to prevent memory leaks, as it releases unused memory back to the system.
What is the primary purpose of the Thread.sleep() method in Java?
A Create a new thread
B Resume thread execution
C Pause thread execution
D Terminate the thread
In Java, Thread.sleep() is used to pause the execution of the current thread for a specified period. This method is useful for creating delays in a multithreaded environment.
In Python, how do you import the os module?
A include os
B from os import *
C use os
D import os
In Python, you import the os module using import os. The os module provides a way of interacting with the operating system, including file manipulation and environment variables.
In Java, how do you start a new thread using Runnable?
A Thread.start(new Runnable())
B new Runnable()
C Thread.run()
D Thread.execute(Runnable)
In Java, to create a new thread using the Runnable interface, you first create an instance of Runnable and pass it to a Thread object. Then, call start() on the Thread object to begin execution.