├── ADS ├── BST.md ├── Backtracking.md ├── Binary Tree.md ├── Day 1 │ ├── Notes.txt │ ├── Readme.md │ ├── Recursion.java │ ├── Recursion1.java │ └── Recursion2.java ├── Day 2 │ ├── Notes.txt │ ├── Readme.md │ ├── Recursion.java │ ├── Recursion1.java │ ├── Recursion2.java │ ├── Recursion3.java │ ├── Recursion4.java │ ├── Recursion5.java │ └── Recursion6.java ├── Day 3 │ ├── ArrayDemo.java │ ├── ArrayDuplicateDemo.java │ ├── ArrayDuplicateDemo1.java │ ├── ArrayDuplicateDemo2.java │ ├── BSearch.java │ ├── LSearch.java │ └── Readme.md ├── Day 4 │ ├── Feb25 Analysis of Algorithm_ Idea.pdf │ ├── Feb25 Examples.pdf │ ├── Feb25 More examples.pdf │ ├── PermutationDemo.java │ └── Readme.md ├── Day 5 │ ├── LinkedListDemo.java │ ├── LinkedListDemo1.java │ ├── LinkedListDemo2.java │ ├── LinkedListDemo3.java │ ├── Notes.txt │ └── Readme.md ├── Day 6 │ ├── Readme.md │ ├── StackDemo.java │ ├── StackDemo1.java │ ├── StackDemo2.java │ ├── StackDemo3.java │ └── StackDemo31.java ├── Day 7 │ ├── DLL.java │ ├── DLL1.java │ ├── DLL2.java │ ├── Notes.txt │ ├── Readme.md │ └── Tree -.pdf ├── Day 8 │ ├── BST.java │ ├── BT.java │ ├── Feb25 Binary Tree .pdf │ ├── Feb25 Tree Traversals .pdf │ ├── Readme.md │ └── Tree -.pdf ├── Day 9 │ ├── Bsort.java │ ├── Bsort1.java │ ├── Hsort.java │ ├── Msort.java │ └── Readme.md ├── Day10 │ ├── CQueue.java │ ├── Hashing FEB25.pdf │ ├── Msort.java │ ├── Qsort.java │ ├── Queue.java │ └── Readme.md ├── Day11 │ ├── Balance Tree FEB25.pdf │ ├── Graph Traversals FEB25.pdf │ ├── Graph_ Data structure FEB25.pdf │ └── Readme.md ├── Feb25Day1.pdf ├── Feb25Day10.pdf ├── Feb25Day11.pdf ├── Feb25Day2.pdf ├── Feb25Day3.pdf ├── Feb25Day4.pdf ├── Feb25Day5.pdf ├── Feb25Day6.pdf ├── Feb25Day7.pdf └── Feb25Day8.pdf ├── Additional Programs ├── 100 Java Interview Questions with Answers.pdf ├── Core java cheat sheet.pdf ├── Java Interview.pdf ├── Java Programming Cheatsheet.pdf ├── JavaString-cheatsheet.pdf ├── Readme.md └── String cheatsheet.pdf ├── Answer framing _ St.pdf ├── Books ├── Book Java complete reference.pdf ├── Essential Algorithms - A Practical Approach to Computer Algorithms.epub ├── Introduction to Algorithms - Third Edition.pdf ├── James Gosling, Bill Joy, Guy L. Steele Jr., Gilad Bracha, Alex Buckley - The Java Language Specification, Java SE 7 Edition (2013, Addison-Wesley Professional) - libgen.lc.epub ├── Object.Oriented.Analysis.and.Design.with.Applications.3rd.Edition.by.Booch.pdf └── Readme.md ├── ER Diagram Feb2025_st.pdf ├── OOPJ ├── Day 1 │ ├── Abc.java │ ├── Exampl2.java │ ├── Example2.java │ ├── Hello.java │ ├── Hello1.java │ ├── Hello2.java │ ├── Notes.txt │ └── Readme.md ├── Day 10 │ ├── DownCastingDemo2.java │ ├── GarbageCollectionDemo.java │ ├── GarbageCollectionDemo1.java │ ├── Notes.txt │ ├── Readme.md │ ├── StringDemo.java │ ├── StringDemo1.java │ ├── StringDemo2.java │ ├── StringDemo3.java │ └── UsernameValidator.java ├── Day 2 │ ├── DataDemo.java │ ├── DataDemo1.java │ ├── DataDemo2.java │ ├── Exampl2.java │ ├── Example2.java │ ├── IdentifierDemo.java │ ├── Narrowing.java │ ├── Notes.txt │ ├── Readme.md │ └── Widening.java ├── Day 3 │ ├── ArithmeticOperators.java │ ├── CmdArgs.java │ ├── CmdArgs1.java │ ├── ForDemo.java │ ├── ForDemo1.java │ ├── InputDemo.java │ ├── LogicalOperators.java │ ├── Notes.txt │ ├── OperatorDemo.java │ ├── OperatorDemo5.java │ ├── Readme.md │ ├── RelationalOperators.java │ ├── SwitchDemo.java │ ├── SwitchDemo1.java │ └── TernaryDemo.java ├── Day 4 │ ├── ArrayDemo1.java │ ├── ArrayDemo2.java │ ├── ArrayDemo3.java │ ├── ArrayDemo4.java │ ├── ArrayDemo5.java │ ├── ArrayDemo6.java │ ├── ArrayDemo7.java │ ├── EmployeeDemo.java │ ├── EmployeeDemo1.java │ ├── EmployeeDemo2.java │ ├── EmployeeDemo3.java │ ├── EmployeeDemo4.java │ ├── Notes.txt │ ├── Readme.md │ ├── StaticDemo.java │ ├── StaticDemo1.java │ ├── Test.java │ └── Test1.java ├── Day 5 │ ├── ArrayDemo10.java │ ├── ArrayDemo11.java │ ├── ArrayDemo12.java │ ├── ArrayDemo13.java │ ├── ArrayDemo6.java │ ├── ArrayDemo7.java │ ├── ArrayDemo8.java │ ├── ArrayDemo9.java │ ├── EmployeeDemo3.java │ ├── EmployeeDemo4.java │ ├── EmployeeDemo5.java │ ├── EmplyeeDemo5.java │ └── Readme.md ├── Day 6 │ ├── EmployeeDemo5.java │ ├── EmployeeDemo6.java │ ├── EmployeeDemo7.java │ ├── EmployeeDemo8.java │ ├── EmployeeDemo9.java │ ├── ExampleDemo.java │ ├── ExampleDemo1.java │ ├── ExampleDemo2.java │ ├── ExampleDemo3.java │ ├── ExampleDemo4.java │ ├── Notes.txt │ └── Readme.md ├── Day 7 │ ├── AbstractionDemo.java │ ├── AggregationDemo.java │ ├── AssociationDemo.java │ ├── EncapsulationDemo.java │ ├── HierarchicallInheritanceDemo.java │ ├── InterfaceDemo.java │ ├── MultilevelInheritanceDemo.java │ ├── MultipleInheritanceDemo.java │ ├── MultipleInheritanceDemo1.java │ ├── MultipleInheritanceDemo2.java │ ├── MultipleInheritanceDemo3.java │ ├── MultipleInheritanceDemo4.java │ ├── Notes.txt │ ├── Readme.md │ └── SingleInheritanceDemo.java ├── Day 8 │ ├── AggregationDemo.java │ ├── CompositionDemo.java │ ├── InheritanceDemo.java │ ├── InheritanceDemo1.java │ ├── MethodOverloading1.java │ ├── MethodOverloading2.java │ ├── MethodOverloading3.java │ ├── MethodOverloading4.java │ ├── Notes.txt │ ├── OverridingDemo.java │ ├── OverridingDemo1.java │ ├── OverridingDemo2.java │ ├── OverridingDemo3.java │ └── Readme.md ├── Day 9 │ ├── DownCastingDemo.java │ ├── DownCastingDemo1.java │ ├── DownCastingDemo2.java │ ├── FinalDemo.java │ ├── FinalDemo1.java │ ├── FinalDemo2.java │ ├── FinalDemo3.java │ ├── FinalDemo4.java │ ├── FinalDemo5.java │ ├── FinalDemo6.java │ ├── FinalDemo7.java │ ├── FinalDemo8.java │ ├── InstanceOpDemo.java │ ├── Notes.txt │ ├── OverridingDemo4.java │ ├── OverridingDemo5.java │ ├── OverridingDemo6.java │ ├── OverridingDemo7.java │ ├── OverridingDemo8.java │ ├── OverridingDemo9.java │ ├── Readme.md │ └── UpcastingDemo.java ├── Day11 │ ├── ExceptionDemo.java │ ├── ExceptionDemo1.java │ ├── ExceptionDemo2.java │ ├── ExceptionDemo3.java │ ├── ExceptionDemo4.java │ ├── ExceptionDemo5.java │ ├── GetClassDemo.java │ ├── HashCodeDemo.java │ ├── ObjectDemo1.java │ ├── Readme.md │ ├── ToStringDemo.java │ ├── WrapperDemo.java │ ├── WrapperDemo1.java │ └── WrapperDemo2.java ├── Day12 │ ├── ChDemo.java │ ├── ChDemo1.java │ ├── ChDemo2.java │ ├── ChDemo3.java │ ├── ChDemo4.java │ ├── ChDemo5.java │ ├── ChDemo6.java │ ├── ChDemo7.java │ ├── ChDemo8.java │ ├── ChDemo9.java │ ├── ExceptionDemo.java │ ├── ExceptionDemo1.java │ ├── ExceptionDemo2.java │ ├── ExceptionDemo3.java │ ├── ExceptionDemo4.java │ ├── ExceptionDemo5.java │ ├── ExceptionDemo6.java │ ├── ExceptionDemo7.java │ ├── ExceptionDemo8.java │ ├── ExceptionDemo9.java │ ├── Finally.java │ ├── Notes.txt │ ├── Readme.md │ ├── ThrowDemo.java │ ├── ThrowDemo1.java │ └── UnCheckedDemo.java ├── Day13 │ ├── Employee.java │ ├── PrivateDemo.java │ ├── Readme.md │ ├── Singleton.java │ └── com.zip ├── Day14 │ ├── ArrayListDemo.java │ ├── ArrayListDemo1.java │ ├── CollectionDemo.java │ ├── CollectionDemo1.java │ ├── CollectionDemo2.java │ ├── CollectionDemo3.java │ ├── HashMapDemo.java │ ├── HashMapDemo2.java │ ├── HashTableDemo.java │ ├── HashsetDemo.java │ ├── LinkedHashMapDemo3.java │ ├── LinkedHashsetDemo2.java │ ├── LinkedListDemo.java │ ├── Notes.txt │ ├── Readme.md │ ├── StackDemo.java │ ├── TreeMapDemo.java │ ├── TreeSetDemo.java │ └── VectorDemo.java ├── Day15 │ ├── AnonymousClassDemo.java │ ├── GenericDemo.java │ ├── GenericDemo1.java │ ├── GenericDemo2.java │ ├── InnerClassDemo.java │ ├── InnerClassDemo1.java │ ├── LambdaEx1.java │ ├── LocalInnerClassDemo.java │ ├── Readme.md │ ├── ReflectionDemo.java │ └── StaticInnerClassDemo.java ├── Day16 │ ├── Notes.txt │ ├── Readme.md │ ├── ThreadDemo1.java │ ├── ThreadDemo10.java │ ├── ThreadDemo2.java │ ├── ThreadDemo3.java │ ├── ThreadDemo4.java │ ├── ThreadDemo5.java │ ├── ThreadDemo6.java │ ├── ThreadDemo7.java │ ├── ThreadDemo8.java │ └── ThreadDemo9.java ├── Feb25 Day1.pdf ├── Feb25 Day10.pdf ├── Feb25 Day11.pdf ├── Feb25 Day13.pdf ├── Feb25 Day14.pdf ├── Feb25 Day15.pdf ├── Feb25 Day2.pdf ├── Feb25 Day3.pdf ├── Feb25 Day4.pdf ├── Feb25 Day5.pdf ├── Feb25 Day6.pdf ├── Feb25 Day7.pdf ├── Feb25 Day8.pdf └── Feb25 Day9.pdf └── README.md /ADS/Day 1/Readme.md: -------------------------------------------------------------------------------- 1 | # Homework: Solve the following Interview questions 2 | ### Algorithms 3 | 1.What is an algorithm? 4 | 2.Why is algorithm analysis important? 5 | 3.What are the key criteria for analyzing an algorithm? 6 | 4.What are the different approaches to developing algorithms? 7 | 5.What are the characteristics of a good algorithm? 8 | 9 | ### Data Structures 10 | 1.What are different types of data structures? 11 | 2.What is the difference between an array and a linked list? 12 | 3.How does a stack work? Provide an realtime example. 13 | 4.What are the operations on a queue? Explain different types of queues. 14 | 5.What is a graph? Explain different types of graphs. 15 | 16 | ### Recursion 17 | 1.What is recursion, and how does it work? 18 | 2.Why is recursion used in programming? 19 | 3.What are the advantages and disadvantages of recursion? 20 | 4.Differentiate between recursion and iteration. 21 | 5.What are base cases in recursion, and why are they important? 22 | 6.Which problems can be solved using recursion? 23 | -------------------------------------------------------------------------------- /ADS/Day 1/Recursion.java: -------------------------------------------------------------------------------- 1 | 2 | class Recursion { 3 | static void show(){ 4 | System.out.println("Hi Girls....!!!"); 5 | show(); 6 | } 7 | public static void main(String[] args) { 8 | show(); 9 | 10 | } 11 | } -------------------------------------------------------------------------------- /ADS/Day 1/Recursion1.java: -------------------------------------------------------------------------------- 1 | //Recursion infinite loop 2 | class Recursion1 { 3 | static int i=0; 4 | static void show(){ 5 | i++; 6 | if(i<=5) 7 | { 8 | System.out.println("Hi Girls!!!"); 9 | show(); 10 | 11 | } 12 | 13 | } 14 | public static void main(String[] args) { 15 | show(); 16 | 17 | } 18 | } -------------------------------------------------------------------------------- /ADS/Day 1/Recursion2.java: -------------------------------------------------------------------------------- 1 | //Recursion infinite loop 2 | class Recursion2 { 3 | 4 | static int show(int n){ 5 | 6 | if(n==4)//base condition 7 | { 8 | return n; 9 | } 10 | else{ 11 | return 2*show(n+1); 12 | 13 | } 14 | 15 | } 16 | public static void main(String[] args) { 17 | 18 | System.out.println(show(2)); 19 | } 20 | } -------------------------------------------------------------------------------- /ADS/Day 2/Notes.txt: -------------------------------------------------------------------------------- 1 | ----------------------------------------- 2 | Day 2: Algorithms and Data Structures 3 | Date : 26-March-2025 4 | ----------------------------------------- 5 | 6 | Topics: 7 | - Recursion 8 | 9 | Recursion : 10 | ------------ 11 | 1 Terminates when the base case becomes true. 12 | 2 Logic is built by solving smaller subproblems. 13 | 3 Each call uses extra stack memory. 14 | 4 Results in shorter, cleaner code. 15 | 16 | Iteration: 17 | ---------- 18 | 1 Terminates when the loop condition becomes false. 19 | 2 Logic is built by repeating operations over data. 20 | 3 No additional memory usage for each step. 21 | 4 Often leads to longer, more verbose code. 22 | 23 | 24 | 25 | 2 ways to implement the program: 26 | ---------------------------------- 27 | 1.Iterative 28 | 2.Recursive 29 | 30 | class A{ 31 | abc(){ 32 | 33 | abc(); 34 | } 35 | 36 | main(){ 37 | 38 | abc(); 39 | } 40 | } 41 | 42 | Recursion work: 43 | -------------- 44 | 45 | Base condition: 46 | -The base condition provides the termination condition for the recursion 47 | 48 | Recursive case: 49 | -The recursive case moves towards the base condition by reducing the problem size at each step. 50 | 51 | Recursion Type: 52 | --------------- 53 | 1.Tail recursion: 54 | ----------------- 55 | -when the call is given to the recursive method and it is the last statement executed insidethe recursive method is called as tail recursion. 56 | 57 | tail(3); 58 | void tail(int n){ 59 | if(n == 0) 60 | return n; 61 | else 62 | SOP("Tail"); 63 | tail(n-1);//Recursive call:last 64 | } 65 | 66 | 2.Head recursion: 67 | ------------------- 68 | -when the call is given to the recursive method and it is the first statement executed insidethe recursive method is called as head recursion. 69 | 70 | head(3); 71 | 72 | void head(int n){ 73 | if(n == 1) 74 | return n; 75 | else{ 76 | head(n-1);//Recursive call: first 77 | SOP("Head"); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /ADS/Day 2/Readme.md: -------------------------------------------------------------------------------- 1 | ### Homework: 2 | ![image](https://github.com/user-attachments/assets/aa5cffc5-5b0f-4611-8366-3951c3bbf67a) 3 | 4 | ![image](https://github.com/user-attachments/assets/4f144da1-e996-4dab-bb6f-97ea331f91ad) 5 | 6 | ![image](https://github.com/user-attachments/assets/195d6f21-00af-400a-8a2d-28528ab2b35a) 7 | 8 | ![image](https://github.com/user-attachments/assets/dab5fefe-9518-4a49-b384-909a5745075a) 9 | 10 | 11 | ![WhatsApp Image 2025-03-26 at 19 34 40_b597783f](https://github.com/user-attachments/assets/cdc8b706-5a27-4adb-864f-d73f5a2ae334) 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /ADS/Day 2/Recursion.java: -------------------------------------------------------------------------------- 1 | 2 | class Recursion { 3 | static void show(){ 4 | System.out.println("Hi Girls....!!!"); 5 | show(); 6 | } 7 | public static void main(String[] args) { 8 | show(); 9 | 10 | } 11 | } -------------------------------------------------------------------------------- /ADS/Day 2/Recursion1.java: -------------------------------------------------------------------------------- 1 | //Recursion infinite loop 2 | class Recursion1 { 3 | static int i=0; 4 | static void show(){ 5 | i++; 6 | if(i<=5) 7 | { 8 | System.out.println("Hi Girls!!!"); 9 | show(); 10 | 11 | } 12 | 13 | } 14 | public static void main(String[] args) { 15 | show(); 16 | 17 | } 18 | } -------------------------------------------------------------------------------- /ADS/Day 2/Recursion2.java: -------------------------------------------------------------------------------- 1 | //Recursion infinite loop 2 | class Recursion2 { 3 | 4 | static int show(int n){ 5 | 6 | if(n==4)//base condition 7 | { 8 | return n; 9 | } 10 | else{ 11 | return 2*show(n+1); 12 | 13 | } 14 | 15 | } 16 | public static void main(String[] args) { 17 | 18 | System.out.println(show(2)); 19 | } 20 | } -------------------------------------------------------------------------------- /ADS/Day 2/Recursion3.java: -------------------------------------------------------------------------------- 1 | //Fibnacci series: 2 | 3 | //f1=0, f2=1 4 | 5 | //series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, ... 6 | 7 | class Recursion4 { 8 | 9 | static int fibonacci(int n){ 10 | if(n <= 1){ 11 | return n; 12 | } 13 | return fibonacci(n-1) + fibonacci(n-2); 14 | } 15 | 16 | public static void main(String[] args) { 17 | int number = 10; 18 | for(int i=1;i<= number;i++){ 19 | 20 | System.out.print(fibonacci(i)+" "); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /ADS/Day 2/Recursion4.java: -------------------------------------------------------------------------------- 1 | //Fibnacci series: 2 | 3 | //f1=0, f2=1 4 | 5 | //series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, ... 6 | 7 | class Recursion4 { 8 | 9 | static int fibonacci(int n){ 10 | if(n <= 1){ 11 | return n; 12 | } 13 | return fibonacci(n-1) + fibonacci(n-2); 14 | } 15 | 16 | public static void main(String[] args) { 17 | int number = 50; 18 | for(int i=0;i<= number;i++){ 19 | 20 | System.out.print(fibonacci(i)+" "); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /ADS/Day 2/Recursion5.java: -------------------------------------------------------------------------------- 1 | 2 | class Recursion5 { 3 | 4 | static int sum(int n){ 5 | if(n > 0) 6 | return n+sum(n-1); 7 | else 8 | return 0; 9 | } 10 | 11 | public static void main(String[] args) { 12 | 13 | 14 | 15 | System.out.print("Sum of nos: "+sum(10)); 16 | } 17 | } -------------------------------------------------------------------------------- /ADS/Day 2/Recursion6.java: -------------------------------------------------------------------------------- 1 | 2 | class Recursion6 { 3 | 4 | static void toh(int n, char s, char inter,char d){ 5 | if(n == 1){ 6 | System.out.println("Disk from "+s+" to "+d); 7 | } 8 | else{ 9 | toh(n-1,s,d,inter); 10 | System.out.println("Disk from "+s+" to "+d); 11 | toh(n-1,inter,s,d); 12 | } 13 | 14 | } 15 | 16 | public static void main(String[] args) { 17 | 18 | 19 | int n=3; 20 | toh(n,'A','B','C'); 21 | } 22 | } -------------------------------------------------------------------------------- /ADS/Day 3/ArrayDemo.java: -------------------------------------------------------------------------------- 1 | 2 | class ArrayDemo { 3 | static int a1[] = new int[15]; 4 | static int n=0; 5 | 6 | //display 7 | static void display(){ 8 | for(int i=0;i s1 = new HashSet<>(); 19 | for(int x : arr){ 20 | if(!s1.add(x)){ 21 | System.out.println(x); 22 | } 23 | } 24 | 25 | 26 | 27 | 28 | } 29 | } -------------------------------------------------------------------------------- /ADS/Day 3/BSearch.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | class BSearch{ 4 | 5 | static int bsearch(int arr[],int x,int l,int h){ 6 | 7 | if(h >= l){ 8 | 9 | int mid = l+(h-l)/2; 10 | if(arr[mid] == x) 11 | return mid; 12 | if(arr[mid] > x) 13 | return bsearch(arr,x,l,mid-1); 14 | 15 | return bsearch(arr, x, mid+1,h); 16 | } 17 | return -1; 18 | 19 | 20 | } 21 | 22 | public static void main(String[] args) { 23 | 24 | int arr[] = {10,20,30,40,50}; 25 | int n = arr.length; 26 | 27 | int key =40; 28 | 29 | 30 | int result = bsearch(arr, key,0,n-1); 31 | if(result == -1) 32 | System.out.println("Element not found!"); 33 | else 34 | System.out.println("Element found!"); 35 | 36 | 37 | 38 | } 39 | } -------------------------------------------------------------------------------- /ADS/Day 3/LSearch.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | class LSearch{ 4 | 5 | static int search(int arr[],int x){ 6 | int n = arr.length; 7 | for(int i=0;i"); 23 | n=n.next; 24 | } 25 | } 26 | 27 | 28 | 29 | void insert(int new_data){ 30 | Node new_node = new Node(new_data); 31 | new_node.next = start; 32 | start = new_node; 33 | } 34 | 35 | void inserAfter(Node prev_node, int new_data){ 36 | 37 | Node new_node = new Node(new_data); 38 | new_node.next = prev_node.next; 39 | prev_node.next = new_node; 40 | 41 | } 42 | 43 | void append(int new_data){ 44 | 45 | Node new_node = new Node(new_data); 46 | if(start == null) 47 | { 48 | start = new Node(new_data);// first node in the list 49 | return; 50 | } 51 | Node n = start; 52 | while(n.next != null) 53 | n=n.next; 54 | n.next = new_node; 55 | return; 56 | 57 | } 58 | 59 | public void reverseLL(){ 60 | 61 | Node prev = null; 62 | Node current = start; 63 | Node next = null; 64 | while( current != null) 65 | { 66 | next = current.next; 67 | current.next = prev; 68 | prev = current; 69 | current = next; 70 | 71 | } 72 | start = prev; 73 | //return prev; 74 | } 75 | public static void main(String[] args) { 76 | LinkedListDemo2 l1 = new LinkedListDemo2(); 77 | l1.insert(30); 78 | l1.insert(20); 79 | l1.insert(10); 80 | l1.insert(5); 81 | l1.insert(100); 82 | l1.display(); 83 | System.out.println(" \n"); 84 | l1.inserAfter(l1.start.next, 150); 85 | l1.display(); 86 | System.out.println(" \n"); 87 | l1.append(250); 88 | l1.display(); 89 | System.out.println(" \n"); 90 | l1.reverseLL(); 91 | l1.display(); 92 | 93 | 94 | 95 | 96 | } 97 | } -------------------------------------------------------------------------------- /ADS/Day 5/LinkedListDemo3.java: -------------------------------------------------------------------------------- 1 | 2 | class LinkedListDemo3{ 3 | 4 | Node start;//start 5 | 6 | static class Node{ 7 | int data;//data 8 | Node next;//next link 9 | 10 | Node(int d){ 11 | data = d; 12 | next = null; 13 | } 14 | 15 | } 16 | 17 | void display(){ 18 | 19 | Node n = start; 20 | while( n!= null) 21 | { 22 | System.out.print(n.data+"--->"); 23 | n=n.next; 24 | } 25 | } 26 | 27 | 28 | 29 | void insert(int new_data){ 30 | Node new_node = new Node(new_data); 31 | new_node.next = start; 32 | start = new_node; 33 | } 34 | 35 | void inserAfter(Node prev_node, int new_data){ 36 | 37 | Node new_node = new Node(new_data); 38 | new_node.next = prev_node.next; 39 | prev_node.next = new_node; 40 | 41 | } 42 | 43 | void append(int new_data){ 44 | 45 | Node new_node = new Node(new_data); 46 | if(start == null) 47 | { 48 | start = new Node(new_data);// first node in the list 49 | return; 50 | } 51 | Node n = start; 52 | while(n.next != null) 53 | n=n.next; 54 | n.next = new_node; 55 | return; 56 | 57 | } 58 | 59 | public void reverseLL(){ 60 | 61 | Node prev = null; 62 | Node current = start; 63 | Node next = null; 64 | while( current != null) 65 | { 66 | next = current.next; 67 | current.next = prev; 68 | prev = current; 69 | current = next; 70 | 71 | } 72 | start = prev; 73 | //return prev; 74 | } 75 | 76 | void deleteNode(int key)// 77 | { 78 | Node temp = head, prev = null; 79 | //Deletion at the begining 80 | if(temp != null && temp.data == key) 81 | { 82 | head = temp.next;//head is changed 83 | return; 84 | 85 | } 86 | //Deletion in between 87 | while(temp != null && temp.data !=key) 88 | { 89 | prev = temp; 90 | temp = temp.next; 91 | } 92 | //Deletion of last node 93 | if (temp == null) 94 | return; 95 | prev.next = temp.next; 96 | 97 | } 98 | public static void main(String[] args) { 99 | LinkedListDemo3 l1 = new LinkedListDemo3(); 100 | l1.insert(30); 101 | l1.insert(20); 102 | l1.insert(10); 103 | l1.insert(5); 104 | l1.insert(100); 105 | l1.display(); 106 | System.out.println(" \n"); 107 | l1.inserAfter(l1.start.next, 150); 108 | l1.display(); 109 | System.out.println(" \n"); 110 | l1.append(250); 111 | l1.display(); 112 | System.out.println(" \n"); 113 | l1.reverseLL(); 114 | l1.display(); 115 | System.out.println(" \n"); 116 | l1.deleteNode(30); 117 | l1.display(); 118 | 119 | 120 | 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /ADS/Day 5/Readme.md: -------------------------------------------------------------------------------- 1 | # Home work: 2 | 3 | 1. Create a linked list with insert, delete, traverse, and search functions. 4 | 2. Insert a node at the beginning of a linked list. 5 | 3. Insert a node at the end of a linked list. 6 | 4. Insert a node at a given position in a linked list. 7 | 5. Delete a node by value from a linked list. 8 | 6. Delete a node at a given position in a linked list. 9 | 7. Search for an element in a linked list. 10 | 8. Find the length of a linked list. 11 | 9. Check if a linked list is empty. 12 | 10. Print all elements of a linked list. 13 | 11. Reverse a linked list. 14 | 12. Find the middle node of a linked list. 15 | 13. Detect if a linked list has a cycle. 16 | 14. Merge two sorted linked lists. 17 | 15. Remove duplicates from a sorted linked list. 18 | -------------------------------------------------------------------------------- /ADS/Day 6/Readme.md: -------------------------------------------------------------------------------- 1 | ### Homework 2 | 3 | ![image](https://github.com/user-attachments/assets/0f0ffab4-b3b8-42fb-a11f-f530078427b0) 4 | 5 | -------------------------------------------------------------------------------- /ADS/Day 6/StackDemo.java: -------------------------------------------------------------------------------- 1 | 2 | class Stack{ 3 | static final int MAX = 7; 4 | int top; 5 | int a[] = new int[MAX]; 6 | 7 | Stack(){ 8 | top = -1; 9 | } 10 | 11 | boolean isEmpty(){ 12 | return top < 0; 13 | } 14 | 15 | boolean isFull(){ 16 | return top > MAX-1; 17 | } 18 | 19 | boolean push(int x){ 20 | if(top >= (MAX-1)){ 21 | System.out.println("Stack Overflow!!!"); 22 | return false; 23 | 24 | } 25 | else{ 26 | a[++top] = x; 27 | System.out.println(x+"Element pushed!"); 28 | return true; 29 | 30 | } 31 | 32 | } 33 | 34 | int pop(){ 35 | if(top < 0){ 36 | System.out.println("Stack underflow"); 37 | return 0; 38 | } 39 | else{ 40 | 41 | int x = a[top--]; 42 | return x; 43 | 44 | } 45 | 46 | } 47 | 48 | int peek(){ 49 | if(top < 0){ 50 | System.out.println("Stack underflow"); 51 | return 0; 52 | } 53 | else{ 54 | int x = a[top]; 55 | return x; 56 | } 57 | } 58 | 59 | 60 | } 61 | 62 | class StackDemo{ 63 | public static void main(String[] args) { 64 | 65 | Stack s = new Stack(); 66 | s.push(40); 67 | s.push(10); 68 | s.push(80); 69 | System.out.println(s.peek()); 70 | System.out.println(s.pop()); 71 | System.out.println(s.peek()); 72 | 73 | } 74 | } -------------------------------------------------------------------------------- /ADS/Day 6/StackDemo2.java: -------------------------------------------------------------------------------- 1 | class Node{ 2 | int data; 3 | Node next; 4 | Node(int d) 5 | { 6 | data = d; 7 | next = null; 8 | } 9 | } 10 | 11 | class StackDemo3{ 12 | Node head; 13 | 14 | StackDemo3() 15 | { 16 | this.head = null; 17 | } 18 | 19 | boolean IsEmpty(){ 20 | return head == null; 21 | } 22 | 23 | void push(int new_data){ 24 | Node new_node = new Node(new_data); 25 | new_node.next = head; 26 | head = new_node; 27 | 28 | } 29 | 30 | void pop(){ 31 | 32 | if(IsEmpty()){ 33 | System.out.println("Stack Underflow!!!"); 34 | return; 35 | } 36 | Node temp = head; 37 | head = head.next; 38 | temp.next = null; 39 | temp = null; 40 | 41 | 42 | } 43 | 44 | int peek(){ 45 | if(!IsEmpty()) 46 | return head.data; 47 | else{ 48 | System.out.println("Stack Underflow!!!"); 49 | return -1; 50 | } 51 | } 52 | 53 | public static void main(String[] args) { 54 | 55 | StackDemo3 s1 = new StackDemo3(); 56 | 57 | s1.push(80); 58 | s1.push(20); 59 | s1.push(40); 60 | System.out.println(s1.peek()); 61 | s1.pop(); 62 | System.out.println(s1.peek()); 63 | 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /ADS/Day 6/StackDemo31.java: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ADS/Day 7/DLL.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | class DLL{ 4 | Node head; 5 | 6 | static class Node{ 7 | int data; 8 | Node prev; 9 | Node next; 10 | 11 | Node(int d){ 12 | data = d; 13 | prev = null; 14 | next = null; 15 | } 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /ADS/Day 7/DLL1.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | class DLL{ 4 | Node head; 5 | 6 | static class Node{ 7 | int data; 8 | Node prev; 9 | Node next; 10 | 11 | Node(int d){ 12 | data = d; 13 | prev = null; 14 | next = null; 15 | } 16 | } 17 | 18 | 19 | void insert(int new_data){ 20 | Node new_node = new Node(new_data); 21 | new_node.next = head; 22 | new_node.prev = null; 23 | if(head != null) 24 | head.prev = new_node; 25 | 26 | head = new_node; 27 | } 28 | 29 | void display(Node n){ 30 | Node p = null; 31 | 32 | System.out.println("Forward traversal:"); 33 | while( n != null) 34 | { 35 | System.out.print(n.data+"-->"); 36 | p=n; 37 | n=n.next; 38 | } 39 | System.out.println(); 40 | System.out.println("Backward traversal:"); 41 | while( p != null) 42 | { 43 | System.out.print(p.data+"-->"); 44 | p = p.prev; 45 | } 46 | 47 | } 48 | 49 | void insertAfter(Node prev, int new_data){ 50 | 51 | if(prev == null) 52 | { 53 | return; 54 | } 55 | Node new_node = new Node(new_data); 56 | new_node.next = prev.next;//Important 57 | prev.next = new_node; 58 | new_node.prev = prev; 59 | new_node.next.prev = new_node; 60 | 61 | 62 | } 63 | 64 | void append(int new_data){ 65 | 66 | 67 | Node new_node = new Node(new_data); 68 | Node n = head; 69 | new_node.next = null; 70 | 71 | //Empty DLL next 72 | if(head == null){ 73 | new_node.prev = null; 74 | head = new_node; 75 | return; 76 | } 77 | while(n.next != null){ 78 | n=n.next; 79 | } 80 | n.next = new_node; 81 | new_node.prev = n; 82 | 83 | 84 | 85 | } 86 | 87 | public static void main(String[] args) { 88 | 89 | DLL d1 = new DLL(); 90 | d1.head=null; 91 | //d1.display(d1.head.next); 92 | System.out.println(); 93 | d1.insert(30); 94 | d1.insert(20); 95 | d1.insert(10); 96 | //d1.display(d1.head.next); 97 | System.out.println(); 98 | d1.insert(5); 99 | //d1.display(d1.head); 100 | System.out.println(); 101 | d1.insertAfter(d1.head.next, 17); 102 | //d1.display(d1.head); 103 | 104 | d1.append(50); 105 | d1.display(d1.head); 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /ADS/Day 7/DLL2.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | class DLL{ 4 | Node head; 5 | 6 | static class Node{ 7 | int data; 8 | Node prev; 9 | Node next; 10 | 11 | Node(int d){ 12 | data = d; 13 | prev = null; 14 | next = null; 15 | } 16 | } 17 | 18 | 19 | void insert(int new_data){ 20 | Node new_node = new Node(new_data); 21 | new_node.next = head; 22 | new_node.prev = null; 23 | if(head != null) 24 | head.prev = new_node; 25 | 26 | head = new_node; 27 | } 28 | 29 | void display(Node n){ 30 | Node p = null; 31 | 32 | System.out.println("Forward traversal:"); 33 | while( n != null) 34 | { 35 | System.out.print(n.data+"-->"); 36 | p=n; 37 | n=n.next; 38 | } 39 | System.out.println(); 40 | System.out.println("Backward traversal:"); 41 | while( p != null) 42 | { 43 | System.out.print(p.data+"-->"); 44 | p = p.prev; 45 | } 46 | 47 | } 48 | 49 | void insertAfter(Node prev, int new_data){ 50 | 51 | if(prev == null) 52 | { 53 | return; 54 | } 55 | Node new_node = new Node(new_data); 56 | new_node.next = prev.next;//Important 57 | prev.next = new_node; 58 | new_node.prev = prev; 59 | new_node.next.prev = new_node; 60 | 61 | 62 | } 63 | 64 | void append(int new_data){ 65 | 66 | 67 | Node new_node = new Node(new_data); 68 | Node n = head; 69 | new_node.next = null; 70 | 71 | //Empty DLL next 72 | if(head == null){ 73 | new_node.prev = null; 74 | head = new_node; 75 | return; 76 | } 77 | while(n.next != null){ 78 | n=n.next; 79 | } 80 | n.next = new_node; 81 | new_node.prev = n; 82 | 83 | 84 | 85 | } 86 | void deleteNode(Node del) 87 | { 88 | //case 1 :Empty DLL & del node empty 89 | if(head == null || del == null) 90 | return; 91 | 92 | //case 2 : First node/Head to be deleted 93 | if(head == del){ 94 | head = del.next; 95 | head.prev = null; 96 | } 97 | 98 | //Case3: In between node del 99 | if(del.next != null) 100 | del.next.prev = del.prev; 101 | 102 | //Case3: In between node del 103 | //Case 4: Last node delete 104 | if(del.prev != null) 105 | del.prev.next = del.next; 106 | 107 | return; 108 | 109 | 110 | 111 | 112 | 113 | } 114 | public static void main(String[] args) { 115 | 116 | DLL d1 = new DLL(); 117 | d1.head=null; 118 | //d1.display(d1.head.next); 119 | System.out.println(); 120 | d1.insert(30); 121 | d1.insert(20); 122 | d1.insert(10); 123 | //d1.display(d1.head.next); 124 | System.out.println(); 125 | d1.insert(5); 126 | //d1.display(d1.head); 127 | System.out.println(); 128 | d1.insertAfter(d1.head.next, 17); 129 | //d1.display(d1.head); 130 | 131 | d1.append(50); 132 | d1.display(d1.head); 133 | System.out.println(); 134 | d1.deleteNode(d1.head); 135 | d1.display(d1.head); 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /ADS/Day 7/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ADS/Day 7/Tree -.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/ADS/Day 7/Tree -.pdf -------------------------------------------------------------------------------- /ADS/Day 8/BT.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | class BT{ 4 | Node root; 5 | 6 | static class Node{ 7 | int data; 8 | Node left, right; 9 | 10 | Node(int d){ 11 | data = d; 12 | left=right=null; 13 | } 14 | } 15 | 16 | BT(){ 17 | root = null; //Empty tree 18 | } 19 | 20 | BT(int d){ 21 | root = new Node(d); 22 | } 23 | 24 | //Preorder: Root,LC,RC 25 | void preorder(Node n){ 26 | if( n == null) 27 | return; 28 | System.out.print(n.data + " "); 29 | preorder(n.left); 30 | preorder(n.right); 31 | 32 | } 33 | 34 | //Inorder: LC,Root,RC 35 | void inorder(Node n){ 36 | if( n == null) 37 | return; 38 | inorder(n.left); 39 | System.out.print(n.data + " "); 40 | inorder(n.right); 41 | 42 | } 43 | 44 | //Postorder: LC,RC,Root 45 | void postorder(Node n){ 46 | if( n == null) 47 | return; 48 | postorder(n.left); 49 | postorder(n.right); 50 | System.out.print(n.data + " "); 51 | 52 | } 53 | 54 | public static void main(String[] args) { 55 | 56 | BT t1 = new BT(); 57 | t1.root = new Node(20); 58 | t1.root.left = new Node(34); 59 | t1.root.right = new Node(56); 60 | t1.root.left.left = new Node(15); 61 | t1.root.left.right = new Node(34); 62 | t1.root.right.left = new Node(23); 63 | t1.root.right.right = new Node(34); 64 | 65 | 66 | System.out.println("----Preorder--------"); 67 | t1.preorder(t1.root); 68 | System.out.println("----Inorder--------"); 69 | t1.inorder(t1.root); 70 | System.out.println("-----Postorder-------"); 71 | t1.postorder(t1.root); 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | } 81 | } -------------------------------------------------------------------------------- /ADS/Day 8/Feb25 Binary Tree .pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/ADS/Day 8/Feb25 Binary Tree .pdf -------------------------------------------------------------------------------- /ADS/Day 8/Feb25 Tree Traversals .pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/ADS/Day 8/Feb25 Tree Traversals .pdf -------------------------------------------------------------------------------- /ADS/Day 8/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ADS/Day 8/Tree -.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/ADS/Day 8/Tree -.pdf -------------------------------------------------------------------------------- /ADS/Day 9/Bsort.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | class Bsort{ 4 | void bsort(int arr[]) 5 | { 6 | int n = arr.length; 7 | for(int i =0 ;i arr[j+1]) 10 | { 11 | int temp = arr[j]; 12 | arr[j] = arr[j+1]; 13 | arr[j+1] = temp; 14 | } 15 | } 16 | 17 | 18 | 19 | } 20 | } 21 | 22 | void ssort(int arr[]){ 23 | int n = arr.length; 24 | for(int i=0;i=0 && arr[j] > key){ 45 | arr[j+1] = arr[j]; 46 | j=j-1; 47 | } 48 | arr[j+1] = key; 49 | } 50 | 51 | } 52 | 53 | 54 | void display(int arr[]){ 55 | int n = arr.length; 56 | for(int i=0;i arr[j+1]) 10 | { 11 | int temp = arr[j]; 12 | arr[j] = arr[j+1]; 13 | arr[j+1] = temp; 14 | } 15 | } 16 | 17 | 18 | 19 | } 20 | } 21 | 22 | void display(int arr[]){ 23 | int n = arr.length; 24 | for(int i=0;i arr[largest]) 14 | largest = l; 15 | //RC = largest 16 | if(r < n && arr[r] > arr[largest]) 17 | largest = r; 18 | 19 | //swap 20 | if( largest != i){ 21 | int temp = arr[i]; 22 | arr[i] = arr[largest]; 23 | arr[largest] = temp; 24 | 25 | heapify(arr, n, largest); 26 | } 27 | } 28 | 29 | 30 | void heapsort(int arr[]){ 31 | int n =arr.length; 32 | 33 | for(int i=n/2-1;i>=0;i--){ 34 | heapify(arr,n,i); 35 | } 36 | 37 | for(int i=n-1;i>0;i--){ 38 | int temp = arr[0]; 39 | arr[0] = arr[i];//root=last node 40 | arr[i] = temp; 41 | 42 | heapify(arr,i,0); 43 | } 44 | } 45 | 46 | 47 | 48 | 49 | 50 | void display(int arr[]){ 51 | int n = arr.length; 52 | for(int i=0;i= rear) 55 | { 56 | front = -1; 57 | rear = -1; 58 | } 59 | else{ 60 | front++; 61 | } 62 | System.out.println("Deleted "+x); 63 | return x; 64 | 65 | } 66 | 67 | } 68 | 69 | void display() 70 | { 71 | if(isEmpty()) 72 | System.out.println("Queue is Empty!"); 73 | else 74 | for(int i=front; i<=rear ; i++){ 75 | System.out.print(Q[i]+ " "); 76 | } 77 | } 78 | 79 | 80 | 81 | public static void main(String[] args) { 82 | 83 | Queue q1 = new Queue(); 84 | q1.enqueue(11); 85 | q1.enqueue(12); 86 | q1.enqueue(13); 87 | q1.enqueue(14); 88 | q1.enqueue(15); 89 | q1.enqueue(5); 90 | q1.display(); 91 | q1.dequeue(); 92 | q1.dequeue(); 93 | q1.dequeue(); 94 | q1.dequeue(); 95 | q1.display(); 96 | q1.dequeue(); 97 | q1.display(); 98 | } 99 | } -------------------------------------------------------------------------------- /ADS/Day10/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ADS/Day11/Balance Tree FEB25.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/ADS/Day11/Balance Tree FEB25.pdf -------------------------------------------------------------------------------- /ADS/Day11/Graph Traversals FEB25.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/ADS/Day11/Graph Traversals FEB25.pdf -------------------------------------------------------------------------------- /ADS/Day11/Graph_ Data structure FEB25.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/ADS/Day11/Graph_ Data structure FEB25.pdf -------------------------------------------------------------------------------- /ADS/Day11/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ADS/Feb25Day1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/ADS/Feb25Day1.pdf -------------------------------------------------------------------------------- /ADS/Feb25Day10.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/ADS/Feb25Day10.pdf -------------------------------------------------------------------------------- /ADS/Feb25Day11.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/ADS/Feb25Day11.pdf -------------------------------------------------------------------------------- /ADS/Feb25Day2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/ADS/Feb25Day2.pdf -------------------------------------------------------------------------------- /ADS/Feb25Day3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/ADS/Feb25Day3.pdf -------------------------------------------------------------------------------- /ADS/Feb25Day4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/ADS/Feb25Day4.pdf -------------------------------------------------------------------------------- /ADS/Feb25Day5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/ADS/Feb25Day5.pdf -------------------------------------------------------------------------------- /ADS/Feb25Day6.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/ADS/Feb25Day6.pdf -------------------------------------------------------------------------------- /ADS/Feb25Day7.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/ADS/Feb25Day7.pdf -------------------------------------------------------------------------------- /ADS/Feb25Day8.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/ADS/Feb25Day8.pdf -------------------------------------------------------------------------------- /Additional Programs/100 Java Interview Questions with Answers.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/Additional Programs/100 Java Interview Questions with Answers.pdf -------------------------------------------------------------------------------- /Additional Programs/Core java cheat sheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/Additional Programs/Core java cheat sheet.pdf -------------------------------------------------------------------------------- /Additional Programs/Java Interview.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/Additional Programs/Java Interview.pdf -------------------------------------------------------------------------------- /Additional Programs/Java Programming Cheatsheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/Additional Programs/Java Programming Cheatsheet.pdf -------------------------------------------------------------------------------- /Additional Programs/JavaString-cheatsheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/Additional Programs/JavaString-cheatsheet.pdf -------------------------------------------------------------------------------- /Additional Programs/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Additional Programs/String cheatsheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/Additional Programs/String cheatsheet.pdf -------------------------------------------------------------------------------- /Answer framing _ St.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/Answer framing _ St.pdf -------------------------------------------------------------------------------- /Books/Book Java complete reference.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/Books/Book Java complete reference.pdf -------------------------------------------------------------------------------- /Books/Essential Algorithms - A Practical Approach to Computer Algorithms.epub: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/Books/Essential Algorithms - A Practical Approach to Computer Algorithms.epub -------------------------------------------------------------------------------- /Books/Introduction to Algorithms - Third Edition.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/Books/Introduction to Algorithms - Third Edition.pdf -------------------------------------------------------------------------------- /Books/James Gosling, Bill Joy, Guy L. Steele Jr., Gilad Bracha, Alex Buckley - The Java Language Specification, Java SE 7 Edition (2013, Addison-Wesley Professional) - libgen.lc.epub: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/Books/James Gosling, Bill Joy, Guy L. Steele Jr., Gilad Bracha, Alex Buckley - The Java Language Specification, Java SE 7 Edition (2013, Addison-Wesley Professional) - libgen.lc.epub -------------------------------------------------------------------------------- /Books/Object.Oriented.Analysis.and.Design.with.Applications.3rd.Edition.by.Booch.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/Books/Object.Oriented.Analysis.and.Design.with.Applications.3rd.Edition.by.Booch.pdf -------------------------------------------------------------------------------- /Books/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ER Diagram Feb2025_st.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/ER Diagram Feb2025_st.pdf -------------------------------------------------------------------------------- /OOPJ/Day 1/Abc.java: -------------------------------------------------------------------------------- 1 | //Class, Methods, main method() 2 | class Hello1{ 3 | public static void main(String args[]){ 4 | 5 | System.out.println("Welcome to CDAC Juhu!"); 6 | 7 | } 8 | } 9 | class Abc{ 10 | public static void main(String args[]){ 11 | 12 | System.out.println("Welcome to CDAC Kharghar!"); 13 | 14 | } 15 | } 16 | //Compile: javac 17 | //Run:java 18 | -------------------------------------------------------------------------------- /OOPJ/Day 1/Exampl2.java: -------------------------------------------------------------------------------- 1 | //Class, Methods, main method() 2 | class Example2 3 | { 4 | public static void main(String args[]){ 5 | 6 | int num = 100; 7 | double pi = 3.14159265535; 8 | System.out.printf("Number =%d%n", num); 9 | System.out.printf("Pi =%.2f%n", pi); 10 | 11 | 12 | } 13 | } 14 | 15 | //Compile: javac 16 | //Run:java 17 | -------------------------------------------------------------------------------- /OOPJ/Day 1/Example2.java: -------------------------------------------------------------------------------- 1 | //Class, Methods, main method() 2 | class Example2 3 | { 4 | public static void main(String args[]){ 5 | 6 | int num = 100; 7 | double pi = 3.14159265535; 8 | System.out.printf("Number =%d", num); 9 | System.out.printf("Pi =%.2f", pi); 10 | 11 | 12 | } 13 | } 14 | 15 | //Compile: javac 16 | //Run:java 17 | -------------------------------------------------------------------------------- /OOPJ/Day 1/Hello.java: -------------------------------------------------------------------------------- 1 | //Class, Methods, main method() 2 | class Abc{ 3 | public static void main(String args[]){ 4 | 5 | System.out.println("Welcome to CDAC!"); 6 | 7 | } 8 | } 9 | 10 | -------------------------------------------------------------------------------- /OOPJ/Day 1/Hello1.java: -------------------------------------------------------------------------------- 1 | //Class, Methods, main method() 2 | class Hello1{ 3 | public static void main(String args[]){ 4 | 5 | System.out.println("Welcome to CDAC Juhu!"); 6 | 7 | } 8 | } 9 | class Abc{ 10 | public static void main1(String args[]){ 11 | 12 | System.out.println("Welcome to CDAC Kharghar!"); 13 | 14 | } 15 | } 16 | 17 | class GoodMorning{ 18 | public static void main2(String args[]){ 19 | 20 | System.out.println("Welcome to CDAC Juhu!"); 21 | 22 | } 23 | } 24 | //Compile: javac 25 | //Run:java 26 | -------------------------------------------------------------------------------- /OOPJ/Day 1/Hello2.java: -------------------------------------------------------------------------------- 1 | //Class, Methods, main method() 2 | class Hello2{ 3 | public static void main(String args[]){ 4 | 5 | System.out.println("Welcome to CDAC Juhu!"); 6 | System.out.print("Good"); 7 | System.out.print("Morning"); 8 | System.out.println("Kajal , plz ask question?"); 9 | System.out.println("Kajal , plz ask question?"); 10 | 11 | } 12 | } 13 | 14 | //Compile: javac 15 | //Run:java 16 | -------------------------------------------------------------------------------- /OOPJ/Day 10/DownCastingDemo2.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | class Animal{ 4 | void show(){ 5 | System.out.println("Parent class"); 6 | } 7 | 8 | } 9 | class Cat extends Animal{ 10 | void show(){ 11 | System.out.println("Child class"); 12 | } 13 | 14 | } 15 | 16 | 17 | class DownCastingDemo2{ 18 | public static void main(String args[]){//method 19 | //case 1 20 | Animal a = new Cat();//Upcasting: 21 | Cat c = (Cat) a;//Downcasting 22 | c.show();//child method 23 | 24 | //case 2 25 | /*Animal a1 = new Animal(); 26 | Cat c1 = (Cat) a1;//Downcasting: Exception 27 | c1.show();//child method */ 28 | 29 | //case 3 30 | Animal a2 = new Cat();//Upcasting: 31 | 32 | if(a2 instanceof Cat){ 33 | Cat c2 = (Cat) a2; 34 | c2.show();//child method 35 | }else{ 36 | System.out.println("Downcasting : Not Possible"); 37 | } 38 | 39 | //case 4 40 | Animal a3 = new Animal(); 41 | if(a3 instanceof Cat){ 42 | Cat c3 = (Cat) a3; 43 | c3.show();//child method 44 | }else{ 45 | System.out.println("Downcasting : Not Possible"); 46 | } 47 | 48 | 49 | 50 | 51 | } 52 | 53 | 54 | } 55 | 56 | -------------------------------------------------------------------------------- /OOPJ/Day 10/GarbageCollectionDemo.java: -------------------------------------------------------------------------------- 1 | 2 | class GarbageCollectionDemo{ 3 | 4 | protected void finalize(){ 5 | System.out.println("Finalize method called ...."); 6 | } 7 | public static void main(String args[]){ 8 | 9 | GarbageCollectionDemo g1 = new GarbageCollectionDemo(); 10 | g1 = null; 11 | 12 | System.gc();//Request GC 13 | 14 | 15 | } 16 | 17 | 18 | } 19 | 20 | -------------------------------------------------------------------------------- /OOPJ/Day 10/GarbageCollectionDemo1.java: -------------------------------------------------------------------------------- 1 | class Employee{ 2 | String name; 3 | Employee(String name){ 4 | this.name = name; 5 | } 6 | } 7 | class GarbageCollectionDemo{ 8 | 9 | protected void finalize(){//overriding of method 10 | //System.out.println("Finalize method called ...."); 11 | } 12 | public static void main(String args[]){ 13 | 14 | Employee g1 = new Employee("Java"); 15 | g1 = null; 16 | 17 | System.gc();//Request GC : JVM 18 | Runtime.getRuntime().gc(); 19 | 20 | 21 | } 22 | 23 | 24 | } 25 | 26 | -------------------------------------------------------------------------------- /OOPJ/Day 10/Readme.md: -------------------------------------------------------------------------------- 1 | # String Class summary 2 | https://github.com/Kiranwaghmare123/PG-DAC-Feb2025/blob/main/Additional%20Programs/JavaString-cheatsheet.pdf 3 | 4 | -------------------------------------------------------------------------------- /OOPJ/Day 10/StringDemo.java: -------------------------------------------------------------------------------- 1 | 2 | class StringDemo{ 3 | 4 | 5 | public static void main(String args[]){ 6 | //Method 1 : String literals 7 | String s1 = "ABC";//String literal 8 | String s2 = "ABC"; 9 | String s3 = "ABCD"; 10 | String s4 = "ABCD"; 11 | 12 | //== will compare reference content 13 | //and not the object content (values) 14 | System.out.println((s1 == s2));//true 15 | System.out.println((s3 == s4)); 16 | System.out.println((s1 == s3)); 17 | 18 | //Method 2 19 | String s5 = new String("ABC"); 20 | String s6 = new String("ABCD"); 21 | System.out.println((s5 == s6));//false 22 | System.out.println((s3 == s6));//false 23 | 24 | //.equals(): we are comparing values of the reference 25 | System.out.println((s1.equals(s5))); 26 | System.out.println((s5.equals(s6))); 27 | 28 | String s7 = new String("ABC"); 29 | 30 | System.out.println(s1); 31 | s1.concat("XYZD"); 32 | System.out.println(s1); 33 | s1 = s1.concat("XYZD"); 34 | System.out.println(s1); 35 | } 36 | 37 | 38 | } 39 | 40 | -------------------------------------------------------------------------------- /OOPJ/Day 10/StringDemo1.java: -------------------------------------------------------------------------------- 1 | 2 | class StringDemo1{ 3 | 4 | 5 | public static void main(String args[]){ 6 | String s = "Gtod Morning"; 7 | 8 | System.out.println(s.length()); 9 | System.out.println(s.charAt(5)); 10 | System.out.println(s.substring(5,8)); 11 | 12 | } 13 | 14 | 15 | } 16 | 17 | -------------------------------------------------------------------------------- /OOPJ/Day 10/StringDemo2.java: -------------------------------------------------------------------------------- 1 | 2 | class StringDemo2{ 3 | 4 | 5 | public static void main(String args[]){ 6 | 7 | StringBuffer sb = new StringBuffer("Hello"); 8 | System.out.println(sb); 9 | sb.append("Duniya!"); 10 | System.out.println(sb); 11 | 12 | StringBuilder sb1 = new StringBuilder("Hello"); 13 | System.out.println(sb1); 14 | sb1.append("CDAC!"); 15 | System.out.println(sb1); 16 | 17 | String s = "Hello"; 18 | System.out.println(s); 19 | s.concat("Bhai!"); 20 | System.out.println(s); 21 | s=s.concat("Bhai!"); 22 | System.out.println(s); 23 | } 24 | 25 | 26 | } 27 | 28 | -------------------------------------------------------------------------------- /OOPJ/Day 10/StringDemo3.java: -------------------------------------------------------------------------------- 1 | 2 | class StringDemo2{ 3 | 4 | 5 | public static void main(String args[]){ 6 | 7 | StringBuffer sb = new StringBuffer("Hello"); 8 | System.out.println(sb); 9 | sb.append("Duniya!"); 10 | System.out.println(sb); 11 | 12 | StringBuilder sb1 = new StringBuilder("Hello"); 13 | System.out.println(sb1); 14 | sb1.append("CDAC!"); 15 | System.out.println(sb1); 16 | 17 | String s = "Hello"; 18 | System.out.println(s); 19 | s.concat("Bhai!"); 20 | System.out.println(s); 21 | s=s.concat("Bhai!"); 22 | System.out.println(s); 23 | } 24 | 25 | 26 | } 27 | 28 | -------------------------------------------------------------------------------- /OOPJ/Day 10/UsernameValidator.java: -------------------------------------------------------------------------------- 1 | public class UsernameValidator { 2 | public static boolean isValidUsername(String username) { 3 | if (username.contains(" ")) { 4 | return false; // No spaces allowed 5 | } 6 | if (username.length() < 5) { 7 | return false; // Minimum length is 5 8 | } 9 | if (!username.toLowerCase().contains("user")) { 10 | return false; // Must contain "user" 11 | } 12 | return true; 13 | } 14 | 15 | public static void main(String[] args) { 16 | String user1 = "user123"; 17 | String user2 = "admin"; 18 | String user3 = "User Name"; 19 | 20 | System.out.println(isValidUsername(user1)); // Output: true 21 | System.out.println(isValidUsername(user2)); // Output: false 22 | System.out.println(isValidUsername(user3)); // Output: false 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /OOPJ/Day 2/DataDemo.java: -------------------------------------------------------------------------------- 1 | 2 | class DataDemo{ 3 | 4 | 5 | public static void main(String args[]){ 6 | 7 | /*byte b = 130;//Error: 8 | byte b = 123.45;//Error 9 | byte b = true; //Error 10 | byte b = "Shankar";//Error 11 | 12 | short s = 22767; 13 | short s = -32768; 14 | short s = 123.45; //Error 15 | short s = true; //Error 16 | 17 | long l = 123000 * 60 * 60*24*1000;*/ 18 | 19 | float floatvalue = 3.142343243f; 20 | double doublevalue = 3.1423432433454546546d; 21 | 22 | boolean v = true; 23 | boolean True = true; 24 | boolean v = True; //Error 25 | boolean v1 = 0; //Error 26 | boolean v2 = "false";//Error 27 | 28 | System.out.println(v2); 29 | 30 | 31 | 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /OOPJ/Day 2/DataDemo1.java: -------------------------------------------------------------------------------- 1 | 2 | class DataDemo1{ 3 | 4 | 5 | public static void main(String args[]){ 6 | int x=0; 7 | if(true){ 8 | 9 | System.out.println(x); 10 | 11 | } 12 | 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /OOPJ/Day 2/DataDemo2.java: -------------------------------------------------------------------------------- 1 | 2 | class DataDemo2{ 3 | 4 | 5 | public static void main(String args[]){ 6 | //float f = 123.45f; 7 | double d = 0x123; //Error : 8 | double d1= 1.2e3; //valid (1.2 *1000 = 1200.0) 9 | 10 | /*char ch = 0xBEFA; 11 | char ch = 'ubeaf'; // Error 12 | char ch = -10; //Error 13 | char ch = '\x'; //Error 14 | char ch = 'a';*/ 15 | char ch1 = "a"; 16 | 17 | 18 | System.out.println(ch1); 19 | 20 | 21 | 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /OOPJ/Day 2/Exampl2.java: -------------------------------------------------------------------------------- 1 | //Class, Methods, main method() 2 | class Example2 3 | { 4 | public static void main(String args[]){ 5 | 6 | int num = 100; 7 | double pi = 3.14159265535; 8 | System.out.printf("Number =%d%n", num); 9 | System.out.printf("Pi =%.2f%n", pi); 10 | 11 | 12 | } 13 | } 14 | 15 | //Compile: javac 16 | //Run:java 17 | -------------------------------------------------------------------------------- /OOPJ/Day 2/Example2.java: -------------------------------------------------------------------------------- 1 | //Class, Methods, main method() 2 | class Example2 3 | { 4 | public static void main(String args[]){ 5 | 6 | int num = 100; 7 | double pi = 3.14159265535; 8 | System.out.printf("Number =%d", num); 9 | System.out.printf("Pi =%.2f", pi); 10 | 11 | 12 | } 13 | } 14 | 15 | //Compile: javac 16 | //Run:java 17 | -------------------------------------------------------------------------------- /OOPJ/Day 2/IdentifierDemo.java: -------------------------------------------------------------------------------- 1 | 2 | class DataDemo{ 3 | 4 | 5 | public static void main(String args[]){ 6 | 7 | byte b = 100; 8 | System.out.println(b); 9 | 10 | 11 | 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /OOPJ/Day 2/Narrowing.java: -------------------------------------------------------------------------------- 1 | 2 | class Narrowing{ 3 | 4 | 5 | public static void main(String args[]){ 6 | double d = 9999.99; 7 | int num = (int) d; //Explicit narraowing : double->int 8 | 9 | System.out.println(d); 10 | System.out.println(num); 11 | 12 | 13 | 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /OOPJ/Day 2/Readme.md: -------------------------------------------------------------------------------- 1 | # Exercise 2 | 1. Create a program that declares and initializes all primitive data types in Java and prints their default and assigned values. 3 | 2. Write a program to convert an int value to double automatically and display both values. 4 | 3. Write a program to convert a double value to int using typecasting and explain the data loss. 5 | 4. Write a program to calculate the average of three int numbers using typecasting to display the result in double. 6 | 5. Write a program to demonstrate binary, octal, hexadecimal, and floating-point literals in Java. 7 | 6. Write a program to display character and string literals along with their ASCII values. 8 | 7. Write a program that uses boolean literals to control program flow in an if-else statement. 9 | 8. Write a program to perform addition, subtraction, multiplication, division, and modulus operations on two integer numbers and display the results. 10 | 9. Write a program to perform addition, subtraction, multiplication, division, and modulus operations on two integer numbers and display the results. 11 | 10. Write a program to compare two integers using all relational operators (==, !=, >, <, >=, <=) and display the results. 12 | 11. Write a program to check if a number is positive and even using logical operators (&&, ||, !). 13 | 12. Write a program to demonstrate the use of assignment operators (=, +=, -=, *=, /=, %=) on two integers. 14 | 15 | # Reading content 16 | 1. Data Types : Primitive and Non primitive 17 | 2. Type casting 18 | 19 | ### Prepare well: 20 | 21 | 1. OOPS concepts : Abstraction, Encapsulation, Inheritance, Polymorphism 22 | 2. Concstructor overloading, method Oveloading and method overriding 23 | 3. Exception handling 24 | 4. Collection framework 25 | -------------------------------------------------------------------------------- /OOPJ/Day 2/Widening.java: -------------------------------------------------------------------------------- 1 | 2 | class Widening{ 3 | 4 | 5 | public static void main(String args[]){ 6 | int num =100; 7 | double d = num; 8 | 9 | System.out.println(d); 10 | 11 | 12 | 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /OOPJ/Day 3/ArithmeticOperators.java: -------------------------------------------------------------------------------- 1 | public class ArithmeticOperators { 2 | public static void main(String[] args) { 3 | int a = 10, b = 5; 4 | System.out.println("Addition: " + (a + b)); 5 | System.out.println("Subtraction: " + (a - b)); 6 | System.out.println("Multiplication: " + (a * b)); 7 | System.out.println("Division: " + (a / b)); 8 | System.out.println("Modulus: " + (a % b)); 9 | } 10 | } -------------------------------------------------------------------------------- /OOPJ/Day 3/CmdArgs.java: -------------------------------------------------------------------------------- 1 | class CmdArgs { 2 | public static void main(String[] args) { 3 | int i =10;//compile time 4 | //user input: input required at run time 5 | 6 | String s1 = args[0]; 7 | String s2 = args[1]; 8 | System.out.println(s1); 9 | System.out.println(s2); 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | } 18 | } -------------------------------------------------------------------------------- /OOPJ/Day 3/CmdArgs1.java: -------------------------------------------------------------------------------- 1 | class CmdArgs1 { 2 | public static void main(String[] args) { 3 | //int i =10;//compile time 4 | //user input: input required at run time 5 | 6 | String s1 = args[0]; 7 | String s2 = args[1]; 8 | System.out.println(s1); 9 | System.out.println(s2); 10 | 11 | //Wrapper classes int=Integer, float = Float 12 | int i = Integer.parseInt(s1);//10 converted string into int data type 13 | int j = Integer.parseInt(s2); 14 | 15 | System.out.println(s1+s2); 16 | System.out.println(i+j); 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | } 25 | } -------------------------------------------------------------------------------- /OOPJ/Day 3/ForDemo.java: -------------------------------------------------------------------------------- 1 | class ForDemo { 2 | public static void main(String[] args) { 3 | 4 | for(int i=0;i<=5;i++){ 5 | System.out.println(i); 6 | if(i==3) 7 | break; 8 | System.out.println(i); 9 | } 10 | 11 | 12 | 13 | 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /OOPJ/Day 3/ForDemo1.java: -------------------------------------------------------------------------------- 1 | class ForDemo1 { 2 | public static void main(String[] args) { 3 | 4 | for(int i=0;i<=5;i++){ 5 | System.out.println(i); 6 | if(i==3) 7 | continue; 8 | System.out.println(i); 9 | } 10 | 11 | 12 | 13 | 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /OOPJ/Day 3/InputDemo.java: -------------------------------------------------------------------------------- 1 | class InputDemo { 2 | public static void main(String[] args) { 3 | 4 | 5 | Scanner sc = new Scanner(System.in); 6 | System.out.println("Enter ur name"); 7 | String nm = sc.next(); 8 | System.out.println("Welcome "+nm); 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /OOPJ/Day 3/LogicalOperators.java: -------------------------------------------------------------------------------- 1 | public class LogicalOperators { 2 | public static void main(String[] args) { 3 | boolean a = true, b = false; 4 | System.out.println("AND (&&): " + (a && b)); 5 | System.out.println("OR (||): " + (a || b)); 6 | System.out.println("NOT (!a): " + (!a)); 7 | } 8 | } -------------------------------------------------------------------------------- /OOPJ/Day 3/OperatorDemo.java: -------------------------------------------------------------------------------- 1 | class OperatorDemo { 2 | public static void main(String[] args) { 3 | int a=10; 4 | int b=4; 5 | //Arithmetic 6 | System.out.println(a+b); 7 | //Relational 8 | System.out.println(a> 2; // Leftside by 2 0001 0100 31 | System.out.println(num1); 32 | System.out.println(result1); 33 | 34 | int num2 = -20; // Negative Right shift Binary 0000 0101 35 | int result2 = num2 >> 2; // Leftside by 2 0001 0100 36 | System.out.println(num2); 37 | System.out.println(result2); */ 38 | 39 | 40 | } 41 | } -------------------------------------------------------------------------------- /OOPJ/Day 3/OperatorDemo5.java: -------------------------------------------------------------------------------- 1 | class OperatorDemo5 { 2 | public static void main(String[] args) { 3 | int a=10; 4 | int b=4; 5 | //Arithmetic 6 | System.out.println(a+b); 7 | //Relational 8 | System.out.println(a> 2; // Leftside by 2 0001 0100 31 | System.out.println(num1); 32 | System.out.println(result1); 33 | 34 | int num2 = -20; // Negative Right shift Binary 0000 0101 35 | int result2 = num2 >> 2; // Leftside by 2 0001 0100 36 | System.out.println(num2); 37 | System.out.println(result2); */ 38 | 39 | 40 | } 41 | } -------------------------------------------------------------------------------- /OOPJ/Day 3/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /OOPJ/Day 3/RelationalOperators.java: -------------------------------------------------------------------------------- 1 | public class RelationalOperators { 2 | public static void main(String[] args) { 3 | int x = 10, y = 5; 4 | System.out.println("Equal: " + (x == y)); 5 | System.out.println("Not Equal: " + (x != y)); 6 | System.out.println("Greater than: " + (x > y)); 7 | System.out.println("Less than: " + (x < y)); 8 | System.out.println("Greater or Equal: " + (x >= y)); 9 | System.out.println("Less or Equal: " + (x <= y)); 10 | } 11 | } -------------------------------------------------------------------------------- /OOPJ/Day 3/SwitchDemo.java: -------------------------------------------------------------------------------- 1 | class SwitchDemo { 2 | public static void main(String[] args) { 3 | 4 | long ch = 1;// 5 | switch(ch){ 6 | case 55: 7 | System.out.println("Saturday");break; 8 | case 1: 9 | System.out.println("Monday");break; 10 | case 5: 11 | System.out.println("Saturday");break; 12 | default: 13 | System.out.println("Sunday");break; 14 | } 15 | 16 | 17 | 18 | 19 | 20 | } 21 | } -------------------------------------------------------------------------------- /OOPJ/Day 3/SwitchDemo1.java: -------------------------------------------------------------------------------- 1 | class SwitchDemo1 { 2 | public static void main(String[] args) { 3 | 4 | String ch = "a"; 5 | 6 | switch(ch){ 7 | case "a": 8 | System.out.println("Saturday");break; 9 | case "b": 10 | System.out.println("Monday");break; 11 | case "5": 12 | System.out.println("Saturday");break; 13 | default: 14 | System.out.println("Sunday");break; 15 | } 16 | 17 | 18 | 19 | 20 | 21 | } 22 | } -------------------------------------------------------------------------------- /OOPJ/Day 3/TernaryDemo.java: -------------------------------------------------------------------------------- 1 | class TernaryDemo { 2 | public static void main(String[] args) { 3 | 4 | int i =121; 5 | String s = (i%2 == 0)? i+ " is even" : i +"is odd"; 6 | System.out.println(s); 7 | 8 | System.out.println(i); 9 | System.out.println("Result = "+i); // + : Concatenate operator 10 | System.out.println("Result = "+i+" Sahi hai!"); 11 | boolean b = (i%2==0)? true : false; 12 | System.out.println(b); 13 | 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /OOPJ/Day 4/ArrayDemo1.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class ArrayDemo1{ 4 | 5 | public static void main(String args[]){ 6 | Scanner sc = new Scanner(System.in); 7 | 8 | int arr[] = new int[5]; 9 | //Input in the array 10 | for(int i=0;i<3;i++) 11 | { 12 | //System.out.println("Enter element:"); 13 | arr[i] = sc.nextInt(); 14 | } 15 | 16 | for(int i=0;i<3;i++) 17 | { 18 | System.out.println(arr[i]); 19 | } 20 | 21 | } 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /OOPJ/Day 4/ArrayDemo2.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class ArrayDemo2{ 4 | 5 | public static void main(String args[]){ 6 | Scanner sc = new Scanner(System.in); 7 | //length : Array 8 | //length() : String 9 | 10 | int arr[] = new int[5]; 11 | //Input in the array 12 | for(int i=0;i instanceof 16 | //op1 instanceof InstanceOpDemo 17 | 18 | System.out.println(op1 instanceof InstanceOpDemo);//true 19 | System.out.println(b1 instanceof A);//true 20 | System.out.println(a1 instanceof B);//false 21 | System.out.println(op instanceof A);//Error 22 | 23 | 24 | } 25 | 26 | 27 | } 28 | 29 | -------------------------------------------------------------------------------- /OOPJ/Day 9/OverridingDemo4.java: -------------------------------------------------------------------------------- 1 | class Parent{ 2 | void show(){ 3 | System.out.println("Parent Method: P1"); 4 | } 5 | } 6 | 7 | class Child extends Parent{ 8 | void show1(){ 9 | System.out.println("Child Method: C1"); 10 | } 11 | } 12 | class OverridingDemo4{ 13 | public static void main(String args[]){ 14 | 15 | Parent p = new Parent(); 16 | p.show(); 17 | //p.show1();//Error: CTE 18 | 19 | Child c = new Child(); 20 | c.show1(); 21 | c.show(); 22 | 23 | 24 | 25 | 26 | } 27 | } -------------------------------------------------------------------------------- /OOPJ/Day 9/OverridingDemo5.java: -------------------------------------------------------------------------------- 1 | class Parent{ 2 | void show(){ 3 | System.out.println("Parent Method: P1"); 4 | } 5 | } 6 | 7 | class Child extends Parent{ 8 | void show(){ 9 | super.show();//Parent class method : call 10 | System.out.println("Child Method: C1"); 11 | } 12 | } 13 | class OverridingDemo5{ 14 | public static void main(String args[]){ 15 | 16 | Parent p = new Parent(); 17 | p.show();//Parent class : show() 18 | 19 | 20 | Child c = new Child(); 21 | c.show();//Child class : show() 22 | 23 | 24 | 25 | 26 | 27 | } 28 | } -------------------------------------------------------------------------------- /OOPJ/Day 9/OverridingDemo6.java: -------------------------------------------------------------------------------- 1 | class Parent{ 2 | int i=100; 3 | void show(){ 4 | System.out.println("Parent Method: P1"); 5 | } 6 | 7 | void show1(){ 8 | 9 | } 10 | } 11 | 12 | class Child extends Parent{ 13 | int num =50; 14 | //int i=40; 15 | 16 | void show(){ 17 | super.show();//Parent class method : call 18 | super.show1(); 19 | System.out.println("Child Method: C1"); 20 | } 21 | void display(){ 22 | System.out.println(num); 23 | System.out.println(i);//preference child class 24 | System.out.println(super.i);// parent class 25 | } 26 | } 27 | class OverridingDemo6{ 28 | public static void main(String args[]){ 29 | 30 | Parent p = new Parent(); 31 | p.show();//Parent class : show() 32 | 33 | 34 | Child c = new Child(); 35 | c.show();//Child class : show() 36 | c.display(); 37 | c.show1(); 38 | 39 | 40 | 41 | 42 | 43 | } 44 | } -------------------------------------------------------------------------------- /OOPJ/Day 9/OverridingDemo7.java: -------------------------------------------------------------------------------- 1 | class Parent{ 2 | Parent(){ 3 | System.out.println("Parent Constructor::P1"); 4 | } 5 | 6 | } 7 | 8 | class Child extends Parent{ 9 | 10 | Child(){ 11 | super();//optional 12 | System.out.println("Child Constructor::C1"); 13 | } 14 | 15 | } 16 | class OverridingDemo7{ 17 | public static void main(String args[]){ 18 | 19 | //Parent p = new Parent(); 20 | 21 | 22 | Child c = new Child(); 23 | 24 | 25 | 26 | 27 | 28 | } 29 | } -------------------------------------------------------------------------------- /OOPJ/Day 9/OverridingDemo8.java: -------------------------------------------------------------------------------- 1 | class Parent{ 2 | Parent(String name){ 3 | System.out.println("Parent Constructor::P1= "+name); 4 | } 5 | 6 | } 7 | 8 | class Child extends Parent{ 9 | 10 | Child(String name){ 11 | super(name);//Explicit call for constructor 12 | System.out.println("Child Constructor::C1= "+name); 13 | } 14 | 15 | } 16 | class OverridingDemo8{ 17 | public static void main(String args[]){ 18 | 19 | //Parent p = new Parent(); 20 | 21 | 22 | Child c = new Child(); 23 | Child c1 = new Child("OOPs"); 24 | 25 | 26 | 27 | 28 | 29 | } 30 | } -------------------------------------------------------------------------------- /OOPJ/Day 9/OverridingDemo9.java: -------------------------------------------------------------------------------- 1 | class GrandParent{ 2 | 3 | GrandParent(){ 4 | System.out.println("GP"); 5 | } 6 | } 7 | 8 | class Parent extends GrandParent{ 9 | Parent(){ 10 | //super();//calls GP constructor 11 | System.out.println("P"); 12 | } 13 | 14 | } 15 | 16 | class Child extends Parent{ 17 | 18 | Child(){ 19 | //super();//call P constructor 20 | System.out.println("C"); 21 | } 22 | 23 | } 24 | class OverridingDemo9{ 25 | public static void main(String args[]){ 26 | 27 | Child c = new Child(); 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /OOPJ/Day 9/Readme.md: -------------------------------------------------------------------------------- 1 | # Homework: 2 | 3 | ### **Java Implementation Question: Simple Inheritance with Flower Example** 4 | 5 | #### **Problem Statement:** 6 | Create a **base class (`Flower`)** that contains common properties such as: 7 | - `name` (flower's name) 8 | - `color` (flower's color) 9 | - `hasFragrance` (whether the flower has a fragrance or not) 10 | 11 | Then, create **two subclasses (`Rose` and `Lily`)** that inherit properties from `Flower` and add their own specific characteristics: 12 | 1. **`Rose` class** should have an extra property `hasThorns` (to check if the rose has thorns). 13 | 2. **`Lily` class** should have an extra property `isWaterPlant` (to check if the lily grows in water). 14 | 15 | Write a Java program that allows creating objects of `Rose` and `Lily`, setting their properties, and displaying the details. 16 | 17 | 18 | ### **Sample Input & Output:** 19 | #### **Input:** 20 | The program should create a `Rose` and a `Lily` object with the following properties: 21 | - Rose: **Red, has fragrance, has thorns** 22 | - Lily: **White, has fragrance, grows in water** 23 | 24 | #### **Output:** 25 | ``` 26 | ---- Rose Details ---- 27 | Flower Name: Rose 28 | Color: Red 29 | Has Fragrance: Yes 30 | Has Thorns: Yes 31 | 32 | ---- Lily Details ---- 33 | Flower Name: Lily 34 | Color: White 35 | Has Fragrance: Yes 36 | Grows in Water: Yes 37 | ``` 38 | 39 | --- 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /OOPJ/Day 9/UpcastingDemo.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | class A{ 4 | 5 | InstanceOpDemo op; 6 | } 7 | class B extends A{ 8 | } 9 | class InstanceOpDemo{ 10 | public static void main(String args[]){//method 11 | 12 | InstanceOpDemo op1 = new InstanceOpDemo(); 13 | A a1 = new A(); 14 | B b1 = new B(); 15 | //syntax: instanceof 16 | //op1 instanceof InstanceOpDemo 17 | 18 | System.out.println(op1 instanceof InstanceOpDemo);//true 19 | System.out.println(b1 instanceof A);//true 20 | System.out.println(a1 instanceof B);//false 21 | System.out.println(op instanceof A);//Error 22 | 23 | 24 | } 25 | 26 | 27 | } 28 | 29 | -------------------------------------------------------------------------------- /OOPJ/Day11/ExceptionDemo.java: -------------------------------------------------------------------------------- 1 | class ExceptionDemo{ 2 | 3 | 4 | static void m1(){ 5 | System.out.println("M1 : executing"); 6 | m2(); 7 | } 8 | static void m2(){ 9 | System.out.println("M2 : executing"); 10 | m1(); 11 | } 12 | 13 | 14 | public static void main(String[] args) { 15 | 16 | int i=10; 17 | int j=20; 18 | 19 | m1(); 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /OOPJ/Day11/ExceptionDemo1.java: -------------------------------------------------------------------------------- 1 | class ExceptionDemo1{ 2 | 3 | public static void main(String[] args) { 4 | 5 | int a=100; 6 | int result = a/0; 7 | System.out.println(result); 8 | 9 | 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /OOPJ/Day11/ExceptionDemo2.java: -------------------------------------------------------------------------------- 1 | class ExceptionDemo2{ 2 | 3 | public static void main(String[] args) { 4 | try{ 5 | int a=100; 6 | int result = a/0;//Exception 7 | }catch(ArithmeticException e){ 8 | System.out.println("Cannot divide by zero...."); 9 | } 10 | 11 | //System.out.println(result); 12 | 13 | 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /OOPJ/Day11/ExceptionDemo3.java: -------------------------------------------------------------------------------- 1 | class ExceptionDemo3{ 2 | 3 | public static void main(String[] args) { 4 | System.out.println("Execution started"); 5 | String s1 = "12";//String input 6 | String s2 = "6";//String input 7 | 8 | int i = Integer.parseInt(s1);//converted String to int 9 | int j = Integer.parseInt(s2);//converted String to int 10 | 11 | try{ 12 | 13 | int result = i/j;//Exception =>12/0 14 | 15 | System.out.println(result); 16 | 17 | }catch(ArithmeticException e){ 18 | System.out.println("Cannot divide by zero...."); 19 | } 20 | System.out.println("Excution finished"); 21 | 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /OOPJ/Day11/ExceptionDemo4.java: -------------------------------------------------------------------------------- 1 | class ExceptionDemo4{ 2 | 3 | public static void main(String[] args) { 4 | System.out.println("Execution started"); 5 | String s1 = "12";//String input 6 | String s2 = "0";//String input 7 | 8 | int i = Integer.parseInt(s1);//converted String to int 9 | int j = Integer.parseInt(s2);//converted String to int 10 | 11 | try{ 12 | 13 | int result = i/j;//Exception =>12/0 14 | 15 | System.out.println(result); 16 | 17 | }catch(NumberFormatException e){ 18 | System.out.println("Give integer numbers...."); 19 | }catch(ArrayIndexOutOfBoundsException e){ 20 | System.out.println("Use array element...."); 21 | }catch(ArithmeticException e){ 22 | System.out.println("Cannot divide by zero...."); 23 | } 24 | System.out.println("Excution finished"); 25 | 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /OOPJ/Day11/ExceptionDemo5.java: -------------------------------------------------------------------------------- 1 | class ExceptionDemo5{ 2 | 3 | public static void main(String[] args) { 4 | System.out.println("Execution started"); 5 | String ar[] = {"12","g"}; 6 | 7 | 8 | 9 | try{ 10 | String s1 = ar[0]; 11 | String s2 = ar[1]; 12 | System.out.println(s1); 13 | System.out.println(s2); 14 | 15 | int i = Integer.parseInt(s1);//converted String to int : 12 16 | System.out.println(i); 17 | int j = Integer.parseInt(s2);//converted String to int : g 18 | System.out.println(i); 19 | System.out.println(j); 20 | int result = i/j;//Exception =>12/0 21 | 22 | System.out.println(result); 23 | 24 | }catch(NumberFormatException e){ 25 | System.out.println("Give integer numbers...."); 26 | }catch(ArrayIndexOutOfBoundsException e){ 27 | System.out.println("Use array element...."); 28 | }catch(ArithmeticException e){ 29 | System.out.println("Cannot divide by zero...."); 30 | } 31 | System.out.println("Excution finished"); 32 | 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /OOPJ/Day11/GetClassDemo.java: -------------------------------------------------------------------------------- 1 | class GetClassDemo{ 2 | 3 | public static void main(String[] args) { 4 | GetClassDemo g1 = new GetClassDemo(); 5 | System.out.println(g1.getClass().getName()); 6 | 7 | 8 | } 9 | } 10 | Note: 11 | ------ 12 | Class -----> Object ? instanceof (true/flase) 13 | 14 | 15 | Object ------> Class ? getClass() 16 | 17 | Object ------> Class (Name)? getClass().getName() -------------------------------------------------------------------------------- /OOPJ/Day11/HashCodeDemo.java: -------------------------------------------------------------------------------- 1 | class HashCodeDemo{ 2 | String name; 3 | int id; 4 | 5 | HashCodeDemo(String name, int id){ 6 | this.name = name; 7 | this.id =id; 8 | } 9 | 10 | @Override 11 | public int hashCode(){ 12 | return id;//Using id as a unique hash code must be return 13 | 14 | } 15 | 16 | public static void main(String[] args) { 17 | HashCodeDemo t1 = new HashCodeDemo("Abc",111); 18 | System.out.println(t1.hashCode()); 19 | 20 | 21 | } 22 | } -------------------------------------------------------------------------------- /OOPJ/Day11/ObjectDemo1.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | class Employee1 { 4 | String name; 5 | int id; 6 | 7 | public Employee1(String name, int id) { 8 | this.name = name; 9 | this.id = id; 10 | } 11 | 12 | @Override 13 | public int hashCode() { 14 | return id; // Using ID as a unique hash code 15 | } 16 | 17 | 18 | } 19 | public class ObjectDemo1 { 20 | 21 | public static void main(String[] args) { 22 | Employee1 emp1 = new Employee1("Alice", 101); 23 | System.out.println("HashCode: " + emp1.hashCode()); 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /OOPJ/Day11/ToStringDemo.java: -------------------------------------------------------------------------------- 1 | class ToStringDemo{ 2 | String name; 3 | int id; 4 | 5 | ToStringDemo(String name, int id){ 6 | this.name = name; 7 | this.id =id; 8 | } 9 | 10 | @Override//done overriding with toSting() of Object class 11 | public String toString(){ 12 | return name+ " " +id;//return Sting values of id and name 13 | 14 | } 15 | 16 | public static void main(String[] args) { 17 | ToStringDemo t1 = new ToStringDemo("Abc",111); 18 | System.out.println(t1);//By default toSting method is called 19 | 20 | 21 | } 22 | } -------------------------------------------------------------------------------- /OOPJ/Day11/WrapperDemo.java: -------------------------------------------------------------------------------- 1 | class WrapperDemo{ 2 | 3 | public static void main(String[] args) { 4 | 5 | int a =20;//Primitive data 6 | //Autoboxing: Primitve to wrapper class object 7 | 8 | Byte b = Byte.valueOf("20"); 9 | Short s = Short.valueOf("20");// 10 | Integer i = Integer.valueOf(a); 11 | Long l = Long.valueOf("20"); 12 | 13 | Integer j = a; 14 | 15 | System.out.println(j); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /OOPJ/Day11/WrapperDemo1.java: -------------------------------------------------------------------------------- 1 | class WrapperDemo1{ 2 | 3 | public static void main(String[] args) { 4 | 5 | Integer a = new Integer(30); 6 | //Method 1: 7 | int i = a.intValue();//Explicit call: Unboxing 8 | System.out.println(i); 9 | 10 | //Method 2: 11 | int j = a;//compiler automatic conversion kiya 12 | 13 | System.out.println(j); 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /OOPJ/Day11/WrapperDemo2.java: -------------------------------------------------------------------------------- 1 | class WrapperDemo2{ 2 | 3 | public static void main(String[] args) { 4 | 5 | int i = Integer.parseInt("12345");//parseXxx 6 | float j = Float.parseFloat("1234.5"); 7 | 8 | System.out.println(i); 9 | System.out.println(j); 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /OOPJ/Day12/ChDemo.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | class ChDemo{ 3 | public static void main(String [] args){ 4 | 5 | //int i = Integer.parseInt("ab");//Unchecked Ex 6 | 7 | //int j = System.in.read(); 8 | //Method 1 : try-catch() 9 | try{ 10 | int j = System.in.read(); 11 | }catch(IOException e){ 12 | e.printStackTrace(); 13 | } 14 | 15 | } 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /OOPJ/Day12/ChDemo1.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | class ChDemo1{ 3 | public static void main(String [] args) throws IOException{ 4 | 5 | System.out.println("Enter any character: "); 6 | int j = System.in.read(); 7 | System.out.println("Enter char = " +(char)j); 8 | 9 | } 10 | } 11 | 12 | 13 | //1. try-catch() 14 | //2. throws -------------------------------------------------------------------------------- /OOPJ/Day12/ChDemo2.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | class ChDemo2{ 3 | public static void main(String [] args) { 4 | 5 | m1(); 6 | 7 | } 8 | static void m1(){ 9 | m2(); 10 | } 11 | 12 | static void m2(){ 13 | System.out.println("Enter any character: "); 14 | try{ 15 | int j = System.in.read();//Exception 16 | System.out.println("Enter char = " +(char)j); 17 | }catch(IOException e){ 18 | e.printStackTrace(); 19 | } 20 | } 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /OOPJ/Day12/ChDemo3.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | class ChDemo3{ 3 | public static void main(String [] args) { 4 | 5 | try{ 6 | m1(); 7 | }catch(IOException e){ 8 | System.out.println("Executed "); 9 | } 10 | 11 | System.out.println("3"); 12 | 13 | } 14 | static void m1() throws IOException{ 15 | System.out.println("1"); 16 | m2(); 17 | System.out.println("1"); 18 | } 19 | 20 | static void m2() throws IOException{ 21 | System.out.println("2"); 22 | System.out.println("Enter any character: "); 23 | System.in.close(); 24 | int j = System.in.read();//Exception 25 | 26 | System.out.println("Enter char = " +j); 27 | System.out.println("2"); 28 | 29 | } 30 | } 31 | 32 | 33 | -------------------------------------------------------------------------------- /OOPJ/Day12/ChDemo4.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | class ChDemo4{ 3 | public static void main(String [] args) throws IOException { 4 | 5 | m1(); 6 | System.out.println("3"); 7 | 8 | } 9 | static void m1() throws IOException{ 10 | System.out.println("1"); 11 | m2(); 12 | System.out.println("1"); 13 | } 14 | 15 | static void m2()throws IOException{ 16 | System.out.println("2"); 17 | System.out.println("Enter any character: "); 18 | int j = System.in.read();//Checked Exception 19 | System.out.println("Enter char = " +(char)j); 20 | System.out.println("2"); 21 | 22 | } 23 | } 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /OOPJ/Day12/ChDemo5.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | class ChDemo5{ 3 | public static void main(String [] args) { 4 | try{ 5 | m1(); 6 | }catch(Exception e){ 7 | 8 | } 9 | System.out.println("3"); 10 | 11 | } 12 | static void m1() throws IOException{ 13 | System.out.println("1"); 14 | m2(); 15 | System.out.println("1"); 16 | } 17 | 18 | static void m2()throws IOException{ 19 | System.out.println("2"); 20 | System.out.println("Enter any character: "); 21 | int j = System.in.read();//Checked Exception 22 | System.out.println("Enter char = " +(char)j); 23 | System.out.println("2"); 24 | 25 | } 26 | } 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /OOPJ/Day12/ChDemo6.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | class ChDemo6{ 4 | public static void main(String [] args) { 5 | File f = new File("abc.txt"); 6 | try{ 7 | FileReader fr = new FileReader(f);//Checked Exception 8 | }catch(FileNotFoundException e){ 9 | } 10 | 11 | } 12 | } 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /OOPJ/Day12/ChDemo7.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | class ChDemo7{ 4 | public static void main(String [] args) throws FileNotFoundException { 5 | File f = new File("abc.txt"); 6 | 7 | FileReader fr = new FileReader(f);//Checked Exception 8 | 9 | 10 | } 11 | } 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /OOPJ/Day12/ChDemo8.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | class ChDemo8{ 4 | static void m() throws FileNotFoundException { 5 | System.out.println("start"); 6 | File f = new File("abcd.txt"); 7 | 8 | FileReader fr = new FileReader(f);//Checked Exception 9 | System.out.println("end"); 10 | 11 | } 12 | 13 | public static void main(String args[])throws FileNotFoundException{ 14 | m(); 15 | } 16 | } 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /OOPJ/Day12/ChDemo9.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | class ChDemo8{ 4 | static void m() throws FileNotFoundException { 5 | System.out.println("start"); 6 | File f = new File("abcd.txt"); 7 | 8 | FileReader fr = new FileReader(f);//Checked Exception 9 | System.out.println("end"); 10 | 11 | } 12 | 13 | public static void main(String args[])throws FileNotFoundException{ 14 | int k =3/0;//Unchecked 15 | m();//checked 16 | } 17 | } 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /OOPJ/Day12/ExceptionDemo.java: -------------------------------------------------------------------------------- 1 | class ExceptionDemo{ 2 | 3 | 4 | static void m1(){ 5 | System.out.println("M1 : executing"); 6 | m2(); 7 | } 8 | static void m2(){ 9 | System.out.println("M2 : executing"); 10 | m1(); 11 | } 12 | 13 | 14 | public static void main(String[] args) { 15 | 16 | int i=10; 17 | int j=20; 18 | 19 | m1(); 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /OOPJ/Day12/ExceptionDemo1.java: -------------------------------------------------------------------------------- 1 | class ExceptionDemo1{ 2 | 3 | public static void main(String[] args) { 4 | 5 | int a=100; 6 | int result = a/0; 7 | System.out.println(result); 8 | 9 | 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /OOPJ/Day12/ExceptionDemo2.java: -------------------------------------------------------------------------------- 1 | class ExceptionDemo2{ 2 | 3 | public static void main(String[] args) { 4 | System.out.println("Started"); 5 | try{ 6 | System.out.println("Entery point in try block"); 7 | int a=100; 8 | int result = a/0;//Exception e 9 | System.out.println(result); 10 | }catch(ArithmeticException e){ 11 | e.printStackTrace(); 12 | System.out.println("Cannot divide by zero....");//user 13 | } 14 | 15 | System.out.println("Finished"); 16 | 17 | 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /OOPJ/Day12/ExceptionDemo3.java: -------------------------------------------------------------------------------- 1 | 2 | class A{} 3 | class B extends A{} 4 | class ExceptionDemo3{ 5 | 6 | public static void main(String[] args) { 7 | System.out.println("Started"); 8 | A a = new A(); 9 | try{ 10 | B b =(B)a;//Downcasting: Exception e 11 | }catch(ClassCastException e){ 12 | System.out.println(e.getMessage()); 13 | e.printStackTrace(); 14 | System.out.println("Downcast me issue hai!"); 15 | } 16 | 17 | 18 | System.out.println("Finished"); 19 | 20 | 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /OOPJ/Day12/ExceptionDemo4.java: -------------------------------------------------------------------------------- 1 | 2 | class ExceptionDemo4{ 3 | 4 | void m1(){ 5 | System.out.println("M1 :: Started"); 6 | } 7 | 8 | public static void main(String[] args) { 9 | System.out.println("Started"); 10 | 11 | ExceptionDemo4 a = null; 12 | try{ 13 | a.m1();//Excetion e : NPE 14 | }catch(NullPointerException e){ 15 | e.printStackTrace(); 16 | System.out.println("Null ko inboke mat karo!"); 17 | } 18 | 19 | System.out.println("Finished"); 20 | 21 | 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /OOPJ/Day12/ExceptionDemo5.java: -------------------------------------------------------------------------------- 1 | 2 | class ExceptionDemo5{ 3 | 4 | void m1(){ 5 | System.out.println("M1 :: Started"); 6 | } 7 | 8 | public static void main(String[] args) { 9 | System.out.println("Started"); 10 | 11 | ExceptionDemo5 a = null; 12 | try{ 13 | //a.m1();//Excetion e : NPE 14 | }catch(NullPointerException e){ 15 | e.printStackTrace(); 16 | System.out.println("Null ko invoke mat karo!"); 17 | }finally{ 18 | System.out.println("Release resources!!!"); 19 | } 20 | 21 | System.out.println("Finished"); 22 | 23 | 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /OOPJ/Day12/ExceptionDemo6.java: -------------------------------------------------------------------------------- 1 | 2 | class ExceptionDemo6{ 3 | 4 | void m1(){ 5 | System.out.println("M1 :: Started"); 6 | } 7 | 8 | public static void main(String[] args) { 9 | System.out.println("Started"); 10 | 11 | ExceptionDemo6 a = null; 12 | try{ 13 | //a.m1();//Excetion e : NPE 14 | }finally{ 15 | //System.out.println("Release resources!!!"); 16 | } 17 | 18 | System.out.println("Finished"); 19 | 20 | 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /OOPJ/Day12/ExceptionDemo7.java: -------------------------------------------------------------------------------- 1 | 2 | class ExceptionDemo7{ 3 | 4 | void m1(){ 5 | System.out.println("M1 :: Started"); 6 | } 7 | 8 | public static void main(String[] args) { 9 | System.out.println("Started"); 10 | 11 | ExceptionDemo7 a = null; 12 | try{ 13 | a.m1();//Excetion e : NPE 14 | }finally{ 15 | System.out.println("Release resources!!!"); 16 | } 17 | 18 | System.out.println("Finished"); 19 | 20 | 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /OOPJ/Day12/ExceptionDemo8.java: -------------------------------------------------------------------------------- 1 | 2 | class ExceptionDemo8{ 3 | 4 | 5 | public static void main(String[] args) { 6 | System.out.println("Start"); 7 | 8 | String s1 = "15"; 9 | String s2 = "0"; 10 | 11 | int i = Integer.parseInt(s1); 12 | int j = Integer.parseInt(s2); 13 | 14 | try{ 15 | int k = i/j; 16 | System.out.println(k); 17 | } 18 | /*catch(ArithmeticException e){ 19 | e.printStackTrace(); 20 | System.out.println("Arithmetic Exception"); 21 | }*/ 22 | catch(NullPointerException e){ 23 | //e.printStackTrace(); 24 | System.out.println("NullPointer Exception"); 25 | }finally{ 26 | System.out.println("Release the resources !!!"); 27 | } 28 | System.out.println("Finished"); 29 | 30 | 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /OOPJ/Day12/ExceptionDemo9.java: -------------------------------------------------------------------------------- 1 | 2 | class ExceptionDemo9{ 3 | 4 | 5 | public static void main(String[] args) { 6 | System.out.println("Start"); 7 | String ar[] = {"15", "s"}; 8 | 9 | try{ 10 | String s1 = ar[0]; 11 | String s2 = ar[1]; 12 | 13 | int i = Integer.parseInt(s1); 14 | int j = Integer.parseInt(s2); 15 | 16 | int k = i/j; 17 | System.out.println(k); 18 | }catch(NumberFormatException | ArithmeticException | NullPointerException e){ 19 | e.printStackTrace(); 20 | System.out.println(" NumberFormatException Exception"); 21 | }catch(Exception e){ 22 | e.printStackTrace(); 23 | System.out.println(" Exception"); 24 | }finally{ 25 | System.out.println("Release the resources !!!"); 26 | } 27 | System.out.println("Finished"); 28 | 29 | 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /OOPJ/Day12/Finally.java: -------------------------------------------------------------------------------- 1 | class Finally{ 2 | public static void main(String [] args){ 3 | 4 | 5 | //Not a correct way to stop finally from execution 6 | try{ 7 | 8 | System.exit(0); 9 | 10 | }catch(Exception e){ 11 | System.out.println("Exception aagaya!!"); 12 | 13 | } 14 | finally{ 15 | System.out.println("Finally"); 16 | } 17 | } 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /OOPJ/Day12/Readme.md: -------------------------------------------------------------------------------- 1 | # Home-work 2 | 3 | Implement the following questions to understand Exception handling properly: 4 | 5 | ### **Unchecked Exceptions (Runtime Exceptions)** 6 | Unchecked exceptions extend `RuntimeException` and do not require explicit handling with `throws` or `try-catch`. 7 | 8 | #### **1. Implement `NullPointerException`** 9 | Write a Java program where you initialize a `String` as `null` and try to call the `.length()` method on it. Handle the exception using a `try-catch` block. 10 | 11 | #### **2. Implement `ArithmeticException`** 12 | Write a Java program that performs **division by zero** and catches the `ArithmeticException`. 13 | 14 | #### **3. Implement `ArrayIndexOutOfBoundsException`** 15 | Create an array of 5 elements and try to access an index that does not exist (e.g., index `10`). Handle the exception properly. 16 | 17 | #### **4. Implement `NumberFormatException`** 18 | Write a Java program that tries to convert a **non-numeric string** to an integer using `Integer.parseInt()` and catches the `NumberFormatException`. 19 | 20 | #### **5. Implement `IllegalArgumentException`** 21 | Write a Java method `setAge(int age)` that throws an `IllegalArgumentException` if the age is negative or greater than 150. 22 | 23 | --- 24 | 25 | ### **Checked Exceptions** 26 | Checked exceptions extend `Exception` and must be either **handled using `try-catch`** or **declared with `throws`**. 27 | 28 | #### **6. Implement `IOException`** 29 | Write a Java program that attempts to read from a file that does not exist and catches `IOException`. 30 | #### **7. Implement `FileNotFoundException`** 31 | Write a Java program that tries to open a file that does not exist using `FileReader`, and handle the `FileNotFoundException`. 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /OOPJ/Day12/ThrowDemo.java: -------------------------------------------------------------------------------- 1 | 2 | class ExceptionDemo9{ 3 | 4 | 5 | public static void main(String[] args) { 6 | System.out.println("Start"); 7 | String ar[] = {"15", "s"}; 8 | 9 | try{ 10 | String s1 = ar[0]; 11 | String s2 = ar[1]; 12 | 13 | int i = Integer.parseInt(s1); 14 | int j = Integer.parseInt(s2); 15 | //throw new NumberFormatException 16 | 17 | int k = i/j;// Throw Exception e : 18 | //throw new ArithmeticException e 19 | //throw new NullPointerException e 20 | 21 | 22 | 23 | System.out.println(k); 24 | }catch(NumberFormatException | ArithmeticException | NullPointerException e){ 25 | e.printStackTrace(); 26 | System.out.println(" NumberFormatException Exception"); 27 | }catch(Exception e){ 28 | e.printStackTrace(); 29 | System.out.println(" Exception"); 30 | }finally{ 31 | System.out.println("Release the resources !!!"); 32 | } 33 | System.out.println("Finished"); 34 | 35 | Abc a1 = new Abc(); 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /OOPJ/Day12/ThrowDemo1.java: -------------------------------------------------------------------------------- 1 | 2 | class ThrowDemo1{ 3 | 4 | 5 | public static void main(String[] args) { 6 | System.out.println("Started"); 7 | 8 | try{ 9 | throw new NullPointerException(); 10 | 11 | }catch(NullPointerException e){ 12 | e.printStackTrace(); 13 | System.out.println("Null ko invoke mat karo!"); 14 | }finally{ 15 | System.out.println("Finally!!!"); 16 | } 17 | 18 | 19 | System.out.println("Finished"); 20 | 21 | 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /OOPJ/Day12/UnCheckedDemo.java: -------------------------------------------------------------------------------- 1 | 2 | class UnCheckedDemo{ 3 | static void m3(){ 4 | System.out.println("4"); 5 | int i = 1/0;//Excetion e 6 | System.out.println("4"); 7 | } 8 | static void m2(){ 9 | System.out.println("3"); 10 | m3(); 11 | System.out.println("3"); 12 | } 13 | static void m1(){ 14 | System.out.println("2"); 15 | m2(); 16 | System.out.println("2"); 17 | } 18 | 19 | static void m(){ 20 | System.out.println("1"); 21 | m1(); 22 | System.out.println("1"); 23 | } 24 | 25 | public static void main(String[] args) { 26 | System.out.println("Started"); 27 | m(); 28 | 29 | 30 | 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /OOPJ/Day13/Employee.java: -------------------------------------------------------------------------------- 1 | package Day13.priv; 2 | 3 | public class Employee { 4 | private double salary; 5 | 6 | 7 | public Employee() { 8 | 9 | } 10 | 11 | public Employee(double salary) { 12 | 13 | this.salary = salary; 14 | } 15 | 16 | public void display() { 17 | System.out.println("Salary = "+salary); 18 | } 19 | 20 | public void show() { 21 | System.out.println("Salary = "+salary); 22 | display(); 23 | } 24 | /*public static void main(String[] args) { 25 | Employee e1 = new Employee(40000); 26 | e1.display(); 27 | }*/ 28 | 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /OOPJ/Day13/PrivateDemo.java: -------------------------------------------------------------------------------- 1 | package Day13.priv; 2 | 3 | public class PrivateDemo extends Employee{ 4 | 5 | public static void main(String[] args) { 6 | Employee e = new Employee(50000); 7 | e.display(); 8 | e.show(); 9 | 10 | 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /OOPJ/Day13/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /OOPJ/Day13/Singleton.java: -------------------------------------------------------------------------------- 1 | package Day13; 2 | 3 | public class Singleton { 4 | //Step 1 5 | private static Singleton s1; 6 | //Step 2 7 | private Singleton() { 8 | System.out.println("Singleton reference instance is created!"); 9 | } 10 | //Step 3 11 | public static Singleton getInstance() { 12 | if(s1 == null) { 13 | s1 = new Singleton();//Object will be created 14 | } 15 | return s1; 16 | 17 | } 18 | 19 | public void show() { 20 | System.out.println("Hello, I am here!"); 21 | } 22 | 23 | public static void main(String args[]) { 24 | Singleton obj1 = s1.getInstance(); 25 | Singleton obj2 = s1.getInstance(); 26 | 27 | obj1.show(); 28 | System.out.println(obj1 == obj2);//true 29 | 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /OOPJ/Day13/com.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/OOPJ/Day13/com.zip -------------------------------------------------------------------------------- /OOPJ/Day14/ArrayListDemo.java: -------------------------------------------------------------------------------- 1 | package Day14; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class ArrayListDemo { 6 | 7 | public static void main(String[] args) { 8 | ArrayList a1 = new ArrayList();//Non type safe 9 | ArrayList a11 = new ArrayList<>();//Type safe 10 | a11.add("Tushar"); 11 | a11.add("Kiran"); 12 | a11.add("Pratik"); 13 | a11.add("Isha"); 14 | a11.add("Pratik"); 15 | System.out.println(a11); 16 | 17 | System.out.println(a11.get(0)); 18 | System.out.println(a11.get(3)); 19 | 20 | a11.remove(0); 21 | System.out.println(a11); 22 | a11.remove("Kiran"); 23 | System.out.println(a11); 24 | 25 | 26 | 27 | 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /OOPJ/Day14/ArrayListDemo1.java: -------------------------------------------------------------------------------- 1 | package Day14; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Iterator; 5 | 6 | public class ArrayListDemo1 { 7 | 8 | public static void main(String[] args) { 9 | ArrayList a1 = new ArrayList();//Non type safe 10 | ArrayList a11 = new ArrayList<>();//Type safe 11 | a11.add("Tushar"); 12 | a11.add("Kiran"); 13 | a11.add("Pratik"); 14 | a11.add("Isha"); 15 | a11.add("Pratik"); 16 | System.out.println(a11); 17 | 18 | System.out.println(a11.get(0)); 19 | System.out.println(a11.get(3)); 20 | 21 | a11.remove(0); 22 | System.out.println(a11); 23 | a11.remove("Kiran"); 24 | System.out.println(a11); 25 | System.out.println("-------1------"); 26 | 27 | //Traversing : Method 1 28 | for(int i=0;i< a11.size();i++) { 29 | System.out.println(a11.get(i)); 30 | } 31 | System.out.println("------2-------"); 32 | //Traversing : Method 2 33 | for(String x : a11) { 34 | System.out.println(x); 35 | } 36 | 37 | System.out.println("--------3-----"); 38 | //Traversing : Method 3 39 | Iterator itr = a11.iterator(); 40 | while(itr.hasNext()) { 41 | System.out.println(itr.next()); 42 | } 43 | 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /OOPJ/Day14/CollectionDemo.java: -------------------------------------------------------------------------------- 1 | package Day14; 2 | 3 | import java.util.ArrayList; 4 | 5 | /*class Employee{ 6 | private int empId; 7 | private String empName; 8 | 9 | public Employee(int empId, String empName) { 10 | this.empId = empId; 11 | this.empName = empName; 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | return empId + " " + empName; 17 | } 18 | 19 | 20 | 21 | }*/ 22 | public class CollectionDemo { 23 | 24 | public static void main(String[] args) { 25 | 26 | ArrayList a = new ArrayList<>(); 27 | a.add(new Employee(11, "Ravi")); 28 | a.add(new Employee(21, "Ravi1")); 29 | a.add(new Employee(51, "Ravi2")); 30 | a.add(new Employee(61, "Ravi3")); 31 | a.add(new Employee(14, "Ravi4")); 32 | a.add(new Employee(66, "Ravi5")); 33 | a.add(new Employee(41, "Ravi6")); 34 | 35 | System.out.println(a); 36 | 37 | for(Employee x : a) { 38 | System.out.println(x); 39 | } 40 | 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /OOPJ/Day14/CollectionDemo1.java: -------------------------------------------------------------------------------- 1 | package Day14; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashSet; 5 | 6 | /*class Employee{ 7 | private int empId; 8 | private String empName; 9 | 10 | public Employee(int empId, String empName) { 11 | this.empId = empId; 12 | this.empName = empName; 13 | } 14 | 15 | @Override 16 | public String toString() { 17 | return empId + " :=> " + empName; 18 | } 19 | 20 | @Override 21 | public int hashCode() { 22 | 23 | return empId; 24 | } 25 | 26 | @Override 27 | public boolean equals(Object obj) { 28 | if(obj == null) 29 | return false; 30 | if(obj instanceof Employee) { 31 | Employee e = (Employee) obj; 32 | return empId == e.empId; 33 | } 34 | 35 | return false; 36 | } 37 | 38 | 39 | }*/ 40 | public class CollectionDemo1 { 41 | 42 | public static void main(String[] args) { 43 | 44 | HashSet a = new HashSet<>(); 45 | a.add(new Employee(11, "Ravi")); 46 | a.add(new Employee(21, "Ravi1")); 47 | a.add(new Employee(51, "Ravi2")); 48 | a.add(new Employee(61, "Ravi3")); 49 | a.add(new Employee(14, "Ravi4")); 50 | a.add(new Employee(66, "Ravi5")); 51 | a.add(new Employee(41, "Ravi6")); 52 | 53 | System.out.println(a); 54 | 55 | for(Employee x : a) { 56 | System.out.println(x); 57 | } 58 | 59 | 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /OOPJ/Day14/CollectionDemo2.java: -------------------------------------------------------------------------------- 1 | 2 | package Day14; 3 | 4 | import java.util.ArrayList; 5 | import java.util.HashSet; 6 | import java.util.TreeSet; 7 | 8 | /*class Employee implements Comparable{ 9 | private int empId; 10 | private String empName; 11 | 12 | public Employee(int empId, String empName) { 13 | this.empId = empId; 14 | this.empName = empName; 15 | } 16 | 17 | @Override 18 | public String toString() { 19 | return empId + " :=> " + empName; 20 | } 21 | 22 | @Override 23 | public int compareTo(Employee o) { 24 | return empId - o.empId; 25 | } 26 | 27 | 28 | 29 | }*/ 30 | public class CollectionDemo2 { 31 | 32 | public static void main(String[] args) { 33 | 34 | TreeSet a = new TreeSet<>(); 35 | a.add(new Employee(11, "Ravi")); 36 | a.add(new Employee(21, "Ravi1")); 37 | a.add(new Employee(51, "Ravi2")); 38 | a.add(new Employee(61, "Ravi3")); 39 | a.add(new Employee(14, "Ravi4")); 40 | a.add(new Employee(66, "Ravi5")); 41 | a.add(new Employee(41, "Ravi6")); 42 | 43 | System.out.println(a); 44 | 45 | for(Employee x : a) { 46 | System.out.println(x); 47 | } 48 | 49 | 50 | } 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /OOPJ/Day14/CollectionDemo3.java: -------------------------------------------------------------------------------- 1 | 2 | package Day14; 3 | 4 | import java.util.ArrayList; 5 | import java.util.Comparator; 6 | import java.util.HashSet; 7 | import java.util.TreeSet; 8 | 9 | class Employee{ 10 | int empId; 11 | String empName; 12 | 13 | public Employee(int empId, String empName) { 14 | this.empId = empId; 15 | this.empName = empName; 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return empId + " :=> " + empName; 21 | } 22 | 23 | } 24 | 25 | class EmployeeComparator implements Comparator{ 26 | 27 | @Override 28 | public int compare(Employee o1, Employee o2) { 29 | 30 | return o1.empId - o2.empId; 31 | } 32 | 33 | } 34 | 35 | class EmployeeComparator1 implements Comparator{ 36 | 37 | @Override 38 | public int compare(Employee o1, Employee o2) { 39 | 40 | return o2.empName.compareTo(o1.empName); 41 | } 42 | 43 | } 44 | public class CollectionDemo3 { 45 | 46 | public static void main(String[] args) { 47 | 48 | TreeSet a = new TreeSet(new EmployeeComparator()); 49 | a.add(new Employee(11, "Ravi")); 50 | a.add(new Employee(21, "Ravi1")); 51 | a.add(new Employee(51, "Ravi2")); 52 | a.add(new Employee(61, "Ravi3")); 53 | a.add(new Employee(14, "Ravi4")); 54 | a.add(new Employee(66, "Ravi5")); 55 | a.add(new Employee(41, "Ravi6")); 56 | 57 | System.out.println(a); 58 | 59 | for(Employee x : a) { 60 | System.out.println(x); 61 | } 62 | 63 | System.out.println("======================="); 64 | 65 | TreeSet a1 = new TreeSet(new EmployeeComparator1()); 66 | a1.add(new Employee(11, "Ravi")); 67 | a1.add(new Employee(21, "savi1")); 68 | a1.add(new Employee(51, "Ravi2")); 69 | a1.add(new Employee(61, "Tavi3")); 70 | a1.add(new Employee(14, "Kavi4")); 71 | a1.add(new Employee(66, "Aavi5")); 72 | a1.add(new Employee(41, "Mavi6")); 73 | 74 | System.out.println(a1); 75 | 76 | for(Employee x : a1) { 77 | System.out.println(x); 78 | } 79 | 80 | } 81 | 82 | } 83 | 84 | -------------------------------------------------------------------------------- /OOPJ/Day14/HashMapDemo.java: -------------------------------------------------------------------------------- 1 | package Day14; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class HashMapDemo { 7 | 8 | public static void main(String[] args) { 9 | Map m = new HashMap(); 10 | // 11 | m.put(101, "Aditya"); 12 | m.put(2, "Dhanush"); 13 | m.put(3, "Shweta"); 14 | m.put(4, "Shweta"); 15 | m.put(4, "Shweta");//not allowed 16 | m.put(4, "Rohan"); 17 | m.put(4, "Rohini"); 18 | m.put(115, ""); 19 | System.out.println(m); 20 | System.out.println(m.get(2));// 21 | m.remove(3); 22 | System.out.println(m); 23 | 24 | 25 | 26 | 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /OOPJ/Day14/HashMapDemo2.java: -------------------------------------------------------------------------------- 1 | package Day14; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class HashMapDemo2 { 7 | 8 | public static void main(String[] args) { 9 | Map m = new HashMap(); 10 | 11 | m.put(1, "Aditya"); 12 | m.put(2, "Dhanush"); 13 | m.put(3, "Shweta"); 14 | m.put(4, "Shweta"); 15 | m.put(4, "Shweta");//not allowed 16 | m.put(4, "Rohan"); 17 | m.put(4, "Rohini"); 18 | m.put(5, ""); 19 | System.out.println(m); 20 | System.out.println(m.get(4)); 21 | m.remove(3); 22 | System.out.println(m); 23 | 24 | 25 | 26 | 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /OOPJ/Day14/HashTableDemo.java: -------------------------------------------------------------------------------- 1 | package Day14; 2 | 3 | import java.util.HashMap; 4 | import java.util.Hashtable; 5 | import java.util.LinkedHashMap; 6 | import java.util.Map; 7 | import java.util.TreeMap; 8 | 9 | public class HashTableDemo { 10 | 11 | public static void main(String[] args) { 12 | Map m = new Hashtable<>(); 13 | // 14 | m.put(5, "Rohan"); 15 | m.put(101, "Aditya"); 16 | m.put(52, "Dhanush"); 17 | m.put(3, "Shweta"); 18 | m.put(14, "Shweta"); 19 | m.put(6, "Rohini"); 20 | m.put(7, ""); 21 | m.put(8, ""); 22 | m.put(9, ""); 23 | System.out.println(m); 24 | 25 | 26 | 27 | 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /OOPJ/Day14/HashsetDemo.java: -------------------------------------------------------------------------------- 1 | package Day14; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | public class HashsetDemo { 7 | 8 | public static void main(String[] args) { 9 | Set s1 = new HashSet<>(); 10 | 11 | s1.add("Mango"); 12 | s1.add("Banana"); 13 | s1.add("Grapes"); 14 | s1.add("Mango"); 15 | s1.add("Banana"); 16 | s1.add("Grapes"); 17 | s1.add("Grapes"); 18 | s1.add("Grapes"); 19 | s1.add("Grapes"); 20 | s1.add("Grapes"); 21 | 22 | System.out.println(s1); 23 | 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /OOPJ/Day14/LinkedHashMapDemo3.java: -------------------------------------------------------------------------------- 1 | package Day14; 2 | 3 | import java.util.HashMap; 4 | import java.util.LinkedHashMap; 5 | import java.util.Map; 6 | 7 | public class LinkedHashMapDemo3 { 8 | 9 | public static void main(String[] args) { 10 | Map m = new LinkedHashMap(); 11 | // 12 | m.put(101, "Aditya"); 13 | m.put(2, "Dhanush"); 14 | m.put(3, "Shweta"); 15 | m.put(4, "Shweta"); 16 | m.put(5, "Rohan"); 17 | m.put(6, "Rohini"); 18 | m.put(7, ""); 19 | m.put(8, ""); 20 | m.put(9, ""); 21 | System.out.println(m); 22 | System.out.println(m.get(5));// 23 | m.remove(3); 24 | System.out.println(m); 25 | 26 | 27 | 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /OOPJ/Day14/LinkedHashsetDemo2.java: -------------------------------------------------------------------------------- 1 | package Day14; 2 | 3 | import java.util.HashSet; 4 | import java.util.LinkedHashSet; 5 | import java.util.Set; 6 | 7 | public class LinkedHashsetDemo2 { 8 | 9 | public static void main(String[] args) { 10 | Set s1 = new LinkedHashSet<>(); 11 | 12 | s1.add("Mango"); 13 | s1.add("Banana"); 14 | s1.add("Grapes"); 15 | s1.add("Mango"); 16 | s1.add("Banana"); 17 | s1.add("Grapes"); 18 | s1.add("Grapes"); 19 | s1.add("Grapes"); 20 | s1.add("Grapes"); 21 | s1.add("Grapes"); 22 | 23 | System.out.println(s1); 24 | 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /OOPJ/Day14/LinkedListDemo.java: -------------------------------------------------------------------------------- 1 | package Day14; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | 6 | public class LinkedListDemo { 7 | 8 | public static void main(String[] args) { 9 | //LinkedList l1 = new LinkedList();//Type safe 10 | List l1 = new LinkedList();//Upcasting 11 | l1.add(10); 12 | l1.add(20); 13 | l1.add(30); 14 | l1.add(40); 15 | l1.add(50); 16 | System.out.println(l1); 17 | 18 | //Working with LinkedList method 19 | LinkedList l11 = new LinkedList(); 20 | l11.addFirst(5); 21 | l11.addLast(7); 22 | System.out.println(l11); 23 | 24 | //Not working with List interface check 25 | //l1.addFirst(5); 26 | //l1.addLast(7); 27 | System.out.println(l1); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /OOPJ/Day14/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /OOPJ/Day14/StackDemo.java: -------------------------------------------------------------------------------- 1 | package Day14; 2 | 3 | import java.util.Stack; 4 | 5 | public class StackDemo { 6 | 7 | public static void main(String[] args) { 8 | 9 | Stack s1 = new Stack<>(); 10 | s1.push(1); 11 | s1.push(2); 12 | s1.push(3); 13 | System.out.println(s1); 14 | s1.pop(); 15 | System.out.println(s1); 16 | System.out.println(s1.peek()); 17 | 18 | 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /OOPJ/Day14/TreeMapDemo.java: -------------------------------------------------------------------------------- 1 | package Day14; 2 | 3 | import java.util.HashMap; 4 | import java.util.LinkedHashMap; 5 | import java.util.Map; 6 | import java.util.TreeMap; 7 | 8 | public class TreeMapDemo { 9 | 10 | public static void main(String[] args) { 11 | Map m = new TreeMap<>(); 12 | // 13 | m.put(5, "Rohan"); 14 | m.put(101, "Aditya"); 15 | m.put(52, "Dhanush"); 16 | m.put(3, "Shweta"); 17 | m.put(14, "Shweta"); 18 | m.put(6, "Rohini"); 19 | m.put(7, ""); 20 | m.put(8, ""); 21 | m.put(9, ""); 22 | System.out.println(m); 23 | //System.out.println(m.get(5));// 24 | //m.remove(3); 25 | //System.out.println(m); 26 | 27 | 28 | 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /OOPJ/Day14/TreeSetDemo.java: -------------------------------------------------------------------------------- 1 | package Day14; 2 | 3 | import java.util.Set; 4 | import java.util.TreeSet; 5 | 6 | public class TreeSetDemo { 7 | 8 | public static void main(String[] args) { 9 | Set t1 = new TreeSet<>(); 10 | 11 | t1.add(3); 12 | t1.add(6); 13 | t1.add(9); 14 | t1.add(2); 15 | t1.add(6); 16 | 17 | System.out.println(t1); 18 | 19 | 20 | 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /OOPJ/Day14/VectorDemo.java: -------------------------------------------------------------------------------- 1 | package Day14; 2 | 3 | import java.util.List; 4 | import java.util.Vector; 5 | 6 | public class VectorDemo { 7 | 8 | public static void main(String[] args) { 9 | 10 | List a11 = new Vector<>(); 11 | a11.add("Tushar"); 12 | a11.add("Kiran"); 13 | a11.add("Pratik"); 14 | a11.add("Isha"); 15 | a11.add("Pratik"); 16 | System.out.println(a11); 17 | 18 | a11.remove(1); 19 | System.out.println(a11); 20 | 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /OOPJ/Day15/AnonymousClassDemo.java: -------------------------------------------------------------------------------- 1 | package Day15; 2 | 3 | interface Hello{ 4 | void sayHello(); 5 | } 6 | 7 | interface Helloworld{ 8 | void msg(); 9 | } 10 | 11 | abstract Morning{ 12 | abstract void manage(); 13 | } 14 | public class AnonymousClassDemo { 15 | 16 | public static void main(String[] args) { 17 | Hello h1 = new Hello(){ 18 | public void sayHello() { 19 | System.out.println("Hello world!"); 20 | 21 | } 22 | }; 23 | 24 | //-------------------------------------------------- 25 | Helloworld h2 = new Helloworld() { 26 | 27 | public void msg() { 28 | System.out.println("Testing"); 29 | } 30 | }; 31 | 32 | 33 | 34 | //call for method 35 | h1.sayHello(); 36 | h2.msg(); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /OOPJ/Day15/GenericDemo.java: -------------------------------------------------------------------------------- 1 | package Day15; 2 | 3 | public class GenericDemo { 4 | 5 | static void display(T x){ 6 | System.out.println(x.getClass().getName()+ " "+x); 7 | } 8 | 9 | 10 | public static void main(String[] args) { 11 | 12 | display(11); 13 | display(11.4556767); 14 | display("Generics is too easy!"); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /OOPJ/Day15/GenericDemo1.java: -------------------------------------------------------------------------------- 1 | package Day15; 2 | 3 | public class GenericDemo1 { 4 | T x; 5 | GenericDemo1(T x){ 6 | this.x = x; 7 | } 8 | public T show(){ 9 | return this.x; 10 | } 11 | 12 | public static void main(String[] args) { 13 | 14 | GenericDemo1 g1 = new GenericDemo1<>(15); 15 | GenericDemo1 g2 = new GenericDemo1<>(15.45657587); 16 | GenericDemo1 g3 = new GenericDemo1<>("Generics"); 17 | 18 | System.out.println(g1.show()); 19 | System.out.println(g2.show()); 20 | System.out.println(g3.show()); 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /OOPJ/Day15/GenericDemo2.java: -------------------------------------------------------------------------------- 1 | package Day15; 2 | 3 | public class GenericDemo2 { 4 | T x; 5 | T y; 6 | GenericDemo2(T x, T y){ 7 | this.x = x; 8 | this.y = y; 9 | } 10 | public T show(T x, T y){ 11 | return this.x; 12 | } 13 | 14 | public static void main(String[] args) { 15 | 16 | GenericDemo2 g1 = new GenericDemo2<>(15); 17 | GenericDemo2 g2 = new GenericDemo2<>(15.45657587); 18 | GenericDemo2 g3 = new GenericDemo2<>("Generics"); 19 | 20 | System.out.println(g1.show()); 21 | System.out.println(g2.show()); 22 | System.out.println(g3.show()); 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /OOPJ/Day15/InnerClassDemo.java: -------------------------------------------------------------------------------- 1 | package Day15; 2 | 3 | /*class OuterClass{ 4 | int x = 100; 5 | 6 | public void display(){ 7 | System.out.println("Outer class : Method"); 8 | } 9 | class InnerClass{ 10 | int y = 200; 11 | public void display1(){ 12 | System.out.println("Inner class : Method"); 13 | } 14 | } 15 | 16 | }*/ 17 | public class InnerClassDemo { 18 | 19 | public static void main(String[] args) { 20 | OuterClass o1 = new OuterClass(); 21 | 22 | System.out.println(o1.x);//100 23 | o1.display(); 24 | 25 | 26 | OuterClass.InnerClass o2 = o1.new InnerClass(); 27 | System.out.println(o2.y); 28 | o2.display1(); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /OOPJ/Day15/InnerClassDemo1.java: -------------------------------------------------------------------------------- 1 | package Day15; 2 | 3 | 4 | /*class OuterClass{ 5 | int x = 100; 6 | 7 | public void display(){ 8 | System.out.println("Outer class : Method"); 9 | //System.out.println(y);//CE 10 | 11 | } 12 | class InnerClass{ 13 | int y = 200; 14 | public void display1(){ 15 | System.out.println("Inner class : Method"); 16 | System.out.println(x); 17 | display(); 18 | } 19 | } 20 | 21 | }*/ 22 | public class InnerClassDemo1 { 23 | 24 | public static void main(String[] args) { 25 | OuterClass o1 = new OuterClass();//Ref of Outer class 26 | 27 | System.out.println(o1.x);//100 28 | o1.display(); 29 | 30 | 31 | OuterClass.InnerClass o2 = o1.new InnerClass();//Ref of Inner class 32 | System.out.println(o2.y); 33 | o2.display1(); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /OOPJ/Day15/LambdaEx1.java: -------------------------------------------------------------------------------- 1 | package Day15; 2 | 3 | @FunctionalInterface 4 | interface Hellocdac{ 5 | void sayHello1(); 6 | } 7 | 8 | interface Double{ 9 | int square(int n); 10 | } 11 | 12 | interface MathOp{ 13 | int calculate(int a, int b); 14 | } 15 | public class LambdaEx1 { 16 | 17 | public static void main(String[] args) { 18 | Hellocdac h1 = () -> System.out.println("Hello Lambda!"); 19 | h1.sayHello1(); 20 | 21 | Double d1 = (n) -> n*n; 22 | System.out.println(d1.square(5)); 23 | 24 | MathOp m1 = (a,b) -> a+b; 25 | System.out.println(m1.calculate(5, 10)); 26 | 27 | //Important: 28 | Runnable r = () -> { 29 | for(int i=1;i<=5;i++) { 30 | System.out.println("Thread "+i); 31 | } 32 | }; 33 | 34 | Thread t = new Thread(r); 35 | t.start(); 36 | } 37 | } 38 | 39 | 40 | -------------------------------------------------------------------------------- /OOPJ/Day15/LocalInnerClassDemo.java: -------------------------------------------------------------------------------- 1 | package Day15; 2 | 3 | class OutClass { 4 | int x=100; 5 | //1. Constructor instance 6 | public OutClass(){ 7 | Innerclass local = new Innerclass(); 8 | local.show(); 9 | } 10 | 11 | //2.Instance in method 12 | void display() { 13 | System.out.println("Method 1 : Outer class"); 14 | 15 | Innerclass local = new Innerclass(); 16 | local.show(); 17 | } 18 | //Local method: Instance 19 | //3.Inner class with it's instance 20 | void msg() { 21 | 22 | class Innerclass{ 23 | void show(){ 24 | System.out.println("Method 2 : Inner class"); 25 | } 26 | 27 | } 28 | Innerclass local = new Innerclass(); 29 | local.show(); 30 | } 31 | class Innerclass{ 32 | void show(){ 33 | System.out.println("Method 2 : Inner class"); 34 | } 35 | 36 | } 37 | 38 | //4. Instance block 39 | { 40 | Innerclass local = new Innerclass(); 41 | local.show(); 42 | } 43 | 44 | //5.Instance created 45 | Innerclass local = new Innerclass(); 46 | //local.show();//Reason 47 | 48 | 49 | } 50 | 51 | public class LocalInnerClassDemo { 52 | 53 | public static void main(String[] args) { 54 | 55 | OutClass out = new OutClass(); 56 | out.display(); 57 | 58 | 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /OOPJ/Day15/Readme.md: -------------------------------------------------------------------------------- 1 | ### Exception Handling 2 | ![image](https://github.com/user-attachments/assets/7bac1571-4818-48b9-8456-8f85aa949cbf) 3 | 4 | ### Collection Framework 5 | ![image](https://github.com/user-attachments/assets/ceae17c3-6b62-4895-895f-1b349e3b64c7) 6 | -------------------------------------------------------------------------------- /OOPJ/Day15/ReflectionDemo.java: -------------------------------------------------------------------------------- 1 | package Day15; 2 | 3 | import java.lang.reflect.*; 4 | import java.lang.reflect.Method; 5 | 6 | class Demo{ 7 | T x; 8 | private String s1 = "Learning Reflection"; 9 | 10 | public Demo(){ 11 | System.out.println("Demo:: Constructor"); 12 | } 13 | 14 | public Demo(T x){ 15 | this.x = x; 16 | System.out.println("Demo:: Constructor2"); 17 | } 18 | 19 | public void display(){ 20 | System.out.println("Demo :: Method"); 21 | } 22 | 23 | } 24 | public class ReflectionDemo { 25 | 26 | public static void main(String[] args) { 27 | //Class reflection 28 | Class d1 = Demo.class; 29 | System.out.println(d1.getName()); 30 | 31 | //Constructor Reflection 32 | Constructor[] c1 = d1.getDeclaredConstructors(); 33 | System.out.println("Constructor:-------------"); 34 | for(Constructor constructor : c1 ) { 35 | System.out.println(constructor); 36 | } 37 | 38 | 39 | //Method 40 | Method[] m1 = d1.getDeclaredMethods(); 41 | System.out.println("Methods:-------------"); 42 | for(Method method : m1 ) { 43 | System.out.println(method); 44 | } 45 | 46 | //Fields 47 | Field[] f1 = d1.getDeclaredFields(); 48 | System.out.println("Fields:-------------"); 49 | for(Field field : f1 ) { 50 | System.out.println(field); 51 | } 52 | 53 | 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /OOPJ/Day15/StaticInnerClassDemo.java: -------------------------------------------------------------------------------- 1 | package Day15; 2 | 3 | class Oclass{ 4 | static int x = 100; 5 | int a =500; 6 | 7 | static void display(){ 8 | System.out.println("Static method : M1"); 9 | System.out.println(x); 10 | System.out.println(Iclass.y); 11 | //System.out.println(a); 12 | } 13 | 14 | class Iclass{ 15 | static int y = 100; 16 | 17 | static void display1(){ 18 | System.out.println("Static method : M2"); 19 | System.out.println(x); 20 | System.out.println(y); 21 | //System.out.println(a); 22 | } 23 | } 24 | } 25 | public class StaticInnerClassDemo { 26 | 27 | public static void main(String[] args) { 28 | Oclass o1 = new Oclass(); 29 | System.out.println(o1.x); 30 | //System.out.println(o1.y);//Error 31 | 32 | Oclass.display(); 33 | Oclass.Iclass.display1(); 34 | o1.display(); 35 | //o1.display1();//Error 36 | 37 | Oclass.Iclass o2 = o1.new Iclass(); 38 | 39 | //System.out.println(o2.x); 40 | System.out.println(o2.y); 41 | 42 | 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /OOPJ/Day16/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /OOPJ/Day16/ThreadDemo1.java: -------------------------------------------------------------------------------- 1 | package Day16; 2 | //Method 1: Thread class extends 3 | 4 | class MyThread extends Thread{ 5 | public void run() { 6 | for(int i=0;i<5;i++) { 7 | System.out.println(i+" : "+Thread.currentThread().getName()); 8 | } 9 | } 10 | 11 | } 12 | public class ThreadDemo1 { 13 | 14 | public static void main(String[] args) { 15 | MyThread t1 = new MyThread(); 16 | t1.setName("T1"); 17 | MyThread t2 = new MyThread(); 18 | t2.setName("T2"); 19 | MyThread t3 = new MyThread(); 20 | t3.setName("T3"); 21 | MyThread t4 = new MyThread(); 22 | t4.setName("T4"); 23 | 24 | t1.start(); 25 | t2.start(); 26 | t3.start(); 27 | t4.start(); 28 | 29 | 30 | 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /OOPJ/Day16/ThreadDemo10.java: -------------------------------------------------------------------------------- 1 | package Day16; 2 | 3 | public class ThreadDemo10 extends Thread{ 4 | static ThreadDemo10 d3 = new ThreadDemo10(); 5 | static ThreadDemo10 d4 = new ThreadDemo10(); 6 | 7 | synchronized void m1() { 8 | System.out.println(Thread.currentThread().getName()+" started-m1"); 9 | try {Thread.sleep(1000);}catch(InterruptedException e) {} 10 | 11 | synchronized (d3) { 12 | System.out.println("Locked !!"); 13 | } 14 | System.out.println(Thread.currentThread().getName()+" finished-m1"); 15 | } 16 | 17 | synchronized void m2() { 18 | System.out.println(Thread.currentThread().getName()+" started-m1"); 19 | try {Thread.sleep(1000);}catch(InterruptedException e) {} 20 | synchronized (d3) { 21 | System.out.println("Locked !!"); 22 | } 23 | System.out.println(Thread.currentThread().getName()+" finished-m1"); 24 | } 25 | 26 | public static void main(String[] args) { 27 | 28 | ThreadDemo10 d1 = new ThreadDemo10(); 29 | ThreadDemo10 d2 = new ThreadDemo10(); 30 | 31 | Thread t1 = new Thread() { 32 | public void run() { 33 | d3.m1(); 34 | } 35 | }; 36 | Thread t2 = new Thread() { 37 | public void run() { 38 | 39 | d4.m2(); 40 | } 41 | }; 42 | 43 | t1.setName("T1"); 44 | t2.setName("T2"); 45 | t2.start(); 46 | try {Thread.sleep(1000);}catch(InterruptedException e) {} 47 | t1.start(); 48 | 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /OOPJ/Day16/ThreadDemo2.java: -------------------------------------------------------------------------------- 1 | package Day16; 2 | //Method 2: Runnable interface 3 | //Comman sharing task given to differnt threads 4 | 5 | class MyRun implements Runnable{ 6 | 7 | @Override 8 | public void run() { 9 | for(int i=0;i<5;i++) { 10 | System.out.println(i+" : "+Thread.currentThread().getName()); 11 | } 12 | 13 | } 14 | 15 | } 16 | public class ThreadDemo2 { 17 | public static void main(String[] args) { 18 | MyRun r1 = new MyRun(); 19 | 20 | Thread t1 = new Thread(r1,"T1"); 21 | Thread t2 = new Thread(r1,"T2"); 22 | Thread t3 = new Thread(r1,"T3"); 23 | Thread t4 = new Thread(r1,"T4"); 24 | 25 | t1.start(); 26 | t2.start(); 27 | t3.start(); 28 | t4.start(); 29 | 30 | 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /OOPJ/Day16/ThreadDemo3.java: -------------------------------------------------------------------------------- 1 | package Day16; 2 | 3 | class MyRun1 implements Runnable{ 4 | 5 | @Override 6 | public void run() { 7 | for(int i=0;i<5;i++) { 8 | System.out.println(i+" : "+Thread.currentThread().getName()); 9 | } 10 | 11 | } 12 | 13 | } 14 | public class ThreadDemo3 { 15 | 16 | public static void main(String[] args) { 17 | Runnable r1 = () -> { 18 | System.out.println("Lambda expressions are working!"); 19 | }; 20 | 21 | Thread t1 = new Thread(r1); 22 | 23 | t1.start(); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /OOPJ/Day16/ThreadDemo4.java: -------------------------------------------------------------------------------- 1 | package Day16; 2 | 3 | 4 | class AddRunnable implements Runnable{ 5 | @Override 6 | public void run() { 7 | System.out.println(Thread.currentThread().getName()+" started"); 8 | int sum=0; 9 | for(int i=0;i<20;i++) { 10 | sum += i; 11 | } 12 | System.out.println("sum = "+sum+Thread.currentThread().getName()+" Ended"); 13 | 14 | } 15 | } 16 | class MulRunnable implements Runnable{ 17 | @Override 18 | public void run() { 19 | System.out.println(Thread.currentThread().getName()+" started"); 20 | int res=1; 21 | for(int i=1;i<10;i++) { 22 | res *= i; 23 | } 24 | System.out.println("Result = "+res+Thread.currentThread().getName()+" Ended"); 25 | 26 | } 27 | } 28 | public class ThreadDemo4 { 29 | 30 | public static void main(String[] args) { 31 | 32 | Thread t1 = new Thread(new AddRunnable(), "T1"); 33 | Thread t2 = new Thread(new MulRunnable(), "T2"); 34 | 35 | t1.start(); 36 | t2.start(); 37 | 38 | //Using Anonymous Runnable class 39 | 40 | Thread t3 = new Thread(() ->{ 41 | System.out.println(Thread.currentThread().getName()+" started"); 42 | int res=0; 43 | for(int i=1;i<20;i++) { 44 | if(i % 2 == 0)//even 45 | res +=i; 46 | } 47 | System.out.println("Result = "+res+Thread.currentThread().getName()+" Ended"); 48 | 49 | },"T3-EvenAdd"); 50 | 51 | 52 | //Using Lambda Expression 53 | Thread t4 = new Thread(() -> { 54 | System.out.println(Thread.currentThread().getName()+" started"); 55 | int res=0; 56 | for(int i=1;i<20;i++) { 57 | if(i % 2 != 0) //Odd 58 | res +=i; 59 | } 60 | System.out.println("Result = "+res+Thread.currentThread().getName()+" Ended"); 61 | 62 | },"T4-OddAdd"); 63 | 64 | t3.start(); 65 | t4.start(); 66 | 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /OOPJ/Day16/ThreadDemo5.java: -------------------------------------------------------------------------------- 1 | package Day16; 2 | //Execution of join(): To take the controll of execution 3 | 4 | class MyThread1 extends Thread{ 5 | public void run() { 6 | for(int i=0;i<5;i++) { 7 | System.out.println(i+" : "+Thread.currentThread().getName()); 8 | 9 | } 10 | } 11 | 12 | } 13 | public class ThreadDemo5 { 14 | 15 | public static void main(String[] args) { 16 | System.out.println(Thread.currentThread().getName()+" started"); 17 | MyThread1 t1 = new MyThread1();t1.setName("T1"); 18 | MyThread1 t2 = new MyThread1();t2.setName("T2"); 19 | MyThread1 t3 = new MyThread1();t3.setName("T3"); 20 | MyThread1 t4 = new MyThread1();t4.setName("T4"); 21 | 22 | t1.start(); 23 | t2.start(); 24 | t3.start(); 25 | 26 | //join(): ensures t3 thread completes before t4 27 | try { 28 | t3.join();// throws exception e 29 | }catch(InterruptedException e) { 30 | e.printStackTrace(); 31 | }finally { 32 | System.out.println("Executed!"); 33 | } 34 | 35 | t4.start(); 36 | 37 | 38 | 39 | System.out.println(Thread.currentThread().getName()+" Finished"); 40 | 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /OOPJ/Day16/ThreadDemo6.java: -------------------------------------------------------------------------------- 1 | package Day16; 2 | //sleep(): introduce delay to stagger execution 3 | 4 | class MyThread2 extends Thread{ 5 | public void run() { 6 | for(int i=0;i<5;i++) { 7 | System.out.println(i+" : "+Thread.currentThread().getName()); 8 | 9 | } 10 | System.out.println(Thread.currentThread().getName()+"Sleeeping......"); 11 | try { 12 | Thread.sleep(10000);//throws an exception e 13 | }catch(InterruptedException e) { 14 | e.printStackTrace(); 15 | } 16 | System.out.println(Thread.currentThread().getName()+"Awaking and work done......"); 17 | 18 | } 19 | 20 | } 21 | public class ThreadDemo6 { 22 | 23 | public static void main(String[] args) { 24 | System.out.println(Thread.currentThread().getName()+" Started"); 25 | 26 | MyThread2 t1 = new MyThread2(); 27 | MyThread2 t2 = new MyThread2(); 28 | MyThread2 t3 = new MyThread2(); 29 | MyThread2 t4 = new MyThread2(); 30 | 31 | t1.start(); 32 | try {Thread.sleep(1000);}catch(InterruptedException e) {} 33 | t2.start(); 34 | try {Thread.sleep(1000);}catch(InterruptedException e) {} 35 | t3.start(); 36 | try {Thread.sleep(1000);}catch(InterruptedException e) {} 37 | t4.start(); 38 | try {Thread.sleep(1000);}catch(InterruptedException e) {} 39 | System.out.println(Thread.currentThread().getName()+" Finished"); 40 | 41 | 42 | 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /OOPJ/Day16/ThreadDemo7.java: -------------------------------------------------------------------------------- 1 | package Day16; 2 | 3 | class Counter extends Thread{ 4 | int count = 0; 5 | void increment() { 6 | count++; 7 | } 8 | } 9 | public class ThreadDemo7 { 10 | 11 | public static void main(String[] args) throws InterruptedException{ 12 | System.out.println(Thread.currentThread().getName()+" started"); 13 | Counter c1 = new Counter(); 14 | 15 | Thread t1 = new Thread(() ->{ 16 | for(int i=0;i<1000;i++) { 17 | c1.increment(); 18 | } 19 | }," T1"); 20 | 21 | Thread t2 = new Thread(() ->{ 22 | for(int i=0;i<1000;i++) { 23 | c1.increment(); 24 | } 25 | }," T2"); 26 | 27 | t1.start(); 28 | t2.start(); 29 | 30 | t1.join(); 31 | t2.join(); 32 | 33 | System.out.println("Count = "+ c1.count); 34 | System.out.println(Thread.currentThread().getName()+" finished"); 35 | 36 | 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /OOPJ/Day16/ThreadDemo8.java: -------------------------------------------------------------------------------- 1 | package Day16; 2 | 3 | class Counter1 extends Thread{ 4 | int count = 0; 5 | //ensure mutual exclusion 6 | synchronized void increment() { 7 | count++; 8 | } 9 | } 10 | public class ThreadDemo8 { 11 | 12 | public static void main(String[] args) throws InterruptedException{ 13 | System.out.println(Thread.currentThread().getName()+" started"); 14 | Counter1 c1 = new Counter1(); 15 | 16 | Thread t1 = new Thread(() ->{ 17 | for(int i=0;i<1000;i++) { 18 | c1.increment(); 19 | } 20 | }," T1"); 21 | 22 | Thread t2 = new Thread(() ->{ 23 | for(int i=0;i<1000;i++) { 24 | c1.increment(); 25 | } 26 | }," T2"); 27 | 28 | t1.start(); 29 | t2.start(); 30 | 31 | t1.join(); 32 | t2.join(); 33 | 34 | System.out.println("Count = "+ c1.count); 35 | System.out.println(Thread.currentThread().getName()+" finished"); 36 | 37 | 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /OOPJ/Day16/ThreadDemo9.java: -------------------------------------------------------------------------------- 1 | package Day16; 2 | 3 | class Sync extends Thread{ 4 | synchronized void m1(){ 5 | System.out.println(Thread.currentThread().getName()+" started-1"); 6 | try {Thread.sleep(1000);}catch(InterruptedException e) {} 7 | System.out.println(Thread.currentThread().getName()+" finished-1"); 8 | 9 | } 10 | synchronized void m2(){ 11 | System.out.println(Thread.currentThread().getName()+" started-2"); 12 | try {Thread.sleep(1000);}catch(InterruptedException e) {} 13 | System.out.println(Thread.currentThread().getName()+" finished-2"); 14 | 15 | } 16 | void m3(){ 17 | System.out.println(Thread.currentThread().getName()+" started-3"); 18 | try {Thread.sleep(1000);}catch(InterruptedException e) {} 19 | System.out.println(Thread.currentThread().getName()+" finished-3"); 20 | 21 | } 22 | 23 | synchronized static void m4(){ 24 | System.out.println(Thread.currentThread().getName()+" started-4"); 25 | try {Thread.sleep(1000);}catch(InterruptedException e) {} 26 | System.out.println(Thread.currentThread().getName()+" finished-4"); 27 | 28 | } 29 | 30 | synchronized static void m5(){ 31 | System.out.println(Thread.currentThread().getName()+" started-5"); 32 | try {Thread.sleep(1000);}catch(InterruptedException e) {} 33 | System.out.println(Thread.currentThread().getName()+" finished-5"); 34 | 35 | } 36 | 37 | static void m6(){ 38 | System.out.println(Thread.currentThread().getName()+" started"); 39 | try {Thread.sleep(1000);}catch(InterruptedException e) {} 40 | System.out.println(Thread.currentThread().getName()+" finished"); 41 | 42 | } 43 | } 44 | public class ThreadDemo9 { 45 | 46 | public static void main(String[] args) { 47 | Sync s1 = new Sync(); 48 | Sync s2 = new Sync(); 49 | 50 | Thread t1 = new Thread() { 51 | public void run() { 52 | s2.m1(); 53 | } 54 | }; 55 | 56 | Thread t2 = new Thread() { 57 | public void run() { 58 | s2.m1(); 59 | //s2.m2(); 60 | } 61 | }; 62 | 63 | t1.setName("T1"); 64 | t2.setName("T2"); 65 | t2.start(); 66 | try {Thread.sleep(1000);}catch(InterruptedException e) {} 67 | t1.start(); 68 | 69 | 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /OOPJ/Feb25 Day1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/OOPJ/Feb25 Day1.pdf -------------------------------------------------------------------------------- /OOPJ/Feb25 Day10.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/OOPJ/Feb25 Day10.pdf -------------------------------------------------------------------------------- /OOPJ/Feb25 Day11.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/OOPJ/Feb25 Day11.pdf -------------------------------------------------------------------------------- /OOPJ/Feb25 Day13.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/OOPJ/Feb25 Day13.pdf -------------------------------------------------------------------------------- /OOPJ/Feb25 Day14.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/OOPJ/Feb25 Day14.pdf -------------------------------------------------------------------------------- /OOPJ/Feb25 Day15.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/OOPJ/Feb25 Day15.pdf -------------------------------------------------------------------------------- /OOPJ/Feb25 Day2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/OOPJ/Feb25 Day2.pdf -------------------------------------------------------------------------------- /OOPJ/Feb25 Day3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/OOPJ/Feb25 Day3.pdf -------------------------------------------------------------------------------- /OOPJ/Feb25 Day4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/OOPJ/Feb25 Day4.pdf -------------------------------------------------------------------------------- /OOPJ/Feb25 Day5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/OOPJ/Feb25 Day5.pdf -------------------------------------------------------------------------------- /OOPJ/Feb25 Day6.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/OOPJ/Feb25 Day6.pdf -------------------------------------------------------------------------------- /OOPJ/Feb25 Day7.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/OOPJ/Feb25 Day7.pdf -------------------------------------------------------------------------------- /OOPJ/Feb25 Day8.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/OOPJ/Feb25 Day8.pdf -------------------------------------------------------------------------------- /OOPJ/Feb25 Day9.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kiranwaghmare123/PG-DAC-Feb2025/dd06cd7cf8c25dfc6c1c220248ab0188a32dc34b/OOPJ/Feb25 Day9.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PG-DAC-Feb2025 2 | 3 | --------------------------------------------------------------------------------