Cs506 Midterm Solved Subjective by Junaid Malik
Cs506 Midterm Solved Subjective by Junaid Malik
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.*;
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();
}
}