0% found this document useful (0 votes)
201 views6 pages

Cs506 Midterm Solved Subjective by Junaid Malik

The document contains a series of Java programming exercises related to web design and development, focusing on file handling, inheritance, and data streams. It includes code snippets and explanations for scenarios involving reading from files, concatenating strings, and inserting records into a ResultSet. The exercises are aimed at reinforcing concepts in Java programming and object-oriented design.

Uploaded by

aleebaanwar88
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)
201 views6 pages

Cs506 Midterm Solved Subjective by Junaid Malik

The document contains a series of Java programming exercises related to web design and development, focusing on file handling, inheritance, and data streams. It includes code snippets and explanations for scenarios involving reading from files, concatenating strings, and inserting records into a ResultSet. The exercises are aimed at reinforcing concepts in Java programming and object-oriented design.

Uploaded by

aleebaanwar88
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/ 6

CS506- WEB DESIGN &

DEVELOP
(SUBJECTIVE)
FROM MIDTERM PAPERS
LECTURE (1-22)
ajtechinstitute24@gmail. For More Visit: vujunaid.com JUNAID MALIK (0304-
com 1659294)
ÂL-JÛÑÂÎD TÊCH
JOIN OUR GROUP FOR MORE UPDATE
Click Button
CS619 & CS519 ÂL-JÛÑÂÎD TÊCH

1. Suppose we have a text file "string.txt" and there is only one line written
what will be the output of give programe in each of the folllowing secenerio ?
Strings.txt file is present in same directory where Fblock java is availbale .
strings.txt file is not available
ANSWER:
import javax.swing.JOptionPane;
public class stringConcate {
public static void main(String[] args) {
String s1 = JOptionPane.showInputDialog("Enter first string:");
String s2 = JOptionPane.showInputDialog("Enter second string:");
String s3 = s1.concat(s2);
System.out.println("Concatenated string: " + s3);
}
}
2. Suppose we have a text file "string.txt" and there is only one line written
what will be the output of give programe in each of the folllowing secenerio ?
Strings.txt file is present in same directory where Fblock java is availbale .
strings.txt file is not available
Answer:
import java.io.*;
public class Fblock {
public static void main(String[] args) {
try {
File file = new File("strings.txt");
ÂL-JÛÑÂÎD TÊCH
BufferedReader br = new BufferedReader(new FileReader(file));
String line = br.readLine();
System.out.println(line);
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

3. Class person is base Class and students is child class. You are required to
implement inheritance by writing Java code for following;
- Create person clas (name and age attributes)
- Inherit person class from student class (without method and attributes)
- Call base class constructor explicitly from student class
- Create an object of student class by calling default constructor
- Create an object of person class by calling parameterized by constructor.
Answer:

class Person {
private String name;
private int age;
public Person() {
this("Unknown", 0);
}
public Person(String name, int age) {
ÂL-JÛÑÂÎD TÊCH
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
class Student extends Person {
public Student() {
super(); }
public Student(String name, int age) {
super(name, age); }
}

4. We can divide stream into two types of classes based on data. You are
required to mention names of those stream type based on following cases.
- Class which contains the word stream in their name.
ÂL-JÛÑÂÎD TÊCH
- Class which contains the word reader/writer.
Answer:
In Java, there are two types of classes that are commonly used for working with streams
of data:
Classes that contain the word "stream" in their name: These classes are used for working
with streams of bytes. Examples include InputStream, OutputStream,
ByteArrayInputStream, and ByteArrayOutputStream. These classes are typically used for
low-level input/output operations, such as reading and writing binary data.
Classes that contain the word "reader" or "writer" in their name: These classes are used
for working with streams of characters. Examples include Reader, Writer, StringReader,
and StringWriter. These classes are typically used for high-level input/output operations,
such as reading and writing text data.

It's worth noting that, Java.io package has multiple classes that can help you in
reading/writing different types of data in different way. The aforementioned classes is
one of the most common used in reading/writing data.
5. Suppose a resultSet Object rs is representing the table given below write java
code of a new student record into resultset . sent Record Detail : rollno :13 ,
name : rida , subject: IT , Course : BSIT
Answer:

import java.sql.*;

public class InsertRecord {


public static void main(String[] args) throws SQLException {

ResultSet rs = ...;
rs.moveToInsertRow();
rs.updateInt("rollno", 13);
rs.updateString("name", "rida");
ÂL-JÛÑÂÎD TÊCH
rs.updateString("subject", "IT");
rs.updateString("course", "BSIT");
rs.insertRow();
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy