Programming In Java | Week 10
Programming In Java Week 10 Answers NPTEL
Quiz
Q1. Which of the following statement(s) is(are) true?
a. TCPis not reliable.
b. UDP is most reliable.
c. TCPis fast and UDP is slow.
d. In HTTPS, all communication between two computers are encrypted.
Q2. Which of the following statement(s) is/are true?
a. DatagramSocket implements Object.
b. DatagramSocket implements Closeable.
c. DatagramSocket extends Object.
d. DatagramSocket extends Closeable.
e. DatagramSocket extends Object implements Closeable
Q3. Which of the following is/are interface(s) present in java.net package?
a. InterfaceAddress
b. FileNameMap
c. DatagramPacket
d. DatagramSocket
Q4. Which of the following statement(s) is/are true?
a. Addresses belongs to a Low-Level API.
b. Sockets belong to High-Level API.
c. URIs and URLs are Low-Level API.
d. Interfaces are High-Level API.
Q5. In context of the following URL, identify the correct option.
https://nptel.ac.in
a. There is no protocol provided in the above link.
b. The website provides a secure connection.
c. The given link is incomplete and hence cannot open a website.
d. The ac.in refers to the website path.
Q6. Which of the following is/are application layer protocol(s)?
a. TCP
b. UDP
c. ARP
d. SMTP
Q7. What is true about IP:PORT in the following options?
a. Port number 21 is the default FTP port.
b. Only port number is required for FTP connections and no IP is required.
c. 127.0.0.1 and localhost are same.
d. There is no concept of PORT in IPv6.
Q8. Which of the following is/are valid Data Definition Language (DDL) command(s)?
a. SELECT
b. INSERT
c. UPDATE
d. ALTER TABLE
Q9. In JDBC, all raw data types (including binary documents or images) should be read and uploaded to the database as an array of
a. byte
b. vector
c. char
d. file
Q10. The package, which is required to be imported for the JDBC programming?
a. java.net
b. java.lang
c. java.io
d. java.sql
Assignment
1. The following code needs some package to work properly. Write appropriate code to import the required package(s) in order to make the program compile and execute successfully.
Solution:
import java.sql.*;
import java.lang.*;
2. Write the JDBC codes needed to create a Connection interface using the DriverManager class and the variable DB_URL. Check whether the connection is successful using ‘isAlive(timeout)’ method to generate the output, which is either ‘true’ or ‘false’.
Note the following points carefully:
1. Name the connection object as ‘conn’ only.
2. Use timeout value as 1.
Solution:
conn = DriverManager.getConnection (DB_URL);
System.out.print(conn.isValid(1));
3. Due to some mistakes in the below code, the code is not compiled/executable. Modify and debug the JDBC code to make it execute successfully.
Solution:
import java.sql.*;
import java.lang.*;
import java.util.Scanner;
public class Question103 {
public static void main(String args[]) {
try {
Connection conn = null;
Statement stmt = null;
String DB_URL = "jdbc:sqlite:/tempfs/db";
System.setProperty("org.sqlite.tmpdir", "/tempfs");
conn = DriverManager.getConnection(DB_URL);
conn.close();
System.out.print(conn.isClosed());
}
catch(Exception e){ System.out.println(e);}
}
}
4. Complete the code segment to create a new table named ‘PLAYERS’ in SQL database using the following information.
Solution:
String CREATE_TABLE_SQL="CREATE TABLE players (UID INT, First_Name VARCHAR(45), Last_Name VARCHAR(45), Age INT);";
stmt.executeUpdate(CREATE_TABLE_SQL);
5. Complete the code segment to rename an already created table named ‘PLAYERS’ into ‘SPORTS’.
Solution:
String alter="ALTER TABLE players RENAME TO sports;";
stmt.executeUpdate(alter);
* The material and content uploaded on this website are for general information and reference purposes only and don’t copy the answers of this website to any other domain without any permission or else copyright abuse will be in action.
Please do it by your own first!
