Part A
1. Why compile error? (Infosys)
try {
int[] arr = {1,2,3};
[Link](arr[5]);
} catch(Exception e, ArrayIndexOutOfBoundsException a) {
[Link]("Error");
Options:
A) Valid syntax
B) Compile Error: Multi-catch incorrect
C) Prints Error
D) Runtime Error
2. Select the correct option and justify. (Wipro)
class MyException extends Exception {
MyException(String s){ super(s); }
public class Main {
public static void main(String[] args) throws MyException {
throw new MyException("Custom Error");
Options:
A) Prints Custom Error
B) Compile Error
C) Runtime Exception with message
D) No output
3. What does this do? (HCL)
File f = new File("[Link]");
FileWriter fw = new FileWriter(f);
[Link]("Hello");
[Link]();
Options:
A) Writes Hello to file
B) Compile Error
C) Appends by default
D) Does nothing
4. Compare Input Stream and Output Stream in Java?
5. How to Split String in java? justify
6. Write the purpose of using generic programming.
7. Select the correct option and justify.
import [Link].*;
public class Main {
public static void main(String[] args) {
List list = new ArrayList();
[Link]("Hello");
[Link](100);
for(Object obj : list) {
String s = (String)obj;
[Link](s);
Options:
A) Generics help avoid ClassCastException at runtime
B) Generics make code slower
C) Generics remove all compile-time checks
D) Generics cannot be used with collections
8. List the type of JDBC drivers
9. Select the correct option and justify. (Infosys)
[Link]("[Link]");
Connection con = [Link]("jdbc:mysql://localhost/test","root","");
[Link]("Connected");
Options:
A) Compile Error
B) Connects if driver present
C) Runtime Exception always
D) Prints nothing
10 Name two types of JDBC drivers. Which type is considered the most efficient but requires a database-specific
implementation?
_____________________________________________________________________________________________
1. Predict the output. (Wipro)
public class Main { public static void main(String[] args)
{ Thread t = [Link]();
[Link]([Link]());
[Link]("MyMain");
[Link]([Link]()); } }
Options:
A) main MyMain
B) MyMain MyMain
C) main main
D) Compile Error
2. Distinguish between throw and throws
3. Compare Input Stream and Output Stream in Java?
4. State Generic Type Parameter?
5. What does this do? (HCL)
File f = new File("[Link]");
FileWriter fw = new FileWriter(f); [Link]("Hello");
[Link]();
Options:
A) Writes Hello to file
B) Compile Error
C) Appends by default
D) Does nothing
6. Write about Scanner Class.
7. Draw JDBC architecture neatly
8. Write the output and justify. (HCL)
List<String> list = new ArrayList<>();
[Link]("A");
[Link]("B");
[Link]("C");
[Link]([Link](1));
Options:
A) A
B) B
C) C
D) Compile Error
9. What are the exceptions in JDBC?
10 List the advantages of using Data Source?
_____________________________________________________________________________________________
Part B
11 a) i) List some important features and methods of the String Buffer class
ii) Meet Sneha, a teacher who is developing a grading system for her students.
Sneha’s system accepts marks for each subject. However, some students enter negative values or values above 100,
which should not be allowed.
Task:
Write a program to validate marks for 5 subjects.
If any mark is invalid, throw and handle a custom exception called InvalidMarksException.
Sample Input:
Marks = [85, 72, 110, 67, 90]
Sample Output:
Invalid mark found: 110
Please enter marks between 0 and 100.
(OR)
11 b)
i) Meet Hari, a developer at Zoho Schools of Learning.
He needs to store student names and grades into a file and later read them for performance analysis.
Task:
Use FileWriter to write names and grades of 5 students into a file named [Link].
Then use BufferedReader to read and display the file contents.
Sample Output:
Writing data to [Link]...
Data saved successfully.
Reading from file...
Rahul - 85
Priya - 90
Sita - 76
Ravi - 88
Kiran – 95
ii) Examine the life cycle of a thread and the methods involved in thread management.
12 a) i) Explain I/O Basics in Java. How do you read and write data using Console I/O?
ii) Meet Nithya, a data analyst at Zoho Commerce.
She receives a list of products and their prices and must find:
• The most expensive product
• The least expensive product
• Average price of all products
Task:
Use a HashMap<String, Double> to store product names and prices.
Then find and print the required information.
Sample Input:
{"Mouse"=499.0, "Keyboard"=899.0, "Monitor"=7500.0, "Pendrive"=299.0}
Sample Output:
Most expensive product: Monitor - ₹7500.0
Least expensive product: Pendrive - ₹299.0
Average price: ₹2300.75
(OR)
12 b) i) Give example program for concatenate strings str1=”java” and str2=”programming”: using StringBuffer
ii) Create a thread that prints numbers 1 to 5 with 1-second delay.
Thread -> Prints numbers sequentially
Test Cases:
1. 1 2 3 4 5 (with 1s delay)
2. Another thread prints: A B C D E
3. Sequential printing maintained
13 a) i) Draw the hierarchy of Collection framework
ii) Read a file and count the number of words.
File -> BufferedReader -> count words
Test Cases:
1. File with 'Hello World' -> 2
2. Empty file -> 0
3. File with 'Java programming is fun' -> 4
(OR)
13 b) i) Explain a Java Program to Read and Write Data Using Buffered Reader and Buffered Writer
ii) Scenario:
Meena, a software engineer at Wipro, is building a reusable container class that can store any type of data (Integer,
String, etc.).
She decides to implement this using Generics.
Task:
Create a generic class Box<T> that:
• Accepts one value of any type
• Has methods setValue(T val) and getValue()
Demonstrate storing and retrieving both an integer and a string.
Expected Output:
Integer value: 25
String value: Wipro
14 a) i) Develop a program to add an element (Kotlin) in the array list [Java, C++, Python] and remove Python from
the array list
ii) Meet Rohit, an HR analyst at Infosys HR Portal.
He needs to store employee names and salaries, and then:
• Find the employee with the highest salary
• Calculate the average salary
Task:
Use a HashMap<String, Double> to store employee data and compute the results.
Sample Input:
Employee Data:
Ravi - 45000
Kavya - 50000
Meena - 60000
Arun – 55000
Sample Output:
Highest Paid Employee: Meena - ₹60000
Average Salary: ₹52500.0
(OR)
14 b) i) Develop a program used to find the minimum and the maximum elements using min() and max() methods
of the Java collections framework.
ii) Meet Aravind, a Java developer at EduConnect Pvt Ltd.
He is creating a module to connect to a MySQL database and retrieve student records from a table called students.
Task:
Write a JDBC program to:
1. Connect to a MySQL database
2. Execute a query: SELECT * FROM students
3. Display student ID and Name
Sample Output:
Connecting to database...
Connection successful.
Student Records:
1 Rahul
2 Priya
3 Arjun
15 a) i) Explain Java Connectivity with access with dsn
ii) Meet Rahul, a backend developer at Infosys Education Solutions.
He must fetch student data (ID, Name, Marks) from a database using JDBC,
and export it to a text file called [Link] for report generation.
Task:
1. Connect to a database using JDBC
2. Execute SELECT * FROM students
3. Write the results into a text file using FileWriter
Sample Output:
Connecting to database...
Data fetched successfully.
Writing to [Link]...
File saved successfully!
Contents of [Link]:
101 Rahul 88
102 Priya 92
103 Arjun 79
(OR)
15 b) i) How to connect MySQL or Oracle with Java? Explain the steps in detail.
ii) Meet Kavin, a trainee software engineer at Infosys Technologies.
He is working on a document analysis tool that needs to count how many words are present in a given text file.
Task:
Write a Java program that:
1. Creates a text file named [Link].
2. Writes a few sentences into it using FileWriter.
3. Reads the file content using FileReader (or BufferedReader) and counts the number of words.
4. Prints the total word count.
Sample Output:
Writing data to file...
File saved successfully!
Reading from file...
File Content: Java is a popular programming language
Total Words: 6
_____________________________________________________________________________________________
11 a) i) Meet Sneha, a teacher who is developing a grading system for her students.
Sneha’s system accepts marks for each subject. However, some students enter negative values or values above 100,
which should not be allowed.
Task:
Write a program to validate marks for 5 subjects.
If any mark is invalid, throw and handle a custom exception called InvalidMarksException.
Sample Input:
Marks = [85, 72, 110, 67, 90]
Sample Output:
Invalid mark found: 110
Please enter marks between 0 and 100.
ii) Describe with an example compare two strings
(OR)
11 b) i) Meet Hari, a developer at Zoho Schools of Learning.
He needs to store student names and grades into a file and later read them for performance analysis.
Task:
Use FileWriter to write names and grades of 5 students into a file named [Link].
Then use BufferedReader to read and display the file contents.
Sample Output:
Writing data to [Link]...
Data saved successfully.
Reading from file...
Rahul - 85
Priya - 90
Sita - 76
Ravi - 88
Kiran – 95
ii) With an example, explain the use of nested try statements.
12 a) i) Meet Nithya, a data analyst at Zoho Commerce.
She receives a list of products and their prices and must find:
• The most expensive product
• The least expensive product
• Average price of all products
Task:
Use a HashMap<String, Double> to store product names and prices.
Then find and print the required information.
Sample Input:
{"Mouse"=499.0, "Keyboard"=899.0, "Monitor"=7500.0, "Pendrive"=299.0}
Sample Output:
Most expensive product: Monitor - ₹7500.0
Least expensive product: Pendrive - ₹299.0
Average price: ₹2300.75
ii) Count the vowels present in string “java is fun”, write a java code.
(OR)
12 b) i) Create a thread that prints numbers 1 to 5 with 1-second delay.
Thread -> Prints numbers sequentially
Test Cases:
1. 1 2 3 4 5 (with 1s delay)
2. Another thread prints: A B C D E
3. Sequential printing maintained
ii) List some important features and methods of the String Buffer class
13 a) i) Read a file and count the number of words.
File -> BufferedReader -> count words
Test Cases:
1. File with 'Hello World' -> 2
2. Empty file -> 0
3. File with 'Java programming is fun' -> 4
ii) Write a program to swap two string variables without using a third variable in Java
(OR)
13 b) i) Rahul is creating a list of project names for a Wipro internal dashboard.
He wants to store and display them dynamically using an ArrayList.
Task:
Write a Java program to:
1. Add 5 project names into an ArrayList
2. Remove one project
3. Display the remaining projects using an iterator.
Expected Output:
Project List:
AI Chatbot
Billing System
E-commerce Portal
Payroll System
ii) Describe with an example explain the Get and Set Element in Linked List
14 a) i) Meet Rohit, an HR analyst at Infosys HR Portal.
He needs to store employee names and salaries, and then:
• Find the employee with the highest salary
• Calculate the average salary
Task:
Use a HashMap<String, Double> to store employee data and compute the results.
Sample Input:
Employee Data:
Ravi - 45000
Kavya - 50000
Meena - 60000
Arun – 55000
Sample Output:
Highest Paid Employee: Meena - ₹60000
Average Salary: ₹52500.0
ii) Describe with an example explain the Get and Set Element in Array List
(OR)
14 b) i) Meet Aravind, a Java developer at EduConnect Pvt Ltd.
He is creating a module to connect to a MySQL database and retrieve student records from a table called students.
Task:
Write a JDBC program to:
1. Connect to a MySQL database
2. Execute a query: SELECT * FROM students
3. Display student ID and Name
Sample Output:
Connecting to database...
Connection successful.
Student Records:
1 Rahul
2 Priya
3 Arjun
ii) Lit types of JDBC drivers: and explain each
15 a) i) Meet Rahul, a backend developer at Infosys Education Solutions.
He must fetch student data (ID, Name, Marks) from a database using JDBC,
and export it to a text file called [Link] for report generation.
Task:
1. Connect to a database using JDBC
2. Execute SELECT * FROM students
3. Write the results into a text file using FileWriter
Sample Output:
Connecting to database...
Data fetched successfully.
Writing to [Link]...
File saved successfully!
Contents of [Link]:
101 Rahul 88
102 Priya 92
103 Arjun 79
ii) Develop a program to add an element (banana) in the Linked list [orange, apple, and mango] and
remove orange form the linked list?
(OR)
15 b) i) Meet Kavin, a trainee software engineer at Infosys Technologies.
He is working on a document analysis tool that needs to count how many words are present in a given text file.
Task:
Write a Java program that:
1. Creates a text file named [Link].
2. Writes a few sentences into it using FileWriter.
3. Reads the file content using FileReader (or BufferedReader) and counts the number of words.
4. Prints the total word count.
Sample Output:
Writing data to file...
File saved successfully!
Reading from file...
File Content: Java is a popular programming language
Total Words: 6
ii) How to connect MySQL or Oracle with Java?
____________________________________________________________________________________________
Part C
16 a) i) Give one example for Array Index Out Of Bounds Exception will be thrown
ii) Wipro:
1) Scenario:
A Wipro developer named Asha is working on a project that reads employee data from a file named [Link].
However, sometimes the file might be missing, or the data inside may not be properly formatted.
She needs to make sure her program handles such errors gracefully without crashing.
Task:
Write a Java program that:
1. Tries to open and read the file [Link].
2. Each line in the file contains an employee name and salary (e.g., Ravi 45000).
3. The program should:
o Read and print each employee’s details.
o Handle these exceptions properly:
FileNotFoundException – if the file doesn’t exist.
NumberFormatException – if salary is not a valid number.
IOException – for any other input/output errors.
Sample [Link]:
Ravi 45000
Priya abc
Kumar 50000
Expected Output:
Error reading salary for Priya: [Link]: For input string: "abc"
Employee: Ravi, Salary: 45000
Employee: Kumar, Salary: 50000
File reading completed successfully.
(OR)
16 b) i) How would you handle a FileNotFoundException and an ArithmeticException in a Java program?
ii) Scenario:
Rahul is creating a list of project names for a Wipro internal dashboard.
He wants to store and display them dynamically using an ArrayList.
Task:
Write a Java program to:
1. Add 5 project names into an ArrayList
2. Remove one project
3. Display the remaining projects using an iterator.
Expected Output:
Project List:
AI Chatbot
Billing System
E-commerce Portal
Payroll System
16 a) i) Wipro:
1) Scenario:
A Wipro developer named Asha is working on a project that reads employee data from a file named [Link].
However, sometimes the file might be missing, or the data inside may not be properly formatted.
She needs to make sure her program handles such errors gracefully without crashing.
Task:
Write a Java program that:
1. Tries to open and read the file [Link].
2. Each line in the file contains an employee name and salary (e.g., Ravi 45000).
3. The program should:
o Read and print each employee’s details.
o Handle these exceptions properly:
FileNotFoundException – if the file doesn’t exist.
NumberFormatException – if salary is not a valid number.
IOException – for any other input/output errors.
Sample [Link]:
Ravi 45000
Priya abc
Kumar 50000
Expected Output:
Error reading salary for Priya: [Link]: For input string: "abc"
Employee: Ravi, Salary: 45000
Employee: Kumar, Salary: 50000
File reading completed successfully.
ii) Give one example for Arithmetic Exception will be thrown
(OR)
b) i) Scenario:
Rahul is creating a list of project names for a Wipro internal dashboard.
He wants to store and display them dynamically using an ArrayList.
Task:
Write a Java program to:
1. Add 5 project names into an ArrayList
2. Remove one project
3. Display the remaining projects using an iterator.
Expected Output:
Project List:
AI Chatbot
Billing System
E-commerce Portal
Payroll System
ii) List the advantage of using exception handling in Java?
Which of the following statements will throw an exception?
a. [Link](1/0);
b. [Link](2.0/0);
_____________________________________________________________________________________________