Total No. of Questions : 4] SEAT No.
:
PC1638 [6331]-51 [Total No. of Pages :3
T.Y.B.C.A.
SCIENCE
B.C.A.-351-DSE-I : Programming in Java
(2019 Pattern) (Semester- V)
Time : 3 Hours] [Max. Marks : 70
Instructions to the candidates:
1) Figures to the right indicate full marks.
2) Draw diagram wherever necessary.
Q1) Attempt the following: [5×1=5]
A) Choose the correct options:
a) _______ allows the programmer to destroy an object ×?
i) x. delete( ) ii) [Link]( ).gc( )
iii) x. finalize( ) iv) Only garbage collection
b) Linked List is a collection framework present in ______.
i) [Link].*;
ii) [Link].*;
iii) [Link].*;
iv) [Link].*;
c) Final keyword in java is used with ______.
i) Class attributes ii) Class
iii) Class functions iv) All mentioned
d) To create a menu user need to use ______ class.
i) Jaw+ ii) J Frame
iii) J Menu iv) J Panel
e) _______ driver is called as thin-driver of JDBC.
i) Type-4 driver ii) Type-1 driver
iii) Type-3 driver iv) Type-2 driver
P.T.O.
B) Attempt the following: [5×1=5]
a) What is the use of JDBC API? pg 5.2 below diagram
b) What is a listener? point 4.6.2
c) What is final class? point 2.4.3
d) State any two differences between throw & throws. EOF
e) Write any two implicit object in JSP? point 6.9
Q2) Answer the following (any five): [5×3=15]
fly EOF,
a) Why JSP is Fly compilation? Explain in brief Implicit object in JSP. object 6.9
b) Explain the use of try, catch & finally block. point 3.9.4
c) Enlist the features of swing. point 4.1.1
d) Explain nested interface. point 2.7.2
e) What is Result set? Explain types of Result set. point 5.5.1 & 5.5.2
f) Explain Anonymous Inner Class. point 4.9
Q3) Answer the following (any five): [5×4=20]
a) What is array? How to declare single & multi-dimensional array with
example. point 1.7
b) Explain Runtime polymorphism using [Link] 2.7
c) Differentiate between checked and unchecked Exception. EOF
d) Explain types of Drivers with example. point 5.2.1
e) What is swing? Explain MVK Architecture. point 4.1 & 4.2
f) Explain life cycle of a servlet. point 6.2
g) What is JSP Page Directive & include Directive? point 6.11.1 & 6.11.2
[6331]-51 2
Q4) Answer the following (any five): [5×5=25]
a) Define:
i) Scriplets point 6.10.1
ii) Implicit objects point 6.9
iii) Mouse Adapter point 4.8
iv) J Text Field point 4.4.3
v) JMenu point 4.4.9
b) Differentiate between Statement and prepared statement. EOF
c) Write a Java program to accept Number from user and display [Link]
d) Create a following JFrame using [Link]
e) Write a java program to accept a string from user. Check whether given
string is Palindrome or [Link]
f) What is event? How to hande awt events? Explain with example. EOF
g) Explain Abstraction in detail. EOF
[6331]-51 3
Total No. of Questions : 4] SEAT No. :
PB1942 [6240]- 501
[Total No. of Pages : 3
T.Y. B.C.A.
SCIENCE
BCA-351-DSE 1: Programming in Java
(2019 Pattern) (Semester - V)
Time : 3 Hours] [Max. Marks : 70
Instructions to the candidates:
1) All questions are compulsory.
2) Figures to the right indicates full marks.
3) Draw diagram wherever necessary.
Q1) Attempt the following:
A) Choose the correct option: [5×1=5]
a) Which one of the following will declare an array and initialize it with
five numbers?
i) Array a=new Array(5)
ii) Int a [ ] = new int [5]
iii) Int [ ] a = { 23,22,21,20,19}
iv) Int [5] array
b) _____ these keywords must beused to monitor for exceptions?
i) Try ii) Finally
iii) Throw iv) Catch
c) A _____ is collection of classes and interfaces.
i) Object ii) Package
iii) Inheritance iv) ethod
d) A ______ is a base class for all swing UI components.
i) J Menu ii) J Componemt
iii) J Panel iv) J Frame
e) The JDBC-DDBC bridge is ______.
i) Multi threaded ii) single threaded
iii) Both (i) &(ii) iv) Only (ii)
[6240]-501 1 P.T.O.
B) Attempt the following. [5×1=5]
a) What is array of object? point 1.13
b) Explain use of super [Link] 2.2.1
c) What is Iterators? point 3.8
d) Enlist the feature of Java. point 1.3
e) What is use of final keyword? point 2.4
Q2) Answer the following:(any five) [5×3=15]
a) What is JSP Directives? Explain types of [Link] 6.11
b) Write a short note on; Garbage [Link] 1.17
c) Differentiate between Arraylist and linked [Link]
d) What is inheritance? Explain types of inheritance. point 2.1 & 2.1.3
e) Explain Exception handling. (try, catch, finally) block. point 3.9
f) Explain different types of layout. pg 4.6
Q3) Answer the following:(Any five) [5×4=20]
a) Explain the life cycle of servlets with suitable [Link] 6.2
b) Write a Java, program to accept number from user and display that
number is palindrome or not. EOF
c) What is session tracking? explain cookies and Http session. point 6.6 & 6.6.1
d) Differentiate between Data Input stream and Data Output stream [Link]
e) Explain runtime polymorphism using interface with suitable [Link] 2.3.2
f) Explain types of comments. point 1.6
g) What is Adopters? Explain Mouse Adapter and key [Link] 4.8
Q4) Answer the following. [5×5=25]
a) Write a Java program to create following frame with proper [Link]
Enter string : AHAN
Enter Skey : HA
String is search.
[6240]-501 2
b) Write a java program to display string merge of two [Link]
c) Explain Access specifiers [Link] 1.12
d) Explain wrapper class with example. point 3.2
e) Write a short note;
i) Hash table point 3.7.4
ii) Enumeration pg 3.27
f) Differentiate between checked and unchecked enception EOF
g) Explain the statement, calleble statement with example. point 5.4.1 & 5.4.3
[6240]-501 3
Total No. of Questions: 4] SEAT No. :
P6451 [6158]-51
[Total No. of Pages : 3
T.Y.B.C.A. (Science)
BCA 351-DSE-I : PROGRAMMING IN JAVA
(2019 Pattern) (Semester-V)
Time : 3 Hours] [Max. Marks : 70
Instructions to the candidates:
1) All questions are compulsory.
2) Figures to the right indicate full marks.
3) Draw the Diagrams wherever necessary.
Q1) Attempt the following. [5×1=5]
A) Choose the correct option:
a) ______of the operator is used to allocate memory for an object.
i) malloc ii) alloc
iii) new iv) give
b) _____this interface handle sequences
i) Set ii) List
iii) Comparator iv) Collection
c) Try, catch, finally are related to _____.
i) Function handling ii) String
iii) Exception iv) Extension
d) MVC stands for _____architecture.
i) Model ii) View
iii) Controller iv) All mentioned
e) ______method is used to perform DML statement.
i) execute () ii) execute Query ()
iii) executeupdate () iv) executeResult ()
P.T.O.
B) Attempt the following. [5×1=5]
a) What is method overriding?point 2.3.1
b) Enlist the types of [Link] 5.2.1
No, JavaScript does not
c) What is the use of “this” keyword? point 1.14.2 natively support multiple
catch blocks for a single
try block. However, you
d) Write any three types of layout. pg 4.6 can handle different
types of errors within a
e) State true or false:Java supports multiple catch block (Justify). single catch block by
using conditional logic,
such as if...else or switch
statements, to
differentiate between
error types.
Q2) Answer the following: (Any five) [5×3=15]
a) Explain the concept of Garbage collection point 1.17
b) How to define & Implement interfaces? point 2.6.1 & 2.6.2
c) Explain MVC architecture point 4.2
d) Define:
i) TYPE-FORWARD-ONLY
ii) TYPE-SCROLL-INSENSITIVE pg 5.20
iii) CONCUR-UPDATABLE
e) What is scripting elements? Explain any two type. point 6.10
f) Differentiate between string and string Buffer class. EOF
Q3) Answer the following. (Any five) [5×4=20]
a) Explain the life cycle of JSP. point 6.8
b) Write Java program to calculate the Fibbonacci series. EOF
c) Explain the types of Drivers (JDBC) point 5.2.1
d) How to access, create class in package with example? point 2.8
e) Differentiate between Buffered Reader and Scanner class. EOF
f) Write a program to calculate factorial. EOF
g) Write Java program to create following frame EOF
Male O Female O
Yes O No O
Selected : True or False
[6158]-51 2
Q4) Answer the following (Any five) [5×5=25]
a) Write a Java program that accept number using command line argument
display that the number is perfect or not. EOF
b) Explain Access specifiers in detail. point 1.12
c) What is overriding? Explain runtime polymorphism with example. point 2.3
d) Define:
i) Treeset point 3.6.2
A HashMap is a part of Java's Collection Framework and is implemented in the [Link] package. It is a data struct
ii) Hashmap that stores elements in key-value pairs, where: Keys: Must be unique. / Values: Can be duplicated.
iii) Treemap point 3.7.3
iv) Array List point 3.5.1
v) Linked List point 3.5.2
e) Explain wrapper class with example. point 3.2
f) What is Inheritance? Explain types of Inheritance. point 2.1 & 2.1.3
g) Explain cookies and Http session. point 6.6.1
[6158]-51 3
Total No. of Questions : 4] SEAT No. :
P1360 [Total No. of Pages : 3
[6058]-501
T.Y.B.C.A. (Science)
BCA 351 - DSEI : PROGRAMMING IN JAVA
(2019 Pattern) (Semester - V)
Time : 3 Hours] [Max. Marks : 70
Instructions to the candidates:
1) Figures to the right indicates full marks.
2) Draw lebeled diagram whenever necessary.
Q1) Attempt the following. [5×1=5]
A) Choose the correct options
a) _______of these operators is used to allocate memory for an object.
i) alloc ii) new
iii) give iv) malloc
b) ______is a collection of classes and inter Faces
i) Package ii) Object
iii) Method iv) Inheritance
c) _____of this interface is not a part of java’s collection Framework
i) Set ii) List
iii) Sorted List iv) Sorted Map
d) _____is base class for all swing UI components
i) Jmenu ii) Jcomponent
iii) Jpanel iv) Jformat
e) _____method is used to perform DML statments in JDBC
i) execute () ii) executeQuery ()
iii) executeUpdate () iv) executeResult ()
P.T.O.
B) Attempt the following. [5×1=5]
a) Why Java is called portable? point 1.3
b) What is super class? pg 2.2 1st point
c) Short note on collection inter Face point 3.4
d) List types of layout managers pg 4.6
e) Define Resultset point 5.5.1
Q2) Answer the following: (any five) [5×3=15]
a) Explain static Fields and methods. point 1.15.2
b) Explain Final keyword with suitable examples. point 2.4 & 2.4.1
c) Write a note on exception handing. point 3.9
d) Explain keyboard events with the help of Program. pg 4.50
e) Differentiate between connection and statements. EOF
f) Explain session trackin in details. point 6.6
Q3) Answer the following: (any five) [5×4=20]
a) What is servlet? Explain the types of servlet in detail. point 6.1 & 6.1.2
b) Explain types of JDBC in detail point 5.2.1
c) Write a Java program display menu using JPopMenu. EOF
d) Write a Java program to create abstract class student derived two classes
marks and result From it use proper method to accept and display for
the [Link]
e) Explain various types of access modifiers in detail. point 1.12
f) Differentiate between checked and unchecked exception. EOF
g) Explain JSP directives in detail. point 6.11
[6058]-501 2
Q4) Answer the following: (any five) [5×5=25]
a) What is constructor? Explain types of constructor in details. pg 1.37 & 1.39
b) What is inheritance? Explain any two types of inheritance with suitable
example point 2.1 & 2.1.3
c) Explain any four methods of string class with the help of an example pg 3.40 table
d) Create table of Teacher with fields (Tid, Tname, Taddress) write a JDBC
Program to insert the details and display all teacher details
EOF
e) Write a servlet program which counts how many times a user has visited
a web page (use session) EOF
f) How to create interface? Explain with example point 2.6.2
g) Write a Java program to accept in numbers in vector and display all
statements sum. EOF
[6058]-501 3
Total No. of Questions : 4] SEAT No. :
PA-1092 [Total No. of Pages : 3
[5905]-51
T.Y. B.C.A. (Science)
BCA - 351 : PROGRAMMING IN JAVA
(2019 Pattern) (Semester - V)
Time : 3 Hours] [Max. Marks : 70
Instructions to the candidates:
1) Figures to the right indicate full marks.
2) Draw diagram wherever necessary.
Q1) Attempt the following : [5 × 1 = 5]
A) Choose the correct options :
i) __________ of these operators is used to allocate memory for an
object.
a) malloc b) alloc
c) new d) give
ii) __________ of these keyword must be used to inherit class.
a) super b) this
c) extent d) extends
iii) When error will be occurring then if checked the exception type in
_______ block.
a) try b) catch
c) throw d) block
iv) To create a menu user need to use _________ class.
a) J RadioButton b) J Menu
c) J menuitem d) J Frame
v) __________ interface is used to store the result of query?
a) Statement b) Connection
c) Resultset d) Object
P.T.O.
B) Attempt the following : [5 × 1 = 5]
a) What is J2EE? pg 1.3
b) What is meant by JDBC Driver? point 5.2
c) Which swing classes are used to create menu? Jmenu
d) "Vector is growable or changeble size" - Justify true of [Link]
e) List types of layout managers. pg 4.6
Q2) Attempt the following : (Any Five) [5 × 3 = 15]
a) Explain different types of comments with example. point 1.6
b) What is polymorphism? With help of example explain. Runtime
polymorphism. point 2.7
c) What is Map? Explain any two types of Map Class. point 3.7
d) Explain Dialogs with the suitable example. point 4.5
e) Define the terms :
i) Statement point 5.4.1
ii) Prepared Statement point 5.4.2
iii) Callable Statement point 5.4.3
f) What are different types of scripting elements? point 6.10
Q3) Attempt the following : (Any Five) [5 × 4 = 20]
a) Explain Buffered Reader and Scanner Class with example. point 1.9.1 & 1.9.2
b) What are the primitive data types in Java? Write about type conversion. EOF
c) Write a Java program to check age is greater than 18. Give appropriate
message (using exception handling) EOF
d) With the help of diagram explain MVC Architecture. point 4.2
e) Explain life cycle of a JSP. point 6.8
f) What is 'Super' keyword explain with example. point 2.2.1
g) How to create & access package. point 2.8.1 & 2.8.2
[5905]-51 2
Q4) Attempt the following : (Any five) [5 × 5 = 25]
a) With the help of diagram explain servlet life cycle. point 6.2
b) Write a Java program to check whether number is armstrong or not. EOF
c) What is Adapter class? List the adapter classes. point 4.8
d) Demonstrate constructor overloading concept. EOF 1.14.1
e) Describe about various components in AWT. EOF
f) List any five checked exception & explain it with example. point 3.9.2
g) Write a Java program to create following. EOF
File
Open
New
[5905]-51 3
Total No. of Questions : 4] SEAT No. :
P5257 [Total No. of Pages : 2
[5826]-501
T.Y. B.C.A. (Science)
BCA - 351 : PROGRAMMING IN JAVA
(2019 Pattern) (Semester - V)
Time : 3 Hours] [Max. Marks : 70
Instructions to the candidates:
1) Figures to the right indicate full marks.
2) Draw diagram wherever necessary.
Q1) Attempt the following :
A) Choose the correct options : [5 × 1 = 5]
i) The Java ______ specifications defines an application programming
interface for communication between the web server and the
application program.
a) Servlet b) Server
c) Program d) Randomize
ii) The JDBC - ODBC bridge is _______.
a) Three tiered b) Multithreaded
c) Any platform d) Interim
iii) A _______ is a base class for all swing UI components.
a) J Menu b) J Component
c) J Panel d) J File
iv) ______ class write primitive Java data types to an output stream in
a portable way.
a) Data Input Stream b) File Input Stream
c) Final d) Data Output Stream
v) A _______ is a collection of classes and interfaces.
a) Object b) Package
c) Inheritance d) Method
P.T.O.
B) Answer the following : [5 × 1 = 5]
because it is compiled into bytecode, a platform-
i) Why Java is platform - neutral language? independent intermediary format, which is then
executed by the Java Virtual Machine (JVM)
ii) What is final class? point 2.4.3
iii) Name the classes which implement the list interface. arraylist, linkedlist, vector
iv) What is a listener?point 4.6.2
v) Write any two implicit object in JSP? point 6.9
Q2) Answer the following (Any Five) : [5 × 3 = 15]
a) Explain types of JDBC? point 5.2.1
b) Differentiate between session & cookie. pg 6.30
c) Explain at least any five Features of Java. point 1.3
d) What is Exception? Explain try, catch & finally block. point 3.9
e) Explain in brief the fundamental idea behind MVC architecture? point 4.2
f) Write a short note on built in package and user define package. EOF
Q3) Answer the following (Any Five) : [5 × 4 = 20]
a) Write a java program to display last access and current date using session. EOF
b) Explain life cycle of a servlet. point 6.2
c) Explain types of Result Sets. point 5.5.2
d) Explain features of swing any 5. point 4.1.1
e) Explain any four methods of string Buffer class with proper syntax. pg 3.42
f) How to intending Interface? Explain with [Link]
g) What is a constructors? How many types of constructors are present in
Java? pg 1.37 & 1.38
Q4) Answer the following (Any Five) : [5 × 5 = 25]
a) Write a Java program that accept array elements print the average of all
elements. EOF
b) Explain any five classes of collection framework? point 3.4
c) What is event? How to handle events in AWT? Explain with example. EOF
d) Explain various type of JDBC. Discuss advantages and disadvantages of
each. point 5.2.1
e) What is servlet? Explain the types of servlet in details. point 6.1 & 6.1.2
f) Create a student table with fields (roll-no, name, percentage). Write JDBC
program to insert, delete & display details. EOF
g) Write a Java program that accept number from user and display factorial
of It (use swing & Action Listener) EOF
[5826]-501 2
paper 1.
************************************************************************************
Q1) B) d) State any two differences between throw & throws.
-- Here are two simple differences between throw and throws in Java:
1)throw is used inside a method to actually throw an exception, like throw new Exception();.
throws is used in a method’s signature to say the method might cause exceptions, like void myMethod() throws
Exception.
2)Number of Exceptions:
throw can be used to throw only one exception at a time.
throws can declare multiple exceptions separated by commas in the method signature.
************************************************************************************
Q2) a) Why JSP is Fly compilation.
--JSP is called "fly compilation" because it is compiled into a servlet automatically when it is first requested or
modified. This compilation happens at runtime (on the fly), making development faster and easier since manual
compilation is not needed.
************************************************************************************
Q3) c) Differentiate between checked and unchecked Exception.
Aspect Checked Exception Unchecked Exception
Checked at compile time by the Checked only at runtime, not by the
When Checked
compiler. compiler.
Handling Must be handled using try-catch Handling is optional, not enforced by the
Requirement or declared with throws. compiler.
Caused by external factors like Caused by programming errors like null
Cause
file I/O, network errors. pointer or divide by zero.
NullPointerException,
Example IOException, SQLException
ArithmeticException
************************************************************************************
Q4) b) Differentiate between Statement and prepared statement.
Aspect Statement PreparedStatement
Used for executing simple SQL Used for executing precompiled SQL
Definition
queries. queries.
Compiles the SQL query every time it Compiled once and reused multiple
Compilation
is executed. times.
Accepts parameters and supports
Parameters Does not accept parameters.
placeholders.
Performance Slower for repeated queries. Faster due to precompilation.
SQL Injection Lower risk, safer due to parameter
Higher risk.
Risk binding.
Suitable for dynamic queries with input
Use Case Suitable for static queries.
values.
************************************************************************************
Q4) c) Write a Java program to accept Number from user and display factorial.
--import [Link];
public class FactorialCalculator {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter a number: ");
int number = [Link]();
long factorial = 1;
for (int i = 1; i <= number; i++) {
factorial *= i;
}
[Link]("Factorial of " + number + " is: " + factorial);
[Link]();
}
}
************************************************************************************
Q4) d) Create a following JFrame using Swing.
import [Link].*;
import [Link].*;
public class FormFrame extends JFrame {
public FormFrame() {
setTitle("User Form");
setSize(350, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
// Create labels and text fields
JLabel nameLabel = new JLabel("Name:");
JTextField nameField = new JTextField(15);
JLabel addressLabel = new JLabel("Address:");
JTextField addressField = new JTextField(15);
JLabel phoneLabel = new JLabel("Phone:");
JTextField phoneField = new JTextField(15);
// Create buttons
JButton saveButton = new JButton("Save");
JButton cancelButton = new JButton("Cancel");
// Use GridBagLayout for better control
setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
[Link] = new Insets(5, 5, 5, 5);
// Add Name label and field
[Link] = 0; [Link] = 0; add(nameLabel, gbc);
[Link] = 1; [Link] = 0; add(nameField, gbc);
// Add Address label and field
[Link] = 0; [Link] = 1; add(addressLabel, gbc);
[Link] = 1; [Link] = 1; add(addressField, gbc);
// Add Phone label and field
[Link] = 0; [Link] = 2; add(phoneLabel, gbc);
[Link] = 1; [Link] = 2; add(phoneField, gbc);
// Add buttons
[Link] = 0; [Link] = 3; add(saveButton, gbc);
[Link] = 1; [Link] = 3; add(cancelButton, gbc);
}
public static void main(String[] args) {
[Link](() -> {
new FormFrame().setVisible(true);
});
}
}
************************************************************************************
Q4) e)Write a java program to accept a string from user. Check whether given
string is Palindrome or not
--import [Link];
public class PalindromeCheck {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter a string: ");
String input = [Link]();
String reversed = "";
// Reverse the input string
for (int i = [Link]() - 1; i >= 0; i--) {
reversed += [Link](i);
}
// Check palindrome ignoring case
if ([Link](reversed)) {
[Link](input + " is a palindrome.");
} else {
[Link](input + " is not a palindrome.");
}
[Link]();
}
}
************************************************************************************
Q4) f) What is event? How to hande awt events? Explain with example.
--What is an Event?
An event in Java is an action or occurrence recognized by software that may be handled by the program. It is
typically a change in the state of an object caused by user interaction like clicking a button, typing a key, moving the
mouse, etc.
How to Handle AWT Events?
Java uses the Delegation Event Modelto handle events in AWT. The model involves two key parts:
Event Source: The component (e.g., button) that generates the event.
Event Listener: An object that listens for an event and contains code to respond when the event occurs.
To handle events, you register a listener object with the event source, so when the event happens, the listener’s
method is called.
Example of Handling Button Click Event using AWT
import [Link].*;
import [Link].*;
public class EventExample extends Frame implements ActionListener {
Button button;
TextField textField;
public EventExample() {
setLayout(new FlowLayout());
button = new Button("Click Me");
textField = new TextField(20);
add(button);
add(textField);
// Register the current object as the listener for button click
[Link](this);
setSize(250, 150);
setVisible(true);
// Close window properly
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
[Link](0);
}
});
}
// This method will be called when the button is clicked
public void actionPerformed(ActionEvent e) {
[Link]("Button Clicked!");
}
public static void main(String[] args) {
new EventExample();
}
}
************************************************************************************
Q4) g) Explain Abstraction in detail.
--Abstraction in Object-Oriented Programming (OOP) means hiding the complex internal details of an object or
process and showing only the essential features to the user. It simplifies interaction by focusing on what an object
does rather than how it does it.
For example, when you use a car, you only need to know how to drive it, not how the engine works inside. Similarly,
in programming, abstraction allows you to work with objects without worrying about the internal code.
In Java, abstraction is achieved using:
Abstract classes (classes with some methods defined and some not)
Interfaces (which define methods that must be implemented by any class that uses them).
This helps in reducing complexity, improving code reusability, and making maintenance easier.
Two types of abstraction:
Data Abstraction: Hiding the object's data details, exposing only necessary parts.
Process Abstraction: Hiding the complex implementation of processes or methods.
Abstraction allows programmers to design systems efficiently by focusing on high-level functionalities.
************************************************************************************
paper 2.
************************************************************************************
Q2) c) Differentiate between Arraylist and linked list.
Aspect ArrayList LinkedList
Data Structure Uses dynamic array. Uses doubly linked list.
Access Time Fast (O(1)) for index-based access. Slow (O(n)) for index-based access.
Insertion/Deletion Slower due to shifting elements. Faster, just changes node pointers.
More memory, stores data plus
Memory Usage Less memory, stores only data.
links.
Better choice for frequent access Better choice for frequent
Use Case
operations. insert/delete ops.
************************************************************************************
Q3) d)Write a Java, program to accept number from user and display that
number is palindrome or not
--import [Link];
public class NumberPalindrome {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter a number: ");
int number = [Link]();
int originalNumber = number;
int reversedNumber = 0;
while (number != 0) {
int digit = number % 10;
reversedNumber = reversedNumber * 10 + digit;
number /= 10;
}
if (originalNumber == reversedNumber) {
[Link](originalNumber + " is a palindrome number.");
} else {
[Link](originalNumber + " is not a palindrome number.");
}
[Link]();
}
}
************************************************************************************
Q3) d) Differentiate between Data Input stream and Data Output stream class.
Aspect DataInputStream DataOutputStream
Reads primitive data types from an Writes primitive data types to an
Purpose
input stream. output stream.
Reads data like int, double, boolean, Writes data like int, double, boolean,
Functionality
UTF strings in binary format. UTF strings in binary format.
Superclass Extends FilterInputStream. Extends FilterOutputStream.
Reads data in a portable, machine- Writes data in a portable, machine-
Usage
independent way. independent way.
Example
readInt(), readDouble(), readUTF() writeInt(), writeDouble(), writeUTF()
Methods
************************************************************************************
Q4) a) Write a Java program to create following frame with proper logic.
--import [Link].*;
import [Link].*;
import [Link].*;
public class SearchStringFrame extends JFrame implements ActionListener {
JTextField stringField, keyField;
JLabel resultLabel;
public SearchStringFrame() {
setTitle("String Search");
setSize(300, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
[Link] = new Insets(8, 8, 8, 8);
[Link] = [Link];
// Enter string
[Link] = 0; [Link] = 0;
add(new JLabel("Enter string :"), gbc);
stringField = new JTextField(10);
[Link] = 1;
add(stringField, gbc);
// Enter key
[Link] = 0; [Link] = 1;
add(new JLabel("Enter Skey :"), gbc);
keyField = new JTextField(10);
[Link] = 1;
add(keyField, gbc);
// Search Button
[Link] = 0; [Link] = 2; [Link] = 2;
JButton searchButton = new JButton("Search");
add(searchButton, gbc);
[Link](this);
// Result Label
[Link] = 0; [Link] = 3; [Link] = 2;
resultLabel = new JLabel("");
add(resultLabel, gbc);
}
public void actionPerformed(ActionEvent e) {
String text = [Link]();
String key = [Link]();
if ([Link](key)) {
[Link]("String is search.");
} else {
[Link]("Key not found.");
}
}
public static void main(String[] args) {
[Link](() -> new SearchStringFrame().setVisible(true));
}
}
************************************************************************************
Q4) b) Write a java program to display string merge of two string.
--import [Link];
public class StringMerge {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter first string: ");
String str1 = [Link]();
[Link]("Enter second string: ");
String str2 = [Link]();
String mergedString = str1 + str2;
[Link]("Merged string: " + mergedString);
[Link]();
}
}
************************************************************************************
paper 3.
************************************************************************************
Q2) f) Differentiate between string and string Buffer class.
Aspect String StringBuffer
Immutable (cannot be changed once Mutable (can be changed after
Mutability
created). creation).
Performance Slower with frequent modifications. Faster with frequent modifications.
Memory Uses more memory due to new Uses less memory by modifying the
Usage object creation. same object.
Thread Safety Thread-safe due to immutability. Thread-safe due to synchronization.
No append() method, concatenation Has append(), insert(), delete()
Methods
creates new objects. methods for modifications.
Storage
Stored in String constant pool. Stored in heap memory.
Location
************************************************************************************
Q3) b) Write Java program to calculate the Fibbonacci series.
--import [Link];
public class FibonacciSeries {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter the number of terms: ");
int n = [Link]();
int a = 0, b = 1;
[Link]("Fibonacci Series: ");
for (int i = 1; i <= n; i++) {
[Link](a + " ");
int next = a + b;
a = b;
b = next;
}
[Link]();
}
}
************************************************************************************
Q3) e) Differentiate between Buffered Reader and Scanner class.
Aspect BufferedReader Scanner
Package [Link] [Link]
Reads text efficiently from Reads and parses primitive types and
Reading Capability
character streams. strings.
Performance Faster due to large buffer (8KB). Slower, smaller buffer (1KB).
Synchronization Thread-safe (synchronized). Not thread-safe.
Aspect BufferedReader Scanner
Exception
Throws IOException. Throws InputMismatchException.
Handling
Method to Read nextLine(), plus nextInt(),
readLine() returns a string.
Line nextDouble(), etc.
Efficient for reading large text or
Usage Easy parsing of user input.
files.
Supports parsing to different data
Parsing Support No parsing, reads raw text.
types.
************************************************************************************
Q3) g) Write Java program to create following frame
--import [Link].*;
import [Link].*;
import [Link].*;
public class SelectionFrame extends JFrame {
JRadioButton maleBtn, femaleBtn, yesBtn, noBtn;
JLabel resultLabel;
public SelectionFrame() {
setTitle("Selection Frame");
setSize(280, 150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setLayout(new GridLayout(3, 1));
// Gender selection
JPanel panel1 = new JPanel();
maleBtn = new JRadioButton("Male");
femaleBtn = new JRadioButton("Female");
ButtonGroup genderGroup = new ButtonGroup();
[Link](maleBtn);
[Link](femaleBtn);
[Link](maleBtn);
[Link](femaleBtn);
// Yes/No selection
JPanel panel2 = new JPanel();
yesBtn = new JRadioButton("Yes");
noBtn = new JRadioButton("No");
ButtonGroup optionGroup = new ButtonGroup();
[Link](yesBtn);
[Link](noBtn);
[Link](yesBtn);
[Link](noBtn);
// Result label
JPanel panel3 = new JPanel();
resultLabel = new JLabel("Selected : True or False");
[Link](resultLabel);
// Add panels to frame
add(panel1);
add(panel2);
add(panel3);
// Listener updates label based on selections
ActionListener listener = e -> {
boolean selected = ([Link]() || [Link]()) &&
([Link]() || [Link]());
[Link]("Selected : " + selected);
};
[Link](listener);
[Link](listener);
[Link](listener);
[Link](listener);
}
public static void main(String[] args) {
[Link](() -> new SelectionFrame().setVisible(true));
}
}
************************************************************************************
Q4) a) Write a Java program that accept number using command line argument
display that the number is perfect or not.
--public class PerfectNumber {
public static void main(String[] args) {
if ([Link] == 0) {
[Link]("Please provide a number as a command line argument.");
return;
}
int number = [Link](args[0]);
int sum = 0;
// Find sum of divisors (excluding the number itself)
for (int i = 1; i <= number / 2; i++) {
if (number % i == 0) {
sum += i;
}
}
// Check if sum equals the number
if (sum == number) {
[Link](number + " is a perfect number.");
} else {
[Link](number + " is not a perfect number.");
}
}
}
************************************************************************************
paper 4.
************************************************************************************
Q2) e) Differentiate between connection and statements.
Aspect Connection Statement
Represents a connection to a Used to execute SQL queries on a
Definition
database. database.
Establishes link between Java Sends SQL queries and updates to the
Purpose
application and database. database.
Aspect Connection Statement
Object Created by DriverManager or
Created from a Connection object.
Creation DataSource.
Long-lasting throughout the database Short-lived, used for executing
Scope
session. individual SQL statements.
executeQuery(), executeUpdate(),
Methods open(), close(), commit(), rollback().
execute().
Manages transactions and connection
Usage Performs CRUD operations on data.
state.
************************************************************************************
Q3) c) Write a Java program display menu using JPopMenu.
--import [Link].*;
import [Link].*;
public class PopupMenuShort extends JFrame {
public PopupMenuShort() {
JPopupMenu popup = new JPopupMenu();
[Link](new JMenuItem("Open"));
[Link](new JMenuItem("Save"));
[Link](new JMenuItem("Exit"));
addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
if ([Link]()) [Link]([Link](), [Link](), [Link]());
}
});
setSize(300, 200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args) {
[Link](() -> new PopupMenuShort().setVisible(true));
}
}
************************************************************************************
Q3) d) Write a Java program to create abstract class student derived two classes
marks and result From it use proper method to accept and display for
the same
--import [Link];
abstract class Student {
String name;
int rollNo;
abstract void accept();
abstract void display();
}
class Marks extends Student {
int marks;
void accept() {
Scanner sc = new Scanner([Link]);
[Link]("Enter Name: ");
name = [Link]();
[Link]("Enter Roll No: ");
rollNo = [Link]();
[Link]("Enter Marks: ");
marks = [Link]();
}
void display() {
[Link]("Name: " + name);
[Link]("Roll No: " + rollNo);
[Link]("Marks: " + marks);
}
}
class Result extends Marks {
String grade;
void calculate() {
if (marks >= 75) grade = "A";
else if (marks >= 60) grade = "B";
else if (marks >= 50) grade = "C";
else grade = "Fail";
}
public void display() {
[Link]();
[Link]("Grade: " + grade);
}
}
public class StudentDemo {
public static void main(String[] args) {
Result r = new Result();
[Link]();
[Link]();
[Link]();
}
}
************************************************************************************
Q4) d) Create table of Teacher with fields (Tid, Tname, Taddress) write a JDBC
Program to insert the details and display all teacher details.
--import [Link].*;
import [Link];
public class TeacherJDBC {
public static void main(String[] args) {
String url = "jdbc:mysql://localhost:3306/yourDatabase";
String user = "yourUsername";
String password = "yourPassword";
try (Connection con = [Link](url, user, password);
Scanner sc = new Scanner([Link])) {
// Insert teacher details
[Link]("Enter Tid: ");
int tid = [Link]();
[Link](); // consume newline
[Link]("Enter Tname: ");
String tname = [Link]();
[Link]("Enter Taddress: ");
String taddress = [Link]();
String insertSQL = "INSERT INTO Teacher (Tid, Tname, Taddress) VALUES (?, ?, ?)";
try (PreparedStatement pstmt = [Link](insertSQL)) {
[Link](1, tid);
[Link](2, tname);
[Link](3, taddress);
[Link]();
[Link]("Teacher inserted successfully.");
}
// Display all teacher details
String selectSQL = "SELECT * FROM Teacher";
try (Statement stmt = [Link]();
ResultSet rs = [Link](selectSQL)) {
[Link]("Teacher Details:");
while ([Link]()) {
[Link]("Tid: " + [Link]("Tid") +
", Tname: " + [Link]("Tname") +
", Taddress: " + [Link]("Taddress"));
}
}
} catch (SQLException e) {
[Link]();
}
}
}
************************************************************************************
Q4) e)Write a servlet program which counts how many times a user has visited
a web page (use session).
--import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class VisitCountServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
[Link]("text/html");
PrintWriter out = [Link]();
HttpSession session = [Link](true);
Integer count = (Integer) [Link]("visitCount");
if (count == null) {
count = 1;
} else {
count += 1;
}
[Link]("visitCount", count);
[Link]("<html><body>");
[Link]("<h2>Number of visits: " + count + "</h2>");
[Link]("</body></html>");
}
}
************************************************************************************
Q4) g) Write a Java program to accept in numbers in vector and display all
statements sum.
--import [Link];
import [Link];
public class VectorSum {
public static void main(String[] args) {
Vector<Integer> numbers = new Vector<>();
Scanner scanner = new Scanner([Link]);
[Link]("How many numbers do you want to enter? ");
int n = [Link]();
[Link]("Enter " + n + " numbers:");
for (int i = 0; i < n; i++) {
[Link]([Link]());
}
int sum = 0;
[Link]("Numbers entered:");
for (int num : numbers) {
[Link](num + " ");
sum += num;
}
[Link]("\nSum of numbers: " + sum);
[Link]();
}
}
************************************************************************************
paper 5.
************************************************************************************
Q3) b) What are the primitive data types in Java? Write about type conversion.
--Java has 8 primitive data types:
float, int, byte, short, long, double, char, Boolean.
Type Conversion in Java
Type conversion means converting one data type into another. It occurs in two ways:
1. **Implicit (Widening) Conversion**:
- Automatically done by the compiler.
- Smaller to larger type, e.g. int to long, float to double.
- No data loss.
2. **Explicit (Narrowing) Conversion**:
- Done manually using casting.
- Larger to smaller type, e.g. double to int.
- May cause data loss or truncation.
Example of explicit conversion:
double d = 9.78;
int i = (int) d; // i = 9
************************************************************************************
Q3) c) Write a Java program to check age is greater than 18. Give appropriate
message (using exception handling)
--import [Link];
class AgeException extends Exception {
public AgeException(String message) {
super(message);
}
}
public class AgeCheck {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter your age: ");
int age = [Link]();
try {
if (age <= 18) {
throw new AgeException("Age must be greater than 18.");
} else {
[Link]("Age is greater than 18. You are eligible.");
}
} catch (AgeException e) {
[Link]("Exception: " + [Link]());
} finally {
[Link]();
}
}
}
************************************************************************************
Q4) b) Write a Java program to check whether number is armstrong or not.
--import [Link];
public class ArmstrongNumber {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter a number: ");
int number = [Link]();
int originalNumber = number;
int sum = 0;
// Find number of digits
int digits = [Link](number).length();
while (number > 0) {
int digit = number % 10;
sum += [Link](digit, digits);
number /= 10;
}
if (sum == originalNumber) {
[Link](originalNumber + " is an Armstrong number.");
} else {
[Link](originalNumber + " is not an Armstrong number.");
}
[Link]();
}
}
************************************************************************************
Q4) e) Describe about various components in AWT.
--Here are some basic Java AWT components:
- **Button:** A clickable button.
- **Label:** Displays text.
- **TextField:** Single-line text input.
- **Checkbox:** A box that can be checked or unchecked.
- **Frame:** Main window to hold components.
- **Panel:** Container to group components.
These are the primary building blocks to create simple AWT GUIs.
************************************************************************************
Q4) g) Write a Java program to create following.
--import [Link].*;
import [Link].*;
public class MenuExample extends Frame {
public MenuExample() {
setTitle("Menu Example");
setSize(500, 300);
setLayout(null);
setVisible(true);
MenuBar menuBar = new MenuBar();
Menu fileMenu = new Menu("File");
MenuItem openItem = new MenuItem("Open");
MenuItem newItem = new MenuItem("New");
[Link](openItem);
[Link](newItem);
[Link](fileMenu);
setMenuBar(menuBar);
// Optional: Window close operation
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
}
});
}
public static void main(String[] args) {
new MenuExample();
}
}
************************************************************************************
paper 6.
************************************************************************************
Q2) f) Write a short note on built in package and user define package.
--Short Note on Built-in Package and User-defined Package in Java
Built-in Package:
- These are the predefined packages provided by the Java Development Kit (JDK).
- They contain prewritten classes and interfaces for common functionalities like input/output, networking, data
structures, GUI components, etc.
- Examples include:
- `[Link]` (core language classes like String, Math)
- `[Link]` (collections, date/time)
- `[Link]` (file and stream handling)
- `[Link]` (abstract window toolkit for GUI)
- Built-in packages help developers by providing ready-to-use components to avoid rewriting common functions.
User-defined Package:
- These packages are created by the programmer to organize classes and interfaces logically.
- They help in avoiding naming conflicts and improve modularization and maintainability of code.
- To define a package use `package` keyword at the top of Java source file.
- Example:
java
package mypackage;
public class MyClass {
public void display() {
[Link]("Inside user-defined package");
}
}
- These packages are imported using `import` statement to be accessed in other classes or packages.
************************************************************************************
Q3) a) Write a java program to display last access and current date using session.
-- import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class LastAccessServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
[Link]("text/html");
PrintWriter out = [Link]();
HttpSession session = [Link]();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
// Get current access time
String currentAccess = [Link](new Date());
// Get last access time from session
String lastAccess = (String) [Link]("lastAccess");
// Update session with current time
[Link]("lastAccess", currentAccess);
[Link]("<html><body>");
if (lastAccess == null) {
[Link]("<h3>This is your first visit.</h3>");
} else {
[Link]("<h3>Your last visit was on: " + lastAccess + "</h3>");
}
[Link]("<h3>Current date and time: " + currentAccess + "</h3>");
[Link]("</body></html>");
}
}
************************************************************************************
Q3) f) How to intending Interface? Explain with example.
--Implementing Interface in Java with Example
In Java, to use an interface you implement it in a class that provides concrete implementations for the interface's
abstract methods. This is done using the `implements` keyword.
Example:
// Define an interface
interface Animal {
void sound(); // abstract method
}
// Implement the interface
class Dog implements Animal {
public void sound() {
[Link]("Dog barks");
}
}
public class Main {
public static void main(String[] args) {
Dog d = new Dog();
[Link](); // Outputs: Dog barks
}
}
Explanation:
- The interface `Animal` declares an abstract method `sound()`.
- The class `Dog` **implements** the `Animal` interface and provides the method body for `sound()`.
- The `implements` keyword tells Java that `Dog` will provide concrete behavior for all methods in the `Animal`
interface.
- You cannot create objects of the interface, only of the implementing class.
multiple inheritance in Java.
************************************************************************************
Q4) a) Write a Java program that accept array elements print the average of all
elements.
--import [Link];
public class ArrayAverage {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter the number of elements: ");
int n = [Link]();
int[] arr = new int[n];
int sum = 0;
[Link]("Enter " + n + " elements:");
for (int i = 0; i < n; i++) {
arr[i] = [Link]();
sum += arr[i];
}
double average = (double) sum / n;
[Link]("Average of all elements: " + average);
[Link]();
}
}
************************************************************************************
Q4) f) Create a student table with fields (roll-no, name, percentage). Write JDBC
program to insert, delete & display details.
--import [Link].*;
import [Link];
public class StudentJDBC {
public static void main(String[] args) {
String url = "jdbc:mysql://localhost:3306/yourDatabase";
String user = "yourUsername";
String password = "yourPassword";
try (Connection con = [Link](url, user, password);
Scanner sc = new Scanner([Link])) {
while (true) {
[Link]("1. Insert Student");
[Link]("2. Delete Student");
[Link]("3. Display Students");
[Link]("4. Exit");
[Link]("Choose an option: ");
int choice = [Link]();
[Link](); // consume newline
if (choice == 1) {
[Link]("Enter Roll No: ");
int rollNo = [Link]();
[Link]();
[Link]("Enter Name: ");
String name = [Link]();
[Link]("Enter Percentage: ");
float percentage = [Link]();
[Link]();
String insertSQL = "INSERT INTO Student (roll_no, name, percentage) VALUES (?, ?, ?)";
try (PreparedStatement pstmt = [Link](insertSQL)) {
[Link](1, rollNo);
[Link](2, name);
[Link](3, percentage);
[Link]();
[Link]("Student inserted successfully.");
}
} else if (choice == 2) {
[Link]("Enter Roll No to delete: ");
int rollNo = [Link]();
[Link]();
String deleteSQL = "DELETE FROM Student WHERE roll_no = ?";
try (PreparedStatement pstmt = [Link](deleteSQL)) {
[Link](1, rollNo);
int rows = [Link]();
if (rows > 0) {
[Link]("Student deleted successfully.");
} else {
[Link]("Student not found.");
}
}
} else if (choice == 3) {
String selectSQL = "SELECT * FROM Student";
try (Statement stmt = [Link]();
ResultSet rs = [Link](selectSQL)) {
[Link]("Student Details:");
while ([Link]()) {
[Link]("Roll No: " + [Link]("roll_no") +
", Name: " + [Link]("name") +
", Percentage: " + [Link]("percentage"));
}
}
} else if (choice == 4) {
[Link]("Exiting...");
break;
} else {
[Link]("Invalid choice. Try again.");
}
}
} catch (SQLException e) {
[Link]();
}
}
}
************************************************************************************
Q4) g) Write a Java program that accept number from user and display factorial
of It (use swing & Action Listener).
--import [Link].*;
import [Link].*;
public class FactorialCalculator extends JFrame implements ActionListener {
JTextField numberField;
JLabel resultLabel;
JButton calculateButton;
public FactorialCalculator() {
setTitle("Factorial Calculator");
setSize(300, 150);
setLayout(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JLabel promptLabel = new JLabel("Enter Number:");
[Link](20, 20, 100, 25);
add(promptLabel);
numberField = new JTextField();
[Link](120, 20, 100, 25);
add(numberField);
calculateButton = new JButton("Calculate");
[Link](80, 60, 120, 30);
[Link](this);
add(calculateButton);
resultLabel = new JLabel("Factorial: ");
[Link](20, 100, 250, 25);
add(resultLabel);
}
@Override
public void actionPerformed(ActionEvent e) {
try {
int num = [Link]([Link]());
long factorial = 1;
for (int i = 1; i <= num; i++) {
factorial *= i;
}
[Link]("Factorial: " + factorial);
} catch (NumberFormatException nfe) {
[Link]("Please enter a valid integer.");
}
}
public static void main(String[] args) {
[Link](() -> new FactorialCalculator().setVisible(true));
}
}