0% found this document useful (0 votes)
12 views6 pages

Java Programming Exercises and Concepts

The document outlines a comprehensive set of Java programming tasks across various topics including Java basics, classes and objects, arrays, string handling, packages, inheritance, interfaces, exception handling, multithreading, file handling, applets, AWT components, Swing components, and Swing components with JDBC. Each section contains specific programming exercises aimed at reinforcing concepts such as control structures, object-oriented programming, data structures, and GUI development. The tasks range from simple calculations and string manipulations to complex applications involving database interactions.

Uploaded by

b3262508
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)
12 views6 pages

Java Programming Exercises and Concepts

The document outlines a comprehensive set of Java programming tasks across various topics including Java basics, classes and objects, arrays, string handling, packages, inheritance, interfaces, exception handling, multithreading, file handling, applets, AWT components, Swing components, and Swing components with JDBC. Each section contains specific programming exercises aimed at reinforcing concepts such as control structures, object-oriented programming, data structures, and GUI development. The tasks range from simple calculations and string manipulations to complex applications involving database interactions.

Uploaded by

b3262508
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

I.

Java Basics
1. Write a Java program to compute value of following series
1-3+5-7+…+N
2. Write a simple Java program which will print Fibonacci series, e.g. 0 1 1 2 3 5 8 13 ...
. up to a given number.
3. Write a Java code to check whether give character is vowel or not using switch
statement.
4. Write a java program to check whether a given string is palindrome or not without
using built-in methods.
5. Write a Java code lists the factorial value of a given number using recursion method.
6. Write a Java program to list the prime numbers 1 to N
7. To compute the value of m power n using method.
8. Build a Java code to find the following without using String built-in methods:
a) Length of the given string
b) Reverse of the given string
9. Write a java code to check whether give string is palindrome or not without using
String built-in methods.
10. Write a program to check if the given number is Armstrong number or not.
For example, 153 is an Armstrong number because of 153= 1+ 125+27, which is
equal to 1^3+5^3+3^3

II. Classes and objects


1. Define a class named Employee as described below:
Data Members:
emp_id, emp_name, designation, basic_salary, pf, da;
Methods:
1. Constructor => Parameterized constructor to assign the values
2. calculateSalary() to compute the gross salary with necessary pay
particulars
3. displayDetails() to display employee details
Test this class by creating an object for the class Employee.
2. Java code to calculate the area of a square, rectangle, and circle using the same
method name area() with different parameters using Method overloading.
3. Java by calculating the area of different shapes (square, rectangle, circle) based on
different constructor signatures using constructor overloading.

4. Define a class named Employee as described below:


Data Members:
emp_id, emp_name, designation, basic_salary, pf, da;
Methods:
i. Constructor with this keyword
ii. calculateGross() to compute the gross salary with necessary pay
particulars
iii. calculateNet() to compute the net salary with necessary pay
particulars
iv. displayDetails() to display employee details
Test this class by creating an object for the class Employee.
5. Define a class named Account as described below:
Data Members:
AccNo, Name, BankName, balance, amount
Methods:
• Constructor using this keyword
• deposit()
• withdraw()
• displayDetails()
Use balance as a constant. Based on the user's choice, the corresponding operation
should be [Link] this class by creating an object and invoking the various
methods using a menu-driven approach.

III. Array
1. Write a java code to read integer array dynamically from the user and search the element
present or not. If the element is present, display its index.
2. Write a java code to read integer array dynamically from the user and find the maximum
and minimum of given array.
3. Illustrate Java program to perform sorting of integer array elements using manual.
4. Illustrate Java program to perform sorting of integer array elements using Bubble sort.
5. Write a java code read string elements and store it an array dynamically and perform
the following operations:
a. Display the elements using enhanced for loop
b. Apply the String built-in method to sort and display the elements
6. Write a java program following matrix operations (Addition and Subtraction) using
two-dimensional array. The row and column size should be defined dynamically.

IV. String Handling

1. Write a java program to implement the following string operations using built-in
methods. The string values are defined by the user. The operations are as follows:
i. Length of the given string
ii. Concatenate two strings
iii. Reverse the string
iv. Compare to string
v. Check the given string are equal
vi. Find particular character.
vii. Append the string
viii. Covert upper and lower case
ix. Find substring
x. Split string using StringTokenizer class.
2. Write java to create String array from the keyboard and display into ascending and
descending order. Apply string methods to perform these operations.
V. Packages
1. Define a package named Arithmetic that contain a class Calculation with following
methods:
double Add(double x, double y)
double Sub(double x, double y)
double Mul(double x, double y)
double Div(double x, double y)
Define another class to access the package Arithmetic with necessary inputs.
2. Define a package named college that contains a class Employee to calculate salary
details of an employee.
The class should include:
• A parameterized constructor
• A method GrossSalary() to compute the gross salary
• A method NetSalary() to compute the net salary
Define another class outside the package to create an object of Employee and display
the salary details.

VI. Inheritance
1. Define a class called Department with data members department name, HoD name
and methods Constructor and PrintDepartmentDetails(). Then, define another class
named StaffMembers that extends the Department and which contains data members
staff name, staff qualification and methods Constructor, PrintStaffDetails(). Create
objects for the class StaffMembers and invoke the methods and run it.
2. Design a class to represent BankAccount details as base class and BankProcess as the
sub class. The BankAccount class contains the data members such as name of the
account holder, account number, type of account, balance and the methods are
getdetails(), and printdetails(). And then create BankProcess class which contains
amount as datamember and methods are deposit() and withdraw() and then return
balance. Finally create an object for the subclass and test it.
3. Create Employee as the base class with its constructor and create Regular_Employee
subclass for Employee class with its constructor. Within the subclass constructor invoke
the constructor of base class using super(). Likewise create another subclass for
Employee called Contract_Employee with its constructor. The data members and
methods will be defined by you.

VII. Interfaces
1. Define an interface named Area that contains the declaration of a method as shown
below:
Double getArea();
Define two classes named Circle and Rectangle that implements the interface Area, as
shown below:
Data Member : value
Methods : Constructor, getArea()
Create an object for these two classes and find the area of Circle and Rectangle.
2. Define an interface named Conversion that contains the declaration of a method as
shown below:
Double getConversion();
Define two classes named Dollars and Currency that implements the interface
Conversion, as shown below:
Data Member : rupees
Methods : Constructor, getConversion()
Create an object for these two classes and find the conversion value of rupees in the
form of Dollars and Currency.

VIII. Exception Handling


1. Define java class to show the following exceptions using multiple catch:
i. Arithmetic exception
ii. Number format exception
iii. Array index of bound exception
2. Write a Java program to create a user-defined exception class AgeException. The
program should have a method checkAge(int age) that throws this exception if the age
is less than 18, otherwise it should print that the person is eligible to vote.
3. Create a custom exception class InsufficientBalanceException without using a
constructor to pass messages. Instead, define a custom method (e.g.,
getErrorMessage()) that returns an appropriate error message.
4. Read 20 marks and stores them in an array. Define your own exception named
WrongMarkException. Throw and catch this type of exceptions when mark is < 0 and
a mark is > 100.

IX. Multithreading
1. To develop a Java program using the Runnable interface to create two threads — one
thread to display the Fibonacci series and another thread to display the factorial values.
The values should be assigned using a constructor.
2. Create two threads namely Thread1 and Thread2 by using Thread class. Thread1 will
generate multiplication table of 5 and Thread2 will generate the multiplication table of
2.
3. Create two threads by extending the Thread class. Use the first thread for calculating
the Fixed Deposit and second thread for calculating Recurring Deposit. Declare objects
for both threads in the main thread and execute them.
4. Write a java code to create two threads by extending Thread class. First thread is used
to display the multiplication table of 6. Second thread is used to display the Fibonacci
series. Test these threads by assigning them into MIN_PRIORITY and
MAX_PRIORITY. Execute the Thread class based on the priority.
5. Write a program that executes three threads. First thread displays “Good Morning”
every one second, the second thread displays “Hello” every two seconds and the third
thread displays “Welcome” every three Seconds. Create the three threads by extending
the Thread class.
X. File handling
1. Write a java code to write a string into [Link] file and read string from that file using
FileWriter and FileReader class.
2. Write a java code to write a string into [Link] file and read string from that file using
FileInputStram and FileOutputStream class.
3. Write a program to read one byte at a time from a file and copy it into another file
immediately using FileInputStream and FileOutputStream
XI. Applet
1. Write an Applet program to display “SACRED HEART COLLEGE” ten times with
different font size and colours.
2. Develop an applet program to perform the following
i) Pass and retrieve two integer type value.
ii) Perform all arithmetic operations on the values.
iii) Display the results with different colours and fonts.
3. Develop an applet to receive at least 10 values of student marksheet using parameter
from the applet tags and display in the applet window.
4. Design an applet to draw the following images using Graphics class:
i) Traffic Signal
ii) Smile Please
iii) House
iv) Color Bars
v) Generate a hollow shape
XII. AWT Components
1. Design an applet for college admission form using all the AWT components.
2. Write a program illustrates finding the factorial of a given number using applet with
AWT components.
3. Design an applet program using AWT components to perform calculator with following
options:
Add, Sub, Mul, Div, Mod, Clear, Equal.
Give sample form design.
4. Create a login form to verify username and password using AWT. Use Frame and
ActionListener to display message when the username and password is correct and also
display the corresponding error message.
5. Create a form design for “Product Information” using AWT. Use Frame and
ActionListener to display the total cost of a product with necessary inputs.
XII. SWING Components
1. Create a window application for electricity bill calculation using Swing components.
Create labels namely Customer Name, Mobile No., Address, Number of Units, Cost
Per Unit and Total Amount and its corresponding text fields then create a button to
perform the calculation.
2. Develop a window using Swing components to create an Employee Payroll Form and
calculate salary details such as Gross Salary and Net Salary.
XIII. SWING Components with JDBC
1. Develop an application to establish database using SWING component with MySQL
and implement the following:
i. Insert Student Details (Reg. No, Name, Course, Address) into table
ii. Display all the records from the table
2. Develop an application to establish database using SWING component with MySQL
and implement the following:
i. Insert Emplyee Details (id, name, dob, basic, pf, da, gross and netsalary) into
table
ii. Display all the records from the table

You might also like