0% found this document useful (0 votes)
4 views

adi_java

java programs

Uploaded by

Aditya Chugh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

adi_java

java programs

Uploaded by

Aditya Chugh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 42

PRACTICAL FILE

JAVA PROGRAMMING

SUBMITTED BY: SUBMITTED TO:


ADITI GOYAL DR. RIYA SAPRA
B.TECH CSE ASET
A50105222146

AMITY UNIVERSITY HARYANA


PRACTICAL-1
AIM: To WAP to print your name in Java
Input:

Output:
PRACTICAL-2
AIM: WAP to add 2 numbers. Take input Via Scanner Class.
Input:

Output:
PRACTICAL-3
AIM: WAP to do addition, subtraction, multiplication and division by taking
a) Values for variables

Input:

Output:
b) Values Via scanner class

Input:
PRACTICAL-4
AIM: WAP to calculate factorial of a number taken via scanner class.
Input:

Output:

PRACTICAL-5
AIM: WAP to take 5 numbers as input from user and calculate
a) Average of the numbers

Input:

Output:

b) Maximum and minimum among the numbers


Input:

Output:

PRACTICAL-6
AIM: WAP to take 2 numbers and a symbol (+,-,*,/,%) from user. Using Switch case statement, calculate the desired
arithmetic operation.
Input:

Output:
PRACTICAL-7
AIM: WAP that prompts the user to input an integer and then outputs the number with the digits reversed. For
example, if the input is 12345, the output should be 54321.
Input:

Output:

PRACTICAL-8
AIM: WAP to Find the Largest Element in the array using sort function.
Input:

Output:

PRACTICAL-9
AIM: WAP to multiply two arrays.
Input:

Output:

PRACTICAL-10
AIM: WAP to create a String class that performs String methods (Equal, reverse the string, change case).
Input:

Output:

PRACTICAL-11
AIM: WAP to check whether the substring input by user belongs to a pre-defined String object.
Input:

Output:

PRACTICAL-12
AIM: WAP to create a class circle and define its methods for calculating area and circumference of circle. Use
parametrized constructors to initialize 2 objects of circle class and print the area and circumference of the 2 objects.
Input:

Output:

PRACTICAL-13
AIM: WAP to create a class Rectangle and define its methods for calculating area and perimeter of rectangle. Use
parametrized constructors to initialize 2 objects of rectangle class and print the area and circumference of the 2
objects.
Input:

Output:
PRACTICAL-14
AIM: WAP to create a class Shape and use different parameterized constructors to create objects of different shapes:
a) Shape (10,20).....Rectangle
b) Shape (20.5).... Circle
c) Shape (10)..... Square
Input:
Output:
PRACTICAL-15
AIM: Define a class MyNumber having one private int data member. Write a default constructor to initialize it to 0
and another constructor to initialize it to a value (Use this). Write methods isNegative, isPositive, isZero, isOdd,
isEven. Create 2-3 objects in main method to check the value of the data member.
Input:
Output:
PRACTICAL-16
AIM: WAP to invoke current class method using this keyword. (this.display())
Input:

Output:
PRACTICAL-17
AIM: WAP to invoke current class overloaded constructors using this keyword. (this(10), this()).
Input:

Output:
PRACTICAL-18
AIM: Define a Student class (roll number, name, percentage). Define a default and parameterized constructor. Keep a
count on objects created. Create objects using parameterized constructor and display the object count after each object
is created. (Use static member and method). Also display the contents of each object.
Input:
Output:
PRACTICAL-20
AIM: Write a Java Program to implement the following class diagram. Create 2 object for class Student and Staff
each. Use different functions and constructors to provide values to these objects and finally print the
objects via toString().

Input:
Output:
PRACTICAL-21
AIM: Write a program to implement the following class hierarchy.

Create a class TestShape as code of class is given below and predict the output.
public class TestShape {
public static void main(String[] args) {
Rectangle s1 = new Rectangle("red", 4, 5);
System.out.println(s1);
System.out.println("Area is " + s1.getArea());

Triangle s2 = new Triangle("blue", 4, 5);


System.out.println(s2);
System.out.println("Area is " + s2.getArea());
}
}
Input:

Output:
PRACTICAL-22
AIM: Re-write the abstract superclass Shape into an interface, containing only abstract methods, as follows:

Create a class TestShape as code of class is given below and predict the output.
public class TestShape {
public static void main(String[] args) {
Rectangle s1 = new Rectangle("red", 4, 5);
System.out.println(s1);
System.out.println("Area is " + s1.getArea());

Triangle s2 = new Triangle("blue", 4, 5);


System.out.println(s2);
System.out.println("Area is " + s2.getArea());
}
Input:

Output:
PRACTICAL-23
AIM: Catch an Arithmetic Exception using try catch block.

Input:

Output:
PRACTICAL-24

AIM: Write Create a class Student with attributes roll no, name, age and course. Initilize values through parameterized
constructor. If age of the student is not in between 15 and 21 then generate user-defined exception
“AgeNotWithinRangeException”.

Input:

Output:
PRACTICAL-25
AIM: Define a class MyDate with members day, month, year. Define default and parameterized constructors. Accept
values from the command line and create a date object. Throw user defined – “InvalidDayException” or
InvalidMonthException” if the day and month are invalid. If the date is valid display message “valid date”

Input:

Output:
PRACTICAL-26
AIM: Write a program in Java that will create two threads namely thread1 and Thread2 using Thread Class that will
print the numbers from 1 to 5.

Input:

Output:
PRACTICAL-27
AIM: Write a program in Java that will create two threads namely thread1 and Thread2 using Runnable interface that
will print the alphabet from A to F.

Input:

Output:
PRACTICAL-28
AIM: Implement a class that checks whether a given number is a prime using both the Thread class and Runnable
interface.

Input:
Output:
PRACTICAL-29
AIM: Write WAP to showcase the possible uses of this keyword.

Input:

Output:
PRACTICAL-30
AIM: Write WAP to showcase the possible uses of super keyword.

Input:

Output:
PRACTICAL-31
AIM: WAP to showcase the possible uses of final keyword.

Input:

Output:

You might also like