java
java
ans: A thread is the smallest unit of execution in a program. It is a lightweight process that
runs within the context of a larger process and shares the process’s resources (such as
memory and file handles). Multiple threads within the same process can execute
concurrently, allowing efficient multitasking.
Threads are used to perform multiple operations simultaneously, like handling user input
while performing calculations or downloading data in the background.
New (Created)
• A thread is in this state when it is created using a constructor, like Thread t = new
Thread();
Example (Java):
java
CopyEdit
2. Runnable
• When you call start(), the thread enters the Runnable state.
3. Running
• Only one thread can run on a core at a time, but many can be in the Runnable pool.
4. Blocked
• A thread enters the Blocked state when it tries to access a synchronized section of
code that's locked by another thread.
5. Waiting
• A thread is in the Waiting state when it waits indefinitely for another thread to
perform a task (e.g., notify it).
Que 2:
1. Syntax Errors
Definition:
Errors that occur when the rules (syntax) of the programming language are violated.
Examples:
java
CopyEdit
python
CopyEdit
2. Runtime Errors
Definition:
Errors that occur while the program is running.
• These are typically caused by illegal operations (e.g., dividing by zero, accessing
invalid memory).
Examples:
• Division by zero
• Null reference errors
Java Example:
java
CopyEdit
Python Example:
python
CopyEdit
3. Logical Errors
Definition:
Errors where the program runs without crashing but produces incorrect or unexpected
results.
Example:
java
CopyEdit
python
CopyEdit
def square(n):
• Split into:
try {
int a = 10;
int b = 0;
} catch (ArithmeticException e) {
}
Que 4:
Que 5:
Que 6:
• Button
• Label
• TextField
• TextArea
• Checkbox
• CheckboxGroup
• JButton
• JLabel
• JTextField
• JText
Que 7:
import javax.swing.*;
import java.awt.event.*;
// Create frame
comboBox.addActionListener(new ActionListener() {
});
// Add components to frame
frame.add(comboBox);
frame.add(label);
frame.setSize(300, 200);
frame.setLayout(null);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Que 8:
9:
A proxy server is an intermediate server that sits between a client (user) and the
destination server (like a website). It receives the client's request, forwards it to the
destination, gets the response, and sends it back to the client.
11:
1. getProtocol()
2. getHost()
3. getPort()
4. getDefaultPort()
o Returns the default port for the protocol (e.g., 443 for HTTPS).
5. getPath()
6. getFile()
7. getQuery()
8. getRef()
9. openConnection()
12
The finally block is a part of Java's exception handling mechanism that is used to execute
important code like cleanup code, resource releasing, and closing files or connections.
It is executed after the try and catch blocks, regardless of whether an exception was
thrown or not.
• Files
• Database connections
• Network sockets