Java Lab Manual 2025
Java Lab Manual 2025
(MR24-1CS0401)
Lab Manual
II [Link] I SEMESTER
2025-2026
University Vision:
• To be a world class University visualizing a great future for the young aspirants, with innovative nature,
research culture and ethical sensitivities to meet the global challenges improving the Quality of Human
Life.
University Mission:
• To impart value-based futuristic higher education molding students into globally competent
empowered youth, rich in culture and ethics along with professional expertise.
• To promote Innovation, Entrepreneurship, Research, and Development for the broad purpose of
fulfilling societal goals such as Societal Welfare and benefit.
Department Vision:
• To emerge as a globally recognized center of excellence in Cyber Security education, research, and
innovation, While shaping skilled, ethical, and socially responsible professionals that shall protect and
enhance the digital Ecosystem, leads advanced research in relevant fields, and achieves sustainable
societal, industrial, and national Security objectives in line with Industry 4.0 and 5.0 frameworks
Department Mission:
• To provide a comprehensive and modern education in cyber security by fusing fundamental ideas
with the newest advancements in cutting-edge technologies.
• To promote interdisciplinary research and innovation and global collaborations through patents and
publications.
• To enhance the industry and academia relationship through MoUs, internships, expert lectures, and
start-up incubation.
• To foster responsible cyber citizens by instilling strong ethical, legal, and social values.
• To encourage leadership, global engagement, and sustained participation through professional bodies,
certifications, and Hackathons.
4
PROGRAM OUTCOMES (POS):
PO OUTCOMES
Problem Analysis – Using appropriate analytical and modern research tools, interpret and assess
PO 2 a problem as cyber security, and derive a sound conclusion.
Design & Development – Create and develop systems, processes, or solutions to a given
PO 3 complex problem in Cyber Security, and incorporate the factors of health, safety, culture and
society, plus the environment.
Research & Innovation – Using a sound research and experimental design, investigate complex
PO 4 problems, gather relevant data and using appropriate methods, analyse the data to obtain
reliable results with regard to Cyber Security.
Modern Tool Usage – Employ appropriate modern engineering tools, information technology,
PO 5 and artificial intelligence, as well as the cloud and simulation tools to create advanced and
innovative solutions in Cyber Security.
The Engineer and the World - Assess the legal, social, health, safety, ethical, and
PO 6 environmental factors relevant to professional cybersecurity practice and to provide
responsible, equitable and sustainable solutions.
Ethics and Professional Commitment - Demonstrate ethical behavior, commitment to
PO 7 professionalism, and legal requirements while still making informed decisions while making
decisions that occur in a rapidly evolving cyber landscape.
Teamwork and Collaboration - Work effectively as an individual and as part of diverse and
PO 8 multidisciplinary teams to either lead or contribute to projects designed to address critical
cybersecurity challenges at national and global levels.
Communication Skills
PO 9 Communicate technical information, security policies, and audit results in a clear, effective
manner and form the basis of technical reports, documentation, presentations, and
consultations with stakeholders
Project Management and Innovation
PO 10 Use project management methodologies, entrepreneurial thinking, and innovative approaches
to develop, lead, and deliver scalable and secure cyber solutions within budget and
timeframes.
Lifelong Learning and Tech Adaptability - Continuously adapt to rapidly changing
PO11 technologies like new threats and evolving tools by using self-directed learning approaches,
formally accredited certifications, and active participation in professional learning networks.
5
Program Educational Objectives (PEOs):
• PEO 1: Achieve marked professional success in cyber security, forensics, and other emerging fields.
• PEO 2: Engage in sustained and self-directed participation through professional development activities
such as Research, certification, and advanced education.
• PEO 3: Display ethical, legal, and professional responsibility while actively and effectively responding to
global Security issues.
• PEO 4: Innovate secure, scalable, and AI-integrated solutions leveraging block chain, cloud, and modern
Frame works.
• PSO1: Leveraging advanced cryptographic algorithms, AI-driven threat analytics, and block chain
technologies to design, analyze, and secure complex systems.
• PSO2: Specialize in cyber forensics, incident response, vulnerability assessment, and threat intelligence.
• PSO3: Create industry-compliant cyber security frameworks for the cloud, IoT, and critical infrastructure
that are Scalable and integrated with AI
6
MALLA REDDY UNIVERSITY
7
MALLA REDDY UNIVERSITY
Objectives:
1. Practice programming in the Java.
2. Gain knowledge of object-oriented paradigm in the Java programming language.
3. Learn use of Java in a variety of technologies and on different platforms
Lab Programs
Week-1:
1) Write a java program that prints all real solutions to the quadratic equation ax2 +bx+c=0. Read in a, b, c and use
the quadratic formula.
2) The Fibonacci sequence is defined by the following rule. The first two values in the sequence are 1 and 1. Every
subsequent value is the sum of the two values preceding it. Write a java program that uses both recursive and non-
recursive functions
Week-2:
3) Write a Java Program that prompts the user for an integer and then prints out all the prime numbers up to that Integer.
4) Write a Java program that checks whether a given string is a palindrome or not .
Week-3:
5) Write a program to implement constructor in java.
6) Write a java program to implement method overriding.
Week-4:
7) Write a Program to implement method overloading by using static method in java.
8) Write a Program to implement method overloading in single class in java
Week-5:
9) Write a java program to create an abstract class named Shape that contains two integers and an empty method named
print Area (). 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.
Week-6:
10) WAP to design a class account using the inheritance and static that show all function of bank (withdraw, deposit etc).
11) WAP to design a String class that performs String methods (Equal, Reverse the string, and change the case etc).
8
Week-7:
12) WAP to create a package that access the member of external class as well as same package.
13) WAP that import the user define package and access the member variable of classes that contained by
package.
Week-8:
14) Write a Java program that describes exception handling mechanism.
15) Write a java program Illustrate multiple catch clauses.
Week-9:
16) 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.
Week-10:
17) Write a java program that reads a file name from the user, and then displays 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 .
18) Write a java program that displays the number of characters, lines and words in a text file
Reference Books:
1. P. J. Deitel, H. M. Deitel, “Java for Programmers”, Pearson Education, PHI, 4th Edition, 2007.
2. P. Radha Krishna, “Object Oriented Programming through Java”, Universities Press, 2nd Edition, 2007.
4. Sachin Malhotra, Saurabh Chaudhary, “Programming in Java”, Oxford University Press, 5th Edition, 2010.
9
Malla Reddy University CSE – CYBER SECURITY Department
CO OUTCOMES
CO5 Design and develop applets and multithreaded programs incorporating event
management and package organization.
Course
Outcomes PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PSO1 PSO2 PSO3
(COs)
CO1 3 2 2 1 2 1 – – 1 – 2 2 – –
CO2 3 3 3 2 2 – 1 1 2 2 2 2 2 –
CO3 3 3 3 2 3 2 2 2 2 – 2 3 2 2
CO4 3 3 2 3 3 – – 2 2 1 2 3 2 3
CO5 3 3 3 2 3 – 1 2 2 1 2 3 2 3
Direct
Attainment 3 2.8 2.6 2 2.6 1.5 1.3 1.8 1.8 1.33 2 2.6 2 2.67
10
Malla Reddy University CSE – CYBER SECURITY Department
1) Students are advised to come to the laboratory at least 5 minutes before (to the starting time), those who
come after 5 minutes will not be allowed into the lab.
2) Plan your task properly much before to the commencement, come prepared to the lab with the synopsis /
program / experiment details.
4) Laboratory observation notes with all the details (Problem statement, Aim, Algorithm, Procedure, Program,
Expected Output, etc.,) filled in for the lab session.
5) Laboratory Record updated up to the last session experiments and other utensils (if any) needed in the lab.
7) Sign in the laboratory login register, write the TIME-IN, and occupy the computer system allotted to you by
the faculty.
8) Execute your task in the laboratory, and record the results / output in the lab observation note book, and get
certified by the concerned faculty.
9) All the students should be polite and cooperative with the laboratory staff, must maintain the discipline and
decency in the laboratory.
10) Computer labs are established with sophisticated and high-end branded systems, which should be utilized
properly.
11) Students / Faculty must keep their mobile phones in SWITCHED OFF mode during the lab sessions. Misuse
of the equipment, misbehaviors with the staff and systems etc., will attract severe punishment.
12) Students must take the permission of the faculty in case of any urgency to go out; if anybody found loitering
outside the lab / class without permission during working hours will be treated seriously and punished
appropriately.
13) Students should LOG OFF/ SHUT DOWN the computer system before he/she leaves the lab after completing
the task (experiment) in all aspects. He/she must ensure the system / seat is kept properly.
11
Malla Reddy University CSE – CYBER SECURITY Department
Signature
[Link]. Name of the Experiment Page No
With Date
14
15
13
AIM : Write a java program that prints all real solutions to the quadratic equation ax2 +bx+c=0. Read in a, b, c and use
the quadratic formula.
Program:
package [Link];
import [Link];
public class Quadratic {
public static void main(String[] args) {
if (discriminant > 0) {
[Link]("roots are real solutions");
root1 = (-b + [Link](discriminant)) / (2 * a);
root2 = (-b - [Link](discriminant)) / (2 * a);
[Link]("root1 = %.2f and root2 = %.2f", root1, root2);
}else if (discriminant == 0) {
[Link]("roots are real and equal solutions");
root1 = root2 = -b / (2 * a);
[Link]("root1 = root2 = %.2f;", root1);
}else {
[Link]("There are no real solutions");
double real = -b / (2 * a);
double imaginary = [Link](-discriminant) / (2 * a);
[Link]("root1 = %.2f+%.2fi", real, imaginary);
[Link]("\nroot2 = %.2f-%.2fi", real, imaginary);
}
}
}
OUTPUT:
14
AIM : The Fibonacci sequence is defined by the following rule. The first two values in the sequence are 1 and 1. Every
subsequent value is the sum of the two values preceding it. Write a java program that uses both recursive and non-recursive
functions
Using recursive Program:
package [Link];
import [Link];
OUTPUT:
15
package [Link];
import [Link];
OUTPUT:
AIM : Write a Java Program that prompts the user for an integer and then prints out all the prime numbers up to that Integer.
Program:
package [Link];
16
import [Link];
class PrimeNumber {
public static void main(String[] args) {
Scanner s = new Scanner([Link]);
[Link]("Enter a number: ");
int n = [Link]();
if (isPrime) {
[Link](i + " ");
}
}
}
}
OUTPUT:
AIM : Write a Java program that checks whether a given string is a palindrome or not.
Program:
package [Link];
17
import [Link];
class Palindrome {
public static void main(String args[]) {
String rev = "";
OUTPUT:
18
int id;
// No-arg constructor
public Company() {
[Link]("No-arg constructor");
}
//parameterized constructor
Company(String lang) {
[Link](lang + " Programming Language");
}
OUTPUT:
class Animal {
public void sound() {
19
[Link]("Animal makes a sound");
}
}
[Link]();
[Link]();
[Link]();
}
}
OUTPUT:
AIM : Write a Program to implement method overloading by using static method in java.
Program:
package [Link];
class OverloadStaticMethod {
OUTPUT:
package [Link];
OUTPUT:
AIM : Write a java program to create an abstract class named Shape that contains two integers and an empty method named
print Area (). 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.
Program:
package p1;
import [Link];
Shape(int a, int b) {
this.a = a;
this.b = b;
}
void Printarea() {
[Link]("area of rectangle is " + (a * b));
}
}
void Printarea() {
[Link]("area of triangle is " + (0.5 * a * b));
}
}
void Printarea() {
[Link]("area of circle is " + (3.14 * a * a));
}
}
class Z {
public static void main(String[] args) {
Shape shape = null;
String input;
int width, height;
while (true) {
Scanner scanner = new Scanner([Link]);
[Link]("which shape? circle/rectangle/triangle (write any other thing for quitting): ");
input = [Link]();
if (!"circle".equalsIgnoreCase(input) && !"rectangle".equalsIgnoreCase(input)
&& !"triangle".equalsIgnoreCase(input)) {
23
[Link](0);
}
[Link]("height: ");
height = [Link]();
[Link]("width: ");
width = [Link]();
if ("circle".equalsIgnoreCase(input)) {
shape = new Circle(width, height);
} else if ("rectangle".equalsIgnoreCase(input)) {
shape = new Rectangle(width, height);
} else { // == triangle
shape = new Triangle(width, height);
}
[Link]();
}
}
}
OUTPUT:
AIM : Write a Program to design a class account using the inheritance and static that show all function of bank (withdraw,
deposit etc).
Program:
package p1;
import [Link];
class BankDetails {
private String accno;
private String name;
private String acc_type;
24
private long balance;
Scanner sc = new Scanner([Link]);
OUTPUT:
AIM : Write a Program to design a String class that performs String methods (Equal, Reverse the string, and change the case
etc).
Program:
package p1;
public class StringMethodsDemo {
public static void main(String[] args) {
String targetString = "Java is fun to learn";
String s1 = "JAVA";
String s2 = "Java";
String s3 = " Hello Java ";
[Link]("Char at index 2(third position): " + [Link](2));
[Link]("After Concat: " + [Link]("-Enjoy- "));
[Link]("Checking equals ignoring case: " + [Link](s1));
[Link]("Checking equals with case: " + [Link](s1));
27
[Link]("Checking Length: " + [Link]());
[Link]("Replace function: " + [Link]("fun", "easy"));
[Link]("SubString of targetString: " + [Link](8));
[Link]("SubString of targetString: " + [Link](8, 12));
[Link]("Converting to lower case: " + [Link]());
[Link]("Converting to upper case: " + [Link]());
[Link]("Triming string: " + [Link]());
[Link]("searching s1 in targetString: " + [Link](s1));
[Link]("searching s2 in targetString: " + [Link](s2));
OUTPUT:
AIM : Write a Program to create a package that access the member of external class as well as same package.
Program:
package pack1;
interface pack1Interface {
String name = "This is the Interface of pack1";
void pack1Interface();
}
28
public void setName(String name) {
[Link] = name;
}
}
package pack2;
interface pack3Interface {
String name = "pack";
pack3(int a, int b) {
[Link] = a;
[Link] = b;
}
package pack2;
import pack1.*;
OUTPUT:
AIM : Write a Program that import the user define package and access the member variable of classes that contained by
package.
Program:
package udp;
public pack() {
[Link]("Constructor of user defined pack");
}
30
import [Link];
class packex{
public static void main(String[] args) {
pack obj = new pack();
[Link](obj.a);
obj.mypackm1();
}
}
OUTPUT:
OUTPUT:
31
AIM : Write a java program Illustrate multiple catch clauses.
Program:
package p1;
AIM : 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.
Program:
package p1;
import [Link];
Square(int n) {
x = n;
}
Cube(int n) {
x = n;
}
OUTPUT:
33
AIM : Write a java program that reads a file name from the user, and then displays 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 .
Program:
package p1;
import [Link];
import [Link];
import [Link];
import [Link];
class filedemo {
public static void p(String str) {
[Link](str);
}
OUTPUT:
AIM : Write a java program that displays the number of characters, lines and words in a text file
Program:
package p1;
import [Link].*;
OUTPUT:
36