Java Skill-Based Practical Questions & Answers
1. Design a Java-based Unit Conversion Utility (temperature, currency, length)
Type: Skill | Skills Gained: Type conversion, control structures, method declaration
public class UnitConverter {
public static double celsiusToFahrenheit(double c) {
return (c * 9/5) + 32; // formula
}
public static void main(String[] args) {
double c = 30.0;
double f = celsiusToFahrenheit(c);
[Link](c + "degC = " + f + "degF");
}
}
2. Build a Date-Time Calculator
Type: Skill | Skills Gained: [Link] API (LocalDate, Period, Duration)
import [Link].*;
public class DateTimeCalculator {
public static void main(String[] args) {
LocalDate today = [Link]();
LocalDate afterTen = [Link](10); // add 10 days
Period diff = [Link](today, afterTen); // difference
[Link]("Today: " + today);
[Link]("10 days later: " + afterTen);
[Link]("Difference: " + [Link]() + " days");
}
}
3. Develop a Student Marks Analyzer
Type: Skill | Skills Gained: 2D arrays, enhanced for-loop
public class MarksAnalyzer {
public static void main(String[] args) {
int[][] marks = {
{90, 80, 70},
{75, 85, 65}
};
for (int i = 0; i < [Link]; i++) {
int total = 0;
for (int m : marks[i]) {
total += m;
}
[Link]("Student " + (i+1) + " Average: " + (total / marks[i].length));
}
}
}
4. Implement a Vehicle Management System using Inheritance
Type: Skill | Skills Gained: Class design, inheritance, overriding, constructor chaining
class Vehicle {
String brand;
Vehicle(String brand) { [Link] = brand; }
void display() { [Link]("Brand: " + brand); }
}
class Car extends Vehicle {
String model;
Car(String brand, String model) {
Java Skill-Based Practical Questions & Answers
super(brand); // call parent constructor
[Link] = model;
}
@Override
void display() {
[Link]();
[Link]("Model: " + model);
}
public static void main(String[] args) {
new Car("Toyota", "Innova").display();
}
}
5. Develop a Role-Based Access Control (RBAC) System
Type: Skill | Skills Gained: Abstract classes, interfaces, dynamic binding
interface Role {
void permissions();
}
class Admin implements Role {
public void permissions() { [Link]("Admin - full access"); }
}
class User implements Role {
public void permissions() { [Link]("User - read-only access"); }
}
public class RBACDemo {
public static void main(String[] args) {
Role r1 = new Admin();
Role r2 = new User();
[Link]();
[Link]();
}
}
6. Create a Modular Library System with Package & Access Control
Type: Skill | Skills Gained: Access modifiers, modular design, encapsulation
class Book {
private String title; // private encapsulated field
public Book(String title) { [Link] = title; }
public void info() { [Link]("Book: " + title); }
}
public class Library {
public static void main(String[] args) {
Book b = new Book("Java Basics");
[Link]();
}
}
7. Build a Custom Exception-Driven Banking Application
Type: Skill | Skills Gained: Custom exceptions, try-catch-finally, throw/throws
class LowBalanceException extends Exception {
LowBalanceException(String msg) { super(msg); }
}
class Bank {
Java Skill-Based Practical Questions & Answers
void withdraw(int balance, int amount) throws LowBalanceException {
if (amount > balance)
throw new LowBalanceException("Insufficient Funds");
[Link]("Withdrawal successful!");
}
}
public class BankApp {
public static void main(String[] args) {
Bank bank = new Bank();
try {
[Link](1000, 1500);
} catch (LowBalanceException e) {
[Link]("Error: " + [Link]());
} finally {
[Link]("Thank you for banking with us!");
}
}
}
8. Develop a Mini Shopping Cart using Collections and Generics
Type: Skill | Skills Gained: ArrayList, HashMap, custom class with generics
import [Link].*;
public class ShoppingCart {
public static void main(String[] args) {
Map<String, Integer> cart = new HashMap<>();
[Link]("Shoes", 2);
[Link]("Shirt", 1);
[Link]((item, qty) -> [Link](item + " Qty: " + qty));
}
}
9. Implement a Product Sorting Engine
Type: Skill | Skills Gained: Comparable, Comparator, lambda expressions
import [Link].*;
class Product implements Comparable<Product> {
String name; int price;
Product(String name, int price) { [Link] = name; [Link] = price; }
public int compareTo(Product p) { return [Link] - [Link]; } // natural order
public String toString() { return name + ": " + price; }
}
public class SortProducts {
public static void main(String[] args) {
List<Product> list = [Link](
new Product("Pen", 10),
new Product("Book", 40),
new Product("Pencil", 5)
);
[Link]((a,b) -> [Link] - [Link]); // lambda comparator
[Link]("Sorted by price: " + list);
}
}
10. Create a Functional Data Processing Pipeline
Type: Skill | Skills Gained: Stream API filter, map, reduce
Java Skill-Based Practical Questions & Answers
import [Link].*;
import [Link].*;
public class DataPipeline {
public static void main(String[] args) {
List<Integer> nums = [Link](1,2,3,4,5,6);
int sumSquaresEven = [Link]()
.filter(n -> n % 2 == 0)
.map(n -> n * n)
.reduce(0, Integer::sum);
[Link]("Sum of squares of even numbers: " + sumSquaresEven);
}
}
11. Simulate a Multithreaded Ticket Booking System
Type: Skill | Skills Gained: Thread lifecycle, synchronization, race condition avoidance
class TicketBooking extends Thread {
static int tickets = 10;
public void run() {
synchronized ([Link]) { // class-level lock
if (tickets > 0) {
[Link]([Link]().getName() + " booked ticket " + tickets--);
} else {
[Link]("Sold out");
}
}
}
public static void main(String[] args) {
for (int i = 0; i < 12; i++) new TicketBooking().start();
}
}
12. Build a Producer-Consumer Simulation with BlockingQueue
Type: Skill | Skills Gained: BlockingQueue, inter-thread communication, concurrency control
import [Link].*;
public class ProducerConsumer {
public static void main(String[] args) {
BlockingQueue<Integer> q = new ArrayBlockingQueue<>(5);
Runnable producer = () -> {
try {
for (int i = 1; i <= 5; i++) {
[Link](i);
[Link]("Produced: " + i);
}
} catch (InterruptedException e) {}
};
Runnable consumer = () -> {
try {
for (int i = 1; i <= 5; i++) {
[Link]("Consumed: " + [Link]());
}
} catch (InterruptedException e) {}
};
new Thread(producer).start();
new Thread(consumer).start();
}
Java Skill-Based Practical Questions & Answers
13. Design and Build a File-Based Contact Book with Serialization
Type: Skill | Skills Gained: File I/O, byte character streams, object serialization
import [Link].*;
class Contact implements Serializable {
String name; String phone;
Contact(String name, String phone) { [Link] = name; [Link] = phone; }
}
public class ContactBook {
public static void main(String[] args) throws Exception {
Contact c = new Contact("Mammu", "9999999999");
try(ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("[Link]"))) {
[Link](c);
}
Contact read;
try(ObjectInputStream in = new ObjectInputStream(new FileInputStream("[Link]"))) {
read = (Contact) [Link]();
}
[Link]("Name: " + [Link] + ", Phone: " + [Link]);
}
}