0% found this document useful (0 votes)
3 views20 pages

JPR Java Complete

The document outlines the JPR Java Programming Final Practical Exam for 2026, consisting of 25 programming tasks covering various topics such as basic Java, object-oriented programming, multithreading, exceptions, GUI, and networking. Each task includes a brief description and sample code demonstrating the required functionality. The exam aims to assess students' understanding and application of Java programming concepts.

Uploaded by

aartik1798
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)
3 views20 pages

JPR Java Complete

The document outlines the JPR Java Programming Final Practical Exam for 2026, consisting of 25 programming tasks covering various topics such as basic Java, object-oriented programming, multithreading, exceptions, GUI, and networking. Each task includes a brief description and sample code demonstrating the required functionality. The exam aims to assess students' understanding and application of Java programming concepts.

Uploaded by

aartik1798
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

JPR Java Programming

Final Practical Exam 2026 — All 25 Programs

Complete Code: Header to Closing Brace

Ms. M.K. Kute / Mrs. V.R. Pingale


Index
Q
Greatest among 3 numbers Basic
01

Q
Day of week Basic
02

Q
Vowel or not Basic
03

Q
Command line arguments Basic
04

Q
Constructors (default, parameterized, copy) OOP
05

Q
10 methods of String class Basic
06

Q
5 methods of StringBuffer class Basic
07

Q
Array elements using for-each loop Basic
08

Q
Insert elements in Vector Basic
09

Q
10 methods of Vector class Basic
10

Q
Multilevel Inheritance OOP
11

Q
Area using interface Shape OOP
12

Q
Multithreading — Runnable interface Thread
13

Q
Multithreading — Thread class Thread
14

Q
try, catch, finally block Exception
15

Q
User-defined exception Exception
16

Q
AWT Form design GUI
17

Q
Swing Login form GUI
18

Q
KeyListener — Key events GUI
19

Q
MouseListener — Mouse events GUI
20

Q
ActionListener — Action event GUI
21

Q
Methods of URL class Network
22
Q
Methods of URLConnection class Network
23

Q
Socket programming (Server & Client) Network
24

Q
JDBC — ResultSet JDBC
25
Q Greatest among 3 numbers (multiple if-else) Basic
1

import [Link];

public class Q1_Greatest {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter 3 numbers: ");
int a = [Link](), b = [Link](), c = [Link]();

if (a >= b && a >= c)


[Link]("Greatest: " + a);
else if (b >= a && b >= c)
[Link]("Greatest: " + b);
else
[Link]("Greatest: " + c);
}
}

Q Day of week (switch case) Basic


2

import [Link];

public class Q2_Day {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter day number (1-7): ");
int day = [Link]();

switch (day) {
case 1: [Link]("Monday"); break;
case 2: [Link]("Tuesday"); break;
case 3: [Link]("Wednesday"); break;
case 4: [Link]("Thursday"); break;
case 5: [Link]("Friday"); break;
case 6: [Link]("Saturday"); break;
case 7: [Link]("Sunday"); break;
default: [Link]("Invalid day");
}
}
}

Q Vowel or not (switch case) Basic


3
import [Link];

public class Q3_Vowel {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter a character: ");
char ch = [Link]().toLowerCase().charAt(0);

switch (ch) {
case 'a': case 'e': case 'i': case 'o': case 'u':
[Link](ch + " is a Vowel");
break;
default:
[Link](ch + " is not a Vowel");
}
}
}

Q Command line arguments (for loop) Basic


4

public class Q4_CmdArgs {


public static void main(String[] args) {
[Link]("Total arguments: " + [Link]);

for (int i = 0; i < [Link]; i++) {


[Link]("Argument " + (i + 1) + ": " + args[i]);
}
}
}

// How to run:
// javac Q4_CmdArgs.java
// java Q4_CmdArgs Hello World Java

Q Constructors — default, parameterized, copy OOP


5
public class Q5_Constructor {
int id;
String name;

// Default Constructor
Q5_Constructor() {
id = 0;
name = "Unknown";
[Link]("Default Constructor: " + id + ", " + name);
}

// Parameterized Constructor
Q5_Constructor(int id, String name) {
[Link] = id;
[Link] = name;
[Link]("Parameterized Constructor: " + id + ", " + name);
}

// Copy Constructor
Q5_Constructor(Q5_Constructor obj) {
[Link] = [Link];
[Link] = [Link];
[Link]("Copy Constructor: " + id + ", " + name);
}

public static void main(String[] args) {


Q5_Constructor c1 = new Q5_Constructor();
Q5_Constructor c2 = new Q5_Constructor(101, "Alice");
Q5_Constructor c3 = new Q5_Constructor(c2);
}
}
Q 10 methods of String class Basic
6

public class Q6_StringMethods {


public static void main(String[] args) {
String s = "Hello World";

[Link]("1. length() : " + [Link]());


[Link]("2. toUpperCase() : " + [Link]());
[Link]("3. toLowerCase() : " + [Link]());
[Link]("4. charAt(0) : " + [Link](0));
[Link]("5. substring(6) : " + [Link](6));
[Link]("6. replace() : " + [Link]("World", "Java"));
[Link]("7. contains() : " + [Link]("World"));
[Link]("8. indexOf() : " + [Link]("o"));
[Link]("9. trim() : " + " Hi ".trim());
[Link]("10. equals() : " + [Link]("Hello World"));
}
}

Q 5 methods of StringBuffer class Basic


7

public class Q7_StringBufferMethods {


public static void main(String[] args) {
StringBuffer sb = new StringBuffer("Hello");

[Link](" World");
[Link]("1. append() : " + sb);

[Link](5, ",");
[Link]("2. insert() : " + sb);

[Link](5, 6);
[Link]("3. delete() : " + sb);

[Link]();
[Link]("4. reverse() : " + sb);

[Link]("5. length() : " + [Link]());


}
}

Q Array elements using for-each loop Basic


8

public class Q8_ForEach {


public static void main(String[] args) {
int[] arr = {10, 20, 30, 40, 50};

[Link]("Array elements:");
for (int x : arr) {
[Link](x + " ");
}
}
}
Q Insert elements in Vector and display Basic
9

import [Link];

public class Q9_Vector {


public static void main(String[] args) {
Vector<Integer> v = new Vector<>();

[Link](10);
[Link](20);
[Link](30);
[Link](40);
[Link](50);

[Link]("Vector elements: " + v);


[Link]("Size: " + [Link]());
}
}

Q
10 methods of Vector class Basic
1
0

import [Link];

public class Q10_VectorMethods {


public static void main(String[] args) {
Vector<Integer> v = new Vector<>();
[Link](10); [Link](20); [Link](30); [Link](40);

[Link]("1. size() : " + [Link]());


[Link]("2. get(1) : " + [Link](1));
[Link]("3. contains(20) : " + [Link](20));
[Link]("4. indexOf(30) : " + [Link](30));
[Link]("5. isEmpty() : " + [Link]());
[Link](0, 99);
[Link]("6. set(0,99) : " + v);
[Link]([Link](99));
[Link]("7. remove(99) : " + v);
[Link]("8. firstElement() : " + [Link]());
[Link]("9. lastElement() : " + [Link]());
[Link]();
[Link]("10. clear() : " + v);
}
}
Q
Multilevel Inheritance OOP
1
1

class Animal {
void eat() {
[Link]("Animal is eating");
}
}

class Dog extends Animal {


void bark() {
[Link]("Dog is barking");
}
}

class Puppy extends Dog {


void weep() {
[Link]("Puppy is weeping");
}
}

public class Q11_Multilevel {


public static void main(String[] args) {
Puppy p = new Puppy();
[Link](); // inherited from Animal
[Link](); // inherited from Dog
[Link](); // own method
}
}

Q
Area of Rectangle & Circle using interface Shape OOP
1
2
interface Shape {
double area();
}

class Rectangle implements Shape {


double length, breadth;

Rectangle(double l, double b) {
length = l;
breadth = b;
}

public double area() {


return length * breadth;
}
}

class Circle implements Shape {


double radius;

Circle(double r) {
radius = r;
}

public double area() {


return 3.14 * radius * radius;
}
}

public class Q12_Interface {


public static void main(String[] args) {
Shape rect = new Rectangle(5, 3);
Shape circle = new Circle(4);
[Link]("Rectangle Area : " + [Link]());
[Link]("Circle Area : " + [Link]());
}
}

Q
Multithreading using Runnable interface Thread
1
3
class MyRunnable implements Runnable {
public void run() {
for (int i = 1; i <= 3; i++) {
[Link]([Link]().getName() + " count: " + i);
try {
[Link](500);
} catch (InterruptedException e) {
[Link](e);
}
}
}
}

public class Q13_Runnable {


public static void main(String[] args) {
Thread t1 = new Thread(new MyRunnable(), "Thread-1");
Thread t2 = new Thread(new MyRunnable(), "Thread-2");
[Link]();
[Link]();
}
}
Q
Multithreading by extending Thread class Thread
1
4

class MyThread extends Thread {


public void run() {
for (int i = 1; i <= 3; i++) {
[Link](getName() + " count: " + i);
try {
[Link](500);
} catch (InterruptedException e) {
[Link](e);
}
}
}
}

public class Q14_Thread {


public static void main(String[] args) {
MyThread t1 = new MyThread();
MyThread t2 = new MyThread();
[Link]("Thread-A");
[Link]("Thread-B");
[Link]();
[Link]();
}
}

Q
try, catch, finally block Exception
1
5

public class Q15_TryCatch {


public static void main(String[] args) {
try {
int a = 10, b = 0;
int result = a / b; // causes ArithmeticException
[Link]("Result: " + result);
} catch (ArithmeticException e) {
[Link]("Exception caught: " + [Link]());
} finally {
[Link]("Finally block always executes.");
}
}
}

Q
User-defined exception for negative number Exception
1
6
import [Link];

class NegativeNumberException extends Exception {


NegativeNumberException(String message) {
super(message);
}
}

public class Q16_UserException {

static void checkNumber(int n) throws NegativeNumberException {


if (n < 0) {
throw new NegativeNumberException("Negative number not allowed: " + n);
}
[Link]("Valid number: " + n);
}

public static void main(String[] args) {


Scanner sc = new Scanner([Link]);
[Link]("Enter a number: ");
int num = [Link]();
try {
checkNumber(num);
} catch (NegativeNumberException e) {
[Link]("Exception: " + [Link]());
}
}
}
Q
Form design using AWT components GUI
1
7

import [Link].*;

public class Q17_AWTForm extends Frame {

Q17_AWTForm() {
setLayout(new FlowLayout());
setTitle("Student Registration Form");

add(new Label("Name:"));
add(new TextField(15));

add(new Label("Gender:"));
CheckboxGroup cbg = new CheckboxGroup();
add(new Checkbox("Male", cbg, true));
add(new Checkbox("Female", cbg, false));

add(new Label("City:"));
Choice city = new Choice();
[Link]("Pune");
[Link]("Mumbai");
[Link]("Nashik");
add(city);

add(new Button("Submit"));
add(new Button("Reset"));

setSize(350, 220);
setVisible(true);
}

public static void main(String[] args) {


new Q17_AWTForm();
}
}

Q
User login form using Swing components GUI
1
8
import [Link].*;

public class Q18_SwingLogin extends JFrame {

Q18_SwingLogin() {
setTitle("User Login");
setLayout(null);
setSize(320, 220);
setDefaultCloseOperation(EXIT_ON_CLOSE);

JLabel l1 = new JLabel("Username:");


[Link](30, 40, 90, 25);
JTextField tf = new JTextField();
[Link](130, 40, 140, 25);

JLabel l2 = new JLabel("Password:");


[Link](30, 80, 90, 25);
JPasswordField pf = new JPasswordField();
[Link](130, 80, 140, 25);

JButton login = new JButton("Login");


[Link](80, 130, 80, 30);
JButton cancel = new JButton("Cancel");
[Link](170, 130, 80, 30);

add(l1); add(tf); add(l2); add(pf);


add(login); add(cancel);
setVisible(true);
}

public static void main(String[] args) {


new Q18_SwingLogin();
}
}
Q
Key events using KeyListener Interface GUI
1
9

import [Link].*;
import [Link].*;

public class Q19_KeyEvent extends Frame implements KeyListener {

Label msg = new Label("Press any key...");

Q19_KeyEvent() {
setTitle("KeyListener Demo");
setLayout(new FlowLayout());
add(msg);
addKeyListener(this);
setSize(350, 150);
setVisible(true);
}

public void keyPressed(KeyEvent e) {


[Link]("Key Pressed : " + [Link]());
}

public void keyReleased(KeyEvent e) {


[Link]("Key Released : " + [Link]());
}

public void keyTyped(KeyEvent e) {


[Link]("Key Typed : " + [Link]());
}

public static void main(String[] args) {


new Q19_KeyEvent();
}
}

Q
Mouse events using MouseListener Interface GUI
2
0
import [Link].*;
import [Link].*;

public class Q20_MouseEvent extends Frame implements MouseListener {

Label msg = new Label("Perform a mouse action...");

Q20_MouseEvent() {
setTitle("MouseListener Demo");
setLayout(new FlowLayout());
add(msg);
addMouseListener(this);
setSize(350, 150);
setVisible(true);
}

public void mouseClicked(MouseEvent e) { [Link]("Mouse Clicked"); }


public void mousePressed(MouseEvent e) { [Link]("Mouse Pressed"); }
public void mouseReleased(MouseEvent e) { [Link]("Mouse Released"); }
public void mouseEntered(MouseEvent e) { [Link]("Mouse Entered"); }
public void mouseExited(MouseEvent e) { [Link]("Mouse Exited"); }

public static void main(String[] args) {


new Q20_MouseEvent();
}
}

Q
Action event using ActionListener Interface GUI
2
1

import [Link].*;
import [Link].*;

public class Q21_ActionEvent extends Frame implements ActionListener {

Label msg = new Label("Click the button");


Button btn = new Button("Click Me");

Q21_ActionEvent() {
setTitle("ActionListener Demo");
setLayout(new FlowLayout());
add(btn);
add(msg);
[Link](this);
setSize(300, 150);
setVisible(true);
}

public void actionPerformed(ActionEvent e) {


[Link]("Button Clicked! Action Performed.");
}

public static void main(String[] args) {


new Q21_ActionEvent();
}
}
Q
Various methods of URL class Network
2
2

import [Link].*;

public class Q22_URL {


public static void main(String[] args) throws Exception {
URL url = new URL("[Link]

[Link]("Protocol : " + [Link]());


[Link]("Host : " + [Link]());
[Link]("Port : " + [Link]());
[Link]("Path : " + [Link]());
[Link]("Query : " + [Link]());
[Link]("File : " + [Link]());
[Link]("Ref : " + [Link]());
[Link]("Full URL : " + [Link]());
}
}

Q
Various methods of URLConnection class Network
2
3

import [Link].*;

public class Q23_URLConnection {


public static void main(String[] args) throws Exception {
URL url = new URL("[Link]
URLConnection con = [Link]();
[Link]();

[Link]("Content-Type : " + [Link]());


[Link]("Content-Length : " + [Link]());
[Link]("Date : " + [Link]());
[Link]("Last Modified : " + [Link]());
[Link]("Expiration : " + [Link]());
}
}

Q
Socket programming — Server & Client Network
2
4
Note: Run Q24_Server first, then Q24_Client in a separate terminal
// ============ SERVER — save as Q24_Server.java ============
import [Link].*;
import [Link].*;

public class Q24_Server {


public static void main(String[] args) throws Exception {
ServerSocket ss = new ServerSocket(5000);
[Link]("Server started. Waiting for client...");
Socket s = [Link]();
[Link]("Client connected!");

// Read from client


BufferedReader in = new BufferedReader(
new InputStreamReader([Link]()));
[Link]("Client says: " + [Link]());

// Send to client
PrintWriter out = new PrintWriter([Link](), true);
[Link]("Hello from Server!");

[Link]();
[Link]();
}
}

// ============ CLIENT — save as Q24_Client.java ============


import [Link].*;
import [Link].*;

public class Q24_Client {


public static void main(String[] args) throws Exception {
Socket s = new Socket("localhost", 5000);

// Send to server
PrintWriter out = new PrintWriter([Link](), true);
[Link]("Hello from Client!");

// Read from server


BufferedReader in = new BufferedReader(
new InputStreamReader([Link]()));
[Link]("Server says: " + [Link]());

[Link]();
}
}
Q
Retrieve data from table using ResultSet (JDBC) JDBC
2
5
Note: Add [Link] to classpath before compiling

import [Link].*;

public class Q25_JDBC {


public static void main(String[] args) throws Exception {

// Step 1: Load the driver


[Link]("[Link]");

// Step 2: Establish connection


Connection con = [Link](
"jdbc:mysql://localhost:3306/testdb", "root", "password");

// Step 3: Create statement


Statement stmt = [Link]();

// Step 4: Execute query


ResultSet rs = [Link]("SELECT * FROM student");

// Step 5: Display result


[Link]("ID\tName\t\tMarks");
[Link]("---\t----\t\t-----");
while ([Link]()) {
[Link]([Link]("id") + "\t"
+ [Link]("name") + "\t\t"
+ [Link]("marks"));
}

// Step 6: Close resources


[Link]();
[Link]();
[Link]();
}
}

// MySQL setup commands:


// CREATE DATABASE testdb;
// USE testdb;
// CREATE TABLE student(id INT, name VARCHAR(20), marks INT);
// INSERT INTO student VALUES(1,'Alice',85),(2,'Bob',90),(3,'Carol',78);

JPR Java Practical Exam 2026 · Ms. M.K. Kute / Mrs. V.R. Pingale · All 25 Programs · Best of Luck!

You might also like