HOERNER COLLEGE
NAME – YASH KUMAR PANDEY
SUBJECT – COMPUTER PROJECT
CLASS – XI
TEACHER - MR. SAURABH PANDEY
SCHOOLNAME – HOERNER
COLLEGE
TOPIC - JAVA CODING AND
DECODING
Acknowledgement
I would like to express my sincere gratitude to all these
individuals for mentoring and supporting me in
completing this project.
My teacher for providing me with invaluable insights
and direction. Our esteemed principal for fostering an
environment of learning and creativity within our
school.
To my parents, their constant encouragement,
patience, and understanding have been the pillars of
my success.
I am grateful to my friends who contributed ideas and
perspectives that enriched the project. Thank you
everyone for shaping this project and enhancing my
learning experience.
INTRODUCTION
WHAT IS JAVA ?
Java is a widely used, high-level, object-
oriented programming language and
software platform developed by Sun
Microsystems. It's known for being
platform-independent, meaning code can
run on any system with a Java Virtual
Machine (JVM) installed
WHAT IS OOPS IN
JAVA
In Java, OOPS (Object-Oriented
Programming System) is a programming
paradigm that organizes code around
the concept of "objects". Objects are
instances of classes, which act as
blueprints for creating objects with
specific attributes (data) and methods
(actions). Java leverages OOPS to build
modular, reusable, and scalable
applications.
TYPES OF OOPS
ABSTRACTION
INHERITANCE
POLYMORPHISM
ENCAPSULATION
Java program
(coding)
1. Write a simple Java program to
perform reverse a string
public class StringReverse
{
public static void main(String[] args)
{
String inputString = "example";
String reversedString = reverseString(inputString);
[Link]("Original string: " + inputString);
[Link]("Reversed string: " + reversedString);
}
public static String reverseString(String str)
{
StringBuilder sb = new StringBuilder(str);
return [Link]().toString();
}}
VARIABLE TABLE
Variable Type Description
Name
inputString String Holds the original
string to be reversed
reversedStrin String stores the result
g returned by
reverseString()
method.
str String The input to the
reverseString
method, which will be
reversed.
sb StringBuilder A mutable sequence
of characters used to
reverse the input
string.
2. Check if a String is a Palindrome
public class PalindromeCheck
{
public static void main(String[] args)
{
String inputString = "madam";
boolean isPalindrome = checkPalindrome(inputString);
[Link]("Input string: " + inputString);
if (isPalindrome)
{
[Link]("The string is a palindrome.");
}
else
{
[Link]("The string is not a palindrome.");
} }
public static boolean checkPalindrome(String str)
{
String reversed = new
StringBuilder(str).reverse().toString();
return [Link](reversed);
}}
VARIABLE TABLE
Variable Type Description
Name
inputString String The string to be
checked for being a
palindrome ("madam"
in this case).
isPalindrome boolean Stores the result of
palindrome check
(true or false).
str String The input string passed
to the palindrome
check method.
reversed String Holds the reversed
version of str to
compare with the
original.
3. Check the number of words in
string
public class WordCount
{
public static void main(String[] args)
{
String inputString = "Java is a popular
programming language";
int wordCount = countWords(inputString);
[Link]("Input string: " + inputString);
[Link]("Number of words: " +
wordCount);
}
public static int countWords(String str)
{
if(str == null || [Link]())
{
return 0;
}
String[] words = [Link]().split("\\s+");
return [Link];
}
}
VARIABLE TABLE
Variable Type Description
Name
inputString String The input string in which words
will be counted.
wordCount int Stores the number of words in
the input string.
str String The string passed to the method
for counting words.
words String Array of substrings created by
splitting the string using
whitespace delimiter.
4. Find the frequency of character in
a string
import [Link];
public class CharacterFrequency
{
public static void main(String[] args)
{
String inputString = "programming";
countCharacterFrequency(inputString);
}
public static void countCharacterFrequency(String str)
{
HashMap<Character, Integer> charCountMap = new
HashMap<>();
for(char ch : [Link]())
{
if([Link](ch))
{
[Link](ch, [Link](ch) + 1);
}
else {
[Link](ch, 1);
}
}
[Link]("Character frequencies in \" " + str
+ "\":");
for(Character key : [Link]())
{
[Link](key + " : " +
[Link](key));
}
}
}
VARIABLE TABLE
Variable Type Description
Name
inputString String The string in which character
frequencies are to be counted
("programming").
str String The string passed to the method
to process.
ch char Represents each character in the
string while iterating.
key Characte Represents each unique
r character in the map while
displaying frequencies.
5. Remove vowels from a string
public class RemoveVowels
{
public static void main(String[] args)
{
String inputString = "Beautiful Day";
String resultString = removeVowels(inputString);
[Link]("Original string: " +
inputString);
[Link]("String after removing vowels:
" + resultString);
}
public static String removeVowels(String str)
{
return [Link]("(?i)[aeiou]", "");
}
}
VARIABLE TABLE
Variable Type Description
Name
inputString String The original string from which
vowels are to be removed
("Beautiful Day").
str String The string after removing all
vowels.
resultString String The input string passed to the
method for vowel removal.
6. Linear Searching in 1-D Array
public class LinearSearch
{
public static void main(String[] args)
{
int[] numbers = {10, 20, 30, 40, 50};
int searchElement = 30;
int index = linearSearch(numbers, searchElement);
if(index == -1)
{
[Link]("Element " + searchElement
+ " not found in the array.");
}
else {
[Link]("Element " + searchElement
+ " found at index: " + index);
}
}
public static int linearSearch(int[] arr, int target)
{
for(int i = 0; i < [Link]; i++)
{
if(arr[i] == target)
{
return i; // Return index if found
}
}
return -1; // Return -1 if not found
}}
VARIABLE TABLE
Variable Type Description
Name
numbers Int[] Array of integers in which the
element is to be searched
({10, 20, 30, 40,
50}).
searchElement Int The target element to find in
the array (30).
index Int Stores the result index
returned by
linearSearch() method.
arr Int[] The array passed to the
method for searching.
target Int The element to search for in
the array.
i Int Loop variable used to
traverse the array.
7. Binary Searching in 1-D Array
import [Link];
public class BinarySearchExample {
public static void main(String[] args) {
int[] numbers = {10, 20, 30, 40, 50};
int searchElement = 30;
[Link](numbers);
int index = binarySearch(numbers,
searchElement);
if(index == -1) {
[Link]("Element " + searchElement
+ " not found in the array.");
} else {
[Link]("Element " + searchElement
+ " found at index: " + index);
}
}
public static int binarySearch(int[] arr, int target)
{
int low = 0;
int high = [Link] - 1;
while(low <= high) {
int mid = low + (high - low) / 2;
if(arr[mid] == target) {
return mid;
} else if(arr[mid] < target) {
low = mid + 1;
} else {
high = mid - 1;
}}
return -1;
}}
VARIABLE TABLE
Variable Type Description
Name
numbers Int[] Array of integers in which
the element will be searched
({10, 20, 30, 40,
50}).
searchElemen Int The target element to find in
t the array (30).
index Int Stores the index returned by
the binarySearch()
method.
arr Int[] The array to be searched.
target Int The element to find.
mid Int The middle index of the
current search range.
low int The starting index of the
search range.
high Int The ending index of the
search range.
8. Bubble Sorting in Array
public class BubbleSort
{
public static void main(String[] args)
int[] numbers = {50, 20, 40, 10, 30};
[Link]("Original array:");
printArray(numbers);
bubbleSort(numbers);
[Link]("Sorted array in ascending order:");
printArray(numbers);
public static void bubbleSort(int[] arr)
int n = [Link];
boolean swapped;
for (int i = 0; i < n - 1; i++) {
swapped = false;
for (int j = 0; j < n - 1 - i; j++)
if (arr[j] > arr[j + 1])
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
swapped = true;
public static void printArray(int[] arr)
for (int num : arr)
[Link](num + " ");
[Link]();
}}
VARIABLE TABLE
Variable Type Description
Name
number Int[] The array to be sorted ({50,
20, 40, 10, 30}).
arr Int[] The array being sorted or
printed.
n Int Length of the array.
i, j Int[] Loop counters for passes and
comparisons.
temp Int Temporary variable used
during swapping.
swapped boolean Optimization flag to detect if
any swaps occurred in the
current pass.
num Int Loop variable for printing
array elements.
9. Selection Sorting in Array
public class SelectionSort
public static void main(String[] args)
int[] numbers = {50, 20, 40, 10, 30};
[Link]("Original array:");
printArray(numbers);
selectionSort(numbers);
[Link]("Sorted array in ascending
order:");
printArray(numbers);
public static void selectionSort(int[] arr)
int n = [Link];
for (int i = 0; i < n - 1; i++)
int minIndex = i;
for (int j = i + 1; j < n; j++)
if (arr[j] < arr[minIndex])
minIndex = j;
int temp = arr[minIndex];
arr[minIndex] = arr[i];
arr[i] = temp;
}
public static void printArray(int[] arr)
for (int num : arr) {
[Link](num + " ");
[Link]();
VARIABLE TABLE
Variable Type Description
Name
number Int[] The array to be sorted ({50,
20, 40, 10, 30}).
arr Int[] The array being sorted or
printed.
n Int Length of the array.
i, j Int Loop counters for passes and
comparisons
temp Int Temporary variable used
during swapping.
minIndex int Stores the index of the
minimum element in the
unsorted part of the array.
num Int Loop variable for printing
array elements.
10. Check if a Number is Prime
public class PrimeCheck
{
public static void main(String[] args)
{
int number = 29;
if (isPrime(number))
{
[Link](number + " is a prime
number.");
}
else
{
[Link](number + " is not a prime
number.");
}
}
public static boolean isPrime(int num)
{
if (num <= 1) {
return false;
}
for (int i = 2; i <= [Link](num); i++)
{
if (num % i == 0)
{
return false;
}
}
return true;
}
}
VARIABLE TABLE
Variable Type Description
Name
number Int The number to check for
prime (29).
i Int The loop variable used to
check for factors.
num Int The number passed to the
method for prime checking.
[Link] if a Number is an
Armstrong Number
public class ArmstrongCheck
{
public static void main(String[] args)
{
int number = 153;
if (isArmstrong(number))
{
[Link](number + " is an Armstrong
number.");
} else {
[Link](number + " is not an
Armstrong number.");
}
}
public static boolean isArmstrong(int num)
{
int originalNum = num;
int result = 0;
int n = [Link](num).length();
while (num != 0) {
int digit = num % 10;
result += [Link](digit, n);
num /= 10;
}
return result == originalNum;
}}
VARIABLE TABLE
Variable Type Description
Name
number Int The number to check for
Armstrong condition (153).
originalNum Int Stores the original number
for final comparison.
num Int The number passed to the
method for checking.
result Int Accumulates the sum of digits
raised to the power of the
total digits.
n Int The number of digits in the
number.
digit Int Holds the last digit of the
number during each iteration.
12. Find the Greatest Common
Divisor (GCD) of Two Numbers
public class GCDExample
public static void main(String[] args)
int num1 = 36;
int num2 = 60;
int gcd = findGCD(num1, num2);
[Link]("GCD of " + num1 + " and " + num2
+ " is: " + gcd);
public static int findGCD(int a, int b)
while (b != 0)
int temp = b;
b = a % b;
a = temp;
return a;
}
VARIABLE TABLE
Variable Type Description
Name
Num1 Int First number to find GCD
(36).
Num2 Int Second number to find
.
GCD (60).
gcd Int Stores the result (GCD of
num1 and num2).
a Int First number passed to the
GCD method.
b Int Second number passed to the
GCD method.
temp Int Temporary variable used for
swapping values.
13. Binary Searching in 1-D Array
import [Link];
public class BinarySearchExample {
public static void main(String[] args) {
int[] numbers = {10, 20, 30, 40, 50};
int searchElement = 30;
[Link](numbers);
int index = binarySearch(numbers,
searchElement);
if(index == -1) {
[Link]("Element " + searchElement
+ " not found in the array.");
} else {
[Link]("Element " + searchElement
+ " found at index: " + index);
}
}
public static int binarySearch(int[] arr, int target)
{
int low = 0;
int high = [Link] - 1;
while(low <= high) {
int mid = low + (high - low) / 2;
if(arr[mid] == target) {
return mid;
} else if(arr[mid] < target) {
low = mid + 1;
} else {
high = mid - 1;
}}
return -1;
}}
VARIABLE TABLE
Variable Type Description
Name
numbers Int[] Array of integers in which
the element will be searched
({10, 20, 30, 40,
50}).
searchElemen Int The target element to find in
t the array (30).
index Int Stores the index returned by
the binarySearch()
method.
arr Int[] The array to be searched.
target Int The element to find.
mid Int The middle index of the
current search range.
low int The starting index of the
search range.
high Int The ending index of the
search range.
14. Check if a Number is Prime
public class PrimeCheck
{
public static void main(String[] args)
{
int number = 29;
if (isPrime(number))
{
[Link](number + " is a prime
number.");
}
else
{
[Link](number + " is not a prime
number.");
}
}
public static boolean isPrime(int num)
{
if (num <= 1) {
return false;
}
for (int i = 2; i <= [Link](num); i++)
{
if (num % i == 0)
{
return false;
}
}
return true;
}
}
VARIABLE TABLE
Variable Type Description
Name
number Int The number to check for
prime (29).
i Int The loop variable used to
check for factors.
num Int The number passed to the
method for prime checking.
15. Selection Sorting in Array
public class SelectionSort
public static void main(String[] args)
int[] numbers = {50, 20, 40, 10, 30};
[Link]("Original array:");
printArray(numbers);
selectionSort(numbers);
[Link]("Sorted array in ascending
order:");
printArray(numbers);
public static void selectionSort(int[] arr)
int n = [Link];
for (int i = 0; i < n - 1; i++)
int minIndex = i;
for (int j = i + 1; j < n; j++)
if (arr[j] < arr[minIndex]) {
minIndex = j;
int temp = arr[minIndex];
arr[minIndex] = arr[i];
arr[i] = temp;
public static void printArray(int[] arr)
{
for (int num : arr) {
[Link](num + " ");
[Link]();
VARIABLE TABLE
Variable Type Description
Name
number Int[] The array to be sorted ({50,
20, 40, 10, 30}).
arr Int[] The array being sorted or
printed.
n Int Length of the array.
i, j Int Loop counters for passes and
comparisons
temp Int Temporary variable used
during swapping.
minIndex int Stores the index of the
minimum element in the
unsorted part of the array.
num Int Loop variable for printing
array elements.
16. Remove vowels from a string
public class RemoveVowels
{
public static void main(String[] args)
{
String inputString = "Beautiful Day";
String resultString = removeVowels(inputString);
[Link]("Original string: " +
inputString);
[Link]("String after removing vowels:
" + resultString);
}
public static String removeVowels(String str)
{
return [Link]("(?i)[aeiou]", "");
}
}
VARIABLE TABLE
Variable Type Description
Name
inputString String The original string from which
vowels are to be removed
("Beautiful Day").
str String The string after removing all
vowels.
resultString String The input string passed to the
method for vowel removal.
17. Check the number of words in
string
public class WordCount
{
public static void main(String[] args)
{
String inputString = "Java is a popular
programming language";
int wordCount = countWords(inputString);
[Link]("Input string: " + inputString);
[Link]("Number of words: " +
wordCount);
}
public static int countWords(String str)
{
if(str == null || [Link]())
{
return 0;
}
String[] words = [Link]().split("\\s+");
return [Link];
}
}
VARIABLE TABLE
Variable Type Description
Name
inputString String The input string in which words
will be counted.
wordCount int Stores the number of words in
the input string.
str String The string passed to the method
for counting words.
words String Array of substrings created by
splitting the string using
whitespace delimiter.
18. Check if a String is a
Palindrome
public class PalindromeCheck
{
public static void main(String[] args)
{
String inputString = "madam";
boolean isPalindrome = checkPalindrome(inputString);
[Link]("Input string: " + inputString);
if (isPalindrome)
{
[Link]("The string is a palindrome.");
}
else
{
[Link]("The string is not a palindrome.");
} }
public static boolean checkPalindrome(String str)
{
String reversed = new
StringBuilder(str).reverse().toString();
return [Link](reversed);
}}
VARIABLE TABLE
Variable Type Description
Name
inputString String The string to be
checked for being a
palindrome ("madam"
in this case).
isPalindrome boolean Stores the result of
palindrome check
(true or false).
str String The input string passed
to the palindrome
check method.
reversed String Holds the reversed
version of str to
compare with the
original.
19. Generate Fibonacci series up to
N term
import [Link];
public class FibonacciSeries {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter the number of terms (N):
");
int n = [Link]();
// Initialize the first two terms
int firstTerm = 0;
int secondTerm = 1;
[Link]("Fibonacci series up to " + n +
" terms:");
if (n >= 1) {
[Link](firstTerm + " ");
}
if (n >= 2) {
[Link](secondTerm + " ");
}
for (int i = 3; i <= n; i++) {
int nextTerm = firstTerm + secondTerm;
[Link](nextTerm + " ");
firstTerm = secondTerm;
secondTerm = nextTerm;
}
[Link]();
[Link]();
}
}
VARIABLE TABLE
Variable Type Description
Name
Scanner Scanner An object used to read
user input from the
console.
n int Stores the number of
terms the user wants to
generate in the
Fibonacci series.
firstTerm Int Stores the first of the
two preceding terms
used to calculate the
next Fibonacci
number. Initially set
to 0
secondTerm int Stores the second of the
two preceding terms used
to calculate the next
Fibonacci number. Initially
set to 1.