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 [Link].*;
import [Link].*;
class StudentJDBC {
public static void main(String args[]) throws Exception {
Scanner sc = new Scanner([Link]);
[Link]("Enter Roll No: ");
int roll = [Link]();
[Link]();
[Link]("Enter Name: ");
String name = [Link]();
[Link]("Enter Percentage: ");
float per = [Link]();
Connection con = [Link]("jdbc:postgresql://localhost:5432/yourdb",
"postgres", "yourpass");
PreparedStatement ps = [Link]("insert into student values(?,?,?)");
[Link](1, roll);
[Link](2, name);
[Link](3, per);
[Link]();
ResultSet rs = [Link]().executeQuery("select * from student");
while([Link]()){
[Link]([Link](1)+" "+[Link](2)+" "+[Link](3));
}
[Link]();
}
}
Q: Write a JSP program to accept username & password and validate login.
<%@ page import="[Link].*" %>
<%
String uname = [Link]("uname");
String pass = [Link]("pass");
if([Link](pass)){
[Link]("<h3>Login Successful</h3>");
} else {
[Link]("<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 [Link].*;
class ReverseNames {
public static void main(String args[]) {
Scanner sc = new Scanner([Link]);
LinkedList<String> list = new LinkedList<>();
[Link]("Enter number of students: ");
int n = [Link]();
[Link]();
for(int i=0;i<n;i++){
[Link]("Enter name: ");
[Link]([Link]());
}
[Link](list);
[Link]("Reversed Names: " + list);
}
}
Q: Write a Java program to delete teacher record from database and display remaining records.
import [Link].*;
import [Link].*;
class DeleteTeacher {
public static void main(String args[]) throws Exception {
Scanner sc = new Scanner([Link]);
[Link]("Enter Teacher ID to delete: ");
int id = [Link]();
Connection con = [Link]("jdbc:postgresql://localhost:5432/yourdb",
"postgres", "yourpass");
PreparedStatement ps = [Link]("delete from teacher where tid=?");
[Link](1, id);
[Link]();
ResultSet rs = [Link]().executeQuery("select * from teacher");
while([Link]()) {
[Link]([Link](1)+" "+[Link](2)+" "+[Link](3));
}
[Link]();
}
}