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

Java Practical Programs Guide 2024-2025

The document lists practical Java programming tasks for the 2024-2025 academic year, covering various concepts such as classes, inheritance, interfaces, exception handling, and GUI development. It includes tasks like creating employee records, performing arithmetic operations, and connecting to a MySQL database. Each task is designed to enhance understanding of Java programming fundamentals and application development.

Uploaded by

nehapatil6369
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)
22 views2 pages

Java Practical Programs Guide 2024-2025

The document lists practical Java programming tasks for the 2024-2025 academic year, covering various concepts such as classes, inheritance, interfaces, exception handling, and GUI development. It includes tasks like creating employee records, performing arithmetic operations, and connecting to a MySQL database. Each task is designed to enhance understanding of Java programming fundamentals and application development.

Uploaded by

nehapatil6369
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

Java Practical Program List (2024-2025)

1. Create a class Employee with members: empId, empName, and salary. Add a method
to calculate net salary after 10% tax. Create objects and display results.
2. Define a class Rectangle with methods to calculate area and perimeter. Use
constructors to initialize values and display using an object.
3. Create a menu-driven program using switch-case to perform arithmetic operations.
4. Accept marks of 5 subjects and calculate percentage, grade using if-else ladder.
5. Write a Java program to find whether a number is prime or not using a loop and logical
operators.
6. Write a Java program to demonstrate both (Implicit) and (Explicit) typecasting.
7. Write a Java program to input an array of integers and:
• Display all even numbers
• Find the maximum and minimum elements
8. Write a Java program with a class Person having name and age. Derive a class Student
with roll number and course. Display all details using inheritance.
9. Create three classes:
a. Employee → name, empId
b. Manager → department
c. ProjectManager → projectName
Display full details using multilevel inheritance.
10. Create a base class Vehicle with brand and speed. Derive Car and Bike classes from it,
and display details of both.
11. Create a class Animal with method sound(). In class Dog, override the method and
also call the parent class method using super.
12. Create an interface Printable with method print(). Create class Document that
implements this interface and prints a document name.
13. Create two interfaces:
a. Flyable with method fly()
b. Swimmable with method swim()
c. Implement both in a class Duck. Show how multiple inheritance works via
interfaces.
14. Write a Java program to perform division of two numbers. Handle ArithmeticException
if the denominator is zero.
15. Create a user-defined exception called InvalidAgeException. If a user enters age less
than 18, throw the exception with a message “Underage for Voting”.
16. Create a class that extends the Thread class and print numbers from 1 to 5 using a
thread.
17. Write a Java AWT Program by extending frame class.
18. Write a java AWT program by creating the object of Frame class.
19. Write a program implementing Menu & Menu bars.
20. Write a program implementing Event Listeners.
21. Write a program for simple swing application using swing components.
22. Write a program to connect java application with mysql database.
23. Write a program on TCP Client-Server in Java.
24. Write a program to display:
a. The local host name and IP address
b. The IP address of a domain like [Link]
25. Create a Java application to insert 3 employee records and display them using a
SELECT query with Statement.

Common questions

Powered by AI

Exception handling in Java improves program reliability by allowing the program to manage errors gracefully without crashing. In the division program, catching the 'ArithmeticException' when the denominator is zero prevents the program from terminating unexpectedly and allows it to handle this specific arithmetic condition robustly. Instead of the program failing, an error message or alternative logic can be executed, maintaining the program’s stability and providing a better user experience .

A Java application connects to a MySQL database using JDBC (Java Database Connectivity) by loading the JDBC driver, establishing a connection using a connection string, creating a 'Statement' or 'PreparedStatement' to execute SQL queries, and processing the results. In the practical program list, the example involves inserting employee records and using a SELECT query to display them. These operations require executing SQL through the JDBC API to interact with the database effectively, showcasing SQL injection handling and systematic data retrieval from the database .

Typecasting in Java allows converting one data type to another, directly affecting how data is manipulated. Implicit casting (automatic) occurs without data loss, like converting an 'int' to a 'long'. Explicit casting requires a programmer's intervention and is used for conversions that could involve data loss, such as from a 'double' to an 'int'. This distinction ensures data integrity and accuracy during type conversions, with explicit casting providing greater control and precision in how data is transformed, as demonstrated in the Java programs .

Multilevel inheritance in Java allows a class (child) to inherit from another class (parent) which itself is derived from a third class (grandparent), supporting complex data relationships. For example, in the context of the Employee, Manager, and ProjectManager classes, ProjectManager can inherit properties from Manager, which in turn inherits from Employee. This inheritance chain facilitates a structured hierarchy where shared and additional properties can be distributed across multiple levels, enhancing data modeling and refining organizational structures .

Interfaces in Java define a contract that classes can implement, enabling the reuse of methods across unrelated class hierarchies. They support multiple inheritance by allowing a class to implement multiple interfaces, thereby inheriting the abstract methods defined within them. For example, in the Duck class implementation, the Duck class implements both the 'Flyable' and 'Swimmable' interfaces, inheriting their respective 'fly()' and 'swim()' methods. This enables the Duck class to perform both flying and swimming actions, thus exemplifying how interfaces facilitate multiple inheritance .

Encapsulating arithmetic operations within a menu-driven program enhances user interaction by presenting an intuitive interface for task selection, allowing users to easily navigate and perform specific calculations without needing to understand underlying code. It also promotes program modularity by organizing operations into discrete functions that can be maintained and modified independently. Such structure supports clearer code management and improved user experience, enabling scalable program design .

Thread usage in Java allows concurrent execution of tasks, optimizing processes by enabling multitasking. By extending the 'Thread' class, a Java program can run separated task units simultaneously, such as printing numbers from 1 to 5. Each thread runs its code path and can proceed independently of others, improving the program's efficiency and responsiveness. In the printing example, the main benefit is parallelism, where the numbers print while other processes continue, demonstrating the utility of threads in managing separate execution paths .

AWT (Abstract Window Toolkit) provides a set of tools for building platform-independent GUIs in Java. Its benefits include simplicity and ease of use for creating basic GUI elements like windows, buttons, and layout managers. However, AWT's limitations involve platform-dependent components that can lead to inconsistent behavior across different operating systems, which means GUIs might not look identical everywhere. Furthermore, AWT is less flexible compared to Swing, which offers more components and features, highlighting the need to choose the right toolkit based on application complexity .

Inheritance promotes code reusability and structure by allowing classes to inherit properties and methods from other classes, reducing redundancy. In the Java program, an 'Employee' class could serve as a base class containing shared attributes like 'empId' and 'name'. Classes such as 'Manager' and 'ProjectManager' can inherit from 'Employee', allowing them to utilize shared characteristics while adding specific attributes like 'department' or 'projectName'. This hierarchical organization not only promotes reuse but also enhances code maintainability by managing shared features centrally .

Constructors in Java are special methods used for initializing objects. They set initial values for object attributes and are called when an object is created. In the 'Rectangle' class, constructors initialize dimensions like length and width before any methods for calculating area and perimeter are called. This ensures that every 'Rectangle' object starts with values it needs to function correctly, thus preventing errors and ensuring consistency in calculations .

You might also like