0% found this document useful (0 votes)
0 views19 pages

Cmp712 Lab Java - Programming

The document is a workbook for a JAVA lab course at Yashwantrao Chavan Maharashtra Open University, detailing various practical activities for students to complete. It includes tasks such as writing Java classes, implementing methods, creating exceptions, and working with collections. Each practical section outlines specific programming challenges to enhance students' understanding of Java concepts.
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)
0 views19 pages

Cmp712 Lab Java - Programming

The document is a workbook for a JAVA lab course at Yashwantrao Chavan Maharashtra Open University, detailing various practical activities for students to complete. It includes tasks such as writing Java classes, implementing methods, creating exceptions, and working with collections. Each practical section outlines specific programming challenges to enhance students' understanding of Java concepts.
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
You are on page 1/ 19

Bachelor of Computer Applications (BCA)

JAVA Lab: Workbook

Yashwantrao Chavan Maharashtra Open University


Dnyangangotri, Near Gangapur Dam, Nashik 422 222
Practical Activities
No.

1 i. Write a Java class to swap two numbers without using third


variable.
ii. Write a Java Program to determine reverse the number
iii. Write a Java class to print the Fibonacci sequence till 100
iv. Write a Java Program to determine whether the number is
Armstrong or not.
v. Write a Java Program to determine whether the number is
prime or not.
2 i. Write a Java program for the following scenario: Run a loop
from 1 to 100, while looping when the number is even print its
square and when the number is odd print its cube.

ii. Write a Java program to print the following Floyd Triangle


1
0 1
10 1
010 1

iii. Write a Java Program to print following


12345
1234
123
12
1
3 i. Write a Java class Employee with variables name, age, gender write
setter and getter methods for it.
ii. Write a class mobile with methods call() and sms(). Write a class
Demo and access it.
iii. Write a class Math Demo with methods square() with one parameter
and add() with two parameters. Call these methods
to get the output.
4 Write a Java class for following methods
display() -- Display number from 1 to 100 using while loop in Java
fibonacci() -- Prints Fibonacci series till 100
5 Write a class Automobile with default constructor, write a class Plane
which extends Automobile and has a default as well as parameterized
constructor, write a class Airbus with a default
constructor which extends Plane.
6 i. Write a Java Program to convert “25” to Primitive as well as
Wrapper.
ii. Write a Java program to convert 110011 to decimal value.
7 Write a Java Program to convert the “59” to Primitive float (without
using Constructor of Float)
8 Write a class User with abstract methods pay() and receive(), later make
two concrete class Gold User and Silver User, override the abstract
method.
9 Write a Java program to write the following, class A with method m1( )
and m2( ) and write a class B with methods m3( ) and m4( ),
Override the methods of A in class B.
10  Write an abstract class Car with methods start() and stop(). Write a
class Santro and Audi and override the methods.
 Write two interfaces Sports Car and Commercial Car and
implement the appropriate interface on the appropriate class made in
example 1.
11  Make an Interface CE which have methods call(), sms (), Make
another interface ISO which have methods radiation() and sound().
Make two classes IPhone and Galaxy and make them implement both
the interfaces.
 Write a Java program to make a package com. shapes, make classes
Circle and Square in the same package.
12 i. Write a Java Program to make an Exception Age Exception. When
user passes some age and if age is less than 18 throw this
Exception.
ii. Create an Exception String Not Palindrome Exception. Write a class
with method which throws this Exception when String passed is not
palindrome.
13 i. Write a Java program to determine the number of vowels in a String
ii. Write a Java program for separate hours, minutes and seconds from
following string 01:23:45 PM.
14 i. Write a Java Program to store the following data, in the
collection you feel will suite best.
Name- Tom
Email- [email protected] Phone:9988776655
ii. Write a Java Program to find the minimum value in Vector
[8,9,1,3,4].
iii. Write a Java Program to find the number of String starting
with „S‟ from following Tree Set [ Smith, Alex , Tom, Steve, Mark,
Sammy]
15 Sort the given list of objects in order of their email Contact: id, name,
email, phone
Yashwantrao Chavan Maharashtra
Open University,
Nashik

LAB : JAVA [CMP712]

School of Computer Science


BCA –P131

Lab: JAVA (CMP712)

Practical 1:
Activities:
1. Write a Java class to swap two numbers without using third variable.
2. Write a Java Program to determine reverse the number
3. Write a Java class to print the Fibonacci sequence till100
4. Write a Java Program to determine whether the number is Armstrong or not.
5. Write a Java Program to determine whether the number is prime or not.
-----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

________________________________________________________________________

---------------------------------------------------------------------------------------------------------------------

---- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

Practical 2:
Activities
1. Write a Java program for the following scenario: Run a loop from 1 to 100, while looping
when the number is even print its square and when the number is odd print its cube.
2. Write a Java program to print the following Floyd Triangle
1
01
1 01
0 1 01
3. Write a Java Program to print following
12345
1234
123
12
1
----- ---------------------------------------------------------------------------------------------------------------

________________________________________________________________________

---------------------------------------------------------------------------------------------------------------------

---- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

Practical 3:
Activities :
1. Write a Java class Employee with variables name, age, gender write setter and getter

methods for it.

2. Write a class mobile with methods call() and sms(). Write a class Demo and accessit.

3. Write a class MathDemo with methods square() with one parameter and add() with two

parameters. Call these methods to get the output.

--------------------------------------------------------------------------------------------------------------------

----- ---------------------------------------------------------------------------------------------------------------

________________________________________________________________________

---------------------------------------------------------------------------------------------------------------------

---- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

Practical 4:
Activity 1: Write a Java class for following methods
1. Display() -- Display number from 1 to 100 using while loop in Java
2. Fibonacci() -- Prints Fibonacci series till 100.

-------------------------------------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

________________________________________________________________________

---------------------------------------------------------------------------------------------------------------------

---- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

Practical 5:
Activity 1: Write a class Automobile with default constructor, write a class Plane which extends
Automobile and has a default as well as parameterized constructor, write a class Airbus with a default
constructor which extends Plane.

________________________________________________________________________

---------------------------------------------------------------------------------------------------------------------

---- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

Practical 6:
Activities
1. Write a Java Program to convert “25” to Primitive as well as Wrapper.
2. Write a Java program to convert 110011 to decimal value
.-------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------

________________________________________________________________________

---------------------------------------------------------------------------------------------------------------------

---- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

Practical 7:
Activity 1: Write a Java Program to convert the “59” to Primitive float (without using Constructor
of Float)
-----------------------------------------------------------------------------------------------------------------
________________________________________________________________________

---------------------------------------------------------------------------------------------------------------------

---- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------
Practical 8:

Activity 1: Write a class User with abstract methods pay() and receive(), later make two concrete
class GoldUser and SilverUser, override the abstract method
.-------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------
________________________________________________________________________

---------------------------------------------------------------------------------------------------------------------

---- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------
Practical 9:

Activity 1: Write a Java program to write the following, class A with method m1( ) and m2( ) and
write a class B with methods m3( ) and m4( ),Override the methods of A in class B.

________________________________________________________________________

---------------------------------------------------------------------------------------------------------------------

---- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

Practical 10:
Activities
1. Write an abstract class Car with methods start() and stop(). Write a class Santro and Audi and
override the methods.
2. Write two interfaces SportsCar and Commercial Car and implement the appropriate interface on
the appropriate class made in example 1.
-----------------------------------------------------------------------------------------------------------------
________________________________________________________________________

---------------------------------------------------------------------------------------------------------------------

---- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

Practical 11:
Activities:

1. Make an Interface CE which have methods call(), sms (), Make another interface ISO which have
methods radiation() and sound(). Make two classes IPhone and Galaxy and make them
implement both the interfaces.
2. Write a Java program to make a package com. shapes, make classes Circle and Square in the
same package
.-----------------------------------------------------------------------------------------------------------------
________________________________________________________________________

---------------------------------------------------------------------------------------------------------------------

---- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

Practical 12:
Activities
1. Write a Java Program to make an Exception AgeException. When user passes some age and if
age is less than 18 throw this Exception.
2. Create an Exception StringNotPalindromeException. Write a class with method which throws this
Exception when String passed is not palindrome.
-----------------------------------------------------------------------------------------------------------------
________________________________________________________________________

---------------------------------------------------------------------------------------------------------------------

---- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------
Practical 13:

Activities:

1. Write a Java program to determine the number of vowels in a String


2. Write a Java program for separate hours, minutes and seconds from following string
01:23:45PM
.-----------------------------------------------------------------------------------------------------------------
________________________________________________________________________

---------------------------------------------------------------------------------------------------------------------

---- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------
Practical 14:

Activities :
1. Write a Java Program to store the following data, in the collection you feel will suitebest.
Name- Tom
Email- [email protected]:9988776655
2. Write a Java Program to find the minimum value in Vector [8,9,1,3,4].
3. Write a Java Program to find the number of String starting with „S‟ from following
TreeSet [ Smith, Alex , Tom, Steve, Mark, Sammy]
-----------------------------------------------------------------------------------------------------------------
________________________________________________________________________

---------------------------------------------------------------------------------------------------------------------

---- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------
Practical 15:

Activity 1: Sort the given list of objects in order of their email Contact: id, name, email, phone
-----------------------------------------------------------------------------------------------------------------

________________________________________________________________________

---------------------------------------------------------------------------------------------------------------------

---- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--- -----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------

You might also like