Java Record Ex.no:01 Aim: To Write a Program to implement Arithmetic and Relational Operators Procedure: 1. Create a package named Operator and add a class named OperatorDemo. 2. Import the java.util.Scanner package to accept two integer inputs from the user. 3. Display the student's name and register number, then read the two input values. 4. Perform the Arithmetic Operators (+, - , *, /, %) and display their results. Also handle division by zero using an if condition. 5. Perform the Relational Operators (==, !=, >, <, >=, <=) and display the comparison results. Code: package Operator; import java.util.Scanner; public class OperatorDemo { public static void main(String[] args) { Scanner sc = new Scanner(System. in ); System. out .println("Name : Swathi.R"); System. out .println("Regno : 2413711058049"); System. out .print("Enter 1st number: "); int a = sc.nextInt(); System. out .print("Enter 2nd number: "); int b = sc.nextInt(); // Arithmetic Operators System. out .println(" \ nArithmetic Operators:"); System. out .println("Addition = " + (a + b)); System. out .println("Subtraction = " + (a - b)); System. out .println("Multiplication = " + (a * b)); if (b != 0) { System. out .println("Division = " + (a / b)); System. out .println("Modulus = " + (a % b)); } else { System. out .println("Division and Modulus by Zero are not allowed."); } // Relational Operators System. out .println(" \ nRelational Operators:"); System. out .println("a == b : " + (a == b)); System. out .println("a != b : " + (a != b)); System. out .println("a > b : " + (a > b)); System. out .println("a < b : " + (a < b)); System. out .println("a >= b : " + (a >= b)); System. out .println("a <= b : " + (a <= b)); sc.close(); } } OUTPUT: Result The expected output of the program is achieved successfully. Ex.no:02 Aim: To Write a Program to implement Unary, Assignment and Logical Operators using Java Procedure : 1. Create a package named Operator and add a class named UnaryAssignmentLogical. 2. Declare two integer variables and display the student's name and register number. 3. Implement the Unary Operators (++, -- , unary - ) and display their results. 4. Implement the Logical Operators (&&, ||, !) using suitable conditions and display the output. 5. Implement the Assignment Operators (+=, - =, *=, /=, %=) and display the updated values after each operation. Code: package Operator; public class UnaryAssignmentLogical { public static void main(String[] args) { int a = 10, b = 5; // Student Details System. out .println("Name : Swathi.R"); System. out .println("Regno : 2413711058049"); // Unary Operators System. out .println(" \ nUnary Operators:"); System. out .println("Initial value of a = " + a); System. out .println("++a = " + (++a)); // Pre - increment System. out .println(" -- a = " + ( -- a)); // Pre - decrement System. out .println(" - a = " + ( - a)); // Unary minus // Logical Operators System. out .println(" \ nLogical Operators:"); System. out .println("(a > b) && (b > 0) = " + ((a > b) && (b > 0))); System. out .println("(a < b) || (b > 0) = " + ((a < b) || (b > 0))); System. out .println("!(a > b) = " + (!(a > b))); // Assignment Operators System. out .println(" \ nAssignment Operators:"); int result = a result += b; System. out .println("result += b = " + result); result - = b; System. out .println("result - = b = " + result); result *= b; System. out .println("result *= b = " + result); result /= b; System. out .println("result /= b = " + result); result %= b; System. out .println("result %= b = " + result); } } OUTPUT: Result The expected output of the program is achieved successfully. Ex.no:03 Aim: To Write a Program to implement Classes an Objects using Java Procedure: 1. Create a package named Operator and add two classes named Employee and EmployeeForClassObj 2. Declare the employee data members (empid, name, and salary) and define a display() method in the Employee class. 3. Create an object of the Employee class in the main() method of the EmployeeForClassObj class. 4. Assign values to the employee object's data members and call the display() method using the object. 5. Execute the program to display the student's details along with the employee ID, name, and salary. Code: package Operator; class Employee { int empid; String name; double salary; void display() { System. out .println("Name : Swathi.R"); System. out .println("Regno : 2413711058049"); System. out .println("Employee Id : " + empid); System. out .println("Employee Name : " + name); System. out .println("Employee Salary : " + salary); } } public class EmployeeForClassObj { public static void main(String[] args) { Employee emp1 = new Employee(); emp1.empid = 101; emp1.name = "Swathi"; emp1.salary = 56000; emp1.display(); } } Output: Result The expected output of the program is achieved successfully. Ex.no:04 Aim: To Write a Program to implement Constructors using Java Procedure: 1. Create the package Operator and classes Student and Constructor 2. Define default, parameterized, copy, and private constructors in the Student class. 3. Create a display() method to show the student details. 4. Create objects using each constructor in the main() method. 5. Run the program and display the details using all constructors. Code: package Operator; class Student { int rollno; String name; double marks; // Default Constructor Student() { rollno = 10; name = "Swathi"; marks = 98; System. out .println(" \ nDefault Constructor"); } // Parameterized Constructor Student(int r, String n, double m) { rollno = r; name = n; marks = m; System. out .println(" \ nParameterized Constructor"); } // Copy Constructor Student(Student s) { rollno = s.rollno; name = s.name; marks = s.marks; System. out .println(" \ nCopy Constructor"); } // Private Constructor private Student(int r) { rollno = r; name = "Private Student"; marks = 0; System. out .println(" \ nPrivate Constructor"); } static void CreatePrivateStudent() { Student s = new Student(999); s.display(); } void display() { System. out .println("ROLL NUMBER : " + rollno); System. out .println("NAME : " + name); System. out .println("MARKS : " + marks); } } public class Constructor { public static void main(String[] args) { System. out .println("Name : Swathi.R"); System. out .println("Regno : 2413711058049"); // Default Constructor Student s1 = new Student(); s1.display(); // Parameterized Constructor Student s2 = new Student(103, "ANU", 89); s2.display(); // Copy Constructor Student s3 = new Student(s2); s3.display(); // Private Constructor Student. CreatePrivateStudent (); } } OU TPUT: Result The expected output of the program is achieved successfully. Ex.no:05 Aim: To Write a Program to implement accessing the modifiers in one package using Java Procedure: 1. Create the package Record and add the classes AccessDemo and TestDemo 2. Declare variables using public, protected, default, and private access modifiers in the AccessDemo class. 3. Create the showall () method to display the values of all the variables. 4. Create an object of the AccessDemo class in the TestDemo class and access the permitted variables and methods. 5. Run the program and observe how different access modifiers control the accessibility of class members. Code: 1.AccessDemo package Record; public class AccessDemo { public int publicVar = 10; protected int protectedVar = 20; int defaultVar = 30; private int privateVar = 40; public void showall() { System. out .println("Inside Access Demo"); System. out .println("Public : " + publicVar); System. out .println("Protected : " + protectedVar); System. out .println("Default : " + defaultVar); System. out .println("Private : " + privateVar); } } 2.TestDemo package Record; public class TestDemo { public static void main(String[] args) { System. out .println("Name : Swathi.R"); System. out .println("Reg.no : 2413711058049"); System. out .println(" \ nAccess Modifiers - Same Package"); AccessDemo obj = new AccessDemo(); obj.showall(); System. out .println(" \ nAccessing directly:"); System. out .println("Public : " + obj.publicVar); System. out .println("Protected : " + obj.protectedVar); System. out .println("Default : " + obj.defaultVar); // Private variable cannot be accessed outside its class. // System.out.println(obj.privateVar); } } OUTPUT: Result The expected output of the program is achieved successfully. Ex.no:06 Aim: To Write a Program to implement accessing the modifiers in different package using Java P rocedure: 1. Create a parent class with a method. 2. Create a child class that overrides the method. 3. Create an object of the child class. 4. Invoke the overridden method. 5. Display the output Code: package Record; public class AccessDemo { public int publicVar = 10; protected int protectedVar = 20; int defaultVar = 30; private int privateVar = 40; public void showall() { System. out .println("Inside Access Demo"); System. out .println("Public : " + publicVar); System. out .println("Protected : " + protectedVar); System. out .println("Default : " + defaultVar); System. out .println("Private : " + privateVar); } } package FinalRecord; import Record.AccessDemo; public class TestAccessDifferent extends AccessDemo { public static void main(String[] args) { System. out .println("Name : Swathi.R"); System. out .println("Reg.no : 2413711058049"); System. out .println(" \ nAccess Modifiers - Different Package"); TestAccessDifferent obj = new TestAccessDifferent(); System. out .println("Public : " + obj.publicVar); System. out .println("Protected : " + obj.protectedVar); // Not Accessible // System.out.println(obj.defaultVar); // System.out.println(obj.privateVar); } } output Result The expected output of the program is achieved successfully. Ex.no:07 Aim: To Write a Program to implement Scanner package using Java Procedure: 1. Create the package FinalRecord and add the class ScannerDemo 2. Import the java.util.Scanner package to accept input from the user. 3. Display the student's name and register number, and prompt the user to enter their age. 4. Read the age using the Scanner object and store it in an integer variable. 5. Run the program and display the entered age as the output. Code: package FinalRecord; import java.util.Scanner; public class ScannerDemo { public static void main(String[] args) { System. out .println("Name : Swathi.R"); System. out .println ("Reg.no : 2413711058049"); Scanner sc = new Scanner(System. in ); System. out .print("Enter age: "); int age = sc.nextInt(); System. out .println("You are " + age + " years old"); sc.close(); } } O utput Result The expected output of the program is achieved successfully. Ex.no:08 Aim: To Write a Program to implement Buffer Input using Java Procedure: 1. Create the package FinalRecord and add the class BufferInput 2. Import the java.io.* package to use BufferedReader for input. 3. Create a BufferedReader object to read input from the keyboard. 4. Read the user's name using the readLine() method and store it in a string variable. 5. Run the program and display the entered name as the output Code: package FinalRecord; import java.io.*; public class BufferInput { public static void main(String[] args) throws IOException { System. out .println("Name : Swathi.R"); System. out .println("Reg No : 2413711058049"); BufferedReader br = new BufferedReader(new InputStreamReader(System. in )); System. out .print("Enter your name: "); String name = br.readLine(); System. out .println("Hello " + name); } } output Result The expected output of the program is achieved successfully. Ex.no:09 Aim: To Write a Program to implement Exception Handling(throw throws) using Java Procedure: 1. Create the package FinalRecord and add the class ThrowThrows 2. Define the checkAge() method using the throws keyword and validate the age. 3. Use the throw statement to generate an exception if the age is less than 18. 4. Call the checkAge() method inside a try block and handle the exception using a catch block. 5. Run the program and display whether the person is eligible to vote or the exception message. Code: package FinalRecord; public class ThrowThrows { static void checkAge(int age) throws ArithmeticException { if (age < 18) { throw new ArithmeticException("You are " + age + " years old. Not eligible to vote"); } else { System. out .println("You are " + age + " years old. Eligible to Vote"); } } public static void main(String[] args) { System. out .println("Name : Swathi.R"); System. out .println ("Reg.no : 2413711058049"); try { checkAge (20); } catch (ArithmeticException e) { System. out .println("Exception caught: " + e.getMessage());