0% found this document useful (0 votes)
8 views3 pages

Java Programming Assignments Guide

The document outlines several Java program assignments across different topics: 1. The first section includes assignments on basic Java programs like reversing numbers, checking Armstrong numbers, finding digit sums, etc. 2. The next section covers exceptions handling assignments like handling exceptions in method overloading and demonstrating exceptions in constructors. 3. The third section includes multithreading assignments like using join(), implementing producer-consumer problems. 4. The fourth section covers collections assignments on stacks, arrays, linked lists, sorting lists. 5. The fifth section includes IO assignments on serialization, file handling using DataInput/OutputStreams. 6. The last section covers JDBC assignments on user authentication and basic

Uploaded by

swathi
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)
8 views3 pages

Java Programming Assignments Guide

The document outlines several Java program assignments across different topics: 1. The first section includes assignments on basic Java programs like reversing numbers, checking Armstrong numbers, finding digit sums, etc. 2. The next section covers exceptions handling assignments like handling exceptions in method overloading and demonstrating exceptions in constructors. 3. The third section includes multithreading assignments like using join(), implementing producer-consumer problems. 4. The fourth section covers collections assignments on stacks, arrays, linked lists, sorting lists. 5. The fifth section includes IO assignments on serialization, file handling using DataInput/OutputStreams. 6. The last section covers JDBC assignments on user authentication and basic

Uploaded by

swathi
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 Program Assignments

1. WAP to reverse a given number


2. WAP to check whether the given number is Armstrong or not. If the number is
Armstrong find the sum of digits of the given number else find the product of digits.
3. WAP to find sum of digits of a given number until the sum of digits is single digit
4. WAP to display the given number in Words (eg: 245 => Two Four Five)
5. WAP to reverse every word of the given line of text
Eg:
Given Line of Text : Java is Simple
Output : avaJ si elpmiS

6. WAP to display Palindromes and count number of Palindromes in the given line of
text

Eg:

Given Line of Text: My madam name is liril

Output

Palindromes : madam, liril

No of palindromes : 2

Exceptions

1. Write a program to calculate area of a rectangle and area of a square by using


method overloading. Take the input for dimension of rectangle and square from
Command Line. Handle appropriate exception in order to stop abnormal
termination of execution
2. Demonstrate that a derived-class constructor cannot catch exceptions thrown by
its base-class constructor
3. Write a program which generates ArrayIndexOutOfBoundsException.
4. Write a program which generates ArithmeticException
5. Write a program which generates NullPointerException
6. Write a program which generates NumberFormatException

Multithreading

1. Write a program which demonstrates join() of Thread class


2. Write a program to find sum of even numbers and sum of odd numbers from 1 to
100 using threads
3. Write a program which displays the following output using Interthread
communication
PUT : 1
GOT : 1
PUT : 2
GOT : 2

….
PUT : 10
GOT : 10

Collections

1. Write a program which do the following stack operations


1. PUSH
2. POP
3. DISPLAY
4. PEEK
5. EXIT
2. Create a Java program which read n number of integers using scanner class until the
given number is zero. Store all these integers into ArrayList which can accept only
integers. Find the average of the elements present in the ArrayList.
3. Write program which do the following linked list operations
1. Add element at First
2. Add element at Last
3. Add element at given position
4. Remove First element
5. Remove last element
6. Update element at given position
7. Display elements
8. Exit
4. Write a program to create an Employee class with attributes empNum, empName
and empSalary.
Create a class EmployeeList which stores the Employee objects. Display the
Employee records in the sorted order of their salaries.
5. Write a program which adds the contact details like name and contact number.
Display the contact details in the sorted order of their name.
IO

Write a program which stores a Student class object into a file “[Link]” using
serialization.

1. Write a program which reads an Student class object from the file
“[Link]” using serialization
2. Write a program to store 5 item records (item number, item name, item
quantity and item rate) into a data file “[Link]” using DataOutputStream.
3. Write a program to reads 5 item records ( item number, item name, item
quantity and item rate) from the data file “[Link]” using DataInputStream.
Display the output in the following format
[Link] Item No Item Name Quantity Rate Price
-------------------------------------------------------------------
1 111 Monitor 5 5000 25000
2 222 Mouse 10 200 2000
3 333 Keyboard 7 200 1400
4 444 Pendrive 5 600 3000
5 555 UPS 4 1000 4000
-------------------------------------------------------------------
Total Price : 35400
--------------------------------------------------------------------

JDBC

1. Create the following Users table in oracle


Username Password
aaa aaa
bbb bbb
ccc ccc
Write a Jdbc program which reads username and password from keyboard and
checks whether the user is authenticated or not. If the user is authenticated display
message “Login Successful” else display “Login Not Successful”

2. Create the following Account table in MySQL with the following columns

AccountNo int(3), AccountType Varchar(10), AccountBalance int(6)

Write a JDBC program which displays the following menu options


1. Insert Record in Account Table
2. Update Record in Account Table by accepting AccountNo
3. Delete Record in Account Table by accepting AccountNo
4. Display Records of Account Table
5. Exit
The menu should get displayed until the user chooses Exit

Common questions

Powered by AI

Challenges with Java serialization include compatibility issues, such as changes to class structure leading to `InvalidClassExceptions`, and performance concerns due to large object graphs or frequent I/O operations. Proper versioning and handling of transient fields are essential to address these issues .

Interthread communication using the `PUT` and `GOT` pattern involves synchronized interaction between producer and consumer threads. The producer thread 'puts' data into a shared resource, while the consumer thread 'gets' data from it. This is typically implemented using `wait()` and `notify()` methods to manage shared object state and ensure proper sequence of operations .

The conversion involves iterating over each digit of the number, mapping each to its corresponding string representation, and accumulating these representations. This can be efficiently achieved using a switch-case structure or a mapping array, ensuring correct conversion of each digit into its word form .

An `ArrayIndexOutOfBoundsException` can be generated by attempting to access an index that is outside the allocated range of the array. This is useful for developing exception-handling strategies, testing code robustness, and learning how to appropriately manage boundary conditions .

Key operations for managing a Java stack include `PUSH` (adding elements to the stack), `POP` (removing the top element), `DISPLAY` (showing all elements in order), `PEEK` (viewing the top element without removing it), and `EXIT` (terminating operations). These operations facilitate LIFO management of the stack .

When organizing employee records by salary, it's important to use a collection that allows sorting, such as a TreeMap or PriorityQueue. Considerations should include defining a comparator for sorting by salary, managing duplicates, and handling large data scales efficiently .

The derived-class constructor cannot catch exceptions thrown by its base-class constructor because the base-class must fully complete its constructor before control can advance to the derived-class constructor. As such, exceptions thrown in the base-class must be handled at the same level or escalated .

Method overloading allows defining multiple methods with the same name but different parameters. To calculate the area of a rectangle and a square, two overloaded methods are implemented. One method takes two parameters (length and breadth) for calculating the area of a rectangle, while another takes a single parameter (side) for calculating the area of a square .

JDBC can authenticate users by executing SQL queries verifying credentials against a database table. This enables centralized management of user data. However, it carries security risks such as SQL injection, necessitating prepared statements and secure database connection handling to protect sensitive information .

The `join()` method in Java ensures that a particular thread completes its execution before others that invoke `join()` on it can proceed. It is used to synchronize threads, ensuring a defined sequence of execution, notably when thread dependencies exist .

You might also like