CE251 Java Practical List PDF
CE251 Java Practical List PDF
PART-I LO PO PEO
Data Types, Variables, String, Control Statements, Operators, Arrays
1. Introduction to Object Oriented Concepts, comparison of Java with other object 1 1,3, 1,7
oriented programming languages. Introduction to JDK, JRE, JVM, javadoc, 4,5
command line argument.
Introduction to Eclipse or Netbean IDE and Console Programming.
2. Given a string, return a string made of the first 2 chars (if present), however 1 1,3, 7
include first char only if it is 'o' and include the second only if it is 'z', so 4,5
"ozymandias" yields "oz".
startOz("ozymandias") → "oz"
startOz("bzoo") → "z"
startOz("oxx") → "o"
3. Given two non-negative int values, return true if they have the same last digit, 1 1,3, 7
such as with 27 and 57. Note that the % "mod" operator computes remainders, so 4,5
17 % 10 is 7.
stringMatch("xxcaazz", "xxbaaz") → 3
stringMatch("abc", "abc") → 2
stringMatch("abc", "axc") → 0
6. Computing Body Mass Index 1 1,3, 7
You can use nested if statements to write a program that interprets body mass 4,5
index.
Body Mass Index (BMI) is a measure of health based on height and weight. It can
be calculated by taking your weight in kilograms and dividing it by the square of
your height in meters. The interpretation of BMI for people 20 years or older is as
follows:
BMI Interpretation
Write a program that prompts the user to enter a weight in pounds and height in
inches and displays the BMI. Note that one pound is 0.45359237 kilograms and
one inch is 0.0254 meters. Listing 3.4 gives the program.
Output-
Normal
7. Lottery 1 1,3, 7
The lottery program involves generating random numbers, comparing digits, and 4,5
using Boolean operators.
Suppose you want to develop a program to play lottery. The program randomly
generates a lottery of a two-digit number, prompts the user to enter a two-digit
number, and determines whether the user wins according to the following rules:
1. If the user input matches the lottery number in the exact order, the award is
$10,000.
2. If all digits in the user input match all digits in the lottery number, the award
is $3,000.
3. If one digit in the user input matches a digit in the lottery number, the award is
$1,000.
Note that the digits of a two-digit number may be 0. If a number is less than 10,
we assume the number is preceded by a 0 to form a two-digit number. For
example, number 8 is treated as 08 and number 0 is treated as 00 in the program.
Listing 3.8 gives the complete program.
PART-III
Package & Interface
1. WAP that illustrate the use of interface reference. Interface Luminious Object has 3 1,4,5 3
two method lightOn() and lightOff(). There is one class Solid extended by 2 6
classes Cube and Cone. There is one class LuminiousCone extends Cone and
implements Luminoius Interface. LumminuiousCube extends Cube and
implements Luminious Interface. Create a object of LuminiousCone and
LuminousCube and use the concept of interface reference to invoke the methods
of interface.
2. WAP that illustrate the interface inheritance. 3 1,4,5 3
Interface P is extended by P1 and P2 interfaces. 6
Interface P12 extends both P1 and P2. Each interface declares one method and
one constant. Create one class that implemetns P12. By using the object of the
class invokes each of its method and displays constant.
3. Create an abstract class Robot that has the concretre subclasses , RobotA, 3 1,4,5 3
RobotB, RobotC. Class RobotA1 extends RobotA, RobotB1 extends RobotB and 6
RobotC1 extends RobotC. There is interface Motion that declares 3 methods
forward(), reverse() and stop(), implemented by RobotB and RobotC. Sound
interface declare method beep() implemented by RobotA1, RobotB1 and
RobotC1. Create an instance method of each class and invoke beep() and stop()
method by all objects.
4. Write a java program to create an abstract class named Shape that contains two 3 1,4,5 3
integers and an empty method named printArea(). Provide three classes named 6
Rectangle, Triangle and Circle such that each one of the classes extends the class
Shape. Each one of the classes contain only the method printArea( ) that prints
the area of the given shape.
5. Write a java program to find the details of the students eligible to enroll for the 3 1,4,5 3
examination ( Students, Department combinedly give the eligibility criteria for 6
the enrollement class) using interfaces
6. Write a java program which shows importing of classes from other user define 3 1,4,5 3
packages. 6
7. Write a program that demonstrates use of packages & import statements. 3 1,4,5 3
6
8. Write a program that illustrates the significance of interface default method. 3 1,4,5 3
6
PART-IV
Exception Handling
1,4,5
1. WAP to show the try - catch block to catch the different types of exception. 3 6
3
1,4,5
2. WAP to generate user defined exception using “throw” and “throws” keyword. 3 6
3
Write a program that raises two exceptions. Specify two ‘catch’ clauses for the
two exceptions. Each ‘catch’ block handles a different type of exception. For 1,4,5
3. 3 3
example the exception could be ‘ArithmeticException’ and 6
‘ArrayIndexOutOfBoundsException’. Display a message in the ‘finally’ block.
PART-V
File Handling & Streams
1. WAP to show how to create a file with different mode and methods of File class 2 2,3, 3,8
to find path, directory etc. 4,5
2. Write a program to show a tree view of files and directories under a specified 2 2,3, 3,8
drive/volume.
3. Write a Java program that reads on file name from the user, then displays 2 2,3, 3,8
information about whether the file exists, whether the file is readable, whether
the file is writable, the type of file and the length of the file in bytes?
4. Write a program to transfer data from one file to another file so that if the 2 4,5 3,8
destination file does not exist, it is created.
5. WAP to show use of character and byte stream. 2 2,3, 3,8
6. WAP to read console input and write them into a file. 2 4,5 3,8
(BufferedReader /BufferedWriter).
7. WAP to demonstrate methods of wrapper class. 2 2,3, 3,8
PART-VI
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. Program 2 2,3, 3,8
should distribute the task of summation of N numbers amongst number of 4,5
threads and final result to be displayed on the console.
3. Write a java program that implements a multi-thread application that has three 2 2,3, 3,8
threads. First thread generates random integer every 1 second and if the value is 4,5
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 display it 2 2,3, 3,8
after one second using thread using sleep() method. 4,5
5. Write a program to create three threads ‘FIRST’, ‘SECOND’, ‘THIRD’. Set the 2 2,3, 3,8
priority of the ‘FIRST’ thread to 3, the ‘SECOND’ thread to 5(default) and the 4,5
‘THIRD’ thread to 7.
6. Write a program to solve producer-consumer problem using thread 2 2,3, 3,8
synchronization. 4,5
PART-VII
Collection Framework and Generic
1. Design a Custom Stack using ArrayList class, which implements following functionalties of
stack.
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 words 2 2,3, 3,8
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 the 2 2,3, 3,8
keywords in a HashSet and use the contains method to test if a word is in the keyword 4,5
set.
PART-VII
Beyond Syllabus: Lambda Expression, JJS, New features in Java9/10 (REPL, Functional
Programming), JDBC,