SIVA SIVANI DEGREE COLLEGE
(Autonomous)
Affiliated to Osmania University, Accredited by NAAC with B++ grade
Kompally, Secunderabad – 100
CERTIFICATE OF SKILL TEST SUBMISSION
This is to certify that the Skill Test titled OOPS USING JAVA DEBUGGING is a record of
original work carried out by [Link] REDDY, bearing Roll Number 2 0 1 2 2 5 4 0 5 0 2 1
of B.COM1D Course C O M P U T E R A P P L I C A T I O N S Year 2 0 2 5 - 2 6
Semester during the academic year 2025 – 26.
The skill test has been submitted in partial fulfilment of the requirements for the award
of the degree of Bachelor of Commerce ([Link].), under the Department of Commerce,
Siva Sivani Degree College (Autonomous).
This work has been carried out under the guidance of M V S PAVAN KUMAR , and it
meets the necessary academic standards.
Date:30\12\2025
Signature of the Guide Signature of the HOD
Signature of the Principal
Importance of Debugging
Debugging is one of the most essential parts of software development because no matter
how carefully a program is written, errors are always possible. The process of debugging involves
identifying, analyzing and fixing these errors to make sure the program works correctly and
efficiently.
In Python or any other Programming Languages, even a small error like a missing colon,
wrong indentation or misspelled keyword can cause the entire program to fail. Debugging ensures
that the program produces intended results, prevents crashes and improves the overall quality of
Software.
Without proper debugging software would remain unreliable and users might face unexpected
failures.
Errors in any Programming Language can be broadly categorized into three types: syntax
errors, runtime errors, and logical errors :
Syntax errors are the most common ones, caused when the code does not follow Python’s rules.
For example, missing a colon at the end of a loop, incorrect indentation, or spelling mistakes in
keywords will raise a SyntaxError.
These errors are caught by the Python interpreter before the program even runs, making them
easier to detect.
Runtime errors, also known as exceptions, occur while the program is running. These include
situations like dividing a number by zero (ZeroDivisionError), trying to access a list index that does
not exist (IndexError), or using an undefined variable (NameError). Python provides exception
handling using try-except blocks to handle these gracefully.
Logical errors means the code runs without crashing, but the output is incorrect because the
logic of the program is wrong. For instance, using the wrong formula in a calculation or placing a
loop in the wrong position may not stop execution but will give wrong results. Debugging logical
errors requires carefully tracing the flow of the program and understanding what the code is
intended to do.
WRITE ABOUT JAVA PROGRAMMING
Java is a high-level, object-oriented programming language that is widely used for
developing a variety of software applications. It was created by James Gosling at Sun
Microsystems and released in 1995.
One of Java’s biggest strengths is its platform independence, which means a Java
program can run on any device or operating system that has a Java Virtual
Machine(JVM).This feature is often described as “Write Once, Run Anywhere.”
Java follows the principles of object-oriented programming (OOP), such as
encapsulation, inheritance, polymorphism, and abstraction.
These concepts help developers create programs that are modular, reusable, and
easier to maintain. In Java,everythingis written using classes and objects, making the
code well-structured and organized.
The syntax of Java is similar to C and C++, which makes it easier to learn for
beginners who are familiar with these languages.
Java is also known for being secure and robust. It has strong memory management,
automatic garbage collection, and built-in exception handling, which reduce common
programming errors like memory leaks and crashes.
Java is commonly used in many fields. It is the main language for Android app
development, making it essential for mobile application developers. It is also widely
used in web development, especially for server-side applications using technologies
like Java Servlets, JSP, and frameworks such as Spring and Hibernate.
In addition, Java is used in desktop applications, enterprise software, banking
systems, scientific applications, and even games.
Another advantage of Java is its rich standard library, known as the Java API. This
library provides ready-made classes and methods for tasks such as data structures,
networking, file handling, graphics, and database connectivity. This saves time and
effort for programmers.
Java has a large global community and strong industry support, which means plenty
of learning resources, tools, and job opportunities are available.
Because of its reliability, security, and versatility, Java continues to be one of the
most popular and important programming languages in the world.
In conclusion, Java is a powerful, flexible, and beginner-friendly programming
language that plays a major role in modern software development.
PROGRAM 5 :
public class LoanEligibility {
public static void main(String[] args) {
int age = 35;
double salary = 50000;
int creditScore = 720;
boolean isEmployed = true;
if(age >= 21)
[Link]("Age requirement met");
[Link]("This executes regardless");
if(salary = 50000) {
[Link]("Salary check passed");
}
if(age >= 21 & salary >= 30000 & creditScore >= 650) { [Link]("All
conditions met");
}
if(age < 21) {
[Link]("Too young");
}
else if(age > 65) {
[Link]("Too old");
}
else if(salary < 30000) {
[Link]("Salary too low");
}
if(isEmployed == true) {
if(creditScore >= 650) {
if(salary >= 30000) {
[Link]("Eligible for loan");
return;
}
}
}
[Link]("This might not print");
String status = "approved";
String expectedStatus = "approved";
if(status == expectedStatus) {
[Link]("Status is approved");
}
if(!(age >= 21 || salary >= 30000)) {
[Link]("Eligible");
} else {
[Link]("Not eligible");
}
switch(creditScore / 100) {
case 7:
[Link]("Good credit");
case 8:
[Link]("Excellent credit");
case 6:
[Link]("Fair credit");
break;
default:
[Link]("Poor credit");
}
}
}
Errors in the above Program
1Error:
if(age >= 21)
[Link]("Age requirement met");
[Link]("This executes regardless");
Correction:
if(age >= 21) {
[Link]("Age requirement met");
[Link]("This executes regardless");
}
2Error:
if(salary = 50000) {
Correction:
if(salary == 50000) {
3Error:
if(age >= 21 & salary >= 30000 & creditScore >= 650) {
Correction:
if(age >= 21 && salary >= 30000 && creditScore >= 650) {
4Error:
if(isEmployed == true) {
Correction:
if(isEmployed) {
5Error:
return;
Correction:
// remove return;
6Error:
if(status == expectedStatus) {
Correction:
if([Link](expectedStatus)) {
7Error:
if(!(age >= 21 || salary >= 30000)) {
[Link]("Eligible");
} else {
[Link]("Not eligible");
}
Correction:
if(age >= 21 || salary >= 30000) {
[Link]("Eligible");
} else {
[Link]("Not eligible");
}
8Error:
case 7:
[Link]("Good credit");
case 8:
[Link]("Excellent credit");
case 6:
[Link]("Fair credit");
break;
Correction:
case 7:
[Link]("Good credit");
break;
case 8:
[Link]("Excellent credit");
break;
case 6:
[Link]("Fair credit");
break;
Program Without Errors:
public class LoanEligibility {
public static void main(String[] args) {
// Sample data
int age = 35;
double salary = 50000;
int creditScore = 720;
boolean isEmployed = true;
// Correct: Proper if block with curly braces
if(age >= 21) {
[Link]("Age requirement met");
}
[Link]("Age check completed");
// Correct: Using comparison operator ==
if(salary == 50000) {
[Link]("Salary is exactly 50000");
}
// Correct: Using logical AND operator &&
if(age >= 21 && salary >= 30000 && creditScore >= 650) {
[Link]("All basic conditions met");
}
// Correct: Proper if-else if structure
if(age < 21) {
[Link]("Too young");
} else if(age > 65) {
[Link]("Too old");
} else if(salary < 30000) {
[Link]("Salary too low");
} else {
[Link]("Age and salary OK");
}
// Correct: Simplified nested condition
if(isEmployed && creditScore >= 650 && salary >= 30000) {
[Link]("Eligible for loan");
}
[Link]("This always prints");
// Correct: Using .equals() for string comparison
String status = "approved";
String expectedStatus = "approved";
if([Link](expectedStatus)) {
[Link]("Status is approved");
}
// Correct: Proper logic with AND operator
if(age >= 21 && salary >= 30000) {
[Link]("Eligible");
} else {
[Link]("Not eligible");
}
// Correct: Switch statement with break statements
int scoreRange = creditScore / 100;
switch(scoreRange) {
case 7:
[Link]("Good credit");
break;
case 8:
[Link]("Excellent credit");
break;
case 6:
[Link]("Fair credit");
break;
default:
[Link]("Poor credit");
}
}
}
Output:
2. program 9
public class NarrowingConversion {
public static void main(String[] args) {
double dblValue = 9.99;
int intValue = dblValue; [Link]("Int: " + intValue);
long longValue = 999999999999L;
int intFromLong = (int) longValue;
[Link]("Int from long: " + intFromLong);
double largeDouble = 300.5;
byte byteValue = (byte) largeDouble;
[Link]("Byte: " + byteValue);
float floatVal = 19.99f;
int intFromFloat = (int) floatVal;
[Link]("Int from float: " + intFromFloat);
double d = 256.7;
float f = (float) d;
int i = (int) f;
byte b = (byte) i;
[Link]("Byte after multiple casts: " + b);
double negDouble = -50.5;
byte negByte = (byte) negDouble;
[Link]("Negative byte: " + negByte);
long veryLargeNumber = Long.MAX_VALUE;
int resultInt = (int) veryLargeNumber;
[Link]("Very large number as int: " + resultInt);
Object obj = "Hello";
int unsafeInt = (int) obj;
double num1 = 5.9;
double num2 = 2.3;
int result = (int) num1 + (int) num2; understand casts apply
[Link]("Result: " + result);
String str = "123abc";
int parsed = (int) [Link](str);
}
ERRORS IN THE ABOVE PROGRAM
Error1:
int intValue = dblValue;
correct:
int intValue = (int) dblValue;
error2:
Object obj = "Hello";
int unsafeInt = (int) obj;
correct:
Object obj = "Hello";
String s = (String) obj;
Error3:
int result = (int) num1 + (int) num2; understand casts apply
correct:
int result = (int) num1 + (int) num2;
error4:
String str = "123abc";
int parsed = (int) [Link](str);
correct:
String str = "123";
int parsed = [Link](str);
Program Without Errors
public class NarrowingConversion {
public static void main(String[] args) {
// Correct: Explicit cast required for narrowing
double dblValue = 9.99;
int intValue = (int) dblValue;
[Link]("Int: " + intValue);
// Correct: Check for data loss
long longValue = 999999999999L;
if(longValue > Integer.MAX_VALUE) {
[Link]("Warning: Data loss will occur");
}
int intFromLong = (int) longValue;
[Link]("Int from long: " + intFromLong);
// Correct: Check range before casting to byte
double largeDouble = 300.5;
if(largeDouble > 127 || largeDouble < -128) {
[Link]("Value out of byte range");
}
byte byteValue = (byte) largeDouble;
[Link]("Byte: " + byteValue);
// Correct: Understand that decimal part is truncated
float floatVal = 19.99f;
int intFromFloat = (int) floatVal;
[Link]("Int from float: " + intFromFloat);
// Correct: Multiple casts with awareness of precision loss
double d = 256.7;
float f = (float) d;
int i = (int) f;
byte b = (byte) i;
[Link]("Byte after multiple casts: " + b);
// Correct: Handle negative values properly
double negDouble = -50.5;
byte negByte = (byte) negDouble;
[Link]("Negative byte: " + negByte);
// Correct: Check bounds before casting large numbers
long veryLargeNumber = 300L;
if(veryLargeNumber <= Integer.MAX_VALUE && veryLargeNumber >= Integer.MIN_VALUE)
{
int resultInt = (int) veryLargeNumber;
[Link]("Large number as int: " + resultInt);
}
// Correct: Proper object casting with type check
Object obj = 100;
if(obj instanceof Integer) {
int safeInt = (Integer) obj;
[Link]("Safely cast int: " + safeInt);
}
// Correct: Proper arithmetic with type awareness
double num1 = 5.9;
double num2 = 2.3;
int result = (int) num1 + (int) num2;
[Link]("Result: " + result);
// Correct: Exception handling for parsing
String str = "123";
try {
int parsed = (int) [Link](str);
[Link]("Parsed: " + parsed);
} catch(NumberFormatException e) {
[Link]("Invalid number format");
}
}
}
Output :
3. Program 13
Program With Errors
public class SwitchDemo {
public static void main(String[] args) {
int choice = 2;
switch(choice) {
case 1:
[Link]("Choice 1");
case 2:
[Link]("Choice 2");
case 3:
[Link]("Choice 3");
default:
[Link]("Invalid choice");
}
double value = 1.5;
switch((int)value) {
case 1.5:
[Link]("1.5");
break;
}
switch(choice) {
case 1:
String message = "Case 1";
break;
case 2:
String message = "Case 2";
break;
}
switch(choice) {
case 1:
[Link]("Option 1");
break;
case 2:
[Link]("Option 2");
break;
}
int option = 3;
switch(option = 5) {
case 5:
[Link]("Five");
break;
}
[Link]("Option is: " + option);
int num = 2;
switch(num) {
case 1:
case 2:
if(num == 2) {
break; }
[Link]("Number is 2");
break;
}
int baseCase = 1;
switch(choice) {
case baseCase:
[Link]("Base case");
break;
}
switch(choice) {
case 1:
[Link]("One");
case 2:
[Link]("Two");
case 3:
[Link]("Three");
break;
}
switch(choice) {
case 1:
[Link]("One");
break;
[Link]("Never executes");
break;
default:
[Link]("Default");
break;
}
switch(choice) {
case 1:
[Link]("One");
case 2:
[Link]("Two");
default:
[Link]("Default"); // Bug: Falls through from case 2
break;
}
}
}
Errors in the above program
Error1:
case 1:
[Link]("Choice 1");
case 2:
[Link]("Choice 2");
case 3:
[Link]("Choice 3");
default:
[Link]("Invalid choice");
Correct:
case 1:
[Link]("Choice 1");
break;
case 2:
[Link]("Choice 2");
break;
case 3:
[Link]("Choice 3");
break;
default:
[Link]("Invalid choice");
Error2:
case 1.5:
correct:
case 1:
error3:
case 1:
String message = "Case 1";
case 2:
String message = "Case 2";
Correct:
String message;
switch(choice) {
case 1:
message = "Case 1";
break;
case 2:
message = "Case 2";
break;
}
Error4:
switch(option = 5) {
correct:
switch(option) {
error5:
if(num == 2) {
break;
}
[Link]("Number is 2");
Correct:
if(num == 2) {
[Link]("Number is 2");
break;
}
Error6:
case baseCase:
correct:
case 1:
error7:
case 1:
[Link]("One");
case 2:
[Link]("Two");
case 3:
[Link]("Three");
Correct:
case 1:
[Link]("One");
break;
case 2:
[Link]("Two");
break;
case 3:
[Link]("Three");
break;
error8:
[Link]("Never executes");
Corrct
default:
[Link]("Never executes");
break;
error9:
case 2:
[Link]("Two");
default:
[Link]("Default");
Correct:
case 2:
[Link]("Two");
break;
default:
[Link]("Default");
Program Without Errors
public class SwitchDemo {
public static void main(String[] args) {
int choice = 2;
// Correct: Proper break statements
switch(choice) {
case 1:
[Link]("Choice 1");
break;
case 2:
[Link]("Choice 2");
break;
case 3:
[Link]("Choice 3");
break;
default:
[Link]("Invalid choice");
}
// Correct: Use integers in switch
int value = 1;
switch(value) {
case 1:
[Link]("Value is 1");
break;
case 2:
[Link]("Value is 2");
break;
default:
[Link]("Other value");
}
// Correct: Proper scope with braces for variable declaration
switch(choice) {
case 1: {
String message = "Case 1";
[Link](message);
break;
}
case 2: {
String message = "Case 2";
[Link](message);
break;
}
}
// Correct: Include default case for validation
switch(choice) {
case 1:
[Link]("Option 1");
break;
case 2:
[Link]("Option 2");
break;
default:
[Link]("Invalid option");
}
// Correct: Use value in switch, don't modify it
int option = 3;
switch(option) {
case 3:
[Link]("Three");
break;
case 5:
[Link]("Five");
break;
}
[Link]("Option is: " + option);
// Correct: Use labeled break for switch
int num = 2;
switch(num) {
case 1:
case 2:
[Link]("Number is 1 or 2");
break;
default:
[Link]("Other number");
}
// Correct: Use constant expressions in case
final int BASE_CASE = 1;
switch(choice) {
case BASE_CASE:
[Link]("Base case");
break;
default:
[Link]("Other");
}
// Correct: Proper break placement
switch(choice) {
case 1:
[Link]("One");
break;
case 2:
[Link]("Two");
break;
case 3:
[Link]("Three");
break;
}
// Correct: Remove unreachable code
switch(choice) {
case 1:
[Link]("One");
break;
default:
[Link]("Default");
}
// Correct: Intentional fallthrough documented
switch(choice) {
case 1:
case 2:
[Link]("One or Two");
break;
default:
[Link]("Default"); }
}
}
Output:
PROGRAM 17
public class VariableScopeDemo {
public int instanceVar = 10;
public void method1() {
int instanceVar = 20; // Bug: Shadows instance variable
[Link](instanceVar); // Prints 20
}
public void method2() {
[Link](localVar);
int localVar = 5;
}
public void method3() {
if(true) {
String message = "Inside if";
}
[Link](message);
}
public void method4() {
for(int i = 0; i < 5; i++) {
[Link](i);
}
[Link](i);
}
public static int shared = 100;
public int shared = 50;
public void method5() {
int counter = 0;
counter++;
[Link](counter); }
public void method6() {
if([Link]() > 0) {
[Link](name);
}
}
static int staticCounter = 0;
public void incrementCounter() {
staticCounter++;
}
private int value = 10;
public void setValue(int value) {
value = value; }
int outer = 1;
public void testScope() {
int middle = 2;
{
int inner = 3;
}
[Link](inner); // Bug: inner not in scope
}
}