0% found this document useful (0 votes)
6 views18 pages

TSP - Iii (Aim & Algorithm) 11

The document outlines a series of technical skill practices for Java programming at Panimalar Engineering College, covering various concepts such as tokens, scoping, flow control, arrays, operators, type conversions, access modifiers, non-access modifiers, packages, class creation, inheritance, polymorphism, constructor overloading, static members, custom exceptions, and thread priorities. Each exercise includes an aim and a step-by-step algorithm to demonstrate the respective Java concepts. The exercises are designed to provide hands-on experience with fundamental programming techniques in Java.

Uploaded by

s.bharathashwath
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)
6 views18 pages

TSP - Iii (Aim & Algorithm) 11

The document outlines a series of technical skill practices for Java programming at Panimalar Engineering College, covering various concepts such as tokens, scoping, flow control, arrays, operators, type conversions, access modifiers, non-access modifiers, packages, class creation, inheritance, polymorphism, constructor overloading, static members, custom exceptions, and thread priorities. Each exercise includes an aim and a step-by-step algorithm to demonstrate the respective Java concepts. The exercises are designed to provide hands-on experience with fundamental programming techniques in Java.

Uploaded by

s.bharathashwath
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
You are on page 1/ 18

TECHNICAL SKILL PRACTICES III

Panimalar Engineering College


Dept of CSE

EXR-P1: JAVA TOKENS

AIM:

To demonstrate the use of tokens in Java, including keywords, identifiers, literals,


operators, separators, and data types.
ALGORITHM:

1. Start the Program (Define the main method).


2. Declare and Initialize Variables of different data types (int, double, char, boolean, String).
3. Display variable values using System.out.println
4. Run a for loop from i = 0 to i < 5 and print the iteration count.
5. Use an if-else conditional statement to check if the variable number is greater than 5 and
print the result.
6. End the Program
TECHNICAL SKILL PRACTICES III
Panimalar Engineering College
Dept of CSE

EXR-P2: SCOPING AND PARAMETER PASSING


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

EXR-P3: FLOW CONTROL STATEMENTS


AIM:
To demonstrate flow control statements (if-else, switch-case, for loop, and while loop) in
Java.

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

EXR-P4: ARRAYS AND VARIABLE ARGUMENTS


AIM:
To demonstrate arrays and variable arguments (var-args) in Java by calculating the sum of
elements.

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

EXR-P5: OPERATORS & THEIR PRECEDENCE AND ASSOCIATIVE


AIM:
To demonstrate operator precedence and associativity in Java, including arithmetic,
relational, bitwise, assignment, and unary operators.

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

EXR-P6: NARROWING AND WIDENING CONVERSIONS


AIM:
To demonstrate type conversion in Java, including widening (implicit) and narrowing
(explicit) conversions.

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

EXR-P7: ACCESS MODIFIERS FOR CLASS & CLASS MEMBERS


AIM:
To demonstrate access modifiers (public, protected, default, and private) in Java.

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

EXR-P8: NON-ACCESS MODIFIERS FOR CLASS & CLASS MEMBERS


AIM:
To demonstrate non-access modifiers in Java, including final, static, abstract, synchronized,
and final methods/classes/variables.

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

EXR-P9: PACKAGES AND STATIC IMPORTS


AIM:
To demonstrate package creation, static imports, and using static methods from built-in and
custom classes in Java.

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

EXR-P10: CREATING CLASSES AND INSTANCES


AIM:
To demonstrate class creation, object instantiation, constructors, and instance methods in
Java.

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

EXR-P11 To demonstrate abstract classes, method overloading, and recursion in Java.

AIM:

To demonstrate abstract classes, method overloading, and recursion in Java.

ALGORITHM:

1. Create an abstract class Shape with an abstract method draw().


2. Create a subclass Circle that implements the draw() method.
3. Create a class MethodTypesExample with: o Overloaded add() methods.
o A recursive factorial() method.
4. In main():
o Use overloaded add() methods. o Call factorial() and display the result.
o Use polymorphism to call the draw() method.
5. Display the output.
TECHNICAL SKILL PRACTICES III
Panimalar Engineering College
Dept of CSE
TECHNICAL SKILL PRACTICES III
Panimalar Engineering College
Dept of CSE

EXR-P12 To demonstrate inheritance in Java by accessing parent and child class


methods.

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.

o Methods eat() and sleep().

2. Create a child class Dog that inherits from Animal and adds a bark()
method.
3. In the main() method:

• Create an object of Dog.

• Set the name property.

• Call the eat() and sleep() methods from the parent class.

• Call the bark() method from the child class.

4. Display the output.


TECHNICAL SKILL PRACTICES III
Panimalar Engineering College
Dept of CSE

EXR-P13 To demonstrate polymorphism in Java using method overriding and method


overloading.

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

EXR-P14 To demonstrate constructor overloading in Java using default,


parameterized, and copy constructors.

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

EXR-P15 To demonstrate the use of static and non-static members in Java.

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

EXR-P16 To demonstrate the use of a custom exception in Java.


AIM:
To demonstrate the use of a custom exception in Java.

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

EXR-P17 To demonstrate thread priorities in Java.

AIM:

To demonstrate thread priorities in Java.

ALGORITHM:

1. Create a PriorityThread class by extending Thread:


o Initialize the thread name through the constructor.
o Override the run() method to display the thread name and count.
2. In the main() method:
o Create three PriorityThread objects.
o Set different priorities using setPriority():
▪ MAX_PRIORITY (10) for high priority.
▪ NORM_PRIORITY (5) for medium priority.
▪ MIN_PRIORITY (1) for low priority.
3. Start all threads using start().
4. Use join() to wait for all threads to complete.
5. Display the final message.

You might also like