CHAROTAR UNIVERSITY OF SCIENCE & TECHNOLOGY
FACULTY OF TECHNOLOGY AND ENGINEERING
Devang Patel Institute of Advance Technology and Research
CE/CSE
Subject Name: Java Programming Semester: III
Subject Code: CE251 Academic year: 2021-2022
PART-I L PO PEO
Data Types, Variables, String, Control Statements, Operators, Arrays O
1. Introduction to Object Oriented Concepts, comparison of Java with 1 1,3, 1,7
other object oriented programming languages. Introduction to JDK, 4,5
JRE, JVM, javadoc,command line argument.
Introduction to Eclipse or Netbean IDE,or BlueJ and Console Programming.
2. Write a program that declares one integer variable called var1. Give value 10 to 1 1,3, 1,7
this variable and then, using one println() statement, display the value on the 4,5
screen like this:
“10 is the value of var1.”
3. Write a console program to declare and initialize a double variable with some 1 1,3, 7
value such as 1234.5678. Then retrieve the integral part of the value and store 4,5
it in a variable of type long, and the first four digits of the fractional part and
store them in an integer of type short. Display the value of the double variable
by outputting the two values stored as integers
4. Write an application that creates a two dimension array with int values. 1 1,3, 7
The first, second and third elements should be arrays with one, two and 4,5
three numbers respectively. Display the length of each dimension.
5. An electric appliance shop assigns code 1 to motor,2 to fan,3 to tube and 1 1,3, 7
4 for wires. All other items have code 5 or more. While selling the goods, 4,5
a sales tax of 8% to motor,12% to fan,5% to tube light,7.5% to wires and
3% for all other items is charged. A list containing the product code and
price in two different arrays. Write a java program using switch statement
to prepare the bill.
6. Write a program to show output like: 1 1,3, 7
4,5
*****
****
***
**
*
PART-II LO PO PEO
String
1. Given a string and a non-negative int n, we'll say that the front of the string is 1 1,3, 7
the first 3 chars, or whatever is there if the string is less than length 3. Return 4,5
n copies of the front;
front_times('Chocolate', 2) → 'ChoCho'
front_times('Chocolate', 3) → 'ChoChoCho'
front_times('Abc', 3) → 'AbcAbcAbc'
2. Given an array of ints, return the number of 9's in the array. 1 1,3, 7
4,5
array_count9([1, 2, 9]) → 1
array_count9([1, 9, 9]) → 2
array_count9([1, 9, 9, 3, 9]) → 3
3. Given an array of ints, return True if one of the first 4 elements in the array 1 1,3, 7
is a 9. The array length may be less than 4. 4,5
array_front9([1, 2, 9, 3, 4]) → True
array_front9([1, 2, 3, 4, 9]) → False
array_front9([1, 2, 3, 4, 5]) → False
4. Given a string, return a string where for every char in the original, there are 1 1,3, 7
two chars. 4,5
double_char('The') → 'TThhee'
double_char('AAbb') → 'AAAAbbbb'
double_char('Hi-There') → 'HHii--TThheerree'
5. Write a program that will reverse the sequence of letters in each word of 1 1,3, 7
your chosen paragraph. For instance, “To be or not to be” would become 4,5
“oT e bro ton ot eb”.
6 Perform following functionalities of the string: 1 1,3, 7
● Find Length of the String 4,5
● Lowercase of the String
● Uppercase of the String
● Reverse String
● Sort the string
7 Perform following Functionalities of the string: “CHARUSAT University” 1 1,3, 7
● Find length 4,5
● Replace ‘H’ by ‘N’
● Convert all character in Uppercase
● Extract and print “CHARUSAT” from given string
PART-III LO PO PEO
Object Oriented Programming : Classes, Methods,
Constructors
1. Write a java program for converting Pound into Rupees. (Accept Pounds from 1,3 1,3, 3
command line argument and using scanner class also and take 1 Pound = 100 4,5
6
Rupees.)
2. Write a program that defines TriangleArea class with three constructor. The 1,3 1,3, 3
first form accept no arguments. The second accept one double value for 4,5
6
radius. The third form accept any two arguments.
3. Create a class called Employee that includes three pieces of information as 1,3 1,3, 3
instance variables—a first name (type String), a last name (type String) and a 4,5
6
monthly salary (double). Your class should have a constructor that initializes
the three instance variables. Provide a set and a get method for each instance
variable. If the monthly salary is not positive, set it to 0.0. Write a test
application named EmployeeTest that demonstrates class Employee’s
capabilities. Create two Employee objects and display each object’s yearly
salary. Then give each Employee a 10% raise and dis play each Employee’s
yearly salary again.
4. Create a class called Date that includes three pieces of information as instance 1,3 1,3, 3
variables—a month (type int), a day (type int) and a year (type int). Your class 4,5,
6
should have a constructor that initializes the three instance variables and
assumes that the values provided are correct. Provide a set and a get method for
eachinstance variable. Provide a method displayDate that displays the month,
day and year separated by forward slashes (/). Write a test application named
DateTest that demonstrates class Date’s capabilities.
5. Write a program to print the area of a rectangle by creating a class named 'Area' 1,3 1,3, 3
taking the values of its length and breadth as parameters of its constructor and 4,5,
6
having a method named 'returnArea' which returns the area of the rectangle.
Length and breadth of rectangle are entered through keyboard.
6. Print the sum, difference and product of two complex numbers by creating a 1,3 1,3, 3
class named ‘Complex’ with separate methods for each operation whose real and 4,5,
6
imaginary parts are entered by user.
7. Complete the code and write main () method to execute 1,3 1,3, 3
4,5
6
program.
PART-IV LO PO PE
Inheritance, Interface , Package O
1. Create a class with a method that prints "This is parent class" and its subclass 3 1,4,5 3
with another method that prints "This is child class". Now, create an object for ,6
each of the class and call
1 - method of parent class by object of parent class
2 - method of child class by object of child class
3 - method of parent class by object of child class
2. Create a class named 'Member' having the following members: 3 1,4,5 3
6
Data members
1 - Name
2 - Age
3 - Phone number
4 - Address
5 – Salary
It also has a method named 'printSalary' which prints the salary of the members.
Two classes 'Employee' and 'Manager' inherits the 'Member' class. The
'Employee' and 'Manager' classes have data members 'specialization' and
'department' respectively. Now, assign name, age, phone number, address
and salary to an employee and a manager by making an object of both of
these classes and print the same.
3. Create a class named 'Rectangle' with two data members 'length' and 'breadth' 3 1,4,5 3
and two methods to print the area and perimeter of the rectangle respectively. 6
Its constructor having parameters for length and breadth is used to initialize
length and breadth of the rectangle. Let class 'Square' inherit the 'Rectangle'
class with its constructor having a parameter for its side (suppose s) calling the
constructor of its parent class as 'super(s,s)'. Print the area and perimeter of a
rectangle and a square. Also use array of objects.
4. Create a class named 'Shape' with a method to print "This is This is shape". 3 1,4,5 3
Then create two other classes named 'Rectangle', 'Circle' inheriting the Shape 6
class, both having a method to print "This is rectangular shape" and "This is
circular shape" respectively. Create a subclass 'Square' of 'Rectangle' having a
method to print "Square is a rectangle". Now call the method of 'Shape' and
'Rectangle' class by the object of 'Square' class.
5. Create a class 'Degree' having a method 'getDegree' that prints "I got a degree". 3 1,4,5 3
It has two subclasses namely 'Undergraduate' and 'Postgraduate' each having a ,6
method with the same name that prints "I am an Undergraduate" and "I am a
Postgraduate" respectively. Call the method by creating an object of each of the
three classes.
6. Write a java that implements an interface AdvancedArithmetic which contains 3 1,4,5 3
amethod signature int divisor_sum(int n). You need to write a class 6
calledMyCalculator which implements the interface.
divisorSum function just takes an integer as input and return the sum of all its
divisors. For example divisors of 6 are 1, 2, 3 and 6, so divisor_sum should
return 12. The value of n will be at most 1000.
7. Assume you want to capture shapes, which can be either circles (with a 3 1,4,5 3
radiusand a color) or rectangles (with a length, width, and color). You also 6
want to beable to create signs (to post in the campus center, for example), each
of whichhas a shape (for the background of the sign) and the text (a String) to
put on thesign.
8. Create classes and interfaces for circles, rectangles, shapes, and 3 1,4,5 3
signs. Write a program that illustrates the significance of interface ,6
default method.
9. Write a java program which shows importing of classes from other user 3 1,4,5 3
define packages. 6
PART-V LO PO PE
Exception Handling O
1. Write a java program which takes two integers x & y as input, you have to 3 1,4,5 3
compute x/y. If x and y are not integers or if y is zero, exception will occur 6
and you have to report it.
2. A piece of Java code is given below. You have to complete the code by 3 1,4,5 3
writing down the handlers for exceptions thrown by the code. The 6
exceptions the code may throw along with the handler message are listed
below:
Division by zero: Print "Invalid division".
String parsed to a numeric variable: Print "Format
mismatch". Accessing an invalid index in string: Print
"Index is invalid".
Accessing an invalid index in array: Print "Array index is invalid".
MyException: This is a user defined Exception which you need to create. It
takes a parameter param. When an exception of this class is encountered, the
handler should print "MyException[param]", here param is the parameter passed
to the exception class.
Exceptions other than mentioned above: Any other exception except
the above ones fall in this category. Print "Exception encountered".
Finally, after the exception is handled, print "Exception
Handling Completed".
Example: For an exception of MyException class if the parameter value is
5, the message will look like
MyException[5].
3. Write a java program to generate user defined exception using 3 1,4,5 3
“throw” and “throws” keyword. 6
Also Write a java that differentiate checked and unchecked exceptions.
(Mention at least two checked and two unchecked exception in program).
PART-VI
File Handling & Streams
1. Write a program that will count the number of lines in each file that is 2 2,3, 3,8
specified on the command line. Assume that the files are text files. Note 4,5
that multiple files can be specified, as in "java LineCounts file1.txt file2.txt
file3.txt". Write each file name, along with the number of lines in that file,
to standard output. If an error occurs while trying to read from one of the
files, you should print an error message for that file, but you should still
process all the remaining files.
2. Write an example that counts the number of times a particular character, 2 2,3, 3,8
such as e, appears in a file. The character can be specified at the
command line. You can use xanadu.txt as the input file.
3. Write a Java Program to Search for a given word in a File. Also show 2 2,3, 3,8
use of Wrapper Class with an example.
4. Write a program to copy data from one file to another file. If 2 4,5 3,8
the destination file does not exist, it is created automatically.
5. Write a program to show use of character and byte stream. Also show use 2 2,3, 3,8
of BufferedReader /BufferedWriter to read console input and write them
into a file.
PART-VII
Multithreading
1. Write a program to create thread which display “Hello World” message. 2 2,3, 3,8
A. by extending Thread class 4,5
B. by using Runnable interface.
2. Write a program which takes N and number of threads as an argument. 2 2,3, 3,8
Program should distribute the task of summation of N numbers amongst 4,5
number of threads and final result to be displayed on the console.
3. Write a java program that implements a multi-thread application that has 2 2,3, 3,8
three threads. First thread generates random integer every 1 second and if 4,5
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.
4. Write a program to increment the value of one variable by one and 2 2,3, 3,8
display it after one second using thread using sleep() method. 4,5
5. Write a program to create three threads ‘FIRST’, ‘SECOND’, ‘THIRD’. Set 2 2,3, 3,8
the priority of the ‘FIRST’ thread to 3, the ‘SECOND’ thread to 5(default) 4,5
and the ‘THIRD’ thread to 7.
6. Write a program to solve producer-consumer problem using 2 2,3, 3,8
thread synchronization. 4,5
PART-VIII
Collection Framework and Generic
1. Design a Custom Stack using ArrayList class, which implements following 2 2,3,4 3,8
functionalties of stack. ,5
2. Create a generic method for sorting an array of Comparable objects. 2 2,3 3,8
,
4,5
3. Write a program that counts the occurrences of words in a text and displays the 2 2,3 3,8
words and their occurrences in alphabetical order of the words. Using Map and ,
Set Classes. 4,5
4. Write a code which counts the number of the keywords in a Java source file. Store all 2 2,3 3,8
the keywords in a HashSet and use the contains() method to test if a word is in the ,4,
keyword set. 5
Self-Study: Control statements, flow control (Loops)
Beyond Syllabus: Lambda Expression, JJS, New features in Java9/10 (REPL, Functional
Programming), JDBC
Student Learning Outcome (LOs)
1. Students will be able to use different commands of JDK.
2. Student will able implement GUI as well as multithreaded programming for real
life projects.
3. Students are able to design and develop projects in higher semesters using Object
oriented design approach and java programming language.
The Programme Outcomes (POs)
1. Students with desirable knowledge, skills, positive attitude and professional behavior
2. Sharpening students aptitude, as required by the professional standards of excellence
3. Exposure of the graduates to the latest knowledge and skills, with practical hands-on
experience
4. Industry-ready professional with a strong focus on delivering results according to the
industry need and expectation
5. To enhance the employability and get right talent into the program
6. To revise course program to improve students’ learning needs and curricula
development, based on needs of society in general
7. Learning from international as well as domestic institutions and experts as they
illustrate the best practices in their fields
8. Conductive to learning environment
9. To create and sustain the interest of the stakeholders in terms of Research, Quality
Publications and Mobilization of the Resources
10. To increase and sustain the interest of the students and staff in professional society
and its chapter related activities
The Programme Educational Objectives (PEOs)
1. To have up-to-date curricula of all the academic programs to meet the diverse and
changing global industrial and societal needs, the various challenges and opportunities
for the benefit of the students.
2. To have unique industry-oriented programs in collaboration with leading firms of the
IT industry.
3. To develop and hone students’ technical and behavioral competencies through
appropriate pedagogical engagement regularly.
4. To foster student-faculty interaction programs for better understanding and appreciation
of their mutual issues and evolving meaningful and appropriate mechanisms for
effective learning by students.
5. To develop the professional competencies of faculty members and technical support
staff.
6. To create an ambience where the students are cared for in every aspect and motivated to
become excellent professionals who will continue to cherish their association with the
faculty, staff and co-students.
7. To enhance Knowledge, skill and attitude.
8. To facilitate the development and evaluation of curricula.