0% found this document useful (0 votes)
2 views10 pages

Assignment Solution 10

This document contains an assignment for the NPTEL Online Certification Course on Programming in Java, featuring 10 multiple-choice questions related to Java concepts and components. Each question includes the correct answer and a detailed solution explaining the reasoning behind it. The topics covered include Swing components, SQL usage, networking, and database connections in Java.

Uploaded by

Haf hafeefa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views10 pages

Assignment Solution 10

This document contains an assignment for the NPTEL Online Certification Course on Programming in Java, featuring 10 multiple-choice questions related to Java concepts and components. Each question includes the correct answer and a detailed solution explaining the reasoning behind it. The topics covered include Swing components, SQL usage, networking, and database connections in Java.

Uploaded by

Haf hafeefa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

NPTEL Online Certification Courses

Indian Institute of Technology Kharagpur


NOC25-CS57 (JAN-2025 25S)

PROGRAMMING IN JAVA
Assignment 10
TYPE OF QUESTION: MCQ
Number of questions: 10 Total marks: 10 × 1 = 10

QUESTION 1:

Which Swing component is used to create a button?

JLabel

JButton

JTextField

JPanel

Correct Answer:

JButton

Detailed Solution:

JButton is used to create a clickable button in a Swing-based GUI.


NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 2:

What does a toggle button in Java do?

It switches between two states, like on/off or enabled/disabled.

It only changes the color of the button when clicked.

It displays text inside the button.

It opens a new window when clicked.

Correct Answer:

It switches between two states, like on/off or enabled/disabled.

Detailed Solution:

A toggle button allows users to switch between two states, such as "on" or "off." It behaves like a
checkbox, but it is represented as a button.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 3:

What is the primary purpose of SQL(Structured Query Language) in Java application ? Commented [NP1]: Already given in W11, requesting to
change the question
To create and amange user interfaces Commented [DM2R1]: Thanks , question changed.

To interact with databases for data retrieval and manipulation

To performa systme-level operation like file management

To handle memory allocation in Java programs

Correct Answer:

To interact with databases for data retrieval and manipulation

Detailed Solution:

SQL is used in Java applications primarily to connect to databases, retrieve data, update records, and
perform other database operations, making it essential for handling data within applications.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 4:

Which method is used in Java to check if a network interface is up and running?

isActive()

isUp()

isRunning()

isConnected()

Correct Answer:

isUp()

Detailed Solution:

In Java, the isUp() method is used to check whether a network interface is up and running. This
method is part of the NetworkInterface class from the java.net package.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 5:

Which of the following are considered as basic networking components in Java?

Socket and ServerSocket

String and Integer

JFrame and Jbutton

Scanner and System

Correct Answer:

Socket and ServerSocket

Detailed Solution:

In Java, Socket and ServerSocket are the primary components used for establishing client-server
communication. These classes belong to the java.net package and are fundamental to networking in
Java. String, Integer, JFrame, JButton, Scanner, and System are not used for basic networking
functionality.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 6:

In context of the following URL, identify the correct option.

https://nptel.ac.in

There is no protocol provided in the above link.

The website provides a secure connection.

The given link is incomplete and hence cannot open a website.

The ac.in refers to the domain.

Correct Answer:

The website provides a secure connection.

Detailed Solution:

Resource name is nptel.ac.in. The protocol used is https and hence provides a secure connection to the
website. The link is complete in all aspects and hence can open a website (if hosted). The ac.in portion of
the website is top-level domain part and not a path.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 7:

Which of the following is/are application layer protocol(s)?

TCP

UDP

ARP

SMTP

Correct Answer:

SMTP

Detailed Solution:

TCP, UDP are transport layer protocols. ARP is a Network - IP layer protocol. SMTP is Application layer
protocol.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 8:

What does this Java code snippet do?

import java.sql.*;

public class NPTEL {


public static void main(String[] args) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/mydatabase",
"username", "password");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM employees");
while (rs.next()) {
System.out.println(rs.getString(1)+" "+rs.getString(2));
}
con.close();
} catch (Exception e) {
System.out.println(e);
}
}
}

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

Correct Answer:

a. Connects to a MySQL database, retrieves data from the "employees" table, and prints it

Detailed Solution:

The code snippet establishes a connection to a MySQL database, executes a SELECT query to retrieve
data from the "employees" table, and prints the results.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 9:

Which class provides methods to work with URLs?

a. URLConnection

b. HttpURL

c. NetURL

d. URL

Correct Answer:

d. URL

Detailed Solution:

The URL class provides methods to work with Uniform Resource Locators.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 10:

Which class in Java is used to create a server socket?

Socket

ServerSocket

DatagramSocket

HttpURLConnection

Correct Answer:

b. ServerSocket

Detailed Solution:

ServerSocket is used to listen for incoming connections on a specific port, enabling communication
with clients in server-client applications.

You might also like