Compre CS F213 OOPS Solution Key 2022-23
Compre CS F213 OOPS Solution Key 2022-23
1 import java.util.regex.*; A 0
. public class Archie {
public static void main(String[] args) { B 3
Pattern p = Pattern.compile(args[0]);
C 4
Matcher m = p.matcher(args[1]);
int count = 0; D Compilation fails
while(m.find())
count++;
System.out.print(count);
}
}
And given the command line invocation:
java Archie "\d+" ab2c4d67
What is the result?
4 public class Theory { A The first line of output is abcd abc false
. public static void main(String[]
args) { B The first line of output is abc abc false
String s1 = "abc";
C The first line of output is abc abc true
String s2 = s1;
s1 += "d"; D Compilation error
System.out.println(s1 + " " + s2 + "
" + (s1==s2));
sb1.append("d");
System.out.println(sb1 + " " + sb2 +
" " + (sb1==sb2));
}
}
5 import java.io.*; A ab
. public class ReadingFor { cd
public static void main(String[] args) {
String s; B abcd
try {
C a
FileReader fr = new FileReader("myfile.txt");
b
BufferedReader br = new BufferedReader(fr); c
while((s = br.readLine()) != null) d
System.out.println(s);
br.flush(); D Compilation error
} catch (IOException e) { System.out.println("io error"); }
}
}
And given that myfile.txt contains the following two lines of data:
ab
cd
What is the result?
D Compilation fails
8 Which resources have their close() method called when this code A No close() methods are
. runs? called.
public static void runQuery(Connection conn) throws SQLException {
try (Statement stmt = conn.createStatement()) { B Only Statement
ResultSet rs = stmt.executeQuery("select * from clowns");
C Only Statement and
rs.next(); }} ResultSet
FileInputStream("inputoutput.java");
System.out.print(obj.available());
}
}
int count = 0;
while (matcher.find()) {
count++;
}
System.out.println(count);
}
}
Statement statement =
connection.createStatement();
String query = "SELECT * FROM employees";
ResultSet resultSet =
statement.executeQuery(query);
while (resultSet.next()) {
int id = resultSet.getInt("id");
String name = resultSet.getString("name");
int age = resultSet.getInt("age");
resultSet.close();
statement.close();
connection.close();
} catch (Exception e) {
System.out.println("An exception occurred: " +
e.getMessage());
}
}
}
Solution Key:
A B C D
6
7
10
11
12
13
14
15
BITS email has the following requirements: starts with f or h or p, followed by the year of
admission, followed by 4 numeric digits, followed by hyderabad.bits-pilani.ac.in
BITS password has the following requirements: The password should be 8 characters in length
and It should have at least 1 uppercase, 1 lower case, 1 digit, 1 special character [15 marks].
Rubrics:
Name: ID: 2 0 H
Solution:
import java.awt.*;
import java.awt.event.*;
public class LoginValidator extends Frame implements ActionListener{
TextField tf1;
TextField tf2;
Button b1, b2;
LoginValidator(){
Label l1 = new Label("Email");
Label l2 = new Label("Pwd");
tf1 = new TextField();
tf2 = new TextField();
b1 = new Button("Validate");
b2 = new Button("Exit");
b1.addActionListener(this);
b2.addActionListener(this);
add(l1); add(tf1); add(l2); add(tf2);
add(b1); add(b2);
setLayout(new GridLayout(3,2));
setVisible(true);
setSize(300,300);
}
public void actionPerformed(ActionEvent e) {
String emailpattern =
"^(p|f|h)(2019|2020|2021|2022|2023)(?=.*[0-9]).{4}@hyderabad.bits-pilani.ac.in$";
String pwdpattern =
"^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*]).{8,}$";
if(b2.hasFocus()) {
System.exit(0);
}
if(b1.hasFocus()) {
if(tf1.getText().matches(emailpattern)&&tf2.getText().matches(pwdpattern)) {
tf1.setText("valid password");
tf2.setText("valid password");
}
else {
tf1.setText("invalid email");
tf2.setText("invalid password");
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new LoginValidator();
}
}
2. Explain the different types of JDBC database drivers available. Explain each of them in on
sentence [4 marks]
Fill in the blanks as appropriate to complete the following java code [1x11=11 marks]
import java.sql.*;
try (
"myuser", "xxxx");
String sqlDelete = "delete from books where id >= 3000 and id < 4000";
// INSERT a record
String sqlInsert = "insert into books values (3001, 'Gone Fishing', 'Kumar', 11.11, 11)";
// INSERT multiple records 1st record is 3002, 'Gone Fishing 2', 'Kumar', 22.22, 22; 2nd record is
3003, 'Gone Fishing 3', 'Kumar', 33.33, 33
Name: ID: 2 0 H
// Step 3 & 4: get all the data from book to check the changes
+ rset.getInt("qty"));
} catch(SQLException ex) {
ex.printStackTrace();
3. Sentinel License Development Kit (Sentinel LDK) is a Software Digital Rights Management
(DRM) solution by SafeNet Inc. that delivers strong copy protection, protection for Intellectual
Property (IP), and secure and flexible licensing. Sentinel LDK separates licensing and
production processes (implemented with Sentinel EMS) from the software protection process
(implemented with Sentinel Licensing API or Sentinel LDK Envelope). Sentinel EMS is a
web-based graphical application provided as part of Sentinel LDK that is used to perform a
range of functions required to manage the licensing, production, distribution, customer support,
and maintenance of protected applications. This application is a role-based application designed
to manage the business activities required to implement and maintain Sentinel LDK in the
organization which needs to protect its software. Sentinel EMS Server maintains a database
containing a wide range of information, including data related to product features, licenses,
sales, orders, and customers.
Product Manager defines Features and Products. Users assigned the Development role can
fulfill one of the following development-related activities: Generate bundles of Provisional (Trial)
Products Generate a customized Sentinel LDK Run-time Environment (RTE) installer file
Customize the Sentinel Remote Update System utility (RUS utility) Entitlement Manager defines
and manages customers, and also enters and manages entitlements. Customer Services roles
can manage customers the same way as Entitlement Manager does, and can also manage
Product activation. For entitlements that generate Product Keys, the customer receives an email
from Sentinel EMS that contains the keys. The customer is able to log in to the EMS Customer
Portal using the Product Key in order to activate the Product.
Draw a use case diagram below shows some simplified view of software licensing use cases
supported by Sentinel EMS Application (shown as «Application» stereotyped subject). The
Sentinel EMS handles three major workflows: license planning, order processing and
production, and activation of trial software.[10 marks]
4. Given below are two incomplete java files, RunnableExample.java and RunnableTask.java
If you first compile “RunnableTask.java” and then compile “RunnableExample.java” and then
execute “java RunnableExample” then the following output is obtained:
test1.txt
Hello BITS!
Hello Hyderabad.
test2.txt
You're awesome!
You may not know that
but you are!
test3.txt
test4.txt
test5.txt
RunnableExample.java
import java.util.ArrayList;
import java.util.List;
try {
for (int i = 0; i < 5; i++) {
threads.get(i).join();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Result:");
System.out.println(content);
}
}
Name: ID: 2 0 H
RunnableTask.java
import java.io.*;
import java.nio.file.Path;
import java.nio.file.Paths;
String line;
while ((line = br.readLine()) != null) {
content += line;
System.out.println("File "+this.filename+" retrieved data:
"+ content);
}