TSP - Iii (Aim & Algorithm) 11
TSP - Iii (Aim & Algorithm) 11
AIM:
To demonstrate variable scoping (local & global) and parameter passing (pass-by-value &
pass-by-reference) in Java.
ALGORITHM:
1. Start the program(Define main method)
2. Declare variables globalVar (global) and localVar (local).
3. Modify Local Variable → Call modifyLocalVariable(localVar), but localVar remains
unchanged.
4. Modify Global Variable → Call modifyGlobalVariable(), globalVar changes.
5. Pass-by-Value → Call modifyPrimitive(primitiveValue), value remains unchanged.
6. Pass-by-Reference → Call modifyObject(obj), object value changes.
7. End the program (Print results).
TECHNICAL SKILL PRACTICES III
Panimalar Engineering College
Dept of CSE
ALGORITHM:
1. Start the program (Initialize Scanner for user input and define main method)
2. Use if-else to check if num is even or odd.
3. Use Switch-Case to take input (1-7), print the corresponding day.
4. Use For Loop to print numbers from 1 to 5.
5. Use While Loop to print numbers from 6 to 10.
6. End the program (Close the scanner).
TECHNICAL SKILL PRACTICES III
Panimalar Engineering College
Dept of CSE
ALGORITHM:
1. Start the program (Define main method).
2. Initialize an array, print elements, and calculate sum using sumArray().
3. Use sumVarArgs() to compute sums for different sets of arguments.
4. Display sums of arrays and var-args.
5. End the program (Program execution completes)
TECHNICAL SKILL PRACTICES III
Panimalar Engineering College
Dept of CSE
ALGORITHM:
1. Start the program (Define main method)
2. Arithmetic Operations → Show precedence using +, -, *, /, and parentheses.
3. Relational & Logical Operations → Demonstrate precedence between >, &&, ||.
4. Bitwise Operations → Show precedence of &, |.
5. Assignment Operators → Modify values using +=, *=.
6. Associativity Rules → Demonstrate left-to-right evaluation in -, /, *.
7. Unary Operators → Show pre/post increment effects (++y, y++).
8. End the program (Execution completes)
TECHNICAL SKILL PRACTICES III
Panimalar Engineering College
Dept of CSE
ALGORITHM:
1. Start the program (Define main method)
2. Widening Conversion: Convert int to double and char to int.
3. Narrowing Conversion: Convert double to int and int to byte.
4. Print the original and converted values.
5. End the program (Program execution completes)
TECHNICAL SKILL PRACTICES III
Panimalar Engineering College
Dept of CSE
ALGORITHM:
1. Start the program (Define main method in class AccessModifiersExample)
2. Create Object: Instantiate DemoClass.
3. Access Public Members: Print publicVar, call publicMethod().
4. Access Protected Members: Print protectedVar, call protectedMethod().
5. Access Default Members: Print defaultVar, call defaultMethod().
6. Restrict Private Members: Cannot access privateVar or privateMethod().
7. End the program (Execution completes)
TECHNICAL SKILL PRACTICES III
Panimalar Engineering College
Dept of CSE
ALGORITHM:
1. Start the program (Define main method)
2. Final Class & Members → Create FinalClass, initialize finalVar, call displayFinal()
and displayStatic().
3. Abstract Class & Method → Define AbstractClass with an abstract and
synchronized method.
4. Concrete Class Implementation → Implement abstractMethod() in ConcreteClass.
5. Create Object & Call Methods → Instantiate ConcreteClass, call abstractMethod()
and synchronizedMethod().
6. End the program (Execution completes)
TECHNICAL SKILL PRACTICES III
Panimalar Engineering College
Dept of CSE
ALGORITHM:
1. Start the program (Define the main method)
2. Create Package (mypackage) → Define Utility class with a static method square().
3. Use Static Imports → Import sqrt(), pow(), abs() from Math using import static.
4. Use Custom Package → Import Utility from mypackage.
5. Perform Calculations → Compute square root, power, absolute value, and square
using Utility.square().
6. Display calculated values.
7. End the program (Execution completes)
TECHNICAL SKILL PRACTICES III
Panimalar Engineering College
Dept of CSE
ALGORITHM:
1. Define Class (Person) → Declare name and age as instance variables.
2. Create Constructor → Initialize name and age using this keyword.
3. Define Method (displayInfo) → Print the person’s details.
4. Create Main Class → Instantiate Person objects (person1, person2).
5. Call Methods → Use displayInfo() to print details.
6. End the program (Execution completes)
TECHNICAL SKILL PRACTICES III
Panimalar Engineering College
Dept of CSE
AIM:
ALGORITHM:
AIM:
To demonstrate inheritance in Java by accessing parent and child class methods.
ALGORITHM:
1. Create a parent class Animal with: o A property name.
2. Create a child class Dog that inherits from Animal and adds a bark()
method.
3. In the main() method:
• Call the eat() and sleep() methods from the parent class.
AIM:
To demonstrate polymorphism in Java using method overriding and method overloading.
ALGORITHM:
1. Create a parent class Animal with a sound() method.
2. Create two child classes Dog and Cat that override the sound() method.
3. Create a Calculator class with overloaded add() methods.
4. In main():
o Use parent class references to call the sound() method in Dog and Cat (method
overriding).
o Create a Calculator object and call the overloaded add() methods.
5. Display the output.
TECHNICAL SKILL PRACTICES III
Panimalar Engineering College
Dept of CSE
AIM:
To demonstrate constructor overloading in Java using default, parameterized, and copy
constructors.
ALGORITHM:
1. Create a Student class with:
o Properties name and age.
o A default constructor that sets default values.
o A parameterized constructor that takes name and age as arguments.
o A copy constructor that creates a new object by copying the values from
another object.
2. Add a display() method to show student details.
3. In main():
o Create an object using the default constructor and display its details.
o Create an object using the parameterized constructor and display its details.
o Create an object using the copy constructor and display its details.
4. Display the output.
TECHNICAL SKILL PRACTICES III
Panimalar Engineering College
Dept of CSE
AIM:
To demonstrate the use of static and non-static members in Java.
ALGORITHM:
1. Create a Student class with:
o A static variable studentCount to keep track of the total number of students.
o Non-static variables name and rollNo to store individual student details.
2. Add a constructor to initialize name and rollNo, and increment studentCount.
3. Create a static method displayTotalStudents() to show the total number of students.
4. Create a non-static method displayDetails() to display individual student details.
5. In main():
o Call the static method before creating any objects. o Create multiple
Student objects.
o Call the static method again to display the updated student count.
o Use the non-static method to display each student’s details.
6. Display the output.
TECHNICAL SKILL PRACTICES III
Panimalar Engineering College
Dept of CSE
ALGORITHM:
1. Create a custom exception class InvalidAgeException by extending Exception.
2. Add a constructor to accept and display a custom message.
3. Create a validateAge() method that:
o Throws InvalidAgeException if the age is less than 18.
o Displays a success message if the age is valid.
4. In main():
o Use try-catch to handle the custom exception. o Call validateAge() with
different age values.
o Print the exception message if thrown.
5. Use a finally block to display a completion message.
6. Display the output.
TECHNICAL SKILL PRACTICES III
Panimalar Engineering College
Dept of CSE
AIM:
ALGORITHM: