Course pack Java Programming
Course pack Java Programming
(THEORY + PRACTICAL)
Language Basics:
Loops and Control Statement: If-else, switch case, Loops in Java. Arrays: One-Dimensional Arrays,
Two-dimensional Array, Vectors, Operators-Arithmetic, Boolean logical, Relational and Bitwise
Operators-Operator Precedence. Class: Fundamentals, The General Form of a Class, Object
Declaration, Assigning Object Reference Variables, Methods: Overloading Methods, Using Objects as
Parameters, Access Specifiers in Java. A Closer Look at Argument Passing, Returning Objects, Recursion
Introducing Access Control, Final Variables and Methods, Final class, Finalize Methods, Abstract Methods
and Class, Visibility Control, Constructors -type of constructor, its usage , constructor overloading
3 Write a program to read an integer value through Scanner class and check whether it is
even or odd.
4 Write a program to read an integer value through Scanner class and swap the value i)
with using a third variable
ii) Without using a third variable.
12
123
1234
12345
10
Write a java program to create patterns
*
**
***
****
11 Write a program to display the following pattern:
*********
*******
*****
***
*
12 Write a Java Program to Make a Simple Calculator Using
switch...case and Scanner class.
13 Write a program to Search an Element in a
one dimensional Array in java.
14 Write a program to add two matrices of order 3X3
15 Create a class Student (name, roll_no, marks) with one method show() and initialize instance variables using all
the ways: reference, method and constructor.
16 Write a java code to implement the concept of method overloading.
17 WAP implementing Constructor overloading and use this key word in overloading.
18 Write a program to book a ticket using static keywords
19 Write a java code to implement the concept of simple inheritance, multilevel inheritance, and hierarchical
inheritance
20 Create 2 packages P1 & P2 and create classes Student and BCA in P1 and P2 respectively. Check the
accessibility using all the access modifiers.
COURSEPACK |
21 WAP to implement 3 interfaces and extend one class.
22 Implement multiple inheritance in java using interface.
23 Write a Java program to create an abstract class named Shape that contains two integers
and an empty method named print Area ().
24 Provide three classes named Rectangle,
Triangle, and Circle such that each one of the classes extends the class Shape. Each one
of the classes contains only the method print Area () that prints the area of the given
shape.
25 Write a program to demonstrate operator overloading
26 Write a program to show exception handling
27 Programming with inner class
28 Programming with wrapper class
29 Write a user-defined exception “low amount” and it should be raised when amount goes
below 10000
30 .Write a Java program to print even and odd number series using two threads
31 Write a Java IO program to read in a file
Write a Java IO program to write in a file
Write a Java IO program to read and write in a file
32 Write a Java IO program to copy the content of one file to another
BIBLIOGRAPHY
Text Books
1. R. Naughton and H. Schildt – Java2 (The Complete Reference) – Fifth Edition – TMH – 2004.
2. Head First Java- A Brain Friendly Guide-Kathy Siera-2nd Edition-OReilly-2009
Reference Books
3. K. Arnold and J. Gosling – The Java Programming Language – 3 rdEdition., Pearson
Edu,2005
4. David Flanagan – Java in a Nutshell: A Desktop Quick Reference for Java Programmers– O‘Reilly
& Associates, Inc. 1999
5. K Somasundaram-Introduction to Java Programming-Jaico Publishing House-2014
Webliography
1. https://www.javatpoint.com/java-tutorial
2. https://www.tutorialspoint.com/java/index.htm
SWAYAM/NPTEL/MOOCs Certification (One from Each Platform, Max 3 Platforms)
3. https://www.coursera.org/specializations/object-oriented-programming
4. https://onlinecourses.nptel.ac.in/noc20_cs58/preview
PROBLEM-BASED LEARNING
23 Write a program to find whether the given triangle is right angled or not
24 Write a program to check the given number is prime or not.
25 Write a program ,which will read a text and count all occurrences of a
particular word.
26 Write a Java program that uses the length() and capacity() methods of the
String Buffer class. Give the output
27 Explain the charAt() and setCharAt() methods of the StringBuffer class.
28 Write a Super class interface employee has name and id number. Write manager and
labour derived from employee class. Manager class has member data qfunction and
qualification and manager allowance & rank Labour class
has member data Dailywage, Overtime & grade.
29 Create an Interface called Integer stack. Write a program that uses this
interface to implement fixed stack and dynamic stack.
30 Write a program to implement a class Teacher contains two fields Name and
Qualification. Extend the class to Department, it contains Dept. No and Dept. Name. An
Interface named 318 College it contains one field Name of the
College. Using the above classes and Interface get the appropriate information and display
it.
31 What are the different types of inheritance that can be implied on Java. Write a program to
show the multilevel inheritance.
32 Write a program to create a private inner class that implements a public interface. Write a
method that returns a reference to an instance of the private inner class, upcast to the
interface. Show that the inner class is completely
hidden by trying to downcast to it
33 Create an interface with at least one method, in its own package. Create a class in a separate
package. Add a protected inner class that implements the interface. Ina third package,
inherit from your class and, inside a method, return an object of the protected inner class,
up casting to the interface during
the return.
34 Write an interface called shape with necessary methods. Derive classes circle,
rectangle, triangle, cone, sphere and cube with appropriate constructors and methods for area,
volume also setting & displaying
35 Write a Java program that simulates a traffic light. The program lets the user select
one of three lights: red, yellow, or green with radio buttons. On selecting a button,
an appropriate message with “Stop” or “Ready” or “Go” should appear above the
buttons in selected color. Initially, there is no message shown
36 What is constructor in Java? How can you differentiate between default
constructor, copy constructor and parameterized constructor? Site suitable example
to show the differences.
37 Write a Java program that creates a user interface to perform integer divisions. The
user enters two numbers in the text fields, Num1 and Num2. The division of Num1
and Num 2 is displayed in the Result field when the Divide button is clicked. If
Num1 or Num2 were not an integer, the program would throw a Number Format
Exception. If Num2 were Zero, the program would throw an Arithmetic Exception.
Display the exception in a message dialog box
COURSEPACK |
38 What is operator overloading. Perform operator overloading to show basic
calculating operations
39 Write a menu-based application to display grades of students. Students having >=
90 marks with grade ‘O’, students having 80-89(Grade ‘E’), students having 70-
79(Grade ‘A’), students having 60-69(Grade ‘B’), students having 50-59(Grade
‘C’), students having 40-49(Grade ‘D’) and otherwise students less than 40 –
‘Grade F’
40 Describe different types of inner class with example.
41 Install a database (Mysql or Oracle). Create a table which should contain at least
the following fields: name, password, email-id, phone number Write a java program
to connect to that database and extract data from the tables and display them. Insert
the details of the users who registers with the UI, whenever a new user clicks the
submit button in the registration page
42 Write a Java program that implements a multi-thread application that has three
threads.
First thread generates random integer every 1 second and if the value is even,
second
thread computes the square of the number and prints. If the value is odd, the third
thread will print the value of cube of the number
43 Write a Java program to print Fibonacci series
44 Demonstrate the use of this, super, static and final keywords in java
45 Write a program in Java to reverse a string
COURSEPACK |
STUDENT-CENTERED LEARNING (SELF-LEARNING
TOWARDS LIFE-LONG- LEARNING)
Self-Learning (it’s a typical course-based project to be carried out by a whole class in
groups of four students each; they should exhibit higher level KLs). The students, in
a group, are expected conceive an idea based on the content (objectives/outcomes) and
apply the suitable knowledge to demonstrate their learning. They can attend
Oracle courses for this segment.
https://www.codechef.com/practice/
https://skillsforall.com/course/
S Suggested Projects
No
1 Create a class Box that uses a parametrized constructor to initialize the dimension of
the box. The dimension of the Box are width, height and depth. The class should have a
method that can return the volume of the Box. Create
an object of the Box class and test the functionalities.
2 Create a new class called Calculator with the following methods:
1. A static method called powerInt(int num1,int num2) This
method should return num1 to the power num2.
2. A static method called powerDouble(double num1,int num2). This
method should return num1 to the power num2.
3. Invoke both the methods and test the functionalities. Hint: Use
Math.pow(double,double) to calculate the power.
3 Create a class Author with the following information.
Member variables : name (String), email (String), and gender (char) Parameterized
Constructor: To initialize the variables
Create a class Book with the following information.
Member variables : name (String), author (of the class Author you have just created),
price (double), and qtyInStock (int)
[Assumption: Each book will be written by exactly one Author]
Parameterized Constructor: To initialize the variables
Getters and Setters for all the member variables
In the main method, create a book object and print all details of
the book (including the author details)
4 Create a class called Person with a member variable name. Save it in a file called
Person.java
Create a class called Employee that will inherit the Person class. The other data members
of the Employee class are annual salary (double), the year the employee started to
work, and the national insurance number which is a String. Save this in a file called
Employee.java Your class should have the necessary constructors and getter/setter
methods. Write another class called TestEmployee, containing a main method to fully
test your class definition.
COURSEPACK |
5 Write a program to create a class named shape. It should contain
2 methods, draw() and erase() that prints “Drawing Shape” and “Erasing
Shape” respectively.
For this class, create three sub classes, Circle, Triangle and
Square and each class should override the parent class functions
- draw () and erase ().
The draw() method should print “Drawing Circle”, “Drawing Triangle”
and “Drawing Square” respectively.
The erase() method should print “Erasing Circle”, “Erasing
Triangle” and “Erasing Square” respectively.
Create objects of Circle, Triangle and Square in the following way and
observe the polymorphic nature of the class by calling draw() and erase()
method using each object.
Shape c=new Circle();
Shape t=new Triangle();
Shape s=new Square();
6 Create an abstract class Compartment to represent a rail coach. Provide an
abstract function notice in this class.
public abstract String notice();
Derive FirstClass, Ladies, General, Luggage classes from the compartment
class. Override the notice function in each of them to print notice message
that is suitable to the specific type of compartment.
Create a class TestCompartment.Write main function to do the following:
Declare an array of Compartment of size 10.
Create a compartment of a type as decided by a randomly generated integer in the
range 1 to 4.
Check the polymorphic behavior of the notice method. [i.e
based on the random number genererated, the first
compartment can be Luggage, the second one could be Ladies and so on..]
COURSEPACK |
public int getSpeed()
– returns the current speed of the vehicle.
public void radio()
– provides facility to control the radio device
Honda class extends com.automobile.vehicle class with the following
methods
public int getSpeed()
– Returns the current speed of the vehicle. public
void cdplayer()
– provides facility to control the cd player device which is
available in the car.
Create a test class to test the methods available in all these
child class.
9 Write an interface called Playable, with a method void
play();
Let this interface be placed in a package called music.
Write a class called Veena which implements Playable interface. Let this
class be placed in a package music.string
Write a class called Saxophone which implements Playable interface.
Let this class be placed in a package music.wind Write another class
Test in a package called live. Then,
a. Create an instance of Veena and call play() method
b. Create an instance of Saxophone and call play() method
c. Place the above instances in a variable of type Playable and then
call play()
10 Write a program that takes as input the size of the array and the elements in
the array. The program then asks the user to enter a particular index and
prints the element at that index. Index starts from zero.
This program may generate Array Index Out Of Bounds Exception or
NumberFormatException . Use exception handling mechanisms to handle this
exception.
Sample Input and Output 1:
Enter the number of elements in the array 2
Enter the elements in the array 50
80
Enter the index of the array element you want to access 1
The array element at index 1 = 80
The array element successfully accessed Sample
Input and Output 2:
Enter the number of elements in the array 2
Enter the elements in the array 50
80
COURSEPACK |
Enter the index of the array element you want to access
9
java.lang.ArrayIndexOutOfBoundsException Sample Input and Output 3:
Enter the number of elements in the array 2
Enter the elements in the array 30
j java.lang.NumberFormatException
COURSEPACK |
13 Write a program to initialize an integer array with values and
check if a given number is present in the array or not.
If the number is not found, it will print -1 else it will print the index value of the
given number in the array.
Example 1) If the Array elements are {1,4,34,56,7} and the search element is 90,
then the output expected is -1.
Example 2)If the Array elements are {1,4,34,56,7} and the search element is 56,
then the output expected is 3.
14 Create a class named ‘Animal’ which includes methods like eat() and sleep().
Create a child class of Animal named ‘Bird’ and override the parent class methods.
Add a new method named fly().
Create an instance of Animal class and invoke the eat and sleep methods using this
object.
Create an instance of Bird class and invoke the eat, sleep and fly methods using this
object.
16 Design a student management system using Java
17 Develop an application for managing employee records, including features like adding
new employees, updating details, and generating reports using inner class
18 Create a console-based application that simulates an online voting system for conducting
polls and elections. Users can vote for candidates, and the system tallies the results.
19 Create a banking system simulation where users can open accounts, make transactions,
and view their account balances. Implement features like interest calculation and
account types (using inner class)
20 Create a student management system using inner class
COURSEPACK |