0% found this document useful (0 votes)
18 views36 pages

Java Lab Manual 2025

The document is a lab manual for a Java Programming course under the Department of Cyber Security at Malla Reddy University for the academic year 2025-2026. It outlines the university's vision and mission, program outcomes, educational objectives, and specific lab exercises to be completed by students. The manual also includes general laboratory instructions and a detailed index of experiments to be conducted in the course.

Uploaded by

itsmeplayer018
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)
18 views36 pages

Java Lab Manual 2025

The document is a lab manual for a Java Programming course under the Department of Cyber Security at Malla Reddy University for the academic year 2025-2026. It outlines the university's vision and mission, program outcomes, educational objectives, and specific lab exercises to be completed by students. The manual also includes general laboratory instructions and a detailed index of experiments to be conducted in the course.

Uploaded by

itsmeplayer018
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

Java Programming

(MR24-1CS0401)

Lab Manual
II [Link] I SEMESTER
2025-2026

DEPARTMENT OF CYBER SECURITY


SCHOOL OF ENGINEERING
HOD Dean
Department of Cyber Security

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

Engineering Knowledge – Utilize a combination of mathematics, science, and engineering as


PO 1 appropriate to the Cyber Security discipline in order to identify, assess, and solve complex
related problems with a high level of difficulty.

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.

Program Specific Outcomes (PSOs):

• 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

CSE (Cyber Security) Blooms Taxonomy

Level No. Level Definition Action verb

Exhibit memory of previously learned


material by recalling facts, terms, basic Recall, Recognize,
Level 1 Remember Identify, Match, Define
concepts, and answers

Demonstrate understanding of facts and


ideas by organizing, comparing, Explain, Summarize, Paraphrase,
Level 2 Understand
translating, interpreting, giving Classify, Categorize
descriptions, and stating main ideas.

Solve problems to new situations by


Apply Use, Implement, Solve,
Level 3 applying acquired knowledge, facts,
Demonstrate, Illustrate
techniques and rules in a different way

Examine and break information into


Level 4 Analyze Compare, Contrast,
parts by identifying motives or causes.
Differentiate, Distinguish,
Make inferences and find evidence to
Examine
support generalizations.

Present and defend opinions by Making Criticize, Judge, Defend,


Judgments about information, validity of Appraise, Value, Prioritize,
Level 5 Evaluate
ideas, or quality of work based on a set of Revise, Argue, Support,
criteria. and Re-design.

Compile information together in a


different way by combining elements in a Build, Design, Construct,
Level 6 Create New pattern or proposing alternative Generate, Develop
Solutions.

7
MALLA REDDY UNIVERSITY

II YEAR B. TECH L/T/P/C


-/-/3/1.5

(MR20-1CS0184) Java Programming LAB

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.

3. Bruce Eckel, “Thinking in Java”, Pearson Education, 4th Edition, 2006.

4. Sachin Malhotra, Saurabh Chaudhary, “Programming in Java”, Oxford University Press, 5th Edition, 2010.

9
Malla Reddy University CSE – CYBER SECURITY Department

MALLA REDDY UNIVERSITY

Course Outcomes (CO):

CO OUTCOMES

CO1 Illustrate operations, Expressions, Control-flow statements and Strings.

CO2 Determine Class, Objects, Methods, Inheritance, Exception, User defined


Exception handling mechanism.

CO3 Illustrate simple inheritance, multi-level inheritance, Exception handling


mechanism.

Construct Threads, Event Handling, implement packages, Developing


CO4 applets.

CO5 Design and develop applets and multithreaded programs incorporating event
management and package organization.

CO–PO–PSO Mapping Attainment

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

3- Strong Contribution, 2-Moderate Contribution, 1- Slight Contribution

10
Malla Reddy University CSE – CYBER SECURITY Department

MALLA REDDY UNIVERSITY


Maisammaguda, Dhulapally Post, Via Hakimpet, Secunderabad – 500100

DEPARTMENT OF CYBER SECURITY & IOT

GENERAL LABORATORY INSTRUCTIONS

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.

3) Student should enter into the laboratory with:

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.

6) Proper Dress code and Identity card.

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.

HEAD OF THE DEPARTMENT

11
Malla Reddy University CSE – CYBER SECURITY Department

CSE – CYBER SECURITY DEPARTMENT (II YEAR II SEMESTER)

Java Programming INDEX

Signature
[Link]. Name of the Experiment Page No
With Date

Write a java program that prints all real


1 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
Write a Java Program that prompts the user for
3
an integer and then prints out all the prime
numbers up to that Integer.

Write a Java program that checks whether a


4
given string is a palindrome or not.

Write a program to implement constructor in


java.
5

Write a java program to implement method


6 overriding.

Write a Program to implement method


7 overloading by using static method in java.

Write a Program to implement method


8
overloading in single class in java

Write a java program to create an abstract


9
class named Shape that contains two
integers and an empty method named print
Area (). Provide three classes named
12
Malla Reddy University CSE – CYBER SECURITY Department

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.
WAP to design a class account using the
inheritance and static that show all function of
10 bank (withdraw, deposit etc).

WAP to design a String class that performs


11 String methods (Equal, Reverse the string, and
change the case etc).

WAP to create a package that access the


member of external class as well as same
package.
12

WAP that import the user define package and


access the member variable of classes that
contained by package.
13

Write a Java program that describes exception


handling mechanism.

14

Write a java program Illustrate multiple catch


clauses.

15

Write a java program that implements a multi-


thread application that has three threads. First
thread generates random integer every 1 second
16 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.
Write a java program that reads a file name
19 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.
Write a java program that displays the number
20 of characters, lines and words in a text file

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) {

Scanner s = new Scanner([Link]);


[Link]("Enter a value");
double a = [Link]();
[Link]("Enter a value");
double b = [Link]();
[Link]("Enter a value");
double c = [Link]();
double root1, root2;

// calculate the discriminant


double discriminant = b * b - 4 * a * c;

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];

public class Test {


static int first = 0, second = 1, next = 0;

static void fibonacci(int n) {


if (n > 0) {
next = first + second;
first = second;
second = next;
[Link](" " + next);
fibonacci(n - 1);
}
}

public static void main(String args[]) {


Scanner s = new Scanner([Link]);
[Link]("Enter Fibonacci series:");
int n = [Link]();
[Link](first + " " + second);
fibonacci(n - 2);
}
}

OUTPUT:

Using non-recursive Program:

15
package [Link];

import [Link];

public class Test {


public static void main(String args[]) {
[Link]("Enter a number");
Scanner sc = new Scanner([Link]);
double a = [Link]();
int first = 0, second = 1, next = 0;
[Link](first + " " + second + " ");
for (int i = 0; i < a; i++) {
next = first + second;
first = second;
second = next;
[Link](next + " ");
}
}
}

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]();

for (int i = 2; i <= n; i++) {


boolean isPrime = true;

for (int j = 2; j <= i / 2; j++) {


if (i % j == 0) {
isPrime = false;
break;
}
}

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 = "";

Scanner sc = new Scanner([Link]);


[Link]("Enter a string:");
String str = [Link]();

for (int i = [Link]() - 1; i >= 0; i--){


rev = rev + [Link](i);
}
if ([Link](rev))
[Link](str + " is a palindrome");
else
[Link](str + " is not a palindrome");
}
}

OUTPUT:

AIM : Write a program to implement constructor in java.


Program:
package [Link];
class Company {

18
int id;
// No-arg constructor
public Company() {
[Link]("No-arg constructor");
}

//parameterized constructor
Company(String lang) {
[Link](lang + " Programming Language");
}

public Company(int id) {


[Link] = id;
}

public static void main(String[] args) {


Company obj1 = new Company();
Company obj2 = new Company("Java");
Company obj3 = new Company(999);
[Link]([Link]);
}
}

OUTPUT:

AIM : Write a java program to implement method overriding.


Program:
package [Link];

class Animal {
public void sound() {
19
[Link]("Animal makes a sound");
}
}

class Dog extends Animal {


public void sound() {
[Link]("Dog barks");
}
}

class Cat extends Animal {


public void sound() {
[Link]("Cat meows");
}
}

public class Main {


public static void main(String[] args) {
Animal animal1 = new Animal();
Animal animal2 = new Dog();
Animal animal3 = new Cat();

[Link]();
[Link]();
[Link]();
}
}

OUTPUT:

AIM : Write a Program to implement method overloading by using static method in java.
Program:
package [Link];

class OverloadStaticMethod {

public static void display() {


20
[Link]("Static method called.");
}

public static void display(int x) {


[Link]("An overloaded static method called.");
}

public static void main(String args[]) {


display();
display(160);
}
}

OUTPUT:

AIM : Write a Program to implement method overloading in single class in java


Program:

package [Link];

public class Calculator {

// Method to add two integers


21
public int add(int a, int b) {
return a + b;
}

// Method to add three integers


public int add(int a, int b, int c) {
return a + b + c;
}

// Method to add two doubles


public double add(double a, double b) {
return a + b;
}

public static void main(String[] args) {


Calculator calculator = new Calculator();

// Calling the overloaded methods


[Link]("Sum of 5 and 10 is: " + [Link](5, 10));
[Link]("Sum of 5, 10 and 15 is: "+[Link](5,10, 15));
[Link]("Sum of 3.5 and 2.7 is:"+ [Link](3.5, 2.7));
}
}

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];

abstract class Shape {


22
int a = 10, b = 2;

Shape(int a, int b) {
this.a = a;
this.b = b;
}

abstract void Printarea();


}

class Rectangle extends Shape {


Rectangle(int a, int b) {
super(a, b);
}

void Printarea() {
[Link]("area of rectangle is " + (a * b));
}
}

class Triangle extends Shape {


Triangle(int a, int b) {
super(a, b);
}

void Printarea() {
[Link]("area of triangle is " + (0.5 * a * b));
}
}

class Circle extends Shape {


Circle(int a, int b) {
super(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]);

public void openAccount() {


[Link]("Enter Account No: ");
accno = [Link]();
[Link]("Enter Account type: ");
acc_type = [Link]();
[Link]("Enter Name: ");
name = [Link]();
[Link]("Enter Balance: ");
balance = [Link]();
}

public void showAccount() {


[Link]("Name of account holder: " + name);
[Link]("Account no.: " + accno);
[Link]("Account type: " + acc_type);
[Link]("Balance: " + balance);
}

public void deposit() {


long amt;
[Link]("Enter the amount you want to deposit: ");
amt = [Link]();
balance = balance + amt;
}

public void withdrawal() {


long amt;
[Link]("Enter the amount you want to withdraw: ");
amt = [Link]();
if (balance >= amt) {
balance = balance - amt;
[Link]("Balance after withdrawal: " + balance);
} else {
[Link]("Your balance is less than " + amt + "\tTransaction failed...!!");
}
}

public boolean search(String ac_no) {


if ([Link](ac_no)) {
showAccount();
return (true);
}
return (false);
}

public static void main(String arg[]) {


Scanner sc = new Scanner([Link]);
//create initial accounts
25
[Link]("How many number of customers do you want to input? ");
int n = [Link]();
BankDetails C[] = new BankDetails[n];
for (int i = 0; i < [Link]; i++) {
C[i] = new BankDetails();
C[i].openAccount();
}
int ch;
do {
[Link]("\n ***Banking System Application***");
[Link](
"1. Display all account details \n 2. Search by Account number\n 3. Deposit the
amount \n 4. Withdraw the amount \n [Link]");
[Link]("Enter your choice: ");
ch = [Link]();
switch (ch) {
case 1:
for (int i = 0; i < [Link]; i++) {
C[i].showAccount();
}
break;
case 2:
[Link]("Enter account no. you want to search: ");
String ac_no = [Link]();
boolean found = false;
for (int i = 0; i < [Link]; i++) {
found = C[i].search(ac_no);
if (found) {
break;
}
}
if (!found) {
[Link]("Search failed! Account doesn't exist..!!");
}
break;
case 3:
[Link]("Enter Account no. : ");
ac_no = [Link]();
found = false;
for (int i = 0; i < [Link]; i++) {
found = C[i].search(ac_no);
if (found) {
C[i].deposit();
break;
}
}
if (!found) {
[Link]("Search failed! Account doesn't exist..!!");
}
break;
case 4:
26
[Link]("Enter Account No : ");
ac_no = [Link]();
found = false;
for (int i = 0; i < [Link]; i++) {
found = C[i].search(ac_no);
if (found) {
C[i].withdrawal();
break;
}
}
if (!found) {
[Link]("Search failed! Account doesn't exist..!!");
}
break;
case 5:
[Link]("See you soon...");
break;
}
} while (ch != 5);
}
}

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));

char[] charArray = [Link]();


[Link]("Size of char array: " + [Link]);
[Link]("Printing last element of array: " + charArray[3]);
}
}

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();
}

public class pack1 {


String name;
public String getName() {
return name;
}

28
public void setName(String name) {
[Link] = name;
}
}

package pack2;
interface pack3Interface {
String name = "pack";

public void interfacepack();


}

abstract class packabstract {


String name = "packAbstract";

abstract public void print();


}

public class pack3 {


int first;
int second;

pack3(int a, int b) {
[Link] = a;
[Link] = b;
}

public int add() {


return [Link] + [Link];
}
}
Accessing the members of package 1 class in package 2 class:
package pack1;

public class pack1 {


public int a=20;
public pack1() {
[Link]("Constructor of user defined pack1");
}
public void mypackm1(){
[Link]("I am user define pack1");
}
}

package pack2;
import pack1.*;

public class pack2 {


public static void main(String args[]) {
pack1 ob = new pack1();
ob.mypackm1();
29
[Link](ob.a);
}
}

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 class pack {


public int a = 20;

public pack() {
[Link]("Constructor of user defined pack");
}

public void mypackm1() {


[Link]("I am user define pack");
}
}

30
import [Link];
class packex{
public static void main(String[] args) {
pack obj = new pack();
[Link](obj.a);
obj.mypackm1();
}
}

OUTPUT:

AIM : Write a Java program that describes exception handling mechanism.


Program:
class TestException {
public static void main(String args[]) {
try {
int data = 25 / 5;
[Link](data);
} catch (NullPointerException e) {
[Link](e);
} finally {
[Link]("finally block is always executed");
}
[Link]("rest of the code...");
}
}

OUTPUT:

31
AIM : Write a java program Illustrate multiple catch clauses.
Program:
package p1;

public class MultipleCatchBlock1 {


public static void main(String[] args) {
try {
int a[] = new int[5];
a[5] = 30 / 0;
} catch (ArithmeticException e) {
[Link]("Arithmetic Exception occurs");
} catch (ArrayIndexOutOfBoundsException e) {
[Link]("ArrayIndexOutOfBounds Exception occurs");
} catch (Exception e) {
}
}
}
OUTPUT:

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];

class Square extends Thread {


int x;

Square(int n) {
x = n;
}

public void run() {


int sqr = x * x;
[Link]("Square of " + x + " = " + sqr);
}
32
}

class Cube extends Thread {


int x;

Cube(int n) {
x = n;
}

public void run() {


int cub = x * x * x;
[Link]("Cube of " + x + " = " + cub);
}
}

class Number extends Thread {


public void run() {
Random random = new Random();
for (int i = 0; i < 10; i++) {
int randomInteger = [Link](100);
[Link]("Random Integer generated : " + randomInteger);
Square s = new Square(randomInteger);
[Link]();
Cube c = new Cube(randomInteger);
[Link]();
try {
[Link](1000);
} catch (InterruptedException ex) {
[Link](ex);
}
}
}
}

public class week9 {


public static void main(String args[]) {
Number n = new Number();
[Link]();
}
}

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);
}

public static void analyze(String s) {


File f = new File(s);
if ([Link]()) {
p([Link]() + " is a file");
p([Link]() ? " is readable" : " is not readable");
p([Link]() ? " is writable" : " is not writable");
34
p("Filesize:" + [Link]() + " bytes");
p("File last mdified:" + [Link]());
}
if ([Link]()) {
p([Link]() + " is directory");
p("List of files");
String dir[] = [Link]();
for (int i = 0; i < [Link]; i++)
p(dir[i]);
}
}
}

public class FileDetails {


public static void main(String rr[]) throws IOException {
filedemo fd = new filedemo();
BufferedReader br = new BufferedReader(new InputStreamReader([Link]));
[Link]("Enter the file name:");
String s = [Link]();
[Link](s);
}
}

OUTPUT:

AIM : Write a java program that displays the number of characters, lines and words in a text file
Program:
package p1;

import [Link].*;

public class Test {


public static void main(String[] args) throws IOException {
File file = new File("C:\\Users\\hp\\Desktop\\[Link]");
FileInputStream fileInputStream = new FileInputStream(file);
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String line;
int wordCount = 0;
int characterCount = 0;
int paraCount = 0;
int whiteSpaceCount = 0;
int sentenceCount = 0;
while ((line = [Link]()) != null) {
if ([Link]("")) {
paraCount += 1;
} else {
35
}
}
characterCount += [Link]();
String words[] = [Link]("\\s+");
wordCount += [Link];
whiteSpaceCount += wordCount - 1;
String sentence[] = [Link]("[!?.:]+");
sentenceCount += [Link];
if (sentenceCount >= 1) {
paraCount++;
}
[Link]("Total word count = " + wordCount);
[Link]("Total number of sentences = " + sentenceCount);
[Link]("Total number of characters = " + characterCount);
[Link]("Number of paragraphs = " + paraCount);
[Link]("Total number of whitespaces = " + whiteSpaceCount);
}
}

OUTPUT:

36

You might also like