0% found this document useful (0 votes)
10 views2 pages

Java II Predicted Programs

The document contains predicted exam questions for a Java II course, including Java programs for student data management, user login validation using JSP, reversing a list of student names, and deleting teacher records from a database. Each question is accompanied by sample code demonstrating the required functionality. The document serves as a study guide based on analysis of past exam trends.

Uploaded by

Abhishek Kapse
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)
10 views2 pages

Java II Predicted Programs

The document contains predicted exam questions for a Java II course, including Java programs for student data management, user login validation using JSP, reversing a list of student names, and deleting teacher records from a database. Each question is accompanied by sample code demonstrating the required functionality. The document serves as a study guide based on analysis of past exam trends.

Uploaded by

Abhishek Kapse
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/ 2

Java II - Predicted Exam Paper (Based on Last 4 Years)

HIGH CHANCE QUESTIONS (Based on Analysis)

Q: Write a Java program to accept details of student (rollno, name, percentage). Store into database and

display.

import java.sql.*;
import java.util.*;

class StudentJDBC {
public static void main(String args[]) throws Exception {
Scanner sc = new Scanner(System.in);
System.out.print("Enter Roll No: ");
int roll = sc.nextInt();
sc.nextLine();
System.out.print("Enter Name: ");
String name = sc.nextLine();
System.out.print("Enter Percentage: ");
float per = sc.nextFloat();

Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/yourdb",


"postgres", "yourpass");
PreparedStatement ps = con.prepareStatement("insert into student values(?,?,?)");
ps.setInt(1, roll);
ps.setString(2, name);
ps.setFloat(3, per);
ps.executeUpdate();

ResultSet rs = con.createStatement().executeQuery("select * from student");


while(rs.next()){
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getFloat(3));
}
con.close();
}
}

Q: Write a JSP program to accept username & password and validate login.

<%@ page import="java.io.*" %>


<%
String uname = request.getParameter("uname");
String pass = request.getParameter("pass");
if(uname.equals(pass)){
out.println("<h3>Login Successful</h3>");
} else {
out.println("<h3>Login Failed</h3>");
}
%>
<form method="post">
Java II - Predicted Exam Paper (Based on Last 4 Years)

Username: <input type="text" name="uname"><br>


Password: <input type="password" name="pass"><br>
<input type="submit" value="Login">
</form>

Q: Write a Java program to accept N student names and display them in reverse order using LinkedList.

import java.util.*;
class ReverseNames {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
LinkedList<String> list = new LinkedList<>();
System.out.print("Enter number of students: ");
int n = sc.nextInt();
sc.nextLine();
for(int i=0;i<n;i++){
System.out.print("Enter name: ");
list.add(sc.nextLine());
}
Collections.reverse(list);
System.out.println("Reversed Names: " + list);
}
}

Q: Write a Java program to delete teacher record from database and display remaining records.

import java.sql.*;
import java.util.*;

class DeleteTeacher {
public static void main(String args[]) throws Exception {
Scanner sc = new Scanner(System.in);
System.out.print("Enter Teacher ID to delete: ");
int id = sc.nextInt();

Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/yourdb",


"postgres", "yourpass");
PreparedStatement ps = con.prepareStatement("delete from teacher where tid=?");
ps.setInt(1, id);
ps.executeUpdate();

ResultSet rs = con.createStatement().executeQuery("select * from teacher");


while(rs.next()) {
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
}
con.close();
}
}

You might also like