Programming In Java Week 10 NPTEL Assignment Answers 2025

NPTEL Programming In Java Week 10 Assignment Answers 2024

1. Which class provides methods to work with URLs?
a. URLConnection
b. HttpURL
c. NetURLg
d. URL

Answer :- d
Explanation: The URL class in Java is used to represent a Uniform Resource Locator and provides methods to access the resource at the URL.


2. What does the following code do?
a. Creates a JFrame with a JButton labeled “Programming in Java”
b. Compiles with errors
c. Displays a message dialog
d. Creates a JPanel with a JButton labeled “Programming in Java”

Answer :- a
Explanation: The code creates a JFrame window and adds a JButton to it with the label “Programming in Java”. It’s a basic GUI window setup.


3. What happens when the button in this Java code snippet is clicked?
a. The program exits
b. A message dialog with the text “Welcome to the course” is displayed
c. The button label changes to “Welcome to the course”
d. Nothing happens

Answer :- b
Explanation: The button’s action listener triggers a JOptionPane.showMessageDialog() call when clicked, which displays a dialog box with the message.


4. What GUI component is used to input the password in this Java code snippet?
a. JTextField
b. JButton
c. JtextArea
d. JPasswordField

Answer :- d
Explanation: JPasswordField is the correct Swing component used for accepting password inputs, hiding the characters as they’re typed.


5. What does this Java code snippet create?
a. A frame with a list of colors displayed as buttons
b. A frame with a combo box containing options “Red”, “Green”, and “Blue”
c. A frame with radio buttons for selecting colors
d. A frame with checkboxes for selecting colors

Answer :- b
Explanation: The code creates a GUI with a JComboBox containing the options “Red”, “Green”, and “Blue”.


6. What does this Java code snippet do?
a. Just prints the IP address of the local machine
b. Prints the IP address and host name of the local machine
c. Prints the IP address and host name of “nptel.ac.in”
d. Just prints the IP address of “nptel.ac.in”

Answer :- c
Explanation: The code is likely using InetAddress.getByName("nptel.ac.in") which returns the host name and IP address of that domain.


7. What does this Java code snippet do?
a. Connects to a MySQL database, retrieves data from the “employees” table, and prints it
b. Inserts data into the “employees” table of a MySQL database
c. Deletes data from the “employees” table of a MySQL database
d. Updates data in the “employees” table of a MySQL database

Answer :- a
Explanation: The code contains JDBC logic that performs a SELECT query, which fetches and prints data from the “employees” table.


8. What does this Java code snippet do?
a. Retrieves data from the “employees” table
b. Inserts a new employee record into the “employees” table
c. Updates employee records in the “employees” table
d. Deletes employee records from the “employees” table

Answer :- b
Explanation: The code includes a SQL INSERT statement that adds a new row into the “employees” table using JDBC.


9. What additional code is needed at #1 to complete this Java program to send a message?
a. socket.recieve(packet);
b. Socket.Send(packet);
c. Socket.send(packet);
d. socket.send(packet);

Answer :- d
Explanation: The correct syntax in Java for sending data through a Datagram socket is socket.send(packet);. The other options are invalid or incorrect due to casing or misspelling.


10. What is missing in this Java program?
a. Retrieving the number of employees
b. Deleting employee records
c. Updating employee records
d. Importing necessary JDBC libraries

Answer :- d
Explanation: JDBC operations require importing libraries such as java.sql.*. Without these imports, the program will not compile properly.