├── 09_Oops ├── Packages │ └── Cal │ │ ├── .settings │ │ ├── org.eclipse.core.resources.prefs │ │ └── org.eclipse.jdt.core.prefs │ │ ├── src │ │ ├── module-info.java │ │ └── com │ │ │ └── pg │ │ │ └── cal │ │ │ ├── add │ │ │ └── Add.java │ │ │ └── sub │ │ │ └── Sub.java │ │ ├── bin │ │ ├── module-info.class │ │ └── com │ │ │ └── pg │ │ │ └── cal │ │ │ ├── add │ │ │ └── Add.class │ │ │ └── sub │ │ │ └── Sub.class │ │ ├── .classpath │ │ └── .project ├── _10_Types_Of_Inheritance.java ├── _12_Hierarchical_Inheritance.java ├── _29_Dependency_Injection_ex1.java ├── _11_Multi_Level_Inheritance.java ├── _04_Introduction_to_Constructor.java ├── _17_Rule_to_override_method.java ├── _05_More_on_Constructor.java ├── _02_Shadowing_Problem_Solve_using_this_keyword.java ├── _01_Introduction_to_Encapsulation.java ├── _08_Introduction_to_Inheritance.java ├── _26_Oops_Area_of_Circle.java ├── _25_Oops_Area_of_Square.java ├── _30_NoDuplicates.java ├── _19_Introduction_to_Polymorphism.java ├── _24_Oops_Area_of_Rectangle.java ├── _28_Dependency_Injection.java ├── _13_Types_Of_Method_Inherited.java ├── _06_Constructor_Overloading.java ├── _09_More_On_Inheritance.java ├── _07_this_Method_in_Constructor.java ├── _18_Constructor_execution_in_case_of_inheritance.java ├── _23_Final_Keyword_in_java.java ├── _14_Types_Of_Method_Overidden.java ├── _16_Access_Modifiers.java └── _15_Types_Of_Method_Specizlized.java ├── 17_IO_Operation ├── Hey │ ├── hey.txt │ └── pw.txt ├── _01_Fundamentals_Before_IO_Operation.pdf ├── _03_Create_File_in_Dir.java ├── _04_Check_How_Many_File_in_Dir.java ├── _07_More_On_FileReader.java ├── _06_Reading_Data_Onto_File_using_FileReader.java ├── _02_Introduction_To_IO.java ├── _01_Fundamentals_Before_IO_Operation.java ├── _08_BufferedWriter_And_FileWriter.java ├── _11_Introduction_to_Serialization_and_Deserialization.java ├── _09_BufferedReader_And_FileReader.java ├── _05_Writing_Data_Onto_File_using_FileWriter.java └── _10_Write_Operation_With_PrintWriter.java ├── 13_CollectionFrameWork ├── _pdf_HashSet.pdf ├── _pdf_TreeSet.pdf ├── _pdf_ArrayList.pdf ├── _pdf_LinkedList.pdf ├── _pdf_PriorityQueue.pdf ├── _pdf_WhyCollection.pdf ├── _16_Vector.java ├── _15_FailSafeExample.java ├── _11_Enumeration.java ├── _14_FailFastExample.java ├── _12_Iterator.java └── _03_More_on_ArrayLIst.java ├── 05_Oops_Fundamentals ├── Oops fundamental.pdf ├── _Test.java ├── Method_Overloading.java └── Automatic_Promotion_in_Overloading.java ├── 20_Recursion ├── _01_Introduction_to_Recursion.pdf ├── _13_Valid_Parentheses_Using_Recursion.java ├── _02_Sum_Of_N_Number.java ├── _03_factorial_Using_Recursion.java ├── _05_Finding_Of_Power_Brute_Force.java ├── _04_Fibonacci_Using_Recursion.java ├── _08_Number_Of_Stairs.java ├── _10_Sum_Of_Digit_Using_Recursion.java ├── _14_printBoardPaths_Using_Recursion.java ├── _11_Multiply_Of_an_Number.java ├── _12_Alternate_Sign_Series_Sum.java ├── _06_Finding_Of_Power_Optimized_Approach.java └── _07_Finding_Of_Power_Using_BigInteger.java ├── 18_Complexity_Analysis_and_Array ├── _02_SpaceComplexity.pdf ├── _01_IntroductiontoDSAandTimeComplexity.pdf ├── _03_RecurrenceRelationSolvingSubstitutionMethod.pdf ├── _05_Recurrence_Relation_Solving_Masters_Theorem.pdf ├── _04_Recurrence_Relation_Solving_Recursive_Tree_Method.pdf ├── _09_Duplicate_Elements_Finding.java ├── _06_Palindrome_Array.java ├── _07_Reversal_In_An_Array.java └── _08_Missing_number_In_An_Array.java ├── 19_Searching_Sorting_and_Bit_Manipulation ├── _09_Number_System.pdf ├── _10_Bit_Manipulation.pdf ├── _01_Linear_Search.java ├── _02_Binary_Search.java ├── _04_SquareRoot_Using_BinarySearch.java ├── _06_Insertion_Sort.java ├── _05_Bubble_Sort.java └── _07_Selection_Sort.java ├── 03_Fundamentals_of_Java ├── _01_Boilerplate_of_java_program.java ├── _06_Variables_special_declearation_in_java.java ├── _02_Main_Method_in_java.java ├── _05_Variables_examples_in_java.java ├── _10_Datatypes_Logical_with_Example.java ├── _13_TypeCasting_explicit.java ├── _00_How_java_run.java ├── _03_String_args_in_java.java ├── _07_Datatypes_Introduction.java ├── _12_TypeCasting_Implicit.java ├── _16_Naming_Convention.java ├── _14_TypeCasting_Truncation.java ├── _15_Identifiers.java ├── _04_Variables_in_java.java └── _11_Datatypes_Characters_with_Example.java ├── 30_Dynamic_Programming ├── _11_RodCutting.java ├── _02_FibonacciUsingDP_Tabulation.java ├── _01_FibonacciUsingDP_Memorization.java ├── _03_ClimbingStairs_DP_Memorization.java ├── _04_ClimbingStairsVariation_DP_Tabulation.java ├── _05_0_1_Knapsack_Recursion.java ├── _06_0_1_Knapsack_Memorization.java └── _10_CoinChangeDP_Tabulation.java ├── 22_LinkedList ├── _01_LinkedList_Node.java ├── _02_LinkedList_display.java └── _04_InsertionAtBeginning_LinkedList.java ├── 12_MultiThreading ├── _03_How_To_Create_Threads.java ├── _01_Introduction_to_Multithreading.java ├── _10_Interrupt_In_Threading.java ├── _09_IsAliveMethod_In_Threading.java ├── _08_JoinMethod_In_Threading.java ├── _02_Change_Threads_Property.java └── _04_Multiple_Threads_Creating.java ├── 08_Strings ├── _01_String_Introduction.java ├── _05_equals_Method_String.java ├── _19_split_Method_String.java ├── _04_Ways_of_Comparison.java ├── _06_equalsIgnoreCase_Method_String.java ├── _18_StringBuffer_vs_StringBuilder.java ├── _08_Concatenation_Method2_String.java ├── _07_Concatenation_Method_String.java ├── _15_Introduction_to_Mutable_String.java ├── _14_Pangram_Program.java ├── _09_Concatenation_Method3_String.java ├── _10_String_Mthods_in_java.java ├── _16_final_vs_Immutability.java ├── _20_Static_keyword.java ├── _02_Type_Of_Strings.java └── _12_Palindrome_Program.java ├── 10_Interfacr_&_Lambda_Expression ├── _13_AnnonymousInnerClass.java ├── _15_InnerClass.java ├── _08_What_is_InnerClass_in_java.java ├── _11_StaticClass.java ├── _01_What_is_Interface.java ├── _02_More_On_Interface.java ├── _07_Functional_Interface.java ├── _09_MemberClass.java ├── _04_Implementation_of_Interface.java ├── _10_NonStatic_InnerClass.java ├── _12_StaticNestedClass.java ├── _14_Lambda_Expression.java ├── _03_Interface_Small_Project.java └── _06_Java8_Features.java ├── 07_Arrays ├── _07_Enhanced_For_Loop_for_2D_Array.java ├── _10_ArrayIndexOutOfBoundsException.java ├── _01_Create_An_Array.java ├── _02_Array_Assign_Value.java ├── _06_Enhanced_For_Loop.java ├── _09_Anonymous_Array.java ├── _03_Array_Input_Output_using_methods.java └── _04_2D_Array_Input_Output.java ├── 26_Tree ├── _02_BTCountLeaves.java ├── _01_Tree.java └── _06_Height_Of_Tree.java ├── 11_Exception_Handling ├── _05_Exception_Handling_TryWithResources.java ├── _04_Exception_Handling_TryFinally.java ├── _02_Exception_Handling_Using_TryCatch.java ├── _01_Types_of_Errors.java ├── _07_Custom_Exception_And_Throw_Keyword.java ├── _03_Exception_Handling_TryWithMultipleCatchBlocks.java └── _06_EH_Handling_vs_Ducking.java ├── 23_HashMap_Stack_and_Queue ├── _12_Deque.java ├── _09_Queue.java ├── _04_First_Non_Repeating_character_HashMap.java ├── _02_Types_Of_Map.java ├── _05_Stack.java └── _13_slidingWindow_Using_Deque.java ├── 03_Operators_and_Loops ├── _12_Loops_what_is_loop.java ├── _13_Loop_forLoop_In_java.java ├── _14_Loop_whlileLoop.java ├── _04_Decrementation_Operators.java ├── _15_Loop_do_whileLoop_in_java.java ├── _03_Incrementation_Operators.java ├── _20_Print_vs_Println_in_java.java ├── _01_Operators_introduction.java ├── _17_continue_in_java.java ├── _16_break_in_java.java ├── _21_Nested_loop_in_java.java ├── _18_label_in_java.java ├── _02_Arithmetic_Operators.java ├── _11_Switch_case.java ├── _06_Assignment_Operator.java └── _08_Logical_Operators.java ├── 28_Priority_Queue ├── _05_PriorityQueue_min.java ├── _06_PriorityQueue_max.java ├── _09_KthLargestElement.java ├── _07_PriorityQueue_for_Objects_min.java └── _08_PriorityQueue_for_Objects_max.java ├── 04_Star_Pattern's ├── _01_Square_Pattern_In_java.java ├── _02_Rectange_Pattern_in_java.java ├── _04_Right_Triangle_Star_Pattern.java ├── _07_Downward_Triangle_Star_Pattern.java ├── _03_Pyramid_Program.java ├── _20_Hollow_Power_Drum_in_java.java ├── _10_Right_down_Mirror_Pattern.java ├── _22_Hollow_Multi_Rhombus_In_Rectange.java ├── _09_Reversed_Pyramid_Pattern.java ├── _16_Hollow_F_Pattern_in_java.java ├── _15_Hollow_E_Pattern_in_java.java ├── _05_Left_Triangle_Star_Pattern.java ├── _13_Hollow_H_Pattern_in_java.java ├── _21_Hollow_Rhombus_Pattern.java ├── _14_Hollow_I_Pattern_in_java.java ├── _17_Hollow_Advance_A_Pattern_in_java.java ├── _12_Hollow_A_Pattern_in_java.java ├── _08_Mirrored_Right_Triangle_Pattern.java ├── _18_Hollow_Advance_D_Pattern_in_java.java ├── _11_Hollow_Recttangle_in_java.java ├── _19_Hollow_Advance_X_Pattern_in_java.java ├── _23_Upper_Left_Triangle.java ├── _25_Lower_Left_Triangle.java ├── _26_Lower_Right_Triangle.java └── _24_Upper_Right_Triangle.java ├── 15_Map_and_Generics ├── _13_Generics.java ├── _14_More_On_Generics.java ├── _09_HashMap.java └── _10_WeakHashMap.java ├── 16_Important_API's_and_Annotation ├── _06_More_On_StreamAPI_wayTwo.java ├── _10_Enum_and_Switch_Case.java ├── _01_Date_and_Time.java └── _03_ForEach_Method.java ├── README.md ├── 24_Divide_and_Conquer └── _08_FindPeakElement_Using_DC.java ├── 21_Backtracking ├── _01_Tiling_Problem_Using_Backtracking.java ├── _10_Permutations_Using_Backtracking.java ├── _03_PrintAllPermutations_using_Backtracking.java └── _02_PrintAllSequencens_Using_Backtracking.java └── 25_Greedy_Algorithms └── _04_Minimum_Number_of_Swaps.java /09_Oops/Packages/Cal/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /09_Oops/Packages/Cal/src/module-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | /** 5 | * @author priyanshugour70 6 | * 7 | */ 8 | module Cal { 9 | } -------------------------------------------------------------------------------- /17_IO_Operation/Hey/hey.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priyanshugour70/Java-with-DSA-and-system-design/HEAD/17_IO_Operation/Hey/hey.txt -------------------------------------------------------------------------------- /17_IO_Operation/Hey/pw.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priyanshugour70/Java-with-DSA-and-system-design/HEAD/17_IO_Operation/Hey/pw.txt -------------------------------------------------------------------------------- /13_CollectionFrameWork/_pdf_HashSet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priyanshugour70/Java-with-DSA-and-system-design/HEAD/13_CollectionFrameWork/_pdf_HashSet.pdf -------------------------------------------------------------------------------- /13_CollectionFrameWork/_pdf_TreeSet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priyanshugour70/Java-with-DSA-and-system-design/HEAD/13_CollectionFrameWork/_pdf_TreeSet.pdf -------------------------------------------------------------------------------- /05_Oops_Fundamentals/Oops fundamental.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priyanshugour70/Java-with-DSA-and-system-design/HEAD/05_Oops_Fundamentals/Oops fundamental.pdf -------------------------------------------------------------------------------- /09_Oops/Packages/Cal/bin/module-info.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priyanshugour70/Java-with-DSA-and-system-design/HEAD/09_Oops/Packages/Cal/bin/module-info.class -------------------------------------------------------------------------------- /13_CollectionFrameWork/_pdf_ArrayList.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priyanshugour70/Java-with-DSA-and-system-design/HEAD/13_CollectionFrameWork/_pdf_ArrayList.pdf -------------------------------------------------------------------------------- /13_CollectionFrameWork/_pdf_LinkedList.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priyanshugour70/Java-with-DSA-and-system-design/HEAD/13_CollectionFrameWork/_pdf_LinkedList.pdf -------------------------------------------------------------------------------- /13_CollectionFrameWork/_pdf_PriorityQueue.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priyanshugour70/Java-with-DSA-and-system-design/HEAD/13_CollectionFrameWork/_pdf_PriorityQueue.pdf -------------------------------------------------------------------------------- /13_CollectionFrameWork/_pdf_WhyCollection.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priyanshugour70/Java-with-DSA-and-system-design/HEAD/13_CollectionFrameWork/_pdf_WhyCollection.pdf -------------------------------------------------------------------------------- /20_Recursion/_01_Introduction_to_Recursion.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priyanshugour70/Java-with-DSA-and-system-design/HEAD/20_Recursion/_01_Introduction_to_Recursion.pdf -------------------------------------------------------------------------------- /09_Oops/Packages/Cal/bin/com/pg/cal/add/Add.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priyanshugour70/Java-with-DSA-and-system-design/HEAD/09_Oops/Packages/Cal/bin/com/pg/cal/add/Add.class -------------------------------------------------------------------------------- /09_Oops/Packages/Cal/bin/com/pg/cal/sub/Sub.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priyanshugour70/Java-with-DSA-and-system-design/HEAD/09_Oops/Packages/Cal/bin/com/pg/cal/sub/Sub.class -------------------------------------------------------------------------------- /17_IO_Operation/_01_Fundamentals_Before_IO_Operation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priyanshugour70/Java-with-DSA-and-system-design/HEAD/17_IO_Operation/_01_Fundamentals_Before_IO_Operation.pdf -------------------------------------------------------------------------------- /18_Complexity_Analysis_and_Array/_02_SpaceComplexity.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priyanshugour70/Java-with-DSA-and-system-design/HEAD/18_Complexity_Analysis_and_Array/_02_SpaceComplexity.pdf -------------------------------------------------------------------------------- /19_Searching_Sorting_and_Bit_Manipulation/_09_Number_System.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priyanshugour70/Java-with-DSA-and-system-design/HEAD/19_Searching_Sorting_and_Bit_Manipulation/_09_Number_System.pdf -------------------------------------------------------------------------------- /03_Fundamentals_of_Java/_01_Boilerplate_of_java_program.java: -------------------------------------------------------------------------------- 1 | public class _01_Boilerplate_of_java_program { 2 | public static void main(String args[]){ 3 | System.out.println("Hello World"); 4 | } 5 | } -------------------------------------------------------------------------------- /19_Searching_Sorting_and_Bit_Manipulation/_10_Bit_Manipulation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priyanshugour70/Java-with-DSA-and-system-design/HEAD/19_Searching_Sorting_and_Bit_Manipulation/_10_Bit_Manipulation.pdf -------------------------------------------------------------------------------- /09_Oops/Packages/Cal/src/com/pg/cal/add/Add.java: -------------------------------------------------------------------------------- 1 | package com.pg.cal.add; 2 | 3 | public class Add { 4 | 5 | public static void main(String[] args) { 6 | // TODO Auto-generated method stub 7 | 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /09_Oops/Packages/Cal/src/com/pg/cal/sub/Sub.java: -------------------------------------------------------------------------------- 1 | package com.pg.cal.sub; 2 | 3 | public class Sub { 4 | 5 | public static void main(String[] args) { 6 | // TODO Auto-generated method stub 7 | 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /18_Complexity_Analysis_and_Array/_01_IntroductiontoDSAandTimeComplexity.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priyanshugour70/Java-with-DSA-and-system-design/HEAD/18_Complexity_Analysis_and_Array/_01_IntroductiontoDSAandTimeComplexity.pdf -------------------------------------------------------------------------------- /18_Complexity_Analysis_and_Array/_03_RecurrenceRelationSolvingSubstitutionMethod.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priyanshugour70/Java-with-DSA-and-system-design/HEAD/18_Complexity_Analysis_and_Array/_03_RecurrenceRelationSolvingSubstitutionMethod.pdf -------------------------------------------------------------------------------- /18_Complexity_Analysis_and_Array/_05_Recurrence_Relation_Solving_Masters_Theorem.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priyanshugour70/Java-with-DSA-and-system-design/HEAD/18_Complexity_Analysis_and_Array/_05_Recurrence_Relation_Solving_Masters_Theorem.pdf -------------------------------------------------------------------------------- /18_Complexity_Analysis_and_Array/_04_Recurrence_Relation_Solving_Recursive_Tree_Method.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priyanshugour70/Java-with-DSA-and-system-design/HEAD/18_Complexity_Analysis_and_Array/_04_Recurrence_Relation_Solving_Recursive_Tree_Method.pdf -------------------------------------------------------------------------------- /30_Dynamic_Programming/_11_RodCutting.java: -------------------------------------------------------------------------------- 1 | // In this problem we have given a rod of length n and we have to cut it in such a way that we get maximum profit. 2 | 3 | public class _11_RodCutting { 4 | public static void main(String[] args) { 5 | 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /22_LinkedList/_01_LinkedList_Node.java: -------------------------------------------------------------------------------- 1 | public class _01_LinkedList_Node { 2 | 3 | class Node { 4 | int data; 5 | Node next; 6 | 7 | Node(int data) { 8 | this.data = data; 9 | this.next = null; 10 | } 11 | } 12 | 13 | public static void main(String[] args) { 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /12_MultiThreading/_03_How_To_Create_Threads.java: -------------------------------------------------------------------------------- 1 | 2 | class MyThread extends Thread { 3 | 4 | public void run() { 5 | System.out.println("Child Thread ..!"); 6 | } 7 | } 8 | 9 | public class _03_How_To_Create_Threads { 10 | 11 | public static void main(String[] args) { 12 | 13 | Thread t = new MyThread(); 14 | t.start(); 15 | System.out.println("Main Thread.."); 16 | } 17 | } -------------------------------------------------------------------------------- /08_Strings/_01_String_Introduction.java: -------------------------------------------------------------------------------- 1 | public class _01_String_Introduction { 2 | 3 | public static void main(String args[]){ 4 | 5 | // Collection of Character in doublecorts(" Priyanshu ").. 6 | // Stings are Store in Heap and String Packege is (java.lang.string) 7 | 8 | String myName = "Priyanshu Gour" ; // This is Known as String .. 9 | 10 | System.out.println(myName); 11 | } 12 | } -------------------------------------------------------------------------------- /10_Interfacr_&_Lambda_Expression/_13_AnnonymousInnerClass.java: -------------------------------------------------------------------------------- 1 | interface P { 2 | 3 | void name(); 4 | } 5 | 6 | public class _13_AnnonymousInnerClass { 7 | public static void main(String[] args) { 8 | 9 | P p = new P() { 10 | public void name (){ 11 | System.out.println("hey I am Priyanshu Gour"); 12 | } 13 | }; 14 | 15 | p.name(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /10_Interfacr_&_Lambda_Expression/_15_InnerClass.java: -------------------------------------------------------------------------------- 1 | public class _15_InnerClass { 2 | 3 | 4 | class Inner15 { 5 | 6 | void disp(){ 7 | System.out.println("I am the Inner of the Class.."); 8 | } 9 | } 10 | 11 | public static void main(String[] args) { 12 | 13 | _15_InnerClass.Inner15 e = new _15_InnerClass().new Inner15(); 14 | 15 | e.disp(); 16 | } 17 | } -------------------------------------------------------------------------------- /03_Fundamentals_of_Java/_06_Variables_special_declearation_in_java.java: -------------------------------------------------------------------------------- 1 | public class _06_Variables_special_declearation_in_java { 2 | 3 | 4 | public static void main(String args[]){ 5 | 6 | 7 | // only two Special Character use for creating a Variable.. 8 | 9 | int _hlo = 2332 ; 10 | int $bye = 4343 ; 11 | 12 | System.out.println(_hlo); 13 | System.out.println($bye); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /07_Arrays/_07_Enhanced_For_Loop_for_2D_Array.java: -------------------------------------------------------------------------------- 1 | public class _07_Enhanced_For_Loop_for_2D_Array { 2 | 3 | public static void main(String[] args) { 4 | 5 | int nums[][] = {{1,2,3,4,5},{5,4,3,2,1},{7,8,9,8,7}}; 6 | 7 | for(int a[] : nums){ 8 | for(int b : a){ 9 | System.out.print(b + ", "); 10 | } 11 | System.out.println(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /09_Oops/Packages/Cal/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /26_Tree/_02_BTCountLeaves.java: -------------------------------------------------------------------------------- 1 | 2 | class Tree{ 3 | int countLeaves(Node node){ 4 | if(node==null){ 5 | return 0; 6 | } 7 | if(node.left==null && node.right==null){ 8 | return 1; 9 | } 10 | return countLeaves(node.left)+countLeaves(node.right); 11 | } 12 | } 13 | public class _02_BTCountLeaves { 14 | public static void main(String[] args) { 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /17_IO_Operation/_03_Create_File_in_Dir.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | public class _03_Create_File_in_Dir { 4 | public static void main(String[] args) throws IOException { 5 | 6 | File dir = new File("JAVA"); 7 | System.out.println(dir.isDirectory()); 8 | 9 | dir.mkdir(); 10 | 11 | File file = new File(dir, "HelloWorld.java"); 12 | file.createNewFile(); 13 | System.out.println(file.isFile()); 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /11_Exception_Handling/_05_Exception_Handling_TryWithResources.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class _05_Exception_Handling_TryWithResources { 4 | 5 | public static void main(String[] args) { 6 | 7 | int x = 0; 8 | 9 | try (Scanner sc = new Scanner(System.in)) { // After Input the file is direct Close without use sc.close() 10 | x = sc.nextInt(); 11 | } 12 | 13 | System.out.println(x); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /11_Exception_Handling/_04_Exception_Handling_TryFinally.java: -------------------------------------------------------------------------------- 1 | public class _04_Exception_Handling_TryFinally { 2 | 3 | public static void main(String[] args) { 4 | 5 | try { 6 | System.out.println("try block executed"); 7 | } catch (ArithmeticException e) { 8 | System.out.println("catch block executed"); 9 | } finally { 10 | System.out.println("finally block executed"); 11 | } 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /23_HashMap_Stack_and_Queue/_12_Deque.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayDeque; 2 | import java.util.Deque; 3 | 4 | public class _12_Deque { 5 | public static void main(String[] args) { 6 | Deque deque = new ArrayDeque<>(); 7 | deque.addFirst(1); 8 | deque.addLast(2); 9 | int first = deque.removeFirst(); 10 | int last = deque.removeLast(); 11 | System.out.println("First: " + first + ", Last: " + last); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /03_Operators_and_Loops/_12_Loops_what_is_loop.java: -------------------------------------------------------------------------------- 1 | public class _12_Loops_what_is_loop { 2 | 3 | 4 | public static void main(String args[]){ 5 | 6 | 7 | // In programming, a loop is a way to repeatedly execute a block of code until a certain condition is met. There are three main types of loops in Java: 8 | 9 | // for loop 10 | // while loop 11 | // do-while loop 12 | 13 | // we will discuss sepratly.. 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /07_Arrays/_10_ArrayIndexOutOfBoundsException.java: -------------------------------------------------------------------------------- 1 | public class _10_ArrayIndexOutOfBoundsException { 2 | 3 | public static void main(String args[]){ 4 | 5 | int nums[] = {1,2,3,4,5}; 6 | 7 | System.out.println(nums[5]); // This is an Exception (ArrayIndexOutOfBoundsException) Because Index value is larger or outoff arrary size.. 8 | 9 | System.out.println(nums[nums.length - 1 ]); // This is a way to Handle this Exception 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /10_Interfacr_&_Lambda_Expression/_08_What_is_InnerClass_in_java.java: -------------------------------------------------------------------------------- 1 | public class _08_What_is_InnerClass_in_java { 2 | 3 | public static void main(String[] args) { 4 | 5 | // In Java, an inner class is a class that is defined inside another class. There are four types of inner classes in Java: 6 | 7 | // (1) Non-static or Inner Class 8 | // (2) Static Nested Class 9 | // (3) Member Class 10 | // (4) Anonymous Inner Class 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /03_Fundamentals_of_Java/_02_Main_Method_in_java.java: -------------------------------------------------------------------------------- 1 | public class _02_Main_Method_in_java { 2 | 3 | public static void main(String args []){ 4 | // The First Program run using Main method and the program name and the class name was same which class name same which hold the main method and main method in inbuild method 5 | // public static void main (String args[]){} this is known as main method and main method id the first methond which run firstly in the whole program .. 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /08_Strings/_05_equals_Method_String.java: -------------------------------------------------------------------------------- 1 | public class _05_equals_Method_String { 2 | 3 | public static void main(String[] args) { 4 | // in (equals()) this method java check Value . 5 | 6 | // Normal String Method 7 | String s1 = "Priyanshu" ; 8 | 9 | // Object String Method 10 | String s2 = new String("Priyanshu"); 11 | 12 | 13 | // equals(); 14 | boolean check = s1.equals(s2) ; 15 | System.out.println(check); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /08_Strings/_19_split_Method_String.java: -------------------------------------------------------------------------------- 1 | public class _19_split_Method_String { 2 | 3 | public static void main(String[] args) { 4 | 5 | // The split() method in Java is used to split a string into an array of substrings based on a specified delimiter. It takes a regular expression as its argument and returns an array of strings. 6 | 7 | String str = "Hello World i am Java"; 8 | String[] arr = str.split(" "); 9 | System.out.println(arr[1]); 10 | 11 | } 12 | } -------------------------------------------------------------------------------- /22_LinkedList/_02_LinkedList_display.java: -------------------------------------------------------------------------------- 1 | public class _02_LinkedList_display { 2 | 3 | Node head; 4 | 5 | class Node { 6 | int data; 7 | Node next; 8 | 9 | Node(int data) { 10 | this.data = data; 11 | this.next = null; 12 | } 13 | } 14 | 15 | public void display() { 16 | Node current = head; 17 | while (current != null) { 18 | System.out.print(current.data + " "); 19 | return; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /17_IO_Operation/_04_Check_How_Many_File_in_Dir.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | public class _04_Check_How_Many_File_in_Dir { 4 | public static void main(String[] args) throws IOException { 5 | int count = 0; 6 | File f = new File("JAVA"); 7 | 8 | String strArr[] = f.list(); 9 | 10 | for (String name : strArr) { 11 | count++; 12 | System.out.println(name); 13 | } 14 | 15 | System.out.println("Total " + count + " Files in java."); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /18_Complexity_Analysis_and_Array/_09_Duplicate_Elements_Finding.java: -------------------------------------------------------------------------------- 1 | public class _09_Duplicate_Elements_Finding { 2 | public static void main(String[] args) { 3 | 4 | int arr[] = { 1, 2, 3, 4, 4, 5, 5, 6, 7, 8, 8, 9 }; 5 | 6 | for (int i = 0; arr.length > i; i++) { 7 | for (int j = i + 1; arr.length > j; j++) { 8 | if (arr[i] == arr[j]) { 9 | System.out.println(arr[i] + " is Duplicate Number. "); 10 | } 11 | } 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /18_Complexity_Analysis_and_Array/_06_Palindrome_Array.java: -------------------------------------------------------------------------------- 1 | public class _06_Palindrome_Array { 2 | 3 | public static void main(String[] args) { 4 | 5 | // Time Complexity : O(n) 6 | // Space Complexity : O(1) 7 | 8 | int arr[] = { 1, 2, 3, 4, 4, 3, 2, 1 }; 9 | 10 | for (int i = 0; arr.length / 2 > i; i++) { 11 | 12 | if (arr[i] != arr[arr.length - 1 - i]) { 13 | System.out.println("Array in Not Palindrome"); 14 | break; 15 | } 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /03_Fundamentals_of_Java/_05_Variables_examples_in_java.java: -------------------------------------------------------------------------------- 1 | public class _05_Variables_examples_in_java { 2 | 3 | 4 | public static void main(String args[]){ 5 | 6 | int Hello = 32 ; 7 | 8 | int hlo, bye, go ; 9 | hlo = 23 ; 10 | bye = 54 ; 11 | go = 993 ; 12 | 13 | int come = hlo ; 14 | 15 | System.out.println(Hello); 16 | System.out.println(hlo); 17 | System.out.println(bye); 18 | System.out.println(go); 19 | System.out.println(come); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /07_Arrays/_01_Create_An_Array.java: -------------------------------------------------------------------------------- 1 | public class _01_Create_An_Array { 2 | 3 | public static void main(String args[]){ 4 | 5 | // In Java, an array is a data structure that stores a fixed-size sequential collection of elements of the same data type. The elements of an array are stored in contiguous memory locations and can be accessed using an index. 6 | 7 | int nums[] = {1,2,3,4,5,6,7,8,9,10}; 8 | 9 | System.out.println(nums[0]); 10 | System.out.println(nums[1]); 11 | System.out.println(nums[2]); 12 | } 13 | } -------------------------------------------------------------------------------- /08_Strings/_04_Ways_of_Comparison.java: -------------------------------------------------------------------------------- 1 | public class _04_Ways_of_Comparison { 2 | 3 | public static void main(String args[]){ 4 | 5 | // in (==) this method java check refrence not value 6 | 7 | // Normal String Method 8 | String s1 = "Priyanshu" ; 9 | String s2 = "Priyanshu" ; 10 | 11 | System.out.println(s1 == s2); 12 | 13 | // Object String Method 14 | String s3 = new String("Gour"); 15 | String s4 = new String("Gour"); 16 | 17 | System.out.println(s3 == s4); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /10_Interfacr_&_Lambda_Expression/_11_StaticClass.java: -------------------------------------------------------------------------------- 1 | class I { 2 | 3 | public void Show(){ 4 | System.out.println("Hey ..! I am Show.."); 5 | } 6 | 7 | static class J { 8 | public void Display(){ 9 | System.out.println("Hey ..! I am Display.."); 10 | } 11 | } 12 | } 13 | 14 | 15 | public class _11_StaticClass { 16 | public static void main(String[] args) { 17 | 18 | I i = new I(); 19 | 20 | I.J j = new I.J(); 21 | 22 | i.Show(); 23 | j.Display(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /11_Exception_Handling/_02_Exception_Handling_Using_TryCatch.java: -------------------------------------------------------------------------------- 1 | public class _02_Exception_Handling_Using_TryCatch { 2 | 3 | public static void main(String[] args) { 4 | 5 | int a = 5 ; 6 | int b = 0 ; 7 | 8 | int result = 0 ; 9 | 10 | try{ 11 | result = a / b ; 12 | }catch(Exception obj){ 13 | System.out.println("Something went wrong .. " + obj); 14 | } 15 | 16 | System.out.println("Result is : " + result); 17 | System.out.println("Bye bye.."); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /08_Strings/_06_equalsIgnoreCase_Method_String.java: -------------------------------------------------------------------------------- 1 | public class _06_equalsIgnoreCase_Method_String { 2 | 3 | public static void main(String[] args) { 4 | // in (equalsIgnoreCase()) this method java check Value but ignore casesensivity. 5 | 6 | // Normal String Method 7 | String s1 = "PRIYANSHU" ; 8 | 9 | // Object String Method 10 | String s2 = new String("priyanshu"); 11 | 12 | 13 | // equalsIgnoreCase(); 14 | boolean check = s1.equalsIgnoreCase(s2) ; 15 | System.out.println(check); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /10_Interfacr_&_Lambda_Expression/_01_What_is_Interface.java: -------------------------------------------------------------------------------- 1 | 2 | interface P { 3 | String name = "Priyanshu Gour" ; 4 | } 5 | 6 | 7 | public class _01_What_is_Interface { 8 | 9 | public static void main(String[] args) { 10 | // It will allow only abstract methods. 11 | // It cannot be instantiated 12 | // Variables are "public static final". 13 | // Methods are "public and abstract". 14 | // No Constructor in Interface 15 | 16 | String Name = P.name ; 17 | 18 | System.out.println(Name); 19 | 20 | } 21 | } -------------------------------------------------------------------------------- /03_Operators_and_Loops/_13_Loop_forLoop_In_java.java: -------------------------------------------------------------------------------- 1 | public class _13_Loop_forLoop_In_java { 2 | 3 | 4 | public static void main(String args[]){ 5 | 6 | 7 | // for loop: A for loop is used to iterate over a range of values a fixed number of times. The basic syntax of the for loop is: 8 | 9 | // for(initialization; condition; increment/decrement) { 10 | // // code to be executed 11 | // } 12 | 13 | 14 | for(int i=1; i<=10; i++) { 15 | System.out.println(i); 16 | } 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /03_Fundamentals_of_Java/_10_Datatypes_Logical_with_Example.java: -------------------------------------------------------------------------------- 1 | public class _10_Datatypes_Logical_with_Example { 2 | 3 | 4 | public static void main(String args[]){ 5 | 6 | // To manage Locial type of Data ... 7 | // Ex :- true, false ; 8 | 9 | boolean t_logical = true ; 10 | boolean f_logical = false ; 11 | 12 | System.out.println(t_logical); 13 | System.out.println(f_logical); 14 | 15 | 16 | // we use boolean or logical datatype in huge time and the one of the most important datatype boolean .... 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /03_Operators_and_Loops/_14_Loop_whlileLoop.java: -------------------------------------------------------------------------------- 1 | public class _14_Loop_whlileLoop { 2 | 3 | 4 | public static void main(String args[]){ 5 | 6 | 7 | // while loop: A while loop is used to repeatedly execute a block of code as long as a certain condition is true. The basic syntax of the while loop is: 8 | 9 | 10 | // while(condition) { 11 | // // code to be executed 12 | // } 13 | 14 | 15 | 16 | 17 | int i = 1; 18 | while(i <= 10) { 19 | System.out.println(i); 20 | i++; 21 | } 22 | 23 | } 24 | } -------------------------------------------------------------------------------- /17_IO_Operation/_07_More_On_FileReader.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | public class _07_More_On_FileReader { 4 | public static void main(String[] args) throws IOException { 5 | 6 | File dir = new File("Hey"); 7 | 8 | File file = new File(dir, "hey.txt"); 9 | 10 | FileReader fr = new FileReader(file); 11 | 12 | char ch[] = new char[(int) file.length()]; 13 | 14 | fr.read(ch); 15 | 16 | for (char c : ch) { 17 | System.out.print(c); 18 | } 19 | 20 | System.out.println(); 21 | 22 | fr.close(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /28_Priority_Queue/_05_PriorityQueue_min.java: -------------------------------------------------------------------------------- 1 | import java.util.PriorityQueue; 2 | 3 | public class _05_PriorityQueue_min { 4 | 5 | public static void main(String[] args) { 6 | PriorityQueue pq = new PriorityQueue<>(); 7 | // By default, it is a min priority queue 8 | 9 | pq.add(20); // O(logn) 10 | pq.add(30); 11 | pq.add(50); 12 | pq.add(10); 13 | pq.add(40); 14 | 15 | while (!pq.isEmpty()) { 16 | System.out.println(pq.peek()); // O(1) 17 | pq.remove(); // O(logn) 18 | } 19 | 20 | } 21 | } -------------------------------------------------------------------------------- /03_Fundamentals_of_Java/_13_TypeCasting_explicit.java: -------------------------------------------------------------------------------- 1 | public class _13_TypeCasting_explicit { 2 | 3 | 4 | public static void main(String args []){ 5 | 6 | 7 | // Explicit Typecasting: Explicit typecasting, also known as narrowing, occurs when a data type of higher range is converted into a data type of lower range. Java requires explicit instructions to perform explicit typecasting. For example: 8 | 9 | double num1 = 10.5; 10 | int num2 = (int) num1; // Explicit typecasting from double to int 11 | System.out.println(num2); // Output: 10 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /07_Arrays/_02_Array_Assign_Value.java: -------------------------------------------------------------------------------- 1 | public class _02_Array_Assign_Value { 2 | 3 | public static void main(String[] args) { 4 | 5 | // Declare an array of integers with size 5 6 | int[] numbers = new int[5]; 7 | 8 | // Initialize the array with values 9 | numbers[0] = 10; 10 | numbers[1] = 20; 11 | numbers[2] = 30; 12 | numbers[3] = 40; 13 | numbers[4] = 50; 14 | 15 | // Access and print the value at index 2 16 | System.out.println(numbers[2]); // Output: 30 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /09_Oops/_10_Types_Of_Inheritance.java: -------------------------------------------------------------------------------- 1 | // Single-Level Inheritance 2 | 3 | class Animal { // Parent Class 4 | 5 | void sleep(){ 6 | System.out.println("Animal want sleep Atlest 5 Hours in a Day..."); 7 | } 8 | } 9 | 10 | class Lion extends Animal{ // Child Class 11 | 12 | void disp(){ 13 | System.out.println("I am Lion.."); 14 | } 15 | } 16 | 17 | 18 | public class _10_Types_Of_Inheritance { 19 | 20 | public static void main(String[] args) { 21 | 22 | Lion L = new Lion() ; 23 | 24 | L.sleep() ; 25 | L.disp() ; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /30_Dynamic_Programming/_02_FibonacciUsingDP_Tabulation.java: -------------------------------------------------------------------------------- 1 | // In this program, we will find the nth Fibonacci number using Dynamic Programming and Tabulation method. 2 | // Time Complexity: O(n) 3 | // Space Complexity: O(n) 4 | 5 | public class _02_FibonacciUsingDP_Tabulation { 6 | public static void main(String[] args) { 7 | int n = 10; 8 | int fib[] = new int[n + 1]; 9 | 10 | fib[0] = 0; 11 | fib[1] = 1; 12 | 13 | for (int i = 2; i <= n; i++) { 14 | fib[i] = fib[i - 1] + fib[i - 2]; 15 | } 16 | System.out.println(fib[n]); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /03_Fundamentals_of_Java/_00_How_java_run.java: -------------------------------------------------------------------------------- 1 | public class _00_How_java_run { 2 | 3 | 4 | public static void main(String args[]){ 5 | 6 | 7 | // {java Code} =(Compiler JVM)=> {java.class file (Byte Code)} =(run java file )=> {then we receved mechine understandable code} =(Mechine understand and gives output)=> {Output of the code} 8 | 9 | // What is byte code ? ANS: Byte code is the code which is coverted by JVM using compiler and the byte code is portable which is transfered any where thats why java is portable lanugage.. 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /04_Star_Pattern's/_01_Square_Pattern_In_java.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _01_Square_Pattern_In_java { 4 | 5 | 6 | public static void main(String args[]){ 7 | Scanner sc = new Scanner(System.in); 8 | 9 | int side ; 10 | System.out.println("Enter the side of the Square : "); 11 | side = sc.nextInt(); 12 | 13 | for(int i = 0 ; side > i ; i++){ 14 | for(int j = 0 ; side > j ; j++){ 15 | System.out.print(" * "); 16 | } 17 | System.out.println(); 18 | } 19 | 20 | sc.close(); 21 | } 22 | } -------------------------------------------------------------------------------- /07_Arrays/_06_Enhanced_For_Loop.java: -------------------------------------------------------------------------------- 1 | public class _06_Enhanced_For_Loop { 2 | 3 | public static void main(String args[]){ 4 | 5 | // In Java, the enhanced for loop (also known as the "for-each" loop) is a simplified loop construct that makes it easier to iterate through collections or arrays. It was introduced in Java 5. 6 | 7 | // for (type var : collection) { 8 | // loop body 9 | // } 10 | 11 | 12 | int[] numbers = {1, 2, 3, 4, 5}; 13 | 14 | for (int num : numbers) { 15 | System.out.println(num); 16 | } 17 | 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /10_Interfacr_&_Lambda_Expression/_02_More_On_Interface.java: -------------------------------------------------------------------------------- 1 | interface A { 2 | void Show(); 3 | } 4 | 5 | interface B { 6 | void Disp(); 7 | } 8 | 9 | class C implements A,B{ 10 | 11 | @Override 12 | public void Show(){ 13 | System.out.println("I am Show..!"); 14 | } 15 | 16 | @Override 17 | public void Disp(){ 18 | System.out.println("I am Disp..!"); 19 | } 20 | } 21 | 22 | public class _02_More_On_Interface { 23 | public static void main(String[] args) { 24 | 25 | 26 | C c = new C(); 27 | 28 | c.Show(); 29 | c.Disp(); 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /09_Oops/_12_Hierarchical_Inheritance.java: -------------------------------------------------------------------------------- 1 | 2 | // Hierarchical Inheritance.. 3 | 4 | class fly { 5 | 6 | void flying(){ 7 | System.out.println("I am Flying Bird's.."); 8 | } 9 | } 10 | 11 | class Bird1 extends fly{ 12 | 13 | // Hey ..! I am Bird 1 14 | } 15 | 16 | class Bird2 extends fly{ 17 | 18 | // Hey ..! I am Bird 2 19 | } 20 | 21 | public class _12_Hierarchical_Inheritance { 22 | 23 | public static void main(String[] args) { 24 | 25 | Bird1 B1 = new Bird1() ; 26 | B1.flying(); 27 | 28 | Bird2 B2 = new Bird2() ; 29 | B2.flying(); 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /28_Priority_Queue/_06_PriorityQueue_max.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _06_PriorityQueue_max { 4 | 5 | public static void main(String[] args) { 6 | PriorityQueue pq = new PriorityQueue<>(Comparator.reverseOrder()); 7 | // using Camaparator.reverseOrder() for reverse ordering :- max heap 8 | 9 | pq.add(20); // O(logn) 10 | pq.add(30); 11 | pq.add(50); 12 | pq.add(10); 13 | pq.add(40); 14 | 15 | while (!pq.isEmpty()) { 16 | System.out.println(pq.peek()); // O(1) 17 | pq.remove(); // O(logn) 18 | } 19 | 20 | } 21 | } -------------------------------------------------------------------------------- /03_Operators_and_Loops/_04_Decrementation_Operators.java: -------------------------------------------------------------------------------- 1 | public class _04_Decrementation_Operators { 2 | 3 | 4 | public static void main(String args []){ 5 | 6 | // The decrementation operator in Java is represented by two consecutive minus signs (--). It is used to decrement the value of a variable by 1. 7 | 8 | 9 | int count = 0; 10 | count--; // post-decrement 11 | System.out.println(count); // prints -1 12 | 13 | int i = 5; 14 | int j = --i; // pre-decrement 15 | System.out.println(i); // prints 4 16 | System.out.println(j); // prints 4 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /03_Fundamentals_of_Java/_03_String_args_in_java.java: -------------------------------------------------------------------------------- 1 | public class _03_String_args_in_java { 2 | 3 | 4 | public static void main(String args []){ 5 | System.out.println(args[0]); 6 | System.out.println(args[1]); 7 | } 8 | } 9 | 10 | 11 | // String args plays the role of the Argument which we entered in the program converted in the byted code means in form of .class or other way to say is Compiled file of java . 12 | 13 | // Example :- javac _03_String_args_in_java 14 | // java _03_String_args_in_java hello world 15 | 16 | // Output :- hello 17 | // world -------------------------------------------------------------------------------- /20_Recursion/_13_Valid_Parentheses_Using_Recursion.java: -------------------------------------------------------------------------------- 1 | public class _13_Valid_Parentheses_Using_Recursion { 2 | public static void main(String[] args) { 3 | 4 | validParentheses(2, 0, 0, ""); 5 | 6 | } 7 | 8 | public static void validParentheses(int n, int oc, int cc, String str) { 9 | 10 | if (oc == n && cc == n) { 11 | System.out.println(str); 12 | return; 13 | } 14 | 15 | if (oc < n) { 16 | validParentheses(n, oc + 1, cc, str + "("); 17 | } 18 | if (oc > cc) { 19 | validParentheses(n, oc, cc + 1, str + ")"); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /03_Operators_and_Loops/_15_Loop_do_whileLoop_in_java.java: -------------------------------------------------------------------------------- 1 | public class _15_Loop_do_whileLoop_in_java { 2 | 3 | 4 | public static void main(String args[]){ 5 | 6 | // do-while loop: A do-while loop is similar to a while loop, but the code inside the loop is executed at least once, even if the condition is false. The basic syntax of the do-while loop is: 7 | 8 | 9 | // do { 10 | // // code to be executed 11 | // } while(condition); 12 | 13 | 14 | int i = 1; 15 | do { 16 | System.out.println(i); 17 | i++; 18 | } while(i <= 10); 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /08_Strings/_18_StringBuffer_vs_StringBuilder.java: -------------------------------------------------------------------------------- 1 | public class _18_StringBuffer_vs_StringBuilder { 2 | 3 | public static void main(String[] args) { 4 | 5 | // StringBuffer.. 6 | // Indroduce in JDK: 1.0 version 7 | // In StringBuffer at a time single Thread 8 | // Use Synchronized 9 | // performance is low as compare to StringBuilder 10 | 11 | // StringBuilder.. 12 | // Indroduce in JDK: 1.5 version 13 | // In StringBuilder at a time MuliThread Possible 14 | // Not-Used Synchronized 15 | // performance is high as compare to StringBuffer 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /18_Complexity_Analysis_and_Array/_07_Reversal_In_An_Array.java: -------------------------------------------------------------------------------- 1 | public class _07_Reversal_In_An_Array { 2 | 3 | public static void main(String[] args) { 4 | 5 | // Time Complexity : O(n) 6 | // Space Complexity : O(1) 7 | 8 | int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; 9 | 10 | int temp; 11 | for (int i = 0; arr.length / 2 > i; i++) { 12 | temp = arr[i]; 13 | arr[i] = arr[arr.length - 1 - i]; 14 | arr[arr.length - 1 - i] = temp; 15 | } 16 | 17 | for (int i = 0; arr.length > i; i++) { 18 | System.out.println(arr[i]); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /08_Strings/_08_Concatenation_Method2_String.java: -------------------------------------------------------------------------------- 1 | public class _08_Concatenation_Method2_String { 2 | 3 | public static void main(String[] args) { 4 | 5 | // Using (concat()) Concatenation in String 6 | String s1 = "Priyanshu"; // This variable value presten the Heap (SCP-String Constant Pool) .. 7 | 8 | String s2 = s1.concat("Gour"); // Using this Method and any pre-defined method or any refrence variable the new Object create in Heap. but outoff (SCP).(and one Copy of the value is also present in the SCP but NO one variable refer those value or copy) 9 | 10 | System.out.println(s2); // Priyanshu Gour 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /09_Oops/_29_Dependency_Injection_ex1.java: -------------------------------------------------------------------------------- 1 | class Car { 2 | 3 | private Engine eng ; 4 | 5 | public Car(Engine eng){ 6 | this.eng = eng ; 7 | } 8 | 9 | public void start(){ 10 | eng.CarEngine(); 11 | } 12 | 13 | } 14 | 15 | 16 | class Engine { 17 | 18 | public void CarEngine(){ 19 | System.out.println("This is the Engine of the Car...!"); 20 | } 21 | 22 | } 23 | 24 | 25 | public class _29_Dependency_Injection_ex1 { 26 | 27 | public static void main(String[] args) { 28 | 29 | 30 | Engine e = new Engine(); 31 | 32 | Car c = new Car(e); 33 | c.start(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /15_Map_and_Generics/_13_Generics.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Student { 4 | private String Name; 5 | private int ID; 6 | } 7 | 8 | class Employee { 9 | private String Name; 10 | private int ID; 11 | } 12 | 13 | public class _13_Generics { 14 | public static void main(String[] args) { 15 | 16 | Student std = new Student(); 17 | Student std1 = new Student(); 18 | 19 | Employee emp = new Employee(); 20 | 21 | ArrayList al = new ArrayList(); 22 | 23 | al.add(std); 24 | al.add(std1); 25 | // al.add(emp); // Its give error because type is Student 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /03_Operators_and_Loops/_03_Incrementation_Operators.java: -------------------------------------------------------------------------------- 1 | public class _03_Incrementation_Operators { 2 | 3 | 4 | public static void main(String args[]){ 5 | 6 | // In Java, the incrementation operator ++ is used to add 1 to a variable's current value. It can be used both as a prefix or postfix operator. 7 | 8 | int count = 0; 9 | count++; // post-increment 10 | System.out.println(count); // prints 1 11 | 12 | int i = 5; 13 | int j = ++i; // pre-increment 14 | System.out.println(i); // prints 6 15 | System.out.println(j); // prints 6 16 | 17 | 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /10_Interfacr_&_Lambda_Expression/_07_Functional_Interface.java: -------------------------------------------------------------------------------- 1 | interface Interf{ 2 | 3 | void m1(); 4 | default void m3(){ 5 | System.out.println("m3-I"); 6 | } 7 | 8 | static void m4(){ 9 | System.out.println("m4-I"); 10 | } 11 | 12 | } 13 | 14 | class A implements Interf{ 15 | 16 | @Override 17 | public void m1(){ 18 | System.out.println("m1-A"); 19 | } 20 | } 21 | 22 | public class _07_Functional_Interface{ 23 | 24 | public static void main(String args[]){ 25 | Interf i=new A(); 26 | i.m1(); 27 | i.m3(); 28 | Interf.m4(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /10_Interfacr_&_Lambda_Expression/_09_MemberClass.java: -------------------------------------------------------------------------------- 1 | 2 | class Outer2 { 3 | void printNumbers() { 4 | int x = 10; 5 | System.out.println("This i printNumbers..!" + x); 6 | } 7 | 8 | int y = 100 ; 9 | 10 | class Local { 11 | public void printX() { 12 | System.out.println("Hey I am printX..!" + y); 13 | } 14 | } 15 | } 16 | 17 | public class _09_MemberClass { 18 | public static void main(String[] args) { 19 | 20 | Outer2 obj = new Outer2(); 21 | obj.printNumbers(); 22 | 23 | Outer2.Local obj1 = obj.new Local(); 24 | 25 | obj1.printX(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /03_Operators_and_Loops/_20_Print_vs_Println_in_java.java: -------------------------------------------------------------------------------- 1 | public class _20_Print_vs_Println_in_java { 2 | 3 | 4 | public static void main(String args[]){ 5 | 6 | 7 | // print and println are both methods used for displaying output in Java. 8 | 9 | // print displays the output without adding a new line, while println displays the output and adds a new line at the end. 10 | 11 | System.out.print("Hello "); 12 | System.out.println("world!"); 13 | System.out.println("How are you?"); 14 | 15 | 16 | int num = 42; 17 | System.out.print("The answer is: " + num); 18 | System.out.println("!"); 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /13_CollectionFrameWork/_16_Vector.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _16_Vector { 4 | public static void main(String[] args) { 5 | 6 | Vector v = new Vector<>(); 7 | 8 | v.add(10); 9 | v.add(20); 10 | v.add(30); 11 | v.add(40); 12 | v.add(50); 13 | 14 | Enumeration enr = v.elements(); 15 | 16 | while (enr.hasMoreElements()) { 17 | System.out.println(enr.nextElement()); 18 | } 19 | 20 | Iterator itr = v.iterator(); 21 | 22 | while (itr.hasNext()) { 23 | System.out.println(itr.next()); 24 | } 25 | System.out.println(v); 26 | } 27 | } -------------------------------------------------------------------------------- /03_Operators_and_Loops/_01_Operators_introduction.java: -------------------------------------------------------------------------------- 1 | public class _01_Operators_introduction { 2 | 3 | 4 | public static void main(String args[]){ 5 | // In Java, operators are symbols or special characters that perform specific actions on variables or values. They are used to perform arithmetic, comparison, logical, bitwise, and assignment operations. 6 | 7 | 8 | // Operators in Java can be classified into 6 types: 9 | // 1. Arithmetic Operators 10 | // 2. Relational Operators 11 | // 3. Logical Operators 12 | // 4. Assignment Operators 13 | // 5. Unary Operators 14 | // 6. Bitwise Operators 15 | 16 | } 17 | } -------------------------------------------------------------------------------- /09_Oops/_11_Multi_Level_Inheritance.java: -------------------------------------------------------------------------------- 1 | // Multi-Level Inheritance.. 2 | 3 | class Demo1 { 4 | 5 | void disp1(){ 6 | System.out.println("I am Demo 1"); 7 | } 8 | } 9 | 10 | class Demo2 extends Demo1 { 11 | 12 | void disp2(){ 13 | System.out.println("I am Demo 2"); 14 | } 15 | } 16 | 17 | class Demo3 extends Demo2{ 18 | 19 | void disp3(){ 20 | System.out.println("I am Demo 3"); 21 | } 22 | } 23 | 24 | public class _11_Multi_Level_Inheritance { 25 | 26 | public static void main(String[] args) { 27 | 28 | Demo3 D = new Demo3() ; 29 | 30 | D.disp1(); 31 | D.disp2(); 32 | D.disp3(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /03_Operators_and_Loops/_17_continue_in_java.java: -------------------------------------------------------------------------------- 1 | public class _17_continue_in_java { 2 | 3 | 4 | public static void main(String args[]){ 5 | 6 | 7 | // In Java, the continue statement is used to skip the remaining iterations of a loop and move on to the next iteration. It is typically used within loops to skip some code execution based on certain conditions. 8 | 9 | 10 | // Here is an example of using continue in a for loop in Java: 11 | for (int i = 0; i < 10; i++) { 12 | if (i == 5) { 13 | continue; // skip iteration when i is 5 14 | } 15 | System.out.println(i); 16 | } 17 | 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /10_Interfacr_&_Lambda_Expression/_04_Implementation_of_Interface.java: -------------------------------------------------------------------------------- 1 | interface Dog{ 2 | void dog(); 3 | } 4 | 5 | interface Parrot{ 6 | void parrot(); 7 | } 8 | 9 | 10 | class Animal implements Dog, Parrot { 11 | 12 | @Override 13 | public void dog(){ 14 | System.out.println("I am Dog ..!"); 15 | } 16 | 17 | @Override 18 | public void parrot(){ 19 | System.out.println("I am Parort..!"); 20 | } 21 | } 22 | 23 | 24 | public class _04_Implementation_of_Interface { 25 | 26 | public static void main(String[] args) { 27 | 28 | Animal Ani = new Animal(); 29 | 30 | Ani.dog(); 31 | Ani.parrot(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /13_CollectionFrameWork/_15_FailSafeExample.java: -------------------------------------------------------------------------------- 1 | import java.util.Iterator; 2 | import java.util.concurrent.CopyOnWriteArrayList; 3 | 4 | public class _15_FailSafeExample { 5 | public static void main(String[] args) { 6 | CopyOnWriteArrayList list = new CopyOnWriteArrayList<>(); 7 | list.add(1); 8 | list.add(2); 9 | list.add(3); 10 | 11 | Iterator iterator = list.iterator(); 12 | while (iterator.hasNext()) { 13 | Integer i = iterator.next(); 14 | System.out.println(i); 15 | list.add(4); // This will not throw ConcurrentModificationException in a fail-safe collection 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /17_IO_Operation/_06_Reading_Data_Onto_File_using_FileReader.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | public class _06_Reading_Data_Onto_File_using_FileReader { 4 | public static void main(String[] args) throws IOException { 5 | 6 | File dir = new File("Hey"); 7 | File file = new File(dir, "hey.txt"); 8 | 9 | FileReader fr = new FileReader(file); 10 | 11 | int i = fr.read(); 12 | 13 | while (i != -1) { // if File was null then return type is -1. 14 | System.out.print(i + " -----> "); 15 | System.out.println((char) i); 16 | i = fr.read(); 17 | } 18 | System.out.println(); 19 | fr.close(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /05_Oops_Fundamentals/_Test.java: -------------------------------------------------------------------------------- 1 | public class _Test { 2 | 3 | int Age = 0 ; // Instance Variable 4 | String Name = "Priyanshu Gour" ; // Instance Variable 5 | 6 | public static void main(String ags[]){ 7 | 8 | int Num = 10 ; // Local Variable 9 | 10 | _Test obj1 = new _Test() ; // Object Creation 11 | _Test obj2 = new _Test() ; // Object Creation 12 | 13 | obj1.Name = "Devanshu Gour" ; 14 | obj1.Age = 16 ; 15 | 16 | System.out.println(Num); 17 | 18 | System.out.println(obj1.Age); 19 | System.out.println(obj1.Name); 20 | 21 | System.out.println(obj2.Age); 22 | System.out.println(obj2.Name); 23 | } 24 | } -------------------------------------------------------------------------------- /17_IO_Operation/_02_Introduction_To_IO.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | public class _02_Introduction_To_IO { 4 | public static void main(String[] args) throws IOException { 5 | 6 | // File file = new File("priyanshu.txt"); 7 | // System.out.println(file.exists()); // This for check a File exists or not. 8 | 9 | // file.createNewFile(); // This for Creating a new file.. 10 | // System.out.println(file.exists()); 11 | 12 | File dir = new File("priyanshu"); 13 | System.out.println(dir.exists()); // This for check a Folder exists or not. 14 | 15 | dir.mkdir(); // This for Creating a new Folder.. 16 | System.out.println(dir.exists()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /03_Operators_and_Loops/_16_break_in_java.java: -------------------------------------------------------------------------------- 1 | public class _16_break_in_java { 2 | 3 | 4 | public static void main(String args[]){ 5 | 6 | 7 | // In Java, the break statement is used to prematurely exit a loop (either a for loop, while loop, or do-while loop). When a break statement is executed inside a loop, the control of the program jumps immediately out of the loop. 8 | 9 | 10 | // Here is an example of using break in a for loop in Java: 11 | for (int i = 1; i <= 10; i++) { 12 | System.out.print(i + " "); 13 | if (i == 5) { 14 | break; // exit loop if i equals 5 15 | } 16 | } 17 | 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /18_Complexity_Analysis_and_Array/_08_Missing_number_In_An_Array.java: -------------------------------------------------------------------------------- 1 | public class _08_Missing_number_In_An_Array { 2 | public static void main(String[] args) { 3 | 4 | // Time Complexity : O(n) 5 | // Space Complexity : O(1) 6 | 7 | int[] arr = { 1, 2, 3, 4, 5, 7, 8, 9, 10 }; 8 | 9 | // Sum of natural Number's 10 | int valueSum = (arr.length + 1) * (arr.length + 1 + 1) / 2; 11 | // Sum of given Number's 12 | int arrSum = 0; 13 | 14 | for (int i = 0; arr.length > i; i++) { 15 | arrSum += arr[i]; 16 | } 17 | // Missing Number 18 | System.out.println("Missing Nubmer is : " + (valueSum - arrSum)); 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /04_Star_Pattern's/_02_Rectange_Pattern_in_java.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _02_Rectange_Pattern_in_java { 4 | 5 | public static void main(String args[]){ 6 | Scanner sc = new Scanner(System.in); 7 | 8 | int len, wid ; 9 | System.out.println("Enter the lenth of the Rectange : "); 10 | len = sc.nextInt(); 11 | 12 | System.out.println("Enter the Width of the Rectange : "); 13 | wid = sc.nextInt(); 14 | 15 | for(int i = 0 ; wid > i ; i++){ 16 | for(int j = 0 ; len > j ; j++){ 17 | System.out.print(" * "); 18 | } 19 | System.out.println(); 20 | } 21 | 22 | sc.close(); 23 | } 24 | } -------------------------------------------------------------------------------- /16_Important_API's_and_Annotation/_06_More_On_StreamAPI_wayTwo.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.util.stream.*; 3 | 4 | public class _06_More_On_StreamAPI_wayTwo { 5 | public static void main(String[] args) { 6 | 7 | List list = Arrays.asList(5, 4, 3, 2, 1, 6, 7, 8, 9, 10); 8 | 9 | Stream streamData = list.stream(); 10 | // streamData.forEach(n -> System.out.println(n)); 11 | 12 | // Second Way To witer using method Chaining. 13 | Stream finalStreamData = streamData 14 | .sorted() 15 | .map(n -> n * 2) 16 | .filter(n -> n % 2 == 0); 17 | finalStreamData.forEach(n -> System.out.println(n)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /09_Oops/_04_Introduction_to_Constructor.java: -------------------------------------------------------------------------------- 1 | class Car { 2 | private String make; 3 | private String model; 4 | private int year; 5 | 6 | Car(String make, String model, int year) { 7 | this.make = make; 8 | this.model = model; 9 | this.year = year; 10 | } 11 | 12 | public String getMake(){ 13 | return make ; 14 | } 15 | public String getModel(){ 16 | return model ; 17 | } 18 | public int getYear(){ 19 | return year ; 20 | } 21 | } 22 | 23 | 24 | public class _04_Introduction_to_Constructor { 25 | 26 | public static void main(String[] args) { 27 | Car c = new Car("Tesla", "Electric", 2023); 28 | 29 | c.getMake(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /10_Interfacr_&_Lambda_Expression/_10_NonStatic_InnerClass.java: -------------------------------------------------------------------------------- 1 | // Non-static or Inner Class: 2 | // A non-static or inner class is defined inside another class and has access to all the members of the outer class, including private members. It is used to encapsulate a helper class or a stateful implementation of an interface. 3 | 4 | class Outer { 5 | private int x = 10; 6 | 7 | class Inner { 8 | public void printX() { 9 | System.out.println(x); 10 | } 11 | } 12 | } 13 | 14 | public class _10_NonStatic_InnerClass { 15 | public static void main(String[] args) { 16 | Outer outer = new Outer(); 17 | Outer.Inner inner = outer.new Inner(); 18 | inner.printX(); // prints 10 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /10_Interfacr_&_Lambda_Expression/_12_StaticNestedClass.java: -------------------------------------------------------------------------------- 1 | // Static Nested Class: 2 | // A static nested class is defined inside another class but is marked as static. It does not have access to the members of the outer class, and it can be used as a helper class or a logical grouping of classes. 3 | 4 | 5 | 6 | class Outer1 { 7 | static class StaticNested { 8 | public void print() { 9 | System.out.println("This is a static nested class."); 10 | } 11 | } 12 | } 13 | 14 | public class _12_StaticNestedClass { 15 | public static void main(String[] args) { 16 | Outer1.StaticNested nested = new Outer1.StaticNested(); 17 | nested.print(); // prints "This is a static nested class." 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /03_Fundamentals_of_Java/_07_Datatypes_Introduction.java: -------------------------------------------------------------------------------- 1 | public class _07_Datatypes_Introduction { 2 | 3 | 4 | public static void main(String args[]){ 5 | 6 | // Primitive data types : 7 | // Numeric DataTypes 8 | // Whole Numbers :- 10, 15, 18, 21, 29 ; 9 | // Real Nubmers :- 10.3, 43.2, 34.5, 23.56 ; 10 | 11 | // Characters DataTypes 12 | // char :- 'a', 'A', 'P' ; 13 | 14 | // Logical DataTypes 15 | // true - false ==> boolean 16 | 17 | // Non - Primitive data types : 18 | // classes, Strings, Interfaces, and Arrays. 19 | 20 | 21 | 22 | 23 | // we will learn about primitive datatypes : 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /16_Important_API's_and_Annotation/_10_Enum_and_Switch_Case.java: -------------------------------------------------------------------------------- 1 | enum Result12 { 2 | PASS, FAIL, NR; 3 | } 4 | 5 | public class _10_Enum_and_Switch_Case { 6 | public static void main(String[] args) { 7 | 8 | Result12 res = Result12.PASS; 9 | // Result12 res = Result12.FAIL; 10 | // Result12 res = Result12.NR; 11 | 12 | switch (res) { 13 | case PASS: { 14 | System.out.println("Passed !"); 15 | break; 16 | } 17 | case FAIL: { 18 | System.out.println("Failed ..!"); 19 | break; 20 | } 21 | case NR: { 22 | System.out.println("No Result12 ..!"); 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /20_Recursion/_02_Sum_Of_N_Number.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | // Time Complexity : O(n) 4 | // Space Complexity : O(n) 5 | 6 | public class _02_Sum_Of_N_Number { 7 | 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | 11 | System.out.print("Enter the Number to Find Sum : "); 12 | int n = sc.nextInt(); 13 | 14 | int sum = Sum(n); 15 | 16 | System.out.println("Sum of N Number's is : " + sum); 17 | 18 | sc.close(); 19 | } 20 | 21 | // Recursive code to find Sum of N number ... 22 | public static int Sum(int n) { 23 | if (n <= 1) { 24 | return 1; 25 | } else { 26 | return n + Sum(n - 1); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /28_Priority_Queue/_09_KthLargestElement.java: -------------------------------------------------------------------------------- 1 | import java.util.PriorityQueue; 2 | 3 | public class _09_KthLargestElement { 4 | 5 | public static int findKthLargest(int[] nums, int k) { 6 | PriorityQueue pq = new PriorityQueue<>(); 7 | 8 | for (int num : nums) { 9 | pq.offer(num); 10 | 11 | if (pq.size() > k) { 12 | pq.poll(); 13 | } 14 | } 15 | 16 | return pq.peek(); 17 | } 18 | 19 | public static void main(String[] args) { 20 | int[] nums = { 3, 1, 4, 1, 5, 9, 2, 6, 5 }; 21 | int k = 3; 22 | 23 | int kthLargest = findKthLargest(nums, k); 24 | System.out.println("The " + k + "th largest element is: " + kthLargest); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /20_Recursion/_03_factorial_Using_Recursion.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | // Time Complexity : O(n) 4 | // Space Complexity : O(n) 5 | 6 | public class _03_factorial_Using_Recursion { 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | 10 | System.out.print("Enter the Number to Find Fact : "); 11 | int n = sc.nextInt(); 12 | 13 | int fact = Fact(n); 14 | 15 | System.out.println("Fact of Number is : " + fact); 16 | 17 | sc.close(); 18 | } 19 | 20 | // Recursive Code to find Factorial .. 21 | public static int Fact(int n) { 22 | if (n <= 1) { 23 | return 1; 24 | } else { 25 | return n * Fact(n - 1); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /17_IO_Operation/_01_Fundamentals_Before_IO_Operation.java: -------------------------------------------------------------------------------- 1 | class Student { 2 | private String name; 3 | private int age; 4 | private String city; 5 | 6 | public Student(String name, int age, String city) { 7 | this.name = name; 8 | this.age = age; 9 | this.city = city; 10 | } 11 | 12 | public String toString() { 13 | return "Name : " + name + " | Age : " + age + " | City : " + city; 14 | } 15 | } 16 | 17 | public class _01_Fundamentals_Before_IO_Operation { 18 | public static void main(String[] args) { 19 | 20 | Student stu1 = new Student("John", 18, "New York"); 21 | System.out.println(stu1); 22 | Student stu2 = new Student("Tom", 23, "New York"); 23 | System.out.println(stu2); 24 | } 25 | } -------------------------------------------------------------------------------- /15_Map_and_Generics/_14_More_On_Generics.java: -------------------------------------------------------------------------------- 1 | // :- It Shows the Type of Our Class... 2 | class Gen { 3 | T obj; 4 | 5 | public Gen(T obj) { 6 | this.obj = obj; 7 | } 8 | 9 | void disp() { 10 | System.out.println("Type of the Data is : " + obj.getClass().getName()); 11 | } 12 | 13 | public T getObj() { 14 | return obj; 15 | } 16 | } 17 | 18 | public class _14_More_On_Generics { 19 | public static void main(String[] args) { 20 | 21 | Gen gen = new Gen("Priyansu Gour"); 22 | 23 | gen.disp(); 24 | System.out.println(gen.getObj()); 25 | 26 | Gen gen1 = new Gen(500); 27 | 28 | gen1.disp(); 29 | System.out.println(gen1.getObj()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /04_Star_Pattern's/_04_Right_Triangle_Star_Pattern.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _04_Right_Triangle_Star_Pattern { 4 | 5 | 6 | public static void main(String args[]){ 7 | Scanner sc = new Scanner(System.in); 8 | 9 | // * 10 | // * * 11 | // * * * 12 | // * * * * 13 | // * * * * * 14 | int n ; 15 | System.out.print("Enter the Height of Right Triangel : "); 16 | n = sc.nextInt(); 17 | 18 | 19 | for(int i = 0 ; n > i ; i++){ 20 | for(int j = 0 ; i > j ; j++){ 21 | System.out.print("* "); 22 | } 23 | System.out.println(); 24 | } 25 | 26 | sc.close(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /03_Fundamentals_of_Java/_12_TypeCasting_Implicit.java: -------------------------------------------------------------------------------- 1 | public class _12_TypeCasting_Implicit { 2 | 3 | 4 | public static void main(String args[]){ 5 | 6 | // In Java, typecasting is the process of converting one data type into another. There are two types of typecasting: implicit and explicit. 7 | 8 | 9 | // Implicit Typecasting: Implicit typecasting, also known as widening, occurs when a data type of lower range is converted into a data type of higher range. Java performs implicit typecasting automatically without the need for any explicit instructions. For example: 10 | 11 | int num1 = 10; 12 | double num2 = num1; // Implicit typecasting from int to double 13 | System.out.println(num2); // Output: 10.0 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /09_Oops/Packages/Cal/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Cal 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | 19 | 1680878701051 20 | 21 | 30 22 | 23 | org.eclipse.core.resources.regexFilterMatcher 24 | node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /09_Oops/_17_Rule_to_override_method.java: -------------------------------------------------------------------------------- 1 | class clap { 2 | void Hey(){ 3 | System.out.println("hey .. I am Hey..! in parent calss"); 4 | } 5 | } 6 | 7 | 8 | class childClap extends clap{ 9 | 10 | 11 | // Rule No.1 : in Override case always increse visibility (mean Public => protected => default => Private Never Decrese the visibility in Override. 12 | // Rule No.2 : Never Change the Datatype in Override case . 13 | 14 | @Override 15 | public void Hey(){ 16 | System.out.println("hey .. I am Hey..! in child class"); 17 | } 18 | } 19 | 20 | public class _17_Rule_to_override_method { 21 | 22 | public static void main(String[] args) { 23 | 24 | childClap cc = new childClap(); 25 | 26 | cc.Hey(); 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /10_Interfacr_&_Lambda_Expression/_14_Lambda_Expression.java: -------------------------------------------------------------------------------- 1 | // A lambda expression in Java is a concise way to create an anonymous function, also known as a lambda function. It is a new feature added in Java 8 that simplifies the process of writing code for certain tasks that require the implementation of functional interfaces. 2 | 3 | // To provide the implementation of Functional interface. 4 | // Less Coding. 5 | 6 | @FunctionalInterface 7 | interface Year { 8 | void Age(int age); 9 | } 10 | 11 | 12 | public class _14_Lambda_Expression { 13 | public static void main(String[] args) { 14 | 15 | Year yr = (int age) -> { 16 | System.out.println("hey .. I am Priyanshu Gour and my Age is : " + age); 17 | }; 18 | 19 | 20 | yr.Age(18); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Java-with-DSA-and-system-design 2 | 3 | We will discuss these topics in this course. 4 | 5 | 6 | 7 | 8 | Fundamentals of Computer Science 9 | 10 | Learning OS 11 | 12 | Version Control System and Git 13 | 14 | Getting Started with JAVA 15 | 16 | Understand Advance Java 17 | 18 | Getting Started with Database 19 | 20 | Hanson’s with Sql - MySQL 21 | 22 | Exploring MongoDB 23 | 24 | Learning JDBC 25 | 26 | Introduction to Algorithms and Analysis 27 | 28 | Understanding Array, String, Recursion LLD, Stack and Queue and Much More 29 | 30 | Learning Search, Divide and Conquer, Greedy Algorithm etc 31 | 32 | Design Principal and its importance 33 | 34 | System Design 35 | 36 | Getting Started with Spring Boot 37 | 38 | Spring Rest 39 | 40 | Starting and Completing Full Fledge Project -------------------------------------------------------------------------------- /09_Oops/_05_More_on_Constructor.java: -------------------------------------------------------------------------------- 1 | class Demo 2 | { 3 | private int a; 4 | private int b; 5 | 6 | // public Demo() 7 | // { 8 | 9 | // } 10 | public Demo() 11 | { 12 | System.out.println("Zero parametrized constructor by programmer"); 13 | } 14 | 15 | public Demo(int a, int b) 16 | { 17 | this.a=a; 18 | this.b=b; 19 | } 20 | 21 | void disp() 22 | { 23 | System.out.println(a); 24 | System.out.println(b); 25 | } 26 | } 27 | public class _05_More_on_Constructor 28 | { 29 | public static void main(String[] args) 30 | { 31 | Demo d=new Demo(); 32 | d.disp(); 33 | //d.add(); 34 | 35 | Demo d2=new Demo(10, 20); 36 | d2.disp(); 37 | 38 | 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /20_Recursion/_05_Finding_Of_Power_Brute_Force.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _05_Finding_Of_Power_Brute_Force { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | 7 | System.out.print("Enter the Number to Find Power : "); 8 | int a = sc.nextInt(); 9 | 10 | System.out.print("Enter the Power of Number : "); 11 | int b = sc.nextInt(); 12 | 13 | int pw = Power(a, b); 14 | 15 | System.out.println("Power is : " + pw); 16 | 17 | sc.close(); 18 | } 19 | 20 | // to find Power using Recursion .. 21 | public static int Power(int a, int b) { 22 | if (b <= 1) { 23 | return a; 24 | } else { 25 | return a * Power(a, b - 1); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /20_Recursion/_04_Fibonacci_Using_Recursion.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | // Time Complexity : O(2^n) 4 | // Space Complexity : O(n) 5 | 6 | public class _04_Fibonacci_Using_Recursion { 7 | 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | 11 | System.out.print("Enter the Number to Find Fibonacci : "); 12 | int n = sc.nextInt(); 13 | 14 | int fibo = Fibonacci(n); 15 | 16 | System.out.println("Fibonacci of Number is : " + fibo); 17 | 18 | sc.close(); 19 | } 20 | 21 | // Recursive Code to find Fibonacci .. 22 | public static int Fibonacci(int n) { 23 | if (n <= 1) { 24 | return n; 25 | } else { 26 | return Fibonacci(n - 1) + Fibonacci(n - 2); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /20_Recursion/_08_Number_Of_Stairs.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | // Time Complexity : O(2^n) 4 | // Space Complexity : O(n) 5 | 6 | public class _08_Number_Of_Stairs { 7 | 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | 11 | System.out.print("Enter the Number to Find StairCase : "); 12 | int n = sc.nextInt(); 13 | 14 | int stair = countStairs(n); 15 | 16 | System.out.println("Number of Stair Types is : " + stair); 17 | 18 | sc.close(); 19 | } 20 | 21 | // Recursive Code to find Count Stairs .. 22 | public static int countStairs(int n) { 23 | if (n <= 1) { 24 | return n; 25 | } else { 26 | return countStairs(n - 1) + countStairs(n - 2); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /24_Divide_and_Conquer/_08_FindPeakElement_Using_DC.java: -------------------------------------------------------------------------------- 1 | public class _08_FindPeakElement_Using_DC { 2 | 3 | public static int findPeak(int arr[], int low , int high , int n){ 4 | int m = low + (high - low)/2; 5 | 6 | if((m == 0 || arr[m-1] <= arr[m]) && (m == n-1 || arr[m+1] <= arr[m])){ 7 | return m; 8 | } 9 | else if(m > 0 && arr[m-1] > arr[m]){ 10 | return findPeak(arr, low, m-1, n); 11 | } 12 | else{ 13 | return findPeak(arr, m+1, high, n); 14 | } 15 | } 16 | 17 | public static void main(String[] args) { 18 | int arr[] = {1,2,6,3,2,4,6,3,2}; 19 | 20 | int peak = findPeak(arr, 0, arr.length-1, arr.length); 21 | 22 | System.out.println("Peak Element Index is : " + peak); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /03_Operators_and_Loops/_21_Nested_loop_in_java.java: -------------------------------------------------------------------------------- 1 | public class _21_Nested_loop_in_java { 2 | 3 | 4 | public static void main(String args[]){ 5 | 6 | 7 | // A nested loop in Java is a loop inside another loop. The inner loop is executed multiple times for each iteration of the outer loop. Nested loops are useful for iterating over two-dimensional arrays, performing matrix multiplication, generating permutations, and many other tasks that involve nested iterations. 8 | 9 | // Here's an example of a nested loop in Java that prints the multiplication table up to 10: 10 | for (int i = 1; i <= 10; i++) { 11 | for (int j = 1; j <= 10; j++) { 12 | System.out.print(i * j + " "); 13 | } 14 | System.out.println(); 15 | } 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /08_Strings/_07_Concatenation_Method_String.java: -------------------------------------------------------------------------------- 1 | public class _07_Concatenation_Method_String { 2 | 3 | public static void main(String[] args) { 4 | 5 | // Using ( concat()) Concatenation in String 6 | String s1 = new String("Priyanshu"); 7 | 8 | // Using (concat()) Not change the s1 value because String are Immutable 9 | 10 | s1.concat(" Gour"); // in this way the new String Create in Heap memory (outoff SCP) with the value of (Priyanshu Gour) but No one variable refer the value 11 | System.out.println(s1); // Priyanshu 12 | 13 | s1 = s1.concat(" Gour") ; // in this way the new String Create in Heap memory (outoff SCP) with the value of (Priyanshu Gour) and the s1 variable refer the value . 14 | System.out.println(s1); // Priyanshu Gour 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /30_Dynamic_Programming/_01_FibonacciUsingDP_Memorization.java: -------------------------------------------------------------------------------- 1 | // in this program we are going to find the nth fibonacci number using dynamic programming(Memorization). 2 | // Time Complexity: O(n) 3 | // Space Complexity: O(n) 4 | 5 | public class _01_FibonacciUsingDP_Memorization { 6 | 7 | public static int fibonacci(int n, int fib[]) { 8 | if ((n == 0) || (n == 1)) { 9 | return n; 10 | } 11 | 12 | if (fib[n] != 0) { 13 | return fib[n]; 14 | } 15 | 16 | int ans = fibonacci(n - 1, fib) + fibonacci(n - 2, fib); 17 | fib[n] = ans; 18 | return ans; 19 | } 20 | 21 | public static void main(String[] args) { 22 | int n = 10; 23 | int fib[] = new int[n + 1]; 24 | 25 | System.out.println(fibonacci(n, fib)); 26 | } 27 | } -------------------------------------------------------------------------------- /04_Star_Pattern's/_07_Downward_Triangle_Star_Pattern.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _07_Downward_Triangle_Star_Pattern { 4 | 5 | 6 | public static void main(String args[]){ 7 | Scanner sc = new Scanner(System.in); 8 | 9 | // * * * * * 10 | // * * * * 11 | // * * * 12 | // * * 13 | // * 14 | 15 | int n, o ; 16 | System.out.println("Enter Height of the Triangel : "); 17 | n = sc.nextInt(); 18 | 19 | o = n ; 20 | for(int i = 0 ; n > i ; i++){ 21 | for(int j = o ; 0 < j ; j--){ 22 | System.out.print("* "); 23 | } 24 | System.out.println(); 25 | o--; 26 | } 27 | 28 | 29 | sc.close(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /20_Recursion/_10_Sum_Of_Digit_Using_Recursion.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | // Time Complexity : O() 4 | // Space Complexity : O() 5 | 6 | public class _10_Sum_Of_Digit_Using_Recursion { 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | 10 | System.out.print("Enter The Digit to find Sum : "); 11 | int digit = sc.nextInt(); 12 | 13 | int sumOfDigit = sumDigit(digit); 14 | 15 | System.out.println("Sum of The Digit is : " + sumOfDigit); 16 | 17 | sc.close(); 18 | } 19 | 20 | // To Find Sum of digit ... 21 | public static int sumDigit(int digit) { 22 | if (0 >= digit) { 23 | return 0; 24 | } else { 25 | return ((digit % 10) + sumDigit(digit / 10)); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /08_Strings/_15_Introduction_to_Mutable_String.java: -------------------------------------------------------------------------------- 1 | public class _15_Introduction_to_Mutable_String { 2 | 3 | public static void main(String[] args) { 4 | 5 | // # Mutable String 6 | // Once if we create a String, on that String if we try to perform any operation and if 7 | // those changes get reflected in the same object then such strings are called “Mutable String”. 8 | // Example: StringBuffer, StringBuilder 9 | 10 | StringBuffer pg = new StringBuffer("Priyanshu "); 11 | 12 | System.out.println(pg); 13 | pg.append("Gour"); 14 | System.out.println(pg); 15 | 16 | 17 | StringBuilder dg = new StringBuilder("Devanshu "); 18 | 19 | System.out.println(dg); 20 | dg.append("Gour"); 21 | System.out.println(dg); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /21_Backtracking/_01_Tiling_Problem_Using_Backtracking.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | // Time Complexity : O() 4 | // Space Complexity : O() 5 | 6 | public class _01_Tiling_Problem_Using_Backtracking { 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | 10 | System.out.print("Enter The Size of CartBoard : "); 11 | int n = sc.nextInt(); 12 | 13 | int tilingways = tilingGatways(n); 14 | 15 | System.out.println("tiling Ways in This CartBoard : " + tilingways); 16 | 17 | sc.close(); 18 | 19 | } 20 | 21 | public static int tilingGatways(int n) { 22 | // Base Case.. 23 | if (n <= 3) { 24 | return n; 25 | } else { 26 | return tilingGatways(n - 1) + tilingGatways(n - 2); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /03_Fundamentals_of_Java/_16_Naming_Convention.java: -------------------------------------------------------------------------------- 1 | public class _16_Naming_Convention { 2 | 3 | 4 | public static void main(String args []){ 5 | 6 | // All are not compulsery but those all are Sugested 7 | 8 | // Class => Pascalcase : it means every word start Capital Letter.. 9 | 10 | // // variable => if (single world){ 11 | // then small letter 12 | // }else if(multipule words){ 13 | // then cameleCase 14 | // } 15 | 16 | // // Methods => if (single world){ 17 | // then small letter 18 | // }else if(multipule words){ 19 | // then cameleCase 20 | // } 21 | 22 | } 23 | } -------------------------------------------------------------------------------- /09_Oops/_02_Shadowing_Problem_Solve_using_this_keyword.java: -------------------------------------------------------------------------------- 1 | 2 | class Student { 3 | private String name ; 4 | 5 | // The this keyword refers to the current object in a method or constructor. 6 | // The most common use of the this keyword is to eliminate the confusion between class attributes and parameters 7 | // with the same name (because a class attribute is shadowed by a method or constructor parameter). 8 | 9 | public void setData(String name) { 10 | this.name = name ; 11 | } 12 | 13 | public String getData (){ 14 | return name ; 15 | } 16 | } 17 | 18 | public class _02_Shadowing_Problem_Solve_using_this_keyword { 19 | 20 | public static void main(String[] args) { 21 | 22 | Student s = new Student() ; 23 | 24 | s.setData("Priyanshu Gour"); 25 | } 26 | } -------------------------------------------------------------------------------- /20_Recursion/_14_printBoardPaths_Using_Recursion.java: -------------------------------------------------------------------------------- 1 | public class _14_printBoardPaths_Using_Recursion { 2 | 3 | // Time Complexity : O() 4 | // Space Complexity : O() 5 | 6 | public static void main(String[] args) { 7 | 8 | printBoardPaths(0, 4, ""); 9 | 10 | } 11 | 12 | // To Print Board Paths using Recursion.. 13 | public static void printBoardPaths(int curr, int dest, String str) { 14 | if (curr > dest) { 15 | return; 16 | } 17 | if (curr == dest) { 18 | System.out.println(str); 19 | return; 20 | } 21 | 22 | printBoardPaths(curr + 1, dest, str + 1); 23 | printBoardPaths(curr + 2, dest, str + 2); 24 | printBoardPaths(curr + 3, dest, str + 3); 25 | printBoardPaths(curr + 4, dest, str + 4); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /30_Dynamic_Programming/_03_ClimbingStairs_DP_Memorization.java: -------------------------------------------------------------------------------- 1 | // Climbing Stairs :- Count ways to reach the nth stair. The person can climb either 1 stair or 2 stairs at a time. 2 | // Time Complexity: O(n) 3 | // Space Complexity: O(n) 4 | 5 | public class _03_ClimbingStairs_DP_Memorization { 6 | 7 | public static int climbingStairs(int n, int[] dp) { 8 | if (n < 0 || n == 0) { 9 | return n == 0 ? 1 : 0; 10 | } 11 | 12 | if (dp[n] != 0) { 13 | return dp[n]; 14 | } 15 | 16 | int ans = climbingStairs(n - 1, dp) + climbingStairs(n - 2, dp); 17 | dp[n] = ans; 18 | return ans; 19 | } 20 | 21 | public static void main(String[] args) { 22 | int n = 5; 23 | int[] dp = new int[n + 1]; 24 | System.out.println(climbingStairs(n, dp)); 25 | } 26 | } -------------------------------------------------------------------------------- /09_Oops/_01_Introduction_to_Encapsulation.java: -------------------------------------------------------------------------------- 1 | // Encapsulation in Java is a fundamental concept in object-oriented programming that allows the programmer to hide the implementation details of a class from other classes. Encapsulation provides data security, code reusability, and modularity. 2 | 3 | class Student { 4 | 5 | private String myName ; 6 | private int myAge ; 7 | 8 | public void setData() { 9 | myName = "Priyanshu Gour" ; 10 | myAge = 18 ; 11 | } 12 | 13 | public void showData(){ 14 | System.out.println(myName + " " + myAge); 15 | } 16 | } 17 | 18 | public class _01_Introduction_to_Encapsulation { 19 | 20 | public static void main(String args[]){ 21 | 22 | Student s1 = new Student(); 23 | 24 | s1.showData(); 25 | s1.setData(); 26 | s1.showData(); 27 | } 28 | } -------------------------------------------------------------------------------- /09_Oops/Packages/Cal/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=17 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning 13 | org.eclipse.jdt.core.compiler.release=enabled 14 | org.eclipse.jdt.core.compiler.source=17 15 | -------------------------------------------------------------------------------- /04_Star_Pattern's/_03_Pyramid_Program.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _03_Pyramid_Program { 4 | 5 | public static void main(String args []){ 6 | Scanner sc = new Scanner(System.in); 7 | 8 | // * 9 | // * * 10 | // * * * 11 | // * * * * 12 | // * * * * * 13 | 14 | int n,t ; 15 | System.out.println("Enter the Height of the Pyramid"); 16 | n = sc.nextInt(); 17 | 18 | t = n-1 ; 19 | for(int i = 0 ; n > i ; i++){ 20 | for(int j = t ; 0 < j ; j--){ 21 | System.out.print(" "); 22 | } 23 | for(int k = 0 ; k < i ; k++ ){ 24 | System.out.print("* "); 25 | } 26 | System.out.println(); 27 | t--; 28 | } 29 | 30 | 31 | sc.close(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /05_Oops_Fundamentals/Method_Overloading.java: -------------------------------------------------------------------------------- 1 | class Calc { 2 | 3 | public int Add(int n1 , int n2 ){ 4 | int result = n1 + n2 ; 5 | return result ; 6 | } 7 | 8 | public int Add(int n1, int n2, int n3){ 9 | int result = n1 + n2 + n3 ; 10 | return result ; 11 | } 12 | 13 | public double Add(double n1 , double n2){ 14 | double result = n1 + n2 ; 15 | return result ; 16 | } 17 | } 18 | 19 | 20 | public class Method_Overloading { 21 | 22 | public static void main(String args[]){ 23 | 24 | Calc Sum = new Calc(); 25 | 26 | int res1 = Sum.Add(5, 10); 27 | int res2 = Sum.Add(5, 10, 15); 28 | double res3 = Sum.Add(45.23, 54.77); 29 | 30 | System.out.println(res1); 31 | System.out.println(res2); 32 | System.out.println(res3); 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /09_Oops/_08_Introduction_to_Inheritance.java: -------------------------------------------------------------------------------- 1 | class Human{ // Super class // Base Class // Parent Class 2 | 3 | int age ; 4 | void sleep(){ 5 | age = 18 ; 6 | System.out.println(age + " Hours needed to a Human . "); 7 | } 8 | } 9 | 10 | class Student extends Human{ // child class // sub class // derived class 11 | 12 | } 13 | 14 | public class _08_Introduction_to_Inheritance { 15 | 16 | public static void main(String[] args) { 17 | // Inheritance is a fundamental concept in object-oriented programming, 18 | // which allows a class to inherit properties and behavior from another 19 | // class. In Java, inheritance is achieved by using the "extends" keyword 20 | // to create a subclass that inherits from a superclass. 21 | 22 | 23 | Student st = new Student() ; 24 | 25 | st.sleep(); 26 | } 27 | } -------------------------------------------------------------------------------- /03_Fundamentals_of_Java/_14_TypeCasting_Truncation.java: -------------------------------------------------------------------------------- 1 | public class _14_TypeCasting_Truncation { 2 | 3 | 4 | public static void main(String agrs[]){ 5 | 6 | 7 | // In Java, truncation refers to the process of removing the decimal part of a floating-point number and returning the integer part. 8 | // One way to perform truncation in Java is by casting the floating-point number to an integer type. This will discard the decimal part and return the integer part. Here's an example: 9 | 10 | double number = 3.14159; 11 | int truncatedNumber = (int) number; 12 | System.out.println("Truncated number: " + truncatedNumber); 13 | 14 | 15 | // truncation 16 | int n1 = 12 ; 17 | int n2 = 5 ; 18 | float res = n1/n2 ; 19 | 20 | System.out.println(res); // Ans is 2.4 but due to truncation ANS is 2.0 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /09_Oops/_26_Oops_Area_of_Circle.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class Circle{ 4 | 5 | float radius ; 6 | float area ; 7 | 8 | public void input(){ 9 | System.out.println("Calculation of Circle App : "); 10 | Scanner sc = new Scanner(System.in); 11 | 12 | System.out.print("Enter the Radius : "); 13 | radius = sc.nextFloat(); 14 | 15 | sc.close(); 16 | } 17 | 18 | public void compute(){ 19 | area = 3.14f * radius * radius ; 20 | } 21 | 22 | public void disp(){ 23 | System.out.println("Area of Circle is : " + area); 24 | } 25 | 26 | } 27 | 28 | 29 | public class _26_Oops_Area_of_Circle { 30 | 31 | public static void main(String[] args) { 32 | 33 | Circle cir = new Circle(); 34 | cir.input(); 35 | cir.compute(); 36 | cir.disp(); 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /20_Recursion/_11_Multiply_Of_an_Number.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | // Time Complexity : O() 4 | // Space Complexity : O() 5 | 6 | public class _11_Multiply_Of_an_Number { 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | 10 | System.out.print("Enter The Number : "); 11 | int num = sc.nextInt(); 12 | 13 | System.out.print("Enter Time's To Multiply : "); 14 | int mul = sc.nextInt(); 15 | 16 | multiply(num, mul); 17 | 18 | sc.close(); 19 | } 20 | 21 | // Code For finding Multipul's 22 | public static void multiply(int num, int mul) { 23 | 24 | if (mul == 1) { 25 | System.out.println(num); 26 | return; 27 | } else { 28 | multiply(num, mul - 1); 29 | System.out.println(num * mul); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /09_Oops/_25_Oops_Area_of_Square.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class Square{ 4 | 5 | float length ; 6 | float area ; 7 | 8 | public void input(){ 9 | System.out.println("Calculation of Square App : "); 10 | Scanner sc = new Scanner(System.in); 11 | 12 | System.out.print("Enter the Length : "); 13 | length = sc.nextFloat(); 14 | 15 | sc.close(); 16 | } 17 | 18 | public void compute(){ 19 | area = length * length ; 20 | } 21 | 22 | public void disp(){ 23 | System.out.println("Area of Square is : " + area); 24 | } 25 | 26 | } 27 | 28 | 29 | 30 | public class _25_Oops_Area_of_Square { 31 | 32 | public static void main(String[] args) { 33 | 34 | 35 | Square sqr = new Square(); 36 | 37 | sqr.input(); 38 | sqr.compute(); 39 | sqr.disp(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /11_Exception_Handling/_01_Types_of_Errors.java: -------------------------------------------------------------------------------- 1 | public class _01_Types_of_Errors { 2 | 3 | public static void main(String[] args) { 4 | 5 | // Different types of Errors in Java 6 | // In any programming language we categorise errors into 3 types 7 | // 1. Syntax Error :- If we write wrong syntax. 8 | // 2. Logical Error :- Our logic is wrong in the code. 9 | // 3. Runtime Error :- Some Error on the running time of the code. like 5 divided by 0 this code is right but java shows the error.. 10 | 11 | 12 | // What is an Exception? 13 | // ● An unwanted/expected event that disturbs the normal flow of execution of a program is called "Exception handling". 14 | // ● The main objective of Exception handling is to handle the exception. 15 | // ● It is available for graceful termination of program. 16 | 17 | 18 | } 19 | } -------------------------------------------------------------------------------- /19_Searching_Sorting_and_Bit_Manipulation/_01_Linear_Search.java: -------------------------------------------------------------------------------- 1 | public class _01_Linear_Search { 2 | 3 | // Time Complexity = O(n) 4 | // Time Complexity = O(1) 5 | 6 | public static void main(String[] args) { 7 | 8 | int arr[] = { 1, 2, 3, 4, 10, 9, 8, 7, 6, 5 }; 9 | 10 | int searchingElement = 5; 11 | 12 | LinearSearch(arr, searchingElement); 13 | } 14 | 15 | public static void LinearSearch(int arr[], int k) { 16 | 17 | int val = -1; 18 | for (int i = 0; arr.length > i; i++) { 19 | if (arr[i] == k) { 20 | System.out.println("Your " + k + " th Element is present on the IndexNumber : " + i); 21 | val = i; 22 | break; 23 | } 24 | } 25 | 26 | if (val == -1) { 27 | System.out.println("Your Searching Element is Not Founded ..! "); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /25_Greedy_Algorithms/_04_Minimum_Number_of_Swaps.java: -------------------------------------------------------------------------------- 1 | public class _04_Minimum_Number_of_Swaps { 2 | 3 | public static int minimumNumberOfSwaps(String s){ 4 | int count = 0; 5 | int left = 0; 6 | int right = 0; 7 | int swap = 0; 8 | 9 | char arr [] = s.toCharArray(); 10 | 11 | for(int i = 0; i < arr.length; i++){ 12 | if(arr[i] == '['){ 13 | left++; 14 | if(swap > 0){ 15 | count += swap; 16 | swap--; 17 | } 18 | }else{ 19 | right++; 20 | swap = right - left; 21 | } 22 | } 23 | 24 | 25 | return count; 26 | } 27 | 28 | public static void main(String[] args) { 29 | String s = "[]][]["; 30 | System.out.println("Minimu Number of Swaps is : " + minimumNumberOfSwaps(s)); 31 | } 32 | } -------------------------------------------------------------------------------- /04_Star_Pattern's/_20_Hollow_Power_Drum_in_java.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _20_Hollow_Power_Drum_in_java { 4 | 5 | public static void main(String args[]){ 6 | Scanner sc = new Scanner(System.in); 7 | 8 | // * * 9 | // * * * * 10 | // * * * 11 | // * * * * 12 | // * * 13 | 14 | int n ; 15 | System.out.println("Enter the Size of HollowPowerDrum : "); 16 | n = sc.nextInt(); 17 | 18 | for(int i = 1 ; n >= i ; i++){ 19 | 20 | for(int j = 1 ; n >= j ; j++){ 21 | if(j == 1 || j == n || j ==i || (j + i == n + 1)){ 22 | System.out.print("* "); 23 | }else{ 24 | System.out.print(" "); 25 | } 26 | } 27 | 28 | System.out.println(); 29 | } 30 | 31 | 32 | sc.close(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /26_Tree/_01_Tree.java: -------------------------------------------------------------------------------- 1 | // Create a Tree with 1 to 10 values and print it. 2 | class Node { 3 | int val; 4 | Node left; 5 | Node right; 6 | Node next; 7 | 8 | Node() {} 9 | 10 | Node(int val) { 11 | this.val = val; 12 | this.left = null; 13 | this.right = null; 14 | } 15 | } 16 | 17 | public class _01_Tree { 18 | public static void main(String[] args) { 19 | 20 | // Enter 1 to 10 values in the Tree one by one.. 21 | Node root = new Node(1); 22 | root.left = new Node(2); 23 | root.right = new Node(3); 24 | root.left.left = new Node(4); 25 | root.left.right = new Node(5); 26 | root.right.left = new Node(6); 27 | root.right.right = new Node(7); 28 | root.left.left.left = new Node(8); 29 | root.left.left.right = new Node(9); 30 | root.left.right.left = new Node(10); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /20_Recursion/_12_Alternate_Sign_Series_Sum.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class _12_Alternate_Sign_Series_Sum { 4 | public static void main(String[] args) { 5 | 6 | Scanner sc = new Scanner(System.in); 7 | 8 | System.out.print("Enter Number to Find Alternate Series Sum : "); 9 | int ass = sc.nextInt(); 10 | 11 | int sum = alternateSign(ass); 12 | 13 | System.out.println("Alternate Sign Series Sum is (-1,+2,-3,+4,-5,.... ) : " + sum); 14 | 15 | sc.close(); 16 | } 17 | 18 | // To Find Alternate Sign Series Sum using Recursion.. 19 | public static int alternateSign(int n) { 20 | if (n == 0) { 21 | return 0; 22 | } else { 23 | if (n % 2 == 0) { 24 | return alternateSign(n - 1) - n; 25 | } else { 26 | return alternateSign(n - 1) + n; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /11_Exception_Handling/_07_Custom_Exception_And_Throw_Keyword.java: -------------------------------------------------------------------------------- 1 | class MyException extends Exception { 2 | 3 | public MyException() { 4 | super(); 5 | } 6 | 7 | public MyException(String msg) { 8 | super(msg); 9 | } 10 | } 11 | 12 | public class _07_Custom_Exception_And_Throw_Keyword { 13 | 14 | public static void main(String[] args) { 15 | 16 | int a = 10; 17 | int b = -5; 18 | 19 | int result = 0; 20 | 21 | try { 22 | if (b < 0) { 23 | Exception x = new MyException("Custom"); // also (new Exception("Negative Number..")) 24 | throw x; // throw Keyword 25 | } else { 26 | result = a / b; 27 | System.out.println(result); 28 | } 29 | } catch (Exception x) { 30 | System.out.println("In this program there is a an Error : " + x); 31 | } 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /03_Operators_and_Loops/_18_label_in_java.java: -------------------------------------------------------------------------------- 1 | public class _18_label_in_java { 2 | 3 | 4 | public static void main(String args[]){ 5 | 6 | 7 | // In Java, a label is an identifier that can be used to mark a specific point in the code. Labels are typically used in conjunction with loops or conditional statements to specify a target point for control flow statements like break and continue. 8 | 9 | // Here's an example of how labels can be used in Java: 10 | outerloop: 11 | for (int i = 0; i < 10; i++) { 12 | innerloop: 13 | for (int j = 0; j < 10; j++) { 14 | if (i == 5 ) { 15 | break outerloop; // break out of the outerloop 16 | }else if(j == 5){ 17 | continue innerloop ; // continue of the innerloop 18 | } 19 | System.out.println("i: " + i + ", j: " + j); 20 | } 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /04_Star_Pattern's/_10_Right_down_Mirror_Pattern.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _10_Right_down_Mirror_Pattern { 4 | 5 | 6 | public static void main(String args[]){ 7 | Scanner sc = new Scanner(System.in); 8 | 9 | 10 | // ***** 11 | // **** 12 | // *** 13 | // ** 14 | // * 15 | 16 | int n, temp ; 17 | System.out.println("Enter the Height of Triangle : "); 18 | n = sc.nextInt(); 19 | 20 | temp = n ; 21 | for(int i = 0 ; n > i ; i++){ 22 | 23 | for(int j = 0 ; i > j ; j++){ 24 | System.out.print(" "); 25 | } 26 | 27 | for(int k = temp ; 0 < k ; k--){ 28 | System.out.print("*"); 29 | } 30 | 31 | System.out.println(); 32 | temp--; 33 | } 34 | 35 | sc.close(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /04_Star_Pattern's/_22_Hollow_Multi_Rhombus_In_Rectange.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _22_Hollow_Multi_Rhombus_In_Rectange { 4 | 5 | public static void main(String args[]){ 6 | Scanner sc = new Scanner(System.in); 7 | 8 | 9 | int n ; 10 | System.out.println("Enter The Size of the Multipul Rhombus : "); 11 | n = sc.nextInt(); 12 | 13 | 14 | for(int i = 0 ; n > i ; i++){ 15 | 16 | for(int j = 0 ; n > j ; j++){ 17 | if( (i == j) || (i + j == (n-1)) || (i == 0) || (j == 0) || (i == n-1) || (j == n-1) || (i + j == (n-1)/2) || (j - i == (n-1)/2) || (i - j == (n-1) / 2) || (i + j == (n-1)/2 + (n-1))){ 18 | System.out.print("* "); 19 | }else{ 20 | System.out.print(" "); 21 | } 22 | } 23 | 24 | System.out.println(); 25 | } 26 | 27 | sc.close(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /04_Star_Pattern's/_09_Reversed_Pyramid_Pattern.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _09_Reversed_Pyramid_Pattern { 4 | 5 | public static void main(String args[]){ 6 | Scanner sc = new Scanner(System.in); 7 | 8 | 9 | // * * * * * 10 | // * * * * 11 | // * * * 12 | // * * 13 | // * 14 | 15 | int n, temp ; 16 | System.out.println("Enter the Height of Triangle : "); 17 | n = sc.nextInt(); 18 | 19 | temp = n ; 20 | for(int i = 0 ; n > i ; i++){ 21 | 22 | for(int j = 0 ; i > j ; j++){ 23 | System.out.print(" "); 24 | } 25 | 26 | for(int k = temp ; 0 < k ; k--){ 27 | System.out.print("* "); 28 | } 29 | 30 | System.out.println(); 31 | temp--; 32 | } 33 | 34 | sc.close(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /09_Oops/_30_NoDuplicates.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | 4 | public class _30_NoDuplicates { 5 | 6 | public static void main(String[] args) { 7 | 8 | Scanner sc = new Scanner(System.in); 9 | 10 | System.out.println("Enter the value of string for which hou would like to remove the duplicates : "); 11 | 12 | String S1 = sc.next(); 13 | String S2 = "" ; 14 | 15 | for(int i = 0 ; i < S1.length() ; i++){ 16 | boolean isDuplicate = false ; 17 | for(int j = i + 1 ; j < S1.length(); j++){ 18 | if(S1.charAt(i) == S1.charAt(j)){ 19 | System.out.println(S1.charAt(i)); 20 | isDuplicate = true ; 21 | } 22 | } 23 | if(!isDuplicate){ 24 | S2 = S2 + S1.charAt(i); 25 | } 26 | } 27 | 28 | System.out.println(S2); 29 | 30 | sc.close(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /10_Interfacr_&_Lambda_Expression/_03_Interface_Small_Project.java: -------------------------------------------------------------------------------- 1 | interface Computer{ 2 | void compileCode(); 3 | } 4 | 5 | 6 | class Desktop implements Computer { 7 | @Override 8 | public void compileCode(){ 9 | System.out.println("You got 5 Errors..!, But It is Faster.."); 10 | } 11 | } 12 | 13 | class Laptop implements Computer { 14 | @Override 15 | public void compileCode(){ 16 | System.out.println("You got 5 Errors..!"); 17 | } 18 | } 19 | 20 | 21 | class Devloper{ 22 | 23 | public void buildApp(Computer ref){ 24 | System.out.println("Building App..!"); 25 | ref.compileCode(); 26 | } 27 | } 28 | 29 | public class _03_Interface_Small_Project { 30 | 31 | public static void main(String[] args) { 32 | 33 | Computer dec = new Desktop(); 34 | // Computer dec = new Laptop(); 35 | 36 | Devloper dev = new Devloper(); 37 | dev.buildApp(dec); 38 | } 39 | } -------------------------------------------------------------------------------- /04_Star_Pattern's/_16_Hollow_F_Pattern_in_java.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _16_Hollow_F_Pattern_in_java { 4 | 5 | 6 | public static void main(String arg[]){ 7 | Scanner sc = new Scanner(System.in); 8 | 9 | // * * * * * * 10 | // * 11 | // * * * * * * 12 | // * 13 | // * 14 | // * 15 | 16 | int n ; 17 | System.out.println("Enter the Size of the H : "); 18 | n = sc.nextInt(); 19 | for(int i = 1 ; n >= i ; i++){ 20 | 21 | for(int j = 1 ; n >= j ; j++){ 22 | if(i == 1 || j == 1 || i == n/2 ){ 23 | System.out.print("* "); 24 | }else{ 25 | System.out.print(" "); 26 | } 27 | } 28 | 29 | System.out.println(); 30 | } 31 | 32 | sc.close(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /23_HashMap_Stack_and_Queue/_09_Queue.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _09_Queue { 4 | public static void main(String[] args) { 5 | Queue q = new LinkedList<>(); 6 | 7 | // to add the data inside the queue - enqueue 8 | for (int i = 0; i < 10; i++) { 9 | q.add(i); 10 | } 11 | 12 | System.out.println("Queue data looks like: " + q); 13 | 14 | // to display the top element present in the queue 15 | System.out.println("The top element in the queue before deletion is: " + q.peek()); 16 | 17 | // to remove the element from the queue - dequeue 18 | q.remove(); 19 | 20 | // to display the top element present in the queue 21 | System.out.println("The top element in the queue after deletion is: " + q.peek()); 22 | 23 | // to check the size of the queue 24 | System.out.println("The current size of the queue is: " + q.size()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /19_Searching_Sorting_and_Bit_Manipulation/_02_Binary_Search.java: -------------------------------------------------------------------------------- 1 | public class _02_Binary_Search { 2 | 3 | // Time Complexity = O(log2N) or O(logN) 4 | // Time Complexity = O(i) 5 | 6 | public static int Binary_Search(int arr[], int key) { 7 | 8 | int start = 0, end = arr.length - 1; 9 | 10 | while (start <= end) { 11 | int mid = (start + end) / 2; 12 | 13 | if (arr[mid] == key) { 14 | return mid; 15 | } 16 | if (arr[mid] < key) { 17 | start = mid + 1; 18 | } else { 19 | end = mid - 1; 20 | } 21 | 22 | } 23 | 24 | return -1; 25 | } 26 | 27 | public static void main(String args[]) { 28 | 29 | int arr[] = { 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 }; 30 | int key = 19; 31 | int searched = Binary_Search(arr, key); 32 | 33 | System.out.println(searched); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /04_Star_Pattern's/_15_Hollow_E_Pattern_in_java.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _15_Hollow_E_Pattern_in_java { 4 | 5 | 6 | public static void main(String arg[]){ 7 | Scanner sc = new Scanner(System.in); 8 | 9 | // * * * * * * 10 | // * 11 | // * * * * * * 12 | // * 13 | // * 14 | // * * * * * * 15 | 16 | int n ; 17 | System.out.println("Enter the Size of the H : "); 18 | n = sc.nextInt(); 19 | for(int i = 1 ; n >= i ; i++){ 20 | 21 | for(int j = 1 ; n >= j ; j++){ 22 | if(i == 1 || i == n || j == 1 || i == n/2 ){ 23 | System.out.print("* "); 24 | }else{ 25 | System.out.print(" "); 26 | } 27 | } 28 | 29 | System.out.println(); 30 | } 31 | 32 | sc.close(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /09_Oops/_19_Introduction_to_Polymorphism.java: -------------------------------------------------------------------------------- 1 | // What is polymorphism ? 2 | // if one thing exists in more than one form then it is called polymorphism. 3 | // Polymorphism is a Greek word, where poly means many and morphism means structures or forms. 4 | 5 | // 1. Static Polymorphism . 6 | // 2. Dynamic Polymorphism . 7 | 8 | 9 | 10 | // How to achieve polymorphism: 11 | 12 | // Polymorphism in Java can be achieved in two ways i.e., method overloading and method overriding. 13 | // Polymorphism in Java is mainly divided into two types. 14 | 15 | // 1. Static Polymorphism: 16 | // If polymorphism exists at compilation time then it is called Static Polymorphism. 17 | // Ex: Overloading. 18 | 19 | // 2. Dynamic Polymorphism: 20 | // If the polymorphism exists at runtime then that polymorphism is called Dynamic 21 | // Polymorphism. 22 | // Ex: Overriding 23 | public class _19_Introduction_to_Polymorphism { 24 | 25 | public static void main(String[] args) { 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /04_Star_Pattern's/_05_Left_Triangle_Star_Pattern.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _05_Left_Triangle_Star_Pattern { 4 | 5 | public static void main(String args[]){ 6 | Scanner sc = new Scanner(System.in); 7 | 8 | // * 9 | // * * 10 | // * * * 11 | // * * * * 12 | // * * * * * 13 | 14 | int n, h ; 15 | System.out.println("Enter the Height of the Left Triangle : "); 16 | n = sc.nextInt(); 17 | 18 | h = n-1 ; 19 | for(int i = 0 ; n > i ; i++){ 20 | 21 | for(int j = h ; j > 0 ; j-- ){ 22 | System.out.print(" "); 23 | } 24 | 25 | for(int k = 0 ; i > k ; k++){ 26 | System.out.print("* "); 27 | } 28 | System.out.println(); 29 | h--; 30 | } 31 | sc.close(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /04_Star_Pattern's/_13_Hollow_H_Pattern_in_java.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _13_Hollow_H_Pattern_in_java { 4 | 5 | public static void main(String arg[]){ 6 | Scanner sc = new Scanner(System.in); 7 | 8 | // * * 9 | // * * 10 | // * * * * * * 11 | // * * 12 | // * * 13 | // * * 14 | 15 | int n ; 16 | System.out.println("Enter the Size of the H : "); 17 | n = sc.nextInt(); 18 | for(int i = 1 ; n >= i ; i++){ 19 | 20 | for(int j = 1 ; n >= j ; j++){ 21 | if(j == 1 || j == n || i == n/2 ){ 22 | System.out.print("* "); 23 | }else{ 24 | System.out.print(" "); 25 | } 26 | } 27 | 28 | System.out.println(); 29 | } 30 | 31 | sc.close(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /04_Star_Pattern's/_21_Hollow_Rhombus_Pattern.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _21_Hollow_Rhombus_Pattern { 4 | 5 | public static void main(String args[]){ 6 | Scanner sc = new Scanner(System.in); 7 | 8 | // * 9 | // * * 10 | // * * 11 | // * * 12 | // * 13 | 14 | int n ; 15 | System.out.println("Enter the Size of The Rhombus : "); 16 | n = sc.nextInt(); 17 | 18 | 19 | for(int i = 0 ; n > i ; i++){ 20 | 21 | for(int j = 0 ; n > j ; j++){ 22 | 23 | if( i + j == (n-1)/2 || j - i == (n-1)/2 || i - j == (n-1) / 2 || i + j == (n-1)/2 + (n-1) ){ 24 | System.out.print("* "); 25 | }else{ 26 | System.out.print(" "); 27 | } 28 | } 29 | 30 | System.out.println(); 31 | } 32 | 33 | sc.close(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /04_Star_Pattern's/_14_Hollow_I_Pattern_in_java.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _14_Hollow_I_Pattern_in_java { 4 | 5 | public static void main(String arg[]){ 6 | Scanner sc = new Scanner(System.in); 7 | 8 | // * * * * * * 9 | // * 10 | // * 11 | // * 12 | // * 13 | // * 14 | // * * * * * * 15 | 16 | int n ; 17 | System.out.println("Enter the Size of the H : "); 18 | n = sc.nextInt(); 19 | for(int i = 1 ; n >= i ; i++){ 20 | 21 | for(int j = 1 ; n >= j ; j++){ 22 | if(i == 1 || i == n || j == n/2 ){ 23 | System.out.print("* "); 24 | }else{ 25 | System.out.print(" "); 26 | } 27 | } 28 | 29 | System.out.println(); 30 | } 31 | 32 | sc.close(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /07_Arrays/_09_Anonymous_Array.java: -------------------------------------------------------------------------------- 1 | class print { 2 | 3 | 4 | public int printArray(int arr[]){ 5 | 6 | int result = 0 ; 7 | 8 | for(int n : arr){ 9 | result += n ; 10 | } 11 | 12 | return result ; 13 | 14 | } 15 | } 16 | 17 | public class _09_Anonymous_Array { 18 | 19 | public static void main(String args[]){ 20 | 21 | 22 | // In Java, an anonymous array is an array that is declared and instantiated without assigning it to a variable. This means that the array is created and used all in one line of code, without giving it a name. 23 | 24 | print obj = new print() ; 25 | 26 | int arr [] = {1,2,3,4,5,6,7,8,9,10} ; 27 | 28 | 29 | int Sum1 = obj.printArray(arr) ; // Normal Array .. 30 | int Sum2 = obj.printArray(new int[]{1,2,3,4,5,6,7,8,9,10} ) ; // Anonymous Array.. 31 | 32 | 33 | System.out.println(Sum1); 34 | System.out.println(Sum2); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /16_Important_API's_and_Annotation/_01_Date_and_Time.java: -------------------------------------------------------------------------------- 1 | // import java.util.*; 2 | // import java.sql.*; 3 | 4 | public class _01_Date_and_Time { 5 | 6 | // Date and Time API in java 7 | // Date and Time API: (Joda-Time API) 8 | // ● Until Java 1.7 version the classes present in Java.util package to handle 9 | // Date and Time (like Date, Calendar,TimeZone etc) are not up to the mark with 10 | // respect to convenience and performance. 11 | // ● To overcome this problem in the 1.8 version oracle people introduced 12 | // Joda-Time API. 13 | // ● This API developed by joda.org and available in Java in the form of 14 | // "java.time" package. 15 | public static void main(String[] args) { 16 | 17 | java.util.Date date = new java.util.Date(); 18 | 19 | System.out.println(date); 20 | 21 | long timeInMileSec = date.getTime(); 22 | 23 | java.sql.Date date1 = new java.sql.Date(timeInMileSec); 24 | 25 | System.out.println(date1); 26 | } 27 | } -------------------------------------------------------------------------------- /30_Dynamic_Programming/_04_ClimbingStairsVariation_DP_Tabulation.java: -------------------------------------------------------------------------------- 1 | // in this Climbing Stairs Variation problem:- Count ways to reach the nth stair. The person can climb either 1 stair, 2 stairs and 3 stairs at a time. 2 | // Time Complexity: O(n) 3 | // Space Complexity: O(n) 4 | 5 | public class _04_ClimbingStairsVariation_DP_Tabulation { 6 | 7 | public static int climbingStairTabulation(int n) { 8 | int[] dp = new int[n + 1]; 9 | 10 | for (int i = 1; i <= n; i++) { 11 | if (i == 1) { 12 | dp[i] = 1; 13 | } else if (i == 2) { 14 | dp[i] = 2; 15 | } else if (i == 3) { 16 | dp[i] = 4; 17 | } else { 18 | dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3]; 19 | } 20 | } 21 | 22 | return dp[n]; 23 | } 24 | 25 | public static void main(String[] args) { 26 | int n = 5; 27 | 28 | System.out.println(climbingStairTabulation(n)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /04_Star_Pattern's/_17_Hollow_Advance_A_Pattern_in_java.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _17_Hollow_Advance_A_Pattern_in_java { 4 | 5 | 6 | public static void main(String args[]){ 7 | Scanner sc = new Scanner(System.in); 8 | 9 | // * * * 10 | // * * 11 | // * * * * * 12 | // * * 13 | // * * 14 | 15 | 16 | int n ; 17 | System.out.println("Enter the Size of the A : "); 18 | n = sc.nextInt(); 19 | 20 | for(int i = 1 ; n >= i ; i++){ 21 | for(int j = 1 ; n/2 >= j ; j++){ 22 | if(i == n/2 || (i == 1 && j != n/2 && j != 1) || (j == 1 && i != 1) || (j == n/2 && i != 1)){ 23 | System.out.print("* "); 24 | }else{ 25 | System.out.print(" "); 26 | } 27 | } 28 | System.out.println(); 29 | } 30 | 31 | sc.close(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /04_Star_Pattern's/_12_Hollow_A_Pattern_in_java.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _12_Hollow_A_Pattern_in_java { 4 | 5 | public static void main(String args[]){ 6 | Scanner sc = new Scanner(System.in); 7 | 8 | // * * * * * * 9 | // * * 10 | // * * 11 | // * * * * * * 12 | // * * 13 | // * * 14 | 15 | int n ; 16 | System.out.println("Enter the Size of the A : "); 17 | n = sc.nextInt(); 18 | for(int i = 1 ; n >= i ; i++){ 19 | 20 | for(int j = 1 ; n >= j ; j++){ 21 | if(i == 1 || j == 1 || j == n || i == n/2 ){ 22 | System.out.print("* "); 23 | }else{ 24 | System.out.print(" "); 25 | } 26 | } 27 | 28 | System.out.println(); 29 | } 30 | 31 | sc.close(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /09_Oops/_24_Oops_Area_of_Rectangle.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class Rectangle{ 4 | 5 | float length ; 6 | float breadth ; 7 | float area ; 8 | 9 | public void input(){ 10 | System.out.println("Calculation of Rectangle App : "); 11 | Scanner sc = new Scanner(System.in); 12 | 13 | System.out.print("Enter the Length : "); 14 | length = sc.nextFloat(); 15 | 16 | System.out.print("Enter the Breadth : "); 17 | breadth = sc.nextFloat(); 18 | 19 | sc.close(); 20 | } 21 | 22 | public void compute(){ 23 | area = length * breadth ; 24 | } 25 | 26 | public void disp(){ 27 | System.out.println("Area of Rectangle is : " + area); 28 | } 29 | 30 | } 31 | 32 | 33 | public class _24_Oops_Area_of_Rectangle { 34 | 35 | public static void main(String[] args) { 36 | 37 | Rectangle rec = new Rectangle(); 38 | 39 | rec.input(); 40 | rec.compute(); 41 | rec.disp(); 42 | } 43 | } -------------------------------------------------------------------------------- /08_Strings/_14_Pangram_Program.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _14_Pangram_Program { 4 | 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | 8 | String str = sc.nextLine() ; 9 | 10 | str = str.replace(" ", "") ; 11 | str = str.toUpperCase() ; 12 | 13 | char strArr[] = str.toCharArray() ; 14 | 15 | int intArr[] = new int[26] ; 16 | 17 | for(int i = 0 ; strArr.length > i ; i++){ 18 | intArr[strArr[i]-65]++ ; 19 | } 20 | 21 | boolean check = true ; 22 | 23 | for(int i = 0 ; intArr.length > i ; i++){ 24 | if(intArr[i] == 0){ 25 | check = false ; 26 | } 27 | } 28 | 29 | if(check){ 30 | System.out.println("This Sting is a Pangram ..."); 31 | }else{ 32 | System.out.println("This String is Not-Pangram ..."); 33 | } 34 | 35 | 36 | sc.close(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /15_Map_and_Generics/_09_HashMap.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Employee { 4 | private String name; 5 | private int empId; 6 | 7 | public Employee(String name, int empId) { 8 | this.name = name; 9 | this.empId = empId; 10 | } 11 | 12 | public String toString() { 13 | return empId + ""; 14 | } 15 | 16 | @Override 17 | public void finalize() { 18 | System.out.println("clean up work by GC before de allocating memoery from heap"); 19 | 20 | } 21 | 22 | } 23 | 24 | public class _09_HashMap { 25 | public static void main(String[] args) { 26 | 27 | Employee e = new Employee("Hyder", 171); 28 | 29 | HashMap hm = new HashMap(); 30 | hm.put(e, "Hyder"); 31 | System.out.println(hm); 32 | 33 | e = null;// eligible for garbage collection 34 | 35 | System.gc(); // invocking garbage collector 36 | 37 | System.out.println(hm); 38 | 39 | System.out.println("Last line"); 40 | 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /04_Star_Pattern's/_08_Mirrored_Right_Triangle_Pattern.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _08_Mirrored_Right_Triangle_Pattern { 4 | 5 | public static void main(String args[]){ 6 | Scanner sc = new Scanner(System.in); 7 | 8 | // * 9 | // ** 10 | // *** 11 | // **** 12 | // ***** 13 | // ****** 14 | 15 | int n, blank ; 16 | System.out.println("Enter the Height of the Triangle : "); 17 | n = sc.nextInt(); 18 | 19 | blank = n-1 ; 20 | 21 | for(int i = 0 ; n > i ; i++){ 22 | 23 | for(int j = blank ; 0 < j ; j--){ 24 | System.out.print(" "); 25 | } 26 | 27 | for(int k = 0 ; i > k ; k++){ 28 | System.out.print("*"); 29 | } 30 | 31 | System.out.println(); 32 | blank--; 33 | } 34 | 35 | 36 | sc.close(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /07_Arrays/_03_Array_Input_Output_using_methods.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class _03_Array_Input_Output_using_methods { 4 | 5 | // For input 6 | public static void inputArray(int arr[], int n){ 7 | Scanner sc = new Scanner(System.in); 8 | 9 | for(int i = 0 ; n > i ; i++){ 10 | arr[i] = sc.nextInt(); 11 | } 12 | 13 | sc.close(); 14 | } 15 | 16 | // For Output 17 | public static void printArray(int arr[], int n){ 18 | 19 | for(int i = 0 ; n > i ; i++){ 20 | System.out.println(arr[i]); 21 | } 22 | } 23 | 24 | // Main Function 25 | public static void main(String[] args) { 26 | Scanner sc = new Scanner(System.in); 27 | 28 | int n ; 29 | System.out.println("What is the Size of the Array : "); 30 | n = sc.nextInt(); 31 | 32 | int arr[] = new int[n]; 33 | 34 | inputArray(arr, n); 35 | printArray(arr, n); 36 | 37 | sc.close(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /12_MultiThreading/_01_Introduction_to_Multithreading.java: -------------------------------------------------------------------------------- 1 | public class _01_Introduction_to_Multithreading { 2 | 3 | public static void main(String[] args) { 4 | 5 | // Multithreading in Java allows multiple threads of execution to run 6 | // concurrently within the same program, allowing for more efficient use of 7 | // system resources. This can be particularly useful for applications that 8 | // require parallel processing or handling of multiple tasks simultaneously. 9 | 10 | System.out.println("Main Thread in java"); 11 | 12 | String threadName = Thread.currentThread().getName(); 13 | System.out.println("Name of the Current Thread is : " + threadName); 14 | 15 | long threadId = Thread.currentThread().getId(); 16 | System.out.println("Id of the Current Thread is : " + threadId); 17 | 18 | int threadPriority = Thread.currentThread().getPriority(); 19 | System.out.println("Priority of the Current Thread is : " + threadPriority); 20 | 21 | } 22 | } -------------------------------------------------------------------------------- /11_Exception_Handling/_03_Exception_Handling_TryWithMultipleCatchBlocks.java: -------------------------------------------------------------------------------- 1 | public class _03_Exception_Handling_TryWithMultipleCatchBlocks { 2 | 3 | public static void main(String[] args) { 4 | 5 | // In this code we will see how to include multipule CatchBlocks in a Exception Handling.. 6 | 7 | 8 | int a = 5 ; 9 | int b = 0 ; 10 | 11 | int result = 0 ; 12 | 13 | int marks[] = {1,2,3,4,5} ; 14 | 15 | try{ 16 | result = a / b ; 17 | System.out.println(marks[7]); 18 | }catch(ArithmeticException c){ 19 | System.out.println("you Can't divide by Zero : "+ c); 20 | }catch(ArrayIndexOutOfBoundsException d){ 21 | System.out.println("Please write the index under the Range : " + d); 22 | }catch(Exception e ){ 23 | System.out.println("Something went Wrong in this code : " + e); 24 | } 25 | 26 | System.out.println(result); 27 | System.out.println("Bye bye..!"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /04_Star_Pattern's/_18_Hollow_Advance_D_Pattern_in_java.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _18_Hollow_Advance_D_Pattern_in_java { 4 | 5 | public static void main(String args[]){ 6 | Scanner sc = new Scanner(System.in); 7 | 8 | // * * * * 9 | // * * 10 | // * * 11 | // * * 12 | // * * * * 13 | 14 | int n ; 15 | System.out.println("Enter the Size of D : "); 16 | n = sc.nextInt(); 17 | 18 | for(int i = 1 ; n >= i ; i++){ 19 | 20 | for(int j = 1 ; n/2 >= j ; j++){ 21 | if(j == 1 || (i == 1 && j != n/2) || (j == n/2 && i != 1 && i != n) || (i == n && j != n/2) ){ 22 | System.out.print("* "); 23 | }else{ 24 | System.out.print(" "); 25 | } 26 | } 27 | 28 | System.out.println(); 29 | } 30 | 31 | 32 | sc.close(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /15_Map_and_Generics/_10_WeakHashMap.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Employee1 { 4 | private String name; 5 | private int empId; 6 | 7 | public Employee1(String name, int empId) { 8 | this.name = name; 9 | this.empId = empId; 10 | } 11 | 12 | public String toString() { 13 | return empId + ""; 14 | } 15 | 16 | @Override 17 | public void finalize() { 18 | System.out.println("clean up work by GC before de allocating memoery from heap"); 19 | 20 | } 21 | 22 | } 23 | 24 | public class _10_WeakHashMap { 25 | public static void main(String[] args) { 26 | 27 | Employee1 e = new Employee1("Hyder", 171); 28 | 29 | WeakHashMap hm = new WeakHashMap(); 30 | hm.put(e, "Hyder"); 31 | System.out.println(hm); 32 | 33 | e = null;// eligible for garbage collection 34 | 35 | System.gc(); // invocking garbage collector 36 | 37 | System.out.println(hm); 38 | 39 | System.out.println("Last line"); 40 | 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /28_Priority_Queue/_07_PriorityQueue_for_Objects_min.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _07_PriorityQueue_for_Objects_min { 4 | static class Student implements Comparable { // Overriding 5 | String name; 6 | int rank; 7 | 8 | public Student(String name, int rank) { 9 | this.name = name; 10 | this.rank = rank; 11 | } 12 | 13 | @Override 14 | public int compareTo(Student o) { 15 | return this.rank - o.rank; 16 | } 17 | } 18 | 19 | public static void main(String[] args) { 20 | PriorityQueue pq = new PriorityQueue<>(); 21 | 22 | pq.add(new Student("D", 40)); 23 | pq.add(new Student("A", 10)); 24 | pq.add(new Student("C", 30)); 25 | pq.add(new Student("E", 50)); 26 | pq.add(new Student("B", 20)); 27 | 28 | while (!pq.isEmpty()) { 29 | System.out.println(pq.peek().name + " --> " + pq.peek().rank); 30 | pq.remove(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /04_Star_Pattern's/_11_Hollow_Recttangle_in_java.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _11_Hollow_Recttangle_in_java { 4 | 5 | public static void main(String args[]){ 6 | Scanner sc = new Scanner(System.in); 7 | 8 | // * * * * * * 9 | // * * 10 | // * * 11 | // * * * * * * 12 | 13 | int l , w ; 14 | System.out.println("Enter the Length of the Rectange : "); 15 | l = sc.nextInt(); 16 | 17 | System.out.println("Enter the Width of the Rectange : "); 18 | w = sc.nextInt(); 19 | 20 | for(int i = 1 ; l >= i ; i++){ 21 | 22 | for(int j = 1 ; w >= j ; j++){ 23 | if(i == 1 || j == 1 || j == w || i == l ){ 24 | System.out.print("* "); 25 | }else{ 26 | System.out.print(" "); 27 | } 28 | } 29 | 30 | System.out.println(); 31 | } 32 | 33 | sc.close(); 34 | } 35 | } -------------------------------------------------------------------------------- /08_Strings/_09_Concatenation_Method3_String.java: -------------------------------------------------------------------------------- 1 | public class _09_Concatenation_Method3_String { 2 | 3 | public static void main(String[] args) { 4 | 5 | // Using (+ Operator) Concatenation in String 6 | String s1 = "Hello "; 7 | String s2 = "Priyanshu" + " Gour"; // In This method new s2 variable cont the value of (Priyanshu & Gour) in one variable in (SCP). without new object create becaue if we use refrence variable or pre-defined method then the new object was create in heap . but in this care No One new object create . 8 | String s3 = "Priyanshu" + " Gour" + " From Harda" ; // Same as it is no one new object create 9 | String s4 = s1 + s2 ; // but in this care new Object was created in heap out off the (SCP) because this was use refrence variables. 10 | 11 | 12 | System.out.println(s1); //Hello 13 | System.out.println(s2); // Priyanshu Gour 14 | System.out.println(s3); // Priyanshu Gour Form Harda 15 | System.out.println(s4); // Hello Priyanshu Gour 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /09_Oops/_28_Dependency_Injection.java: -------------------------------------------------------------------------------- 1 | class Student1{ 2 | private Heart h ; 3 | 4 | public Student1(Heart h){ 5 | this.h = h ; 6 | } 7 | 8 | public void setH(Heart h){ 9 | this.h = h ; 10 | } 11 | 12 | 13 | public void call(){ 14 | h.heartBeatr(); 15 | } 16 | } 17 | 18 | 19 | class Heart{ 20 | 21 | public void heartBeatr(){ 22 | System.out.println("heart is important ..!"); 23 | } 24 | } 25 | 26 | 27 | public class _28_Dependency_Injection { 28 | 29 | public static void main(String[] args) { 30 | // Dependency Injection (DI) is a design pattern used in software engineering that allows for the creation of loosely coupled code. In DI, the dependencies of a class are not instantiated within the class itself, but are instead passed in from outside. This helps to improve the testability, maintainability, and flexibility of the code. 31 | 32 | Heart h = new Heart(); 33 | 34 | Student1 s = new Student1(h); 35 | s.setH(h); 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /03_Operators_and_Loops/_02_Arithmetic_Operators.java: -------------------------------------------------------------------------------- 1 | public class _02_Arithmetic_Operators { 2 | 3 | 4 | public static void main(String args[]){ 5 | 6 | 7 | // Arithmetic operators are used in mathematical expressions in the same way that they 8 | // are used in algebra. The following lists the arithmetic operators: 9 | // 1. Addition(+) 10 | // 2. Subtraction(-) 11 | // 3. Multiplication(*) 12 | // 4. Division(/) 13 | // 5. Modulus(%) 14 | 15 | int a = 12; 16 | int b = 5; 17 | int sum = a + b; // addition operator 18 | int difference = a - b; // subtraction operator 19 | int product = a * b; // multiplication operator 20 | int quotient = a / b; // division operator 21 | int reminder = a % b ; // Modulus operator 22 | 23 | 24 | System.out.println(sum); 25 | System.out.println(difference); 26 | System.out.println(product); 27 | System.out.println(quotient); 28 | System.out.println(reminder); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /04_Star_Pattern's/_19_Hollow_Advance_X_Pattern_in_java.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _19_Hollow_Advance_X_Pattern_in_java { 4 | 5 | public static void main(String args[]){ 6 | Scanner sc = new Scanner(System.in); 7 | 8 | // * * 9 | // * * 10 | // * * 11 | // * 12 | // * * 13 | // * * 14 | // * * 15 | 16 | int n ; 17 | System.out.println("Enter the Size of X : "); 18 | n = sc.nextInt(); 19 | 20 | for(int i = 1 ; n >= i ; i++){ 21 | 22 | for(int j = 1 ; n >= j ; j++){ 23 | if(i == j || (i + j == 1 + n)){ 24 | System.out.print("* "); 25 | }else{ 26 | System.out.print(" "); 27 | } 28 | } 29 | 30 | System.out.println(); 31 | } 32 | 33 | sc.close(); 34 | } 35 | } -------------------------------------------------------------------------------- /09_Oops/_13_Types_Of_Method_Inherited.java: -------------------------------------------------------------------------------- 1 | class Aeroplane{ 2 | 3 | void fly(){ 4 | System.out.println("AeroPlane is Flying ..! "); 5 | } 6 | void TackOff(){ 7 | System.out.println("AeroPlane is TakeOff ..!"); 8 | } 9 | } 10 | 11 | 12 | class CargoPlane extends Aeroplane{ 13 | 14 | } 15 | 16 | class PassengerPlane extends Aeroplane{ 17 | 18 | } 19 | 20 | 21 | public class _13_Types_Of_Method_Inherited { 22 | 23 | public static void main(String[] args) { 24 | 25 | 26 | // Inherited methods: Inherited methods are the methods that are inherited from the parent class to the child class. These methods are available to the child class without any need to redefine them. The child class can use these methods as they are or can also override them if needed. 27 | 28 | 29 | CargoPlane cp = new CargoPlane() ; 30 | cp.fly(); 31 | cp.TackOff(); 32 | 33 | PassengerPlane pp = new PassengerPlane(); 34 | pp.fly(); 35 | pp.TackOff(); 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /28_Priority_Queue/_08_PriorityQueue_for_Objects_max.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _08_PriorityQueue_for_Objects_max { 4 | static class Student implements Comparable { // Overriding 5 | String name; 6 | int rank; 7 | 8 | public Student(String name, int rank) { 9 | this.name = name; 10 | this.rank = rank; 11 | } 12 | 13 | @Override 14 | public int compareTo(Student o) { 15 | return this.rank - o.rank; 16 | } 17 | } 18 | 19 | public static void main(String[] args) { 20 | PriorityQueue pq = new PriorityQueue<>(Comparator.reverseOrder()); 21 | 22 | pq.add(new Student("D", 40)); 23 | pq.add(new Student("A", 10)); 24 | pq.add(new Student("C", 30)); 25 | pq.add(new Student("E", 50)); 26 | pq.add(new Student("B", 20)); 27 | 28 | while (!pq.isEmpty()) { 29 | System.out.println(pq.peek().name + " --> " + pq.peek().rank); 30 | pq.remove(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /13_CollectionFrameWork/_11_Enumeration.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Enumeration; 3 | import java.util.Collections; 4 | 5 | public class _11_Enumeration { 6 | public static void main(String[] args) { 7 | 8 | // Enumeration is an interface that allows you to traverse elements in a 9 | // collection, one at a time. It provides two methods hasMoreElements() and 10 | // nextElement() to access the next element in the collection. 11 | 12 | // Create an ArrayList of integers 13 | ArrayList numbers = new ArrayList(); 14 | numbers.add(1); 15 | numbers.add(2); 16 | numbers.add(3); 17 | numbers.add(4); 18 | numbers.add(5); 19 | 20 | // Get the Enumeration object 21 | Enumeration en = Collections.enumeration(numbers); 22 | 23 | // Traverse the ArrayList using the Enumeration object 24 | while (en.hasMoreElements()) { 25 | Integer num = en.nextElement(); 26 | System.out.println(num); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /17_IO_Operation/_08_BufferedWriter_And_FileWriter.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | public class _08_BufferedWriter_And_FileWriter { 4 | public static void main(String[] args) throws IOException { 5 | 6 | // the BufferedWriter and FileWriter classes can be used together to write 7 | // data to a file. The FileWriter class is used to write characters to a file, 8 | // while the BufferedWriter class provides a buffer for efficient writing of 9 | // data to the file. 10 | 11 | File dir = new File("Hey"); 12 | 13 | File file = new File(dir, "hey.txt"); 14 | 15 | FileWriter fw = new FileWriter(file, true); 16 | 17 | BufferedWriter bw = new BufferedWriter(fw); 18 | 19 | bw.write("Hey Why the way I am Priyanshu Gour"); 20 | bw.newLine(); 21 | bw.write(65); // A 22 | bw.newLine(); 23 | char ch[] = { 'j', 'a', 'v', 'a' }; 24 | bw.write(ch); 25 | bw.newLine(); 26 | 27 | bw.flush(); // This flush method is Recommened 28 | bw.close(); 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /03_Fundamentals_of_Java/_15_Identifiers.java: -------------------------------------------------------------------------------- 1 | public class _15_Identifiers { 2 | 3 | 4 | public static void main(String args){ 5 | // Identifiers 6 | // An identifier is a name given to a package, class, interface, method, or variable. All identifiers 7 | // must have different names. 8 | 9 | // In Java, there are a few points to remember while dealing with identifiers : 10 | // Rule 1 − All identifiers should begin with a letter (A to Z or a to z), $ and _ and must be 11 | // unique. 12 | // Rule 2 − After the first character/letter, identifiers can have any combination of characters. 13 | // Rule 3 − A keyword cannot be used as an identifier. 14 | // Rule 4 − The identifiers are case-sensitive. 15 | // Rule 5 – Whitespaces are not permitted.0 16 | 17 | // Examples of legal identifiers: rank, $name, _rate, __2_mark. 18 | // Examples of illegal identifiers: 102pqr, -name. 19 | 20 | // every variable name and or function or other which is use to identify data 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /03_Operators_and_Loops/_11_Switch_case.java: -------------------------------------------------------------------------------- 1 | public class _11_Switch_case { 2 | 3 | 4 | public static void main(String args[]){ 5 | 6 | 7 | // In Java, the switch statement allows you to execute different code blocks based on the value of a variable or an expression. There are several types of switch statements available in Java, including: 8 | 9 | 10 | // Switch statement with a single value: This type of switch statement allows you to test a variable or an expression against a single value. If the value matches the case label, the corresponding code block is executed. 11 | int num = 2; 12 | switch(num) { 13 | case 1: 14 | System.out.println("One"); 15 | break; 16 | case 2: 17 | System.out.println("Two"); 18 | break; 19 | case 3: 20 | System.out.println("Three"); 21 | break; 22 | default: 23 | System.out.println("Invalid number"); 24 | } 25 | 26 | 27 | 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /03_Fundamentals_of_Java/_04_Variables_in_java.java: -------------------------------------------------------------------------------- 1 | public class _04_Variables_in_java{ 2 | 3 | public static void main(String args []){ 4 | 5 | // ● A variable is the name of a memory-allocated reserved area. It may be thought of as 6 | // the name of a memory location, in other words. 7 | 8 | // ● While the Java programme is running, the value is held in a container. 9 | 10 | // ● To identify the storage location, each variable needs to have a special name. 11 | 12 | // ● A data type is assigned to a variable (we will learn about it after this topic). 13 | 14 | // Type variable_name = value; 15 | 16 | // The name of a variable is variable_name. The variable can be initialised by 17 | // supplying an equal sign and a value (initialization i.e. assigning an initial value, is 18 | // optional). However, a Java uninitialized local variable is never given a default 19 | // value by the compiler. 20 | // 21 | 22 | int hey ; 23 | hey = 100 ; 24 | System.out.println(hey); // 100 25 | } 26 | } -------------------------------------------------------------------------------- /07_Arrays/_04_2D_Array_Input_Output.java: -------------------------------------------------------------------------------- 1 | public class _04_2D_Array_Input_Output { 2 | 3 | // For Output Int 4 | public static void printArray(int arr[][], int n1, int n2){ 5 | 6 | for(int i = 0 ; n1 > i ; i++){ 7 | 8 | for(int j = 0 ; n2 > j ; j++){ 9 | System.out.print(arr[i][j] + ", "); 10 | } 11 | System.out.println(); 12 | } 13 | } 14 | 15 | public static void main(String[] args) { 16 | String strings[][] = {{"foo", "bar", "baz"}, {"hello", "world", "java"}}; 17 | 18 | for(int i = 0 ; 2 > i ; i++){ 19 | 20 | for(int j = 0 ; 3 > j ; j++){ 21 | System.out.print(strings[i][j] + ", "); 22 | } 23 | System.out.println(); 24 | } 25 | 26 | 27 | int nums[][] = new int[3][3]; 28 | int count = 1; 29 | for (int i = 0; i < nums.length; i++) { 30 | for (int j = 0; j < nums[i].length; j++) { 31 | nums[i][j] = count++; 32 | } 33 | } 34 | 35 | printArray(nums,3,3); 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /09_Oops/_06_Constructor_Overloading.java: -------------------------------------------------------------------------------- 1 | class Student1 //extends Object 2 | { 3 | private String name; 4 | private int age; 5 | 6 | public Student1() 7 | { 8 | System.out.println("Default Constructor is called"); 9 | name="Rohan"; 10 | age=18; 11 | } 12 | 13 | // Every Constructor have a inbilt Super() or This() Any one method . and Before executing Constructor any one super() or this() was run then Constructor.. 14 | public Student1(String name) 15 | { 16 | this.name=name; 17 | age=19; 18 | } 19 | public Student1(String name, int age) 20 | { 21 | 22 | this.name=name; 23 | this.age=age; 24 | } 25 | public void disp() 26 | { 27 | System.out.println(name); 28 | System.out.println(age); 29 | } 30 | } 31 | 32 | 33 | public class _06_Constructor_Overloading { 34 | public static void main(String[] args) { 35 | 36 | Student1 st1=new Student1(); 37 | st1.disp(); 38 | 39 | Student1 st2=new Student1("Rahul"); 40 | st2.disp(); 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /03_Fundamentals_of_Java/_11_Datatypes_Characters_with_Example.java: -------------------------------------------------------------------------------- 1 | public class _11_Datatypes_Characters_with_Example { 2 | 3 | 4 | public static void main(String args[]){ 5 | 6 | // Characters DataTypes 7 | // char :- 'a', 'A', 'P' ; 8 | 9 | 10 | // ASCII : American Standard Code for Information Interchange 11 | // In ASCII total 128 Characters which means 2pow(7) roundfigure 8bits required means 1 Bytes. if java follow ASCII then char required 1 Byte ..... 12 | 13 | 14 | // UTF : Unicode Transformation Format 15 | // In UTF total 65536 Characters which means 2pow(16) 16 bits required means 2 Bytes. if java follow UTF then char required 2 Bytes..... 16 | 17 | 18 | // JAVA Follow's UTF 19 | // char required 2 Bytes Memory for any character store.. 20 | 21 | 22 | // char hey = 'h' ; valid 23 | // char hey = 'h', 'e' ; Invalid 24 | // char hey = 'he' ; Invalid 25 | 26 | 27 | char A = 'P' ; 28 | 29 | System.out.println(A); 30 | 31 | 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /13_CollectionFrameWork/_14_FailFastExample.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | public class _14_FailFastExample { 4 | public static void main(String[] args) { 5 | ArrayList list = new ArrayList<>(); 6 | list.add(1); 7 | list.add(2); 8 | list.add(3); 9 | list.add(4); 10 | list.add(5); 11 | list.add(6); 12 | 13 | for (int i : list) { 14 | System.out.println(i); 15 | list.add(4); // Throws ConcurrentModificationException 16 | } 17 | 18 | // In the for loop, you are iterating over the list using the enhanced for loop 19 | // syntax (for-each loop), which internally uses an iterator. At the same time, 20 | // you are trying to add an element to the list using the add() method, which 21 | // modifies the list while it is being iterated over. 22 | 23 | // This violates the fail-fast behavior of the ArrayList collection, which is 24 | // designed to throw a ConcurrentModificationException if the list is modified 25 | // while it is being iterated over. 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /09_Oops/_09_More_On_Inheritance.java: -------------------------------------------------------------------------------- 1 | class Human1{ 2 | 3 | private String Name ; 4 | int Age ; 5 | 6 | void setName(){ 7 | Name = "Priyanshu gour" ; 8 | System.out.println(Name); 9 | } 10 | 11 | Human1(){ 12 | System.out.println("Human class Constructor.."); 13 | } 14 | 15 | void sleep(){ 16 | Age = 8 ; 17 | System.out.println("Atlest " + Age + " Age year older then you will drive.."); 18 | } 19 | } 20 | 21 | class Student1 extends Human1 { 22 | 23 | // public Student1(){ 24 | // super(); // By default the constructor call the Super Method and Super() method is call the Parent Constructor 25 | // } 26 | 27 | void disp(){ 28 | System.out.println(Age + "is my Age.. "); 29 | // System.out.println("my Name is " + Name); // We don't Access the (Private Member) of any class. 30 | } 31 | } 32 | 33 | public class _09_More_On_Inheritance { 34 | 35 | public static void main(String[] args) { 36 | 37 | Student1 st1 = new Student1(); 38 | 39 | st1.sleep(); 40 | st1.disp(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /10_Interfacr_&_Lambda_Expression/_06_Java8_Features.java: -------------------------------------------------------------------------------- 1 | interface A { 2 | void Show(); 3 | 4 | default void DefMethod(){ 5 | System.out.println("I am Default Method..!"); 6 | } 7 | 8 | static void StaMethod(){ 9 | System.out.println("I am Static Method..!"); 10 | } 11 | } 12 | 13 | class B implements A{ 14 | 15 | @Override 16 | public void Show(){ 17 | System.out.println("Hey I am Show..!"); 18 | } 19 | 20 | @Override 21 | public void DefMethod(){ 22 | System.out.println("Hey I am Default Method ..!"); 23 | } 24 | 25 | public void StaMethod(){ 26 | System.out.println("hey I am Static method ..!"); 27 | } 28 | } 29 | 30 | 31 | public class _06_Java8_Features { 32 | public static void main(String[] args) { 33 | 34 | // Default Methods: 35 | // Default methods allow you to add functionality to interfaces without breaking existing implementations. 36 | 37 | 38 | 39 | A b = new B() ; 40 | 41 | A.StaMethod(); 42 | 43 | b.Show(); 44 | b.DefMethod(); 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /26_Tree/_06_Height_Of_Tree.java: -------------------------------------------------------------------------------- 1 | // A class to store a binary tree node 2 | class Node 3 | { 4 | int key; 5 | Node left = null, right = null; 6 | 7 | Node(int key) { 8 | this.key = key; 9 | } 10 | } 11 | 12 | public class _06_Height_Of_Tree 13 | { 14 | // Recursive function to calculate the height of a given binary tree 15 | public static int height(Node root) 16 | { 17 | // base case: empty tree has a height of 0 18 | if (root == null) { 19 | return 0; 20 | } 21 | 22 | // recur for the left and right subtree and consider maximum depth 23 | return 1 + Math.max(height(root.left), height(root.right)); 24 | } 25 | 26 | public static void main(String[] args) 27 | { 28 | Node root = new Node(15); 29 | root.left = new Node(10); 30 | root.right = new Node(20); 31 | root.left.left = new Node(8); 32 | root.left.right = new Node(12); 33 | root.right.left = new Node(16); 34 | root.right.right = new Node(25); 35 | 36 | System.out.println("The height of the binary tree is " + height(root)); 37 | } 38 | } -------------------------------------------------------------------------------- /19_Searching_Sorting_and_Bit_Manipulation/_04_SquareRoot_Using_BinarySearch.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | // Time Complexity : O(logN) 4 | // Space Complexity : O(1) 5 | 6 | public class _04_SquareRoot_Using_BinarySearch { 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | 10 | System.out.print("Enter The Number to find Square Root : "); 11 | int num = sc.nextInt(); 12 | 13 | int sr = squareRoot(num); 14 | 15 | System.out.println("Square Root of the Number is : " + sr); 16 | 17 | sc.close(); 18 | } 19 | 20 | public static int squareRoot(int n) { 21 | 22 | int left = 0, right = n - 1, result = -1; 23 | 24 | while (left <= right) { 25 | int mid = (left + right) / 2; 26 | 27 | if (mid * mid == n) { 28 | result = mid; 29 | return result; 30 | } else if (mid * mid > n) { 31 | right = mid - 1; 32 | } else { 33 | left = mid + 1; 34 | result = mid; 35 | } 36 | } 37 | 38 | return result; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /12_MultiThreading/_10_Interrupt_In_Threading.java: -------------------------------------------------------------------------------- 1 | class myThread2 implements Runnable { 2 | 3 | public void run() { 4 | 5 | for (int i = 0; i < 3; i++) { 6 | System.out.println("Hey I am Working on myThread"); 7 | try { 8 | Thread.sleep(3000); // 3 sec in 3000 milesecond 9 | } catch (Exception e) { 10 | System.out.println("If An Any Exception : " + e); 11 | } 12 | } 13 | } 14 | } 15 | 16 | public class _10_Interrupt_In_Threading { 17 | public static void main(String[] args) { 18 | 19 | System.out.println("Main Thread Start.."); 20 | 21 | myThread2 mt = new myThread2(); 22 | 23 | Thread thr = new Thread(mt); 24 | 25 | thr.start(); 26 | thr.interrupt(); 27 | // interrupt() is a method used to interrupt a thread that is currently running. 28 | // When interrupt() is called on a thread, it sets a flag on the thread 29 | // indicating that it has been interrupted, which can be checked using the 30 | // isInterrupted() method. 31 | 32 | System.out.println("Main Thread Closed.. "); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /08_Strings/_10_String_Mthods_in_java.java: -------------------------------------------------------------------------------- 1 | public class _10_String_Mthods_in_java { 2 | 3 | public static void main(String[] args) { 4 | 5 | // All Common String Method we will discuss in this program .. 6 | 7 | String str = "Priyanshu Gour" ; 8 | 9 | System.out.println(str); 10 | System.out.println(str.toUpperCase()); // toUpperCase() 11 | System.out.println(str.toLowerCase()); // toLowerCase() 12 | System.out.println(str.length()); // length() 13 | System.out.println(str.charAt(10)); // charAt() 14 | System.out.print(str.substring(2));//searching from 2 to end of the string 15 | System.out.println(str.substring(4, 14)); // substring(start, end) 16 | System.out.println(str.indexOf('G')) ; // indexOf('G') 17 | System.out.println(str.lastIndexOf('u')); // lastIndexOf('u') 18 | System.out.println(str.trim()); // To remove the blank spaces present at the beginning and end of string but not the blank spaces present at the middle of the String. 19 | 20 | String s="ababab"; 21 | System.out.print(s.replace('a','b')); //bbbbbb 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /17_IO_Operation/_11_Introduction_to_Serialization_and_Deserialization.java: -------------------------------------------------------------------------------- 1 | public class _11_Introduction_to_Serialization_and_Deserialization { 2 | public static void main(String[] args) { 3 | 4 | // Serialization is the process of converting an object into a stream of bytes, 5 | // so that it can be stored in a file, sent over a network, or saved in a 6 | // database. This process is called serialization because it involves taking an 7 | // object and turning it into a series of bytes that can be "serialized" into a 8 | // file or other storage medium. 9 | 10 | // Deserialization is the process of converting a stream of bytes back into an 11 | // object. In other words, it is the process of taking the bytes that were 12 | // produced during serialization and turning them back into an object. 13 | 14 | // Serialization and deserialization are important concepts in Java because they 15 | // allow you to store and retrieve objects in a persistent manner, meaning that 16 | // the data will be preserved even if the application is closed or the computer 17 | // is turned off. 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /20_Recursion/_06_Finding_Of_Power_Optimized_Approach.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | // Time Complexity : O(log2b) 4 | // Space Complexity : O(n) 5 | 6 | public class _06_Finding_Of_Power_Optimized_Approach { 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | 10 | System.out.print("Enter the Number to Find Power : "); 11 | int a = sc.nextInt(); 12 | 13 | System.out.print("Enter the Power of Number : "); 14 | int b = sc.nextInt(); 15 | 16 | int pw = Power(a, b); 17 | 18 | System.out.println("Power is : " + pw); 19 | 20 | sc.close(); 21 | } 22 | 23 | // To find Power of an Element using Recusion Optimize Approach 24 | public static int Power(int a, int b) { 25 | if (b <= 1) { 26 | return a; 27 | } else { 28 | int mid = b / 2; 29 | int result = Power(a, mid); 30 | int finalResult = result * result; 31 | 32 | if (b % 2 != 0) { 33 | return a * finalResult; 34 | } else { 35 | return finalResult; 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /17_IO_Operation/_09_BufferedReader_And_FileReader.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | public class _09_BufferedReader_And_FileReader { 4 | public static void main(String[] args) throws IOException { 5 | 6 | // BufferedReader and FileReader are two classes that are commonly used to read 7 | // data from a file. 8 | // BufferedReader is a class in Java that is used to read text from a character 9 | // input stream (e.g., a file). It reads the data in chunks and stores it in 10 | // memory, which makes it faster than reading the data character-by-character. 11 | // It also provides a readLine() method, which reads a line of text from the 12 | // input stream. 13 | 14 | File dir = new File("Hey"); 15 | File file = new File(dir, "hey.txt"); 16 | 17 | FileReader fr = new FileReader(file); 18 | 19 | BufferedReader br = new BufferedReader(fr); 20 | 21 | String str = br.readLine(); 22 | 23 | while (str != null) { 24 | System.out.println(str); 25 | str = br.readLine(); 26 | } 27 | 28 | System.out.println(); 29 | 30 | br.close(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /23_HashMap_Stack_and_Queue/_04_First_Non_Repeating_character_HashMap.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _04_First_Non_Repeating_character_HashMap { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | 7 | System.out.print("Enter the String : "); 8 | String str = sc.nextLine(); 9 | 10 | HashMap map = new HashMap<>(); 11 | 12 | // Constructing the Hashtable.. 13 | // Key -> unique Characters in the String .. 14 | // value -> frequency of the character in the String .. 15 | 16 | for (int i = 0; str.length() > i; i++) { 17 | char ch = str.charAt(i); 18 | if (map.containsKey(ch)) { 19 | map.put(ch, map.get(ch) + 1); 20 | } else { 21 | map.put(ch, 1); 22 | } 23 | } 24 | 25 | for (int i = 0; map.size() - 1 > i; i++) { 26 | if (map.get(str.charAt(i)) == 1) { 27 | System.out.println("First Non Repeating Character is : " + str.charAt(i)); 28 | break; 29 | } 30 | } 31 | 32 | sc.close(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /08_Strings/_16_final_vs_Immutability.java: -------------------------------------------------------------------------------- 1 | public class _16_final_vs_Immutability { 2 | 3 | public static void main(String[] args) { 4 | 5 | // Final Keyword :- it means if we use final keyword then the refrence is fix we don't change to refrence . 6 | 7 | final float PI = 3.141f ; // the value is fix we can't change to value of PI 8 | 9 | // PI = 3.333 ; 10 | System.out.println(PI); 11 | 12 | // We apply the final keyword knowledge on the Sting 13 | 14 | final String pg = "priyanshu gour" ; 15 | String dg = "devanshu gour" ; 16 | // pg = "devanshu gour" ; // We can't change the value of pg because we use final keyword so we can't chage the refrence of the variable.. 17 | dg = "priyanshu gour" ; 18 | 19 | System.out.println(pg); 20 | System.out.println(dg); 21 | 22 | final StringBuilder strB = new StringBuilder("i am devil"); 23 | 24 | System.out.println(strB); 25 | strB.append(" But not harmfull.") ; // value was change because we use StringBuilder so the refrence was not change but value is change .. 26 | System.out.println(strB); 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /16_Important_API's_and_Annotation/_03_ForEach_Method.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _03_ForEach_Method { 4 | public static void main(String[] args) { 5 | 6 | java.util.List list1 = new java.util.ArrayList(); 7 | 8 | list1.add(20); 9 | list1.add(40); 10 | list1.add(60); 11 | list1.add(80); 12 | list1.add(100); 13 | System.out.println("Normal Input print : " + list1); 14 | 15 | for (Integer i : list1) { 16 | System.out.println(i); 17 | } 18 | 19 | System.out.println("**********************************************"); 20 | 21 | List list2 = Arrays.asList(10, 30, 50, 70, 90); 22 | System.out.println("Sort Input print : " + list2); 23 | 24 | for (Integer i : list2) { 25 | System.out.println(i); 26 | } 27 | 28 | System.out.println("**********************************************"); 29 | 30 | System.out.println("Modern ForEach Loop using Lambda .. !"); 31 | list1.forEach(n -> System.out.println(n)); 32 | // list1.forEach((Integer n) -> System.out.println(n)); // Both are same 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /23_HashMap_Stack_and_Queue/_02_Types_Of_Map.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _02_Types_Of_Map { 4 | public static void main(String[] args) { 5 | // unordered return type 6 | HashMap map = new HashMap<>(); 7 | map.put(3, "Priya"); 8 | map.put(1, "Ajay"); 9 | map.put(7, "Piyush"); 10 | map.put(5, "Jeet"); 11 | 12 | System.out.println("Hashmap class map looks like:" + map); 13 | 14 | // order of insertion retained in LinkedHashMap 15 | LinkedHashMap map1 = new LinkedHashMap<>(); 16 | map1.put(3, "Priya"); 17 | map1.put(1, "Ajay"); 18 | map1.put(7, "Piyush"); 19 | map1.put(5, "Jeet"); 20 | 21 | System.out.println("LinkedHashmap class map looks like:" + map1); 22 | 23 | // sorted output on the basis of the keys 24 | TreeMap map2 = new TreeMap<>(); 25 | map2.put(3, "Priya"); 26 | map2.put(1, "Ajay"); 27 | map2.put(7, "Piyush"); 28 | map2.put(5, "Jeet"); 29 | map2.put(6, "Anjali"); 30 | 31 | System.out.println("TreeMap class map looks like:" + map2); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /04_Star_Pattern's/_23_Upper_Left_Triangle.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _23_Upper_Left_Triangle { 4 | 5 | public static void main(String args[]){ 6 | Scanner sc = new Scanner(System.in); 7 | 8 | // * * * * * * * * 9 | // * * * * * * * 10 | // * * * * * * 11 | // * * * * * 12 | // * * * * 13 | // * * * 14 | // * * 15 | // * 16 | 17 | 18 | int n ; 19 | System.out.println("Enter the Size of the Rhombus : "); 20 | n = sc.nextInt(); 21 | 22 | for(int i = 0 ; n > i ; i++){ 23 | 24 | for(int j = 0 ; n > j ; j++){ 25 | 26 | // for Fill upper left Area ==> (i == 0 && j <= (n-1)/2 || j == 0 && i < (n-1)/2 || i+j <= (n-1)/2) 27 | 28 | if( i == 0 && j <= (n-1)/2 || j == 0 && i < (n-1)/2 || i+j <= (n-1)/2 ){ 29 | System.out.print("* "); 30 | }else{ 31 | System.out.print(" "); 32 | } 33 | } 34 | 35 | System.out.println(); 36 | } 37 | 38 | sc.close(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /12_MultiThreading/_09_IsAliveMethod_In_Threading.java: -------------------------------------------------------------------------------- 1 | class myThread1 implements Runnable { 2 | 3 | public void run() { 4 | 5 | for (int i = 0; i < 3; i++) { 6 | System.out.println("Hey I am Working on myThread"); 7 | try { 8 | Thread.sleep(3000); // 3 sec in 3000 milesecond 9 | } catch (Exception e) { 10 | System.out.println("If An Any Exception : " + e); 11 | } 12 | } 13 | } 14 | } 15 | 16 | public class _09_IsAliveMethod_In_Threading { 17 | public static void main(String[] args) { 18 | 19 | System.out.println("Main Thread is Started ..."); 20 | 21 | myThread1 mt = new myThread1(); 22 | 23 | Thread th = new Thread(mt); 24 | 25 | System.out.println(th.isAlive()); 26 | // isAlive() is a method that checks whether a thread is still running or has 27 | // finished executing. It returns a boolean value of true if the thread is still 28 | // running, and false if it has finished. 29 | 30 | th.start(); 31 | 32 | System.out.println(th.isAlive()); 33 | 34 | System.out.println("Main Thread is Ended ..."); 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /19_Searching_Sorting_and_Bit_Manipulation/_06_Insertion_Sort.java: -------------------------------------------------------------------------------- 1 | public class _06_Insertion_Sort { 2 | 3 | // Time Complexity : O(n^2) 4 | // Space Complexity : O(1) 5 | 6 | public static void main(String[] args) { 7 | 8 | int arr[] = { 5, 4, 3, 2, 1, 6, 7, 8, 9, 8, 7, 3, 1, 6 }; 9 | 10 | System.out.println("Before Sorted Array.. "); 11 | printArray(arr); 12 | insertionSort(arr); 13 | System.out.println("After Sorted Array using Insertion Sort : "); 14 | printArray(arr); 15 | } 16 | 17 | // For Insertion Sort Algo ... 18 | public static void insertionSort(int arr[]) { 19 | 20 | for (int i = 1; arr.length > i; i++) { 21 | int j = i; 22 | 23 | while (j > 0 && arr[j] < arr[j - 1]) { 24 | int temp = arr[j]; 25 | arr[j] = arr[j - 1]; 26 | arr[j - 1] = temp; 27 | j--; 28 | } 29 | 30 | } 31 | 32 | } 33 | 34 | // For printing Array ... 35 | public static void printArray(int arr[]) { 36 | for (int i = 0; arr.length > i; i++) { 37 | System.out.print(arr[i] + " "); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /09_Oops/_07_this_Method_in_Constructor.java: -------------------------------------------------------------------------------- 1 | class Student2 //extends Object 2 | { 3 | private String name; 4 | private int age; 5 | 6 | public Student2() 7 | { 8 | // super(); 9 | this("Rohit", 19); 10 | System.out.println("Default Constructor is called"); 11 | name="Rohan"; 12 | age=18; 13 | } 14 | 15 | // Every Constructor have a inbilt Super() or This() Any one method . and Before executing Constructor any one super() or this() was run then Constructor.. 16 | public Student2(String name) 17 | { 18 | this(); 19 | this.name=name; 20 | age=19; 21 | } 22 | public Student2(String name, int age) 23 | { 24 | 25 | this.name=name; 26 | this.age=age; 27 | } 28 | public void disp() 29 | { 30 | System.out.println(name); 31 | System.out.println(age); 32 | } 33 | } 34 | 35 | 36 | public class _07_this_Method_in_Constructor { 37 | public static void main(String[] args) { 38 | 39 | Student2 st2=new Student2(); 40 | st2.disp(); 41 | 42 | Student2 st3=new Student2("Rahul"); 43 | st3.disp(); 44 | 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /08_Strings/_20_Static_keyword.java: -------------------------------------------------------------------------------- 1 | class Student 2 | { 3 | int age = 5; // instance variable, non - static variable 4 | static String school; // non - instance variable, static variable 5 | 6 | static 7 | { 8 | school = "PW"; 9 | } 10 | 11 | public void show() 12 | { 13 | System.out.println("in show " + age + " " + school); // static variable can be accessed in non-static method 14 | } 15 | public static void study() 16 | { 17 | System.out.println("studying "); // non-static variable cannot be accessed here 18 | } 19 | } 20 | 21 | public class _20_Static_keyword 22 | { 23 | 24 | static{ 25 | System.out.println("in static block"); 26 | } 27 | 28 | public static void main(String[] args) { 29 | 30 | System.out.println("in main method"); 31 | 32 | Student obj = new Student(); 33 | 34 | Student.study(); 35 | obj.age = 19; 36 | obj.school = "PWSkills"; // Student.school = "PWSkills"; 37 | 38 | Student obj1 = new Student(); 39 | System.out.println(obj1.school); 40 | 41 | obj.show(); // in show 19 PWSkills 42 | obj1.show(); // in show 0 ? 43 | 44 | } 45 | } -------------------------------------------------------------------------------- /13_CollectionFrameWork/_12_Iterator.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Iterator; 3 | 4 | public class _12_Iterator { 5 | public static void main(String[] args) { 6 | 7 | // an Iterator is an interface that is used to traverse a collection of 8 | // elements, such as an ArrayList, LinkedList, or HashSet. It provides a way to 9 | // access each element of the collection sequentially without exposing the 10 | // underlying data structure. 11 | 12 | ArrayList numbers = new ArrayList<>(); 13 | numbers.add(10); 14 | numbers.add(20); 15 | numbers.add(30); 16 | 17 | Iterator iterator = numbers.iterator(); 18 | while (iterator.hasNext()) { 19 | Integer number = iterator.next(); 20 | System.out.println(number); 21 | } 22 | // we first create an ArrayList of integers, and then create an Iterator by 23 | // calling the iterator() method on the ArrayList. We then use a while loop to 24 | // iterate over each element in the ArrayList, calling hasNext() to check if 25 | // there is another element, and next() to retrieve the next element 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /19_Searching_Sorting_and_Bit_Manipulation/_05_Bubble_Sort.java: -------------------------------------------------------------------------------- 1 | public class _05_Bubble_Sort { 2 | 3 | // Time Complexity : O(n^2) 4 | // Space Complexity : O(1) 5 | 6 | public static void main(String[] args) { 7 | 8 | int arr[] = { 5, 4, 3, 2, 1, 6, 7, 8, 9, 8, 7, 3, 1, 6 }; 9 | 10 | System.out.println("Before Sorted Array.. "); 11 | printArray(arr); 12 | bubbleSort(arr); 13 | System.out.println("After Sorted Array using Bubble Sort : "); 14 | printArray(arr); 15 | 16 | } 17 | 18 | // For Bubble Sort Algo ... 19 | public static void bubbleSort(int arr[]) { 20 | 21 | for (int i = 0; arr.length > i; i++) { 22 | for (int j = 1; arr.length - i > j; j++) { 23 | 24 | if (arr[j - 1] > arr[j]) { 25 | int temp = arr[j - 1]; 26 | arr[j - 1] = arr[j]; 27 | arr[j] = temp; 28 | } 29 | 30 | } 31 | } 32 | } 33 | 34 | // For printing Array ... 35 | public static void printArray(int arr[]) { 36 | for (int i = 0; arr.length > i; i++) { 37 | System.out.print(arr[i] + " "); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /09_Oops/_18_Constructor_execution_in_case_of_inheritance.java: -------------------------------------------------------------------------------- 1 | class Demox { 2 | 3 | int n, m ; 4 | 5 | public Demox(){ 6 | System.out.println("Hey ..! I am Zero Parameter Constructor.."); 7 | } 8 | 9 | public Demox(int a, int b){ 10 | System.out.println("Hey ..! I am Parameter Constructor.."); 11 | n = a ; 12 | m = b ; 13 | } 14 | } 15 | 16 | class Demoy extends Demox{ 17 | 18 | int x, y ; 19 | public Demoy(){ 20 | 21 | // super(); 22 | // super(10,20); 23 | // this(); 24 | // this(10,20); 25 | System.out.println("Hey ..! I am Zero Parameter Constructor..!"); 26 | } 27 | 28 | public Demoy(int a, int b){ 29 | 30 | // super(); 31 | // super(10,20); 32 | // this(); 33 | // this(10,20); 34 | System.out.println("Hey ..! I am Parameter Constructor..!"); 35 | x = a ; 36 | y = b ; 37 | } 38 | } 39 | 40 | 41 | 42 | public class _18_Constructor_execution_in_case_of_inheritance { 43 | 44 | public static void main(String[] args) { 45 | 46 | Demoy dmo = new Demoy(); 47 | 48 | // Demo2 d2 = new Demo2(10, 20); 49 | 50 | } 51 | } -------------------------------------------------------------------------------- /23_HashMap_Stack_and_Queue/_05_Stack.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _05_Stack { 4 | public static void main(String[] args) { 5 | Stack stack1 = new Stack<>(); 6 | 7 | // push the elements inside the stack 8 | stack1.push(2); 9 | stack1.push(4); 10 | stack1.push(6); 11 | stack1.push(9); 12 | 13 | // print the top most element in the stack 14 | System.out.println("The topmost element in the stack before deletion is: " + stack1.peek()); 15 | 16 | // delete the top element from the stack 17 | stack1.pop(); 18 | 19 | // print the top most element in the stack 20 | System.out.println("The topmost element in the stack after deletion is: " + stack1.peek()); 21 | 22 | // Search an element in the stack 23 | // Search function returns -1 when the element is not present in the stack 24 | System.out.println("Element 1 is present at the the position: " + stack1.search(1)); 25 | 26 | // Check whether the stack is empty or not 27 | // empty function returns the boolean value (true/false) 28 | System.out.println("Is stack empty or not: " + stack1.empty()); 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /11_Exception_Handling/_06_EH_Handling_vs_Ducking.java: -------------------------------------------------------------------------------- 1 | class One { 2 | void ones() throws Exception { 3 | twos(); 4 | } 5 | 6 | void twos() throws Exception { 7 | System.out.println("hey I am Chota Don"); 8 | } 9 | } 10 | 11 | public class _06_EH_Handling_vs_Ducking { 12 | 13 | public static void main(String[] args) { 14 | 15 | One o = new One(); 16 | 17 | try { 18 | o.ones(); 19 | } catch (Exception e) { 20 | System.out.println("Error in this Code : " + e); 21 | } 22 | 23 | } 24 | } 25 | 26 | // Ducking the exception is a term that refers to not handling an exception and 27 | // letting it propagate 28 | // up the call stack until it's handled by some other part of the program or the 29 | // JVM itself. 30 | // This can be done by adding a throws clause to the method signature, which 31 | // indicates that 32 | // the method may throw an exception and that it's the responsibility of the 33 | // calling code to handle it. 34 | // Here's an example: 35 | 36 | // public static int divide(int num1, int num2) throws Exception { 37 | // if (num2 == 0) { 38 | // throw new Exception("Cannot divide by zero"); 39 | // } 40 | // return num1 / num2; 41 | // } 42 | -------------------------------------------------------------------------------- /13_CollectionFrameWork/_03_More_on_ArrayLIst.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _03_More_on_ArrayLIst { 4 | public static void main(String[] args) { 5 | 6 | ArrayList list = new ArrayList(); 7 | 8 | list.add(100); 9 | list.add(200); 10 | list.add(300); 11 | list.add(400); 12 | 13 | // Check if value is present or not in list in ArrayList.. 14 | System.out.println(list.contains(200)); 15 | 16 | // Find Index of the Element 17 | System.out.println(list.indexOf(400)); 18 | 19 | // ensureCapacity(); this method functionality is to reserve memory or extra 20 | // memory. 21 | list.ensureCapacity(10); 22 | 23 | // Size of the memory. 24 | System.out.println(list.size()); 25 | 26 | // trimToSize(); this method is to remove extra reserve memory in ArrayList. 27 | list.trimToSize(); 28 | 29 | // We create new ArrayList using parent class(polymorphism); 30 | List list2 = new ArrayList(); 31 | 32 | list2.add("I "); 33 | list2.add("am "); 34 | list2.add("Priyanshu "); 35 | list2.add("Gour..!"); 36 | 37 | System.out.println(list2); 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /04_Star_Pattern's/_25_Lower_Left_Triangle.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _25_Lower_Left_Triangle { 4 | 5 | public static void main(String args[]){ 6 | Scanner sc = new Scanner(System.in); 7 | 8 | // * 9 | // * * 10 | // * * * 11 | // * * * * 12 | // * * * * * 13 | // * * * * * * 14 | // * * * * * * * 15 | // * * * * * * * * 16 | // * * * * * * * * * 17 | 18 | int n ; 19 | System.out.println("Enter the Size of the Rhombus : "); 20 | n = sc.nextInt(); 21 | 22 | for(int i = 0 ; n > i ; i++){ 23 | 24 | for(int j = 0 ; n > j ; j++){ 25 | 26 | // for Fill lower left Area ==> (j == 0 && i >= (n-1)/2 || j <= (n-1)/2 || i-j >=(n-1)/2) 27 | 28 | if( j == 0 && i >= (n-1)/2 || i==n-1 && j <= (n-1)/2 || i-j >=(n-1)/2 ){ 29 | System.out.print("* "); 30 | }else{ 31 | System.out.print(" "); 32 | } 33 | } 34 | 35 | System.out.println(); 36 | } 37 | 38 | sc.close(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /20_Recursion/_07_Finding_Of_Power_Using_BigInteger.java: -------------------------------------------------------------------------------- 1 | import java.math.BigInteger; 2 | import java.util.Scanner; 3 | 4 | // Time Complexity : O(log2b) 5 | // Space Complexity : O(n) 6 | 7 | public class _07_Finding_Of_Power_Using_BigInteger { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | 11 | System.out.print("Enter the Number to Find Power : "); 12 | BigInteger a = sc.nextBigInteger(); 13 | 14 | System.out.print("Enter the Power of Number : "); 15 | int b = sc.nextInt(); 16 | 17 | BigInteger pw = Power(a, b); 18 | 19 | System.out.println("Power is : " + pw); 20 | 21 | sc.close(); 22 | } 23 | 24 | // To find Power of an Element using Recusion Optimize Approach 25 | public static BigInteger Power(BigInteger a, int b) { 26 | if (b <= 1) { 27 | return a; 28 | } else { 29 | BigInteger result = Power(a, b / 2); 30 | BigInteger finalResult = result.multiply(result); 31 | 32 | if (b % 2 != 0) { 33 | return a.multiply(finalResult); 34 | } else { 35 | return finalResult; 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /09_Oops/_23_Final_Keyword_in_java.java: -------------------------------------------------------------------------------- 1 | 2 | // Final Class: A final class in Java can't be extended or subclassed. It means that the class can't be inherited by any other class. To declare a class as final, the final keyword is used before the class name. 3 | /* final */class MyFinalClass{ 4 | 5 | // Final Variable: A final variable in Java can only be initialized once and its value can't be changed later. To declare a variable as final, the final keyword is used before the variable name. 6 | final int myNumber = 10; 7 | 8 | // Final Method: A final method in Java can't be overridden by any subclass. To declare a method as final, the final keyword is used before the method signature. 9 | final void myMethod() { 10 | // Method implementation 11 | System.out.println("Hey i am Fianl myMethod.."); 12 | } 13 | } 14 | 15 | 16 | // class MyChildClass extends MyFinalClass{ // We can't create a child class of a final class 17 | class MyChildClass extends MyFinalClass{ 18 | 19 | 20 | 21 | } 22 | 23 | public class _23_Final_Keyword_in_java { 24 | 25 | public static void main(String[] args) { 26 | 27 | MyChildClass mcc = new MyChildClass(); 28 | 29 | mcc.myMethod(); 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /19_Searching_Sorting_and_Bit_Manipulation/_07_Selection_Sort.java: -------------------------------------------------------------------------------- 1 | public class _07_Selection_Sort { 2 | // Time Complexity : O(n^2) 3 | // Space Complexity : O(1) 4 | 5 | public static void main(String[] args) { 6 | 7 | int arr[] = { 5, 4, 3, 2, 1, 6, 7, 8, 9, 8, 7, 3, 1, 6 }; 8 | 9 | System.out.println("Before Sorted Array.. "); 10 | printArray(arr); 11 | selectionSort(arr); 12 | System.out.println("After Sorted Array using Selection Sort : "); 13 | printArray(arr); 14 | } 15 | 16 | // For Selection Sort Algo ... 17 | public static void selectionSort(int arr[]) { 18 | for (int i = 0; arr.length - 1 > i; i++) { 19 | int minPos = i; 20 | 21 | for (int j = i + 1; arr.length > j; j++) { 22 | if (arr[j] < arr[minPos]) { 23 | minPos = j; 24 | } 25 | } 26 | int temp = arr[i]; 27 | arr[i] = arr[minPos]; 28 | arr[minPos] = temp; 29 | } 30 | } 31 | 32 | // For printing Array ... 33 | public static void printArray(int arr[]) { 34 | for (int i = 0; arr.length > i; i++) { 35 | System.out.print(arr[i] + " "); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /09_Oops/_14_Types_Of_Method_Overidden.java: -------------------------------------------------------------------------------- 1 | class Aero{ 2 | 3 | void Flying(){ 4 | System.out.println("Flying the Aeroplane ..!"); 5 | } 6 | 7 | void TakeOff(){ 8 | System.out.println("TakeOff the Aeroplane ..!"); 9 | } 10 | } 11 | 12 | class AeroChild1 extends Aero{ 13 | 14 | @Override // Overidden 15 | void Flying(){ 16 | System.out.println("AeroChild1 in the Aeroplane ..!"); 17 | } 18 | 19 | } 20 | 21 | class AeroChild2 extends Aero{ 22 | 23 | @Override // Overidden 24 | void Flying(){ 25 | System.out.println("AeroChild2 in the Aeroplane ..!"); 26 | } 27 | 28 | } 29 | 30 | 31 | public class _14_Types_Of_Method_Overidden { 32 | 33 | public static void main(String[] args) { 34 | 35 | 36 | // Overriding methods: Overriding methods are the methods that are defined in the child class with the same name as that of the parent class. The purpose of overriding is to provide a specific implementation of the method in the child class. 37 | 38 | AeroChild1 ac1 = new AeroChild1(); 39 | ac1.Flying(); 40 | ac1.TakeOff(); 41 | 42 | AeroChild2 ac2 = new AeroChild2() ; 43 | ac2.Flying(); 44 | ac2.TakeOff(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /22_LinkedList/_04_InsertionAtBeginning_LinkedList.java: -------------------------------------------------------------------------------- 1 | public class _04_InsertionAtBeginning_LinkedList { 2 | 3 | // Node Stracture.. 4 | Node head; 5 | 6 | class Node { 7 | int data; 8 | Node next; 9 | 10 | Node(int data) { 11 | this.data = data; 12 | this.next = null; 13 | } 14 | } 15 | 16 | // Insertion a Element At Beginninng in LinkedList.. 17 | public void insertAtBeg(int newData) { 18 | Node newNode = new Node(newData); 19 | newNode.next = head; 20 | head = newNode; 21 | } 22 | 23 | // To Display the LinkedList.. 24 | public void Display() { 25 | Node current = head; 26 | 27 | while (current != null) { 28 | System.out.print(current.data + " "); 29 | current = current.next; 30 | } 31 | System.out.println(); 32 | } 33 | 34 | public static void main(String[] args) { 35 | _04_InsertionAtBeginning_LinkedList list = new _04_InsertionAtBeginning_LinkedList(); 36 | 37 | list.insertAtBeg(10); 38 | list.insertAtBeg(20); 39 | list.insertAtBeg(30); 40 | list.insertAtBeg(40); 41 | list.insertAtBeg(50); 42 | 43 | list.Display(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /09_Oops/_16_Access_Modifiers.java: -------------------------------------------------------------------------------- 1 | public class _16_Access_Modifiers { 2 | 3 | public static void main(String[] args) { 4 | 5 | 6 | System.out.println("Access Modifiers..!"); 7 | 8 | // ***************************************************************************** 9 | // * Access * With Same * Outside Class * Outside Package * Outside Package * 10 | // * Modifiers * Class * Same Package * SubClass * Non-SubClass * 11 | // ***************************************************************************** 12 | // * Public * Yes * Yes * Yes * yes * 13 | // ***************************************************************************** 14 | // * Protected * Yes * Yes * Yes * No * 15 | // ***************************************************************************** 16 | // * default * Yes * Yes * No * No * 17 | // ***************************************************************************** 18 | // * private * Yes * No * No * No * 19 | // ***************************************************************************** 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /12_MultiThreading/_08_JoinMethod_In_Threading.java: -------------------------------------------------------------------------------- 1 | class myThread implements Runnable { 2 | 3 | public void run() { 4 | 5 | for (int i = 0; i < 3; i++) { 6 | System.out.println("Hey I am Working on myThread"); 7 | try { 8 | Thread.sleep(3000); // 3 sec in 3000 milesecond 9 | } catch (Exception e) { 10 | System.out.println("If An Any Exception : " + e); 11 | } 12 | } 13 | } 14 | } 15 | 16 | public class _08_JoinMethod_In_Threading { 17 | public static void main(String[] args) { 18 | 19 | System.out.println("Hey Main Thread Was Started .."); 20 | myThread t1 = new myThread(); 21 | 22 | Thread t2 = new Thread(t1); 23 | 24 | t2.start(); 25 | 26 | try { 27 | t2.join(); 28 | // join() is a method that waits for a thread to complete its execution before 29 | // moving on to the next line of code. This is often used to ensure that a 30 | // thread has finished before continuing with the rest of the program 31 | } catch (Exception e) { 32 | System.out.println("There is an Exception : " + e); 33 | } 34 | 35 | System.out.println("Hey Main Thread Was Started .."); 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /03_Operators_and_Loops/_06_Assignment_Operator.java: -------------------------------------------------------------------------------- 1 | public class _06_Assignment_Operator { 2 | 3 | 4 | public static void main(String args []){ 5 | 6 | // There are several types of assignment operators in Java: 7 | 8 | // Simple assignment operator = 9 | 10 | int a = 5; 11 | System.out.println(a); 12 | 13 | 14 | // Addition assignment operator += 15 | 16 | int b = 5; 17 | b += 3; // equivalent to x = x + 3; 18 | System.out.println(b); 19 | 20 | 21 | // Subtraction assignment operator -= 22 | 23 | int c = 5; 24 | c -= 3; // equivalent to x = x - 3; 25 | System.out.println(c); 26 | 27 | 28 | // Multiplication assignment operator *= 29 | 30 | int d = 5; 31 | d *= 3; // equivalent to x = x * 3; 32 | System.out.println(d); 33 | 34 | 35 | // Division assignment operator /= 36 | 37 | int e = 5; 38 | e /= 3; // equivalent to x = x / 3; 39 | System.out.println(e); 40 | 41 | 42 | // Modulus assignment operator %= 43 | 44 | int f = 5; 45 | f %= 3; // equivalent to x = x % 3; 46 | System.out.println(f); 47 | 48 | a = b = c = d = e = f = 100 ; 49 | 50 | System.out.println(a); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /30_Dynamic_Programming/_05_0_1_Knapsack_Recursion.java: -------------------------------------------------------------------------------- 1 | // in this problem we have to find the maximum profit that we can get from the given items 2 | // we have to take the items in such a way that the total weight of the items is less than or equal to the given weight 3 | 4 | // Time Complexity: O(2^n) 5 | // Space Complexity: O(1) 6 | 7 | public class _05_0_1_Knapsack_Recursion { 8 | 9 | public static int knapsack(int val[], int wt[], int W, int n) { 10 | if (W == 0 || n == 0) { 11 | return 0; 12 | } 13 | if (wt[n - 1] <= W) { 14 | // we have two choices either we can take the item or we can leave the item 15 | int ans1 = val[n - 1] + knapsack(val, wt, W - wt[n - 1], n - 1); 16 | // we are not taking the item 17 | int ans2 = knapsack(val, wt, W, n - 1); 18 | return Math.max(ans1, ans2); 19 | } else { 20 | // we are not taking the item 21 | return knapsack(val, wt, W, n - 1); 22 | } 23 | } 24 | 25 | public static void main(String[] args) { 26 | int val[] = { 15, 14, 10, 45, 30 }; 27 | int wt[] = { 2, 5, 1, 3, 4 }; 28 | int W = 7; 29 | int n = val.length; 30 | 31 | System.out.println(knapsack(val, wt, W, n)); 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /17_IO_Operation/_05_Writing_Data_Onto_File_using_FileWriter.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | public class _05_Writing_Data_Onto_File_using_FileWriter { 4 | public static void main(String[] args) throws IOException { 5 | File dir = new File("Hello"); 6 | dir.mkdir(); 7 | File file = new File(dir, "hello.txt"); 8 | file.createNewFile(); 9 | 10 | // FileWriter fw = new FileWriter(file); 11 | // in FileWriter we only use parameter file then write in which file. this file 12 | // all data is remove and new data was added. 13 | 14 | FileWriter fw = new FileWriter(file, true); 15 | // but in case we will write parameter file and true then the data was modified 16 | // in the previous file. 17 | 18 | fw.write("Hello World!"); 19 | fw.write("\n"); 20 | fw.write(65); // output is store in ASCII 21 | fw.write("\n"); 22 | fw.write(97); // output is store in ASCII 23 | fw.write("\n"); 24 | char ch[] = { 'j', 'a', 'v', 'a' }; 25 | fw.write(ch); 26 | 27 | fw.close(); // If we can't close fw then the data was not added in file. 28 | // fw.flush(); // flush is also use to close the function. 29 | 30 | System.out.println("Check hello.txt for output"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /09_Oops/_15_Types_Of_Method_Specizlized.java: -------------------------------------------------------------------------------- 1 | class Aero1{ 2 | void Flying(){ 3 | System.out.println("Flying the Aeroplane ..!"); 4 | } 5 | 6 | void TakeOff(){ 7 | System.out.println("TakeOff the Aeroplane ..!"); 8 | } 9 | } 10 | 11 | class AeroChild3 extends Aero1{ 12 | void CarryPassenger1(){ 13 | // Specialized methods 14 | System.out.println("I Have a Multipule Passeger in my Aerochild3"); 15 | } 16 | } 17 | 18 | class AeroChild4 extends Aero1{ 19 | void CarryPassenger2(){ 20 | // Specialized methods 21 | System.out.println("I Have a Multipule Passeger in my Aerochild4"); 22 | } 23 | } 24 | 25 | 26 | public class _15_Types_Of_Method_Specizlized { 27 | 28 | public static void main(String[] args) { 29 | 30 | 31 | // Specialized methods: Specialized methods are the methods that are defined in the child class and are not present in the parent class. These methods provide specialized functionality to the child class. 32 | 33 | AeroChild3 ac3 = new AeroChild3(); 34 | ac3.Flying(); 35 | ac3.TakeOff(); 36 | ac3.CarryPassenger1(); 37 | 38 | AeroChild4 ac4 = new AeroChild4(); 39 | ac4.Flying(); 40 | ac4.TakeOff(); 41 | ac4.CarryPassenger2(); 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /21_Backtracking/_10_Permutations_Using_Backtracking.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.List; 3 | 4 | // Time Complexity : O(n! * n) 5 | // Space Complexity : O(n! * n) 6 | 7 | public class _10_Permutations_Using_Backtracking { 8 | public static void main(String[] args) { 9 | 10 | int[] nums = { 1, 2, 3 }; 11 | 12 | Solution sol = new Solution(); 13 | 14 | List> result = sol.permute(nums); 15 | 16 | System.out.println(result); 17 | 18 | } 19 | } 20 | 21 | class Solution { 22 | 23 | public void backtrack(List> result, List temp, int[] nums) { 24 | 25 | if (temp.size() == nums.length) { 26 | result.add(new ArrayList(temp)); 27 | return; 28 | } 29 | 30 | for (int i = 0; i < nums.length; i++) { 31 | if (temp.contains(nums[i])) { 32 | continue; 33 | } 34 | temp.add(nums[i]); 35 | backtrack(result, temp, nums); 36 | temp.remove(temp.size() - 1); 37 | } 38 | 39 | } 40 | 41 | public List> permute(int[] nums) { 42 | List> result = new ArrayList<>(); 43 | 44 | backtrack(result, new ArrayList(), nums); 45 | 46 | return result; 47 | } 48 | } -------------------------------------------------------------------------------- /04_Star_Pattern's/_26_Lower_Right_Triangle.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _26_Lower_Right_Triangle { 4 | 5 | public static void main(String args[]){ 6 | Scanner sc = new Scanner(System.in); 7 | 8 | // * 9 | // * * 10 | // * * * 11 | // * * * * 12 | // * * * * * 13 | // * * * * * * 14 | // * * * * * * * 15 | // * * * * * * * * 16 | 17 | int n ; 18 | System.out.println("Enter the Size of the Rhombus : "); 19 | n = sc.nextInt(); 20 | 21 | for(int i = 0 ; n > i ; i++){ 22 | 23 | for(int j = 0 ; n > j ; j++){ 24 | 25 | // for Fill Lower right Area ==> (j == n-1 && i >= (n-1)/2 || i == n-1 && j >= (n-1)/2 || i+j > n-1 + (n-1)/2 ) 26 | 27 | if( j == n-1 && i >= (n-1)/2 || i == n-1 && j >= (n-1)/2 || i+j > n-1 + (n-1)/2 ){ 28 | System.out.print("* "); 29 | }else{ 30 | System.out.print(" "); 31 | } 32 | } 33 | 34 | System.out.println(); 35 | } 36 | 37 | sc.close(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /30_Dynamic_Programming/_06_0_1_Knapsack_Memorization.java: -------------------------------------------------------------------------------- 1 | public class _06_0_1_Knapsack_Memorization { 2 | 3 | public static int knapsack(int val[], int wt[], int W, int n, int dp[][]) { 4 | if (W == 0 || n == 0) { 5 | return 0; 6 | } 7 | if (dp[n][W] != -1) { 8 | return dp[n][W]; 9 | } 10 | if (wt[n - 1] <= W) { 11 | // we have two choices either we can take the item or we can leave the item 12 | int ans1 = val[n - 1] + knapsack(val, wt, W - wt[n - 1], n - 1, dp); 13 | // we are not taking the item 14 | int ans2 = knapsack(val, wt, W, n - 1, dp); 15 | return dp[n][W] = Math.max(ans1, ans2); 16 | } else { 17 | // we are not taking the item 18 | return dp[n][W] = knapsack(val, wt, W, n - 1, dp); 19 | } 20 | } 21 | 22 | public static void main(String[] args) { 23 | int val[] = { 15, 14, 10, 45, 30 }; 24 | int wt[] = { 2, 5, 1, 3, 4 }; 25 | int W = 7; 26 | int dp[][] = new int[val.length + 1][W + 1]; 27 | for (int i = 0; i < dp.length; i++) { 28 | for (int j = 0; j < dp[0].length; j++) { 29 | dp[i][j] = -1; 30 | } 31 | } 32 | System.out.println(knapsack(val, wt, W, val.length, dp)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /03_Operators_and_Loops/_08_Logical_Operators.java: -------------------------------------------------------------------------------- 1 | public class _08_Logical_Operators { 2 | 3 | 4 | public static void main(String args[]){ 5 | 6 | 7 | // In Java, there are three types of logical operators: 8 | 9 | // AND operator (&&) 10 | // The AND operator (&&) returns true if and only if both operands are true. Otherwise, it returns false. Here's an example: 11 | 12 | int x = 5; 13 | int y = 10; 14 | if (x > 0 && y > 0) { 15 | System.out.println("Both x and y are positive"); 16 | } 17 | 18 | 19 | // OR operator (||) 20 | // The OR operator (||) returns true if at least one of the operands is true. Otherwise, it returns false. Here's an example: 21 | 22 | int p = 5; 23 | int q = -10; 24 | if (p > 0 || q > 0) { 25 | System.out.println("At least one of p and q is positive"); 26 | } 27 | 28 | 29 | // NOT operator (!) 30 | // The NOT operator (!) returns the opposite of the boolean value of the operand. If the operand is true, it returns false. If the operand is false, it returns true. Here's an example: 31 | 32 | boolean a = true; 33 | if (!a) { 34 | System.out.println("a is false"); 35 | } else { 36 | System.out.println("a is true"); 37 | } 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /04_Star_Pattern's/_24_Upper_Right_Triangle.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _24_Upper_Right_Triangle { 4 | 5 | public static void main(String args[]){ 6 | Scanner sc = new Scanner(System.in); 7 | 8 | // * * * * * * * * * 9 | // * * * * * * * * 10 | // * * * * * * * 11 | // * * * * * * 12 | // * * * * * 13 | // * * * * 14 | // * * * 15 | // * * 16 | // * 17 | 18 | int n ; 19 | System.out.println("Enter the Size of the Rhombus : "); 20 | n = sc.nextInt(); 21 | 22 | for(int i = 0 ; n > i ; i++){ 23 | 24 | for(int j = 0 ; n > j ; j++){ 25 | 26 | // for Fill upper right Area ==> (i == 0 && j >= (n-1)/2 || j==n-1 && i <=(n-1)/2 || j-i >= (n-1)/2) 27 | 28 | if(i == 0 && j >= (n-1)/2 || j==n-1 && i <=(n-1)/2 || j-i >= (n-1)/2 ){ 29 | System.out.print("* "); 30 | }else{ 31 | System.out.print(" "); 32 | } 33 | } 34 | 35 | System.out.println(); 36 | } 37 | 38 | sc.close(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /12_MultiThreading/_02_Change_Threads_Property.java: -------------------------------------------------------------------------------- 1 | public class _02_Change_Threads_Property { 2 | 3 | public static void main(String[] args) { 4 | 5 | System.out.println("Before Change Thread in java"); 6 | 7 | String threadName = Thread.currentThread().getName(); 8 | System.out.println("Name of the Current Thread is : " + threadName); 9 | 10 | long threadId = Thread.currentThread().getId(); 11 | System.out.println("Id of the Current Thread is : " + threadId); 12 | 13 | int threadPriority = Thread.currentThread().getPriority(); 14 | System.out.println("Priority of the Current Thread is : " + threadPriority); 15 | 16 | System.out.println("**********************************************"); 17 | 18 | System.out.println("After Change Thread in java"); 19 | 20 | Thread t = Thread.currentThread(); 21 | 22 | t.setName("Priyanshu"); 23 | t.setPriority(3); 24 | 25 | String threadName1 = Thread.currentThread().getName(); 26 | System.out.println("Name of the Current Thread is : " + threadName1); 27 | 28 | int threadPriority1 = Thread.currentThread().getPriority(); 29 | System.out.println("Priority of the Current Thread is : " + threadPriority1); 30 | 31 | System.out.println("**********************************************"); 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /08_Strings/_02_Type_Of_Strings.java: -------------------------------------------------------------------------------- 1 | public class _02_Type_Of_Strings { 2 | 3 | public static void main(String args[]){ 4 | // Types of String 5 | 6 | // In java Strings are classified into 2 types 7 | // 1. Mutable String 8 | // 2. Immutable String 9 | 10 | 11 | // Mutable String 12 | 13 | // Once if we create a String, on that String if we try to perform any operation and 14 | // if those changes get reflected in the same object then such strings are called 15 | // “Mutable String”. 16 | // Example: StringBuffer, StringBuilder 17 | StringBuilder name = new StringBuilder("Priyanshu Gour"); 18 | System.out.println(name); 19 | name.append(" From Bhopal"); // Mutable String 20 | System.out.println(name); 21 | 22 | 23 | // Immutable String 24 | 25 | // Once if we create a String, on that String if we try to perform any operation 26 | // then those changes won’t be reflected in the same object, rather a new object 27 | // will be created.Such type of String is called as “Immutable String”. 28 | // Example: String 29 | String myName = "Priyanshu Gour" ; 30 | System.out.println(myName); 31 | myName.concat(" From Bhopal"); // Immutable String 32 | System.out.println(myName); 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /08_Strings/_12_Palindrome_Program.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _12_Palindrome_Program { 4 | 5 | public static void secondCasePalindrome(String str1){ 6 | 7 | String str2 = ""; 8 | 9 | for(int i = str1.length()-1; i >= 0 ; i--){ 10 | str2 = str2 + str1.charAt(i) ; 11 | } 12 | 13 | if(str1.equals(str2)){ 14 | System.out.println("Given Sting is Palindrome.."); 15 | }else{ 16 | System.out.println("Given String is not Palindrome.."); 17 | } 18 | 19 | } 20 | 21 | public static void main(String[] args) { 22 | Scanner sc = new Scanner(System.in) ; 23 | 24 | System.out.print("Enter A Word to Check Palindrome or not : "); 25 | String str = sc.nextLine() ; 26 | 27 | boolean check = true ; 28 | int strLen = str.length(); 29 | 30 | for(int i = 0 ; strLen/2 > i ; i++){ 31 | if(str.charAt(i) == str.charAt(strLen-1-i)){ 32 | check =true ; 33 | }else{ 34 | check = false ; 35 | } 36 | } 37 | 38 | if(check){ 39 | System.out.println(str + " is Palindrome"); 40 | }else{ 41 | System.out.println(str + " is Not-Palindrome"); 42 | } 43 | 44 | secondCasePalindrome(str); 45 | 46 | sc.close(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /05_Oops_Fundamentals/Automatic_Promotion_in_Overloading.java: -------------------------------------------------------------------------------- 1 | class Automatic { 2 | public static void Show(Byte n ){ 3 | System.out.println("Byte : " + n); 4 | } 5 | 6 | public static void Show(Short n ){ 7 | System.out.println("Short : " + n); 8 | } 9 | 10 | public static void Show(char n ){ 11 | System.out.println("Char : " + n); 12 | } 13 | 14 | public static void Show(int n ){ 15 | System.out.println("Int : " + n); 16 | } 17 | 18 | public static void Show(double n ){ 19 | System.out.println("Double : " + n); 20 | } 21 | } 22 | 23 | 24 | public class Automatic_Promotion_in_Overloading { 25 | 26 | public static void main(String args []){ 27 | 28 | // Automatic promotion in Java is a mechanism in which the parameters of a method are automatically converted to a larger data type if the original data type is smaller. This can happen during method overloading, which is the process of defining multiple methods with the same name in a class, but with different parameter types or number of parameters. 29 | // byte -> short -> int -> long -> float -> double 30 | 31 | 32 | 33 | // Automatic obj = new Automatic() ; 34 | 35 | // Byte a = 5 ; 36 | 37 | // obj.Show(a) ; 38 | // obj.Show('P'); 39 | // obj.Show(5); 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /21_Backtracking/_03_PrintAllPermutations_using_Backtracking.java: -------------------------------------------------------------------------------- 1 | public class _03_PrintAllPermutations_using_Backtracking { 2 | public static String swap(String str, int i, int j) { 3 | char temp; 4 | char[] charArray = str.toCharArray(); 5 | temp = charArray[i]; 6 | charArray[i] = charArray[j]; 7 | charArray[j] = temp; 8 | 9 | return String.valueOf(charArray); 10 | } 11 | 12 | /* 13 | * str - input string 14 | * l - starting index 15 | * r - ending index 16 | */ 17 | public static void permute(String str, int l, int r) { 18 | if (l == r) { 19 | System.out.println(str); 20 | } else { 21 | for (int i = l; i <= r; i++) { 22 | str = swap(str, l, i); 23 | permute(str, l + 1, r); 24 | 25 | // backtracking 26 | str = swap(str, l, i); 27 | } 28 | } 29 | } 30 | 31 | public static void main(String[] args) { 32 | String str1 = "XY"; 33 | int n1 = str1.length(); 34 | System.out.println("Permutations for string : " + str1 + " are : "); 35 | permute(str1, 0, n1 - 1); 36 | System.out.println(); 37 | 38 | String str2 = "ABC"; 39 | int n2 = str2.length(); 40 | System.out.println("Permutations for string : " + str2 + " are : "); 41 | permute(str2, 0, n2 - 1); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /23_HashMap_Stack_and_Queue/_13_slidingWindow_Using_Deque.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class _13_slidingWindow_Using_Deque { 4 | public static int[] maxSlidingWindow(int[] a, int k) { 5 | int n = a.length; 6 | int[] r = new int[n - k + 1]; 7 | int ri = 0; 8 | // store index 9 | Deque q = new ArrayDeque<>(); 10 | 11 | for (int i = 0; i < a.length; i++) { 12 | // remove numbers out of range k 13 | while (!q.isEmpty() && q.peek() < i - k + 1) { 14 | q.poll(); 15 | } 16 | // remove smaller numbers in k range as they are useless 17 | while (!q.isEmpty() && a[q.peekLast()] < a[i]) { 18 | q.pollLast(); 19 | } 20 | // q contains index... r contains content 21 | q.offer(i); 22 | if (i >= k - 1) { 23 | r[ri++] = a[q.peek()]; 24 | } 25 | } 26 | return r; 27 | } 28 | 29 | public static void main(String args[]) { 30 | int[] arr = { 1, 3, -1, -3, 5, 3, 6, 7 }; 31 | int n = 8; 32 | int k = 3; 33 | int[] res = new int[n - k + 1]; 34 | res = maxSlidingWindow(arr, k); 35 | 36 | System.out.println("The desired output is : "); 37 | 38 | for (int i = 0; i < n - k + 1; i++) { 39 | System.out.print(res[i] + " "); 40 | } 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /12_MultiThreading/_04_Multiple_Threads_Creating.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class calc extends Thread { 4 | 5 | public void run() { 6 | 7 | System.out.println("Calculation Task Started..!"); 8 | 9 | Scanner sc = new Scanner(System.in); 10 | System.out.println("Please enter first Number : "); 11 | int num1 = sc.nextInt(); 12 | 13 | System.out.println("Please enter 2nd Number : "); 14 | int num2 = sc.nextInt(); 15 | 16 | int result = num1 + num2; 17 | 18 | System.out.println(result); 19 | System.out.println("Calculation Task Ended "); 20 | 21 | System.out.println("***************************************************8"); 22 | 23 | sc.close(); 24 | } 25 | } 26 | 27 | class Message extends Thread { 28 | 29 | public void run() { 30 | System.out.println("Displaying important message task "); 31 | for (int i = 0; i < 3; i++) { 32 | System.out.println("Focus is important to master skills "); 33 | } 34 | 35 | System.out.println("Displaying import message task ended ..!"); 36 | } 37 | } 38 | 39 | public class _04_Multiple_Threads_Creating { 40 | public static void main(String[] args) { 41 | 42 | System.out.println("Main Thread started ..!"); 43 | 44 | calc cal = new calc(); 45 | 46 | Message msg = new Message(); 47 | 48 | cal.start(); 49 | msg.start(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /17_IO_Operation/_10_Write_Operation_With_PrintWriter.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | public class _10_Write_Operation_With_PrintWriter { 4 | 5 | public static void main(String[] args) throws IOException { 6 | 7 | // a PrintWriter is a class that provides methods to write formatted text to a 8 | // destination such as a file or console. It is different from other classes 9 | // such as OutputStreamWriter and FileWriter because it can handle different 10 | // types of data and provides more flexible options for formatting the output. 11 | 12 | // One of the benefits of using a PrintWriter is that it allows you to write 13 | // different types of data to the output stream using methods like print() and 14 | // println(). These methods can accept parameters of different types such as 15 | // integers, floats, strings, and objects, and they automatically convert the 16 | // data to a string format that can be written to the output stream. 17 | 18 | File dir = new File("Hey"); 19 | 20 | File file = new File(dir, "hey.txt"); 21 | 22 | FileWriter fw = new FileWriter(file, true); 23 | PrintWriter pw = new PrintWriter(fw); 24 | 25 | pw.print("hey ..! "); 26 | pw.println("Hello world!"); 27 | pw.println(32423); 28 | pw.println("I am The Devil of my World..! "); 29 | 30 | pw.close(); 31 | // pw.flush(); 32 | } 33 | } -------------------------------------------------------------------------------- /30_Dynamic_Programming/_10_CoinChangeDP_Tabulation.java: -------------------------------------------------------------------------------- 1 | // In this problem we have to find the minimum number of coins required to make the given amount. 2 | // Time Complexity: O(n*m) where n is the number of coins and m is the amount 3 | // Space Complexity: O(n*m) where n is the number of coins and m is the amount 4 | 5 | public class _10_CoinChangeDP_Tabulation { 6 | 7 | public static int coinChange(int coins[], int sum) { 8 | int n = coins.length; 9 | int dp[][] = new int[n + 1][sum + 1]; 10 | 11 | // initialization - sum is 0 12 | for (int i = 0; i <= n; i++) { 13 | dp[i][0] = 1; 14 | } 15 | 16 | // initialization - coins is 0 17 | for (int j = 1; j <= sum; j++) { 18 | dp[0][j] = 0; 19 | } 20 | 21 | // choice diagram 22 | for (int i = 1; i < n + 1; i++) { 23 | for (int j = 1; j < sum + 1; j++) { 24 | if (coins[i - 1] <= j) { 25 | dp[i][j] = dp[i][j - coins[i - 1]] + dp[i - 1][j]; 26 | } else { 27 | dp[i][j] = dp[i - 1][j]; 28 | } 29 | } 30 | } 31 | 32 | // return the last element of the matrix 33 | return dp[n][sum]; 34 | } 35 | 36 | public static void main(String[] args) { 37 | int coins[] = { 1, 2, 3 }; 38 | int sum = 4; 39 | 40 | System.out.println(coinChange(coins, sum)); 41 | } 42 | } -------------------------------------------------------------------------------- /21_Backtracking/_02_PrintAllSequencens_Using_Backtracking.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Arrays; 3 | 4 | public class _02_PrintAllSequencens_Using_Backtracking { 5 | public static void printSequences(int[] arr, int index, ArrayList tempArr) { 6 | // base case 7 | if (index == arr.length) { 8 | // print all the sequences -- but do not print empty entries 9 | if (tempArr.size() > 0) { 10 | System.out.println(tempArr); 11 | } 12 | return; 13 | } 14 | 15 | // recursive call 16 | 17 | // include 18 | printSequences(arr, index + 1, tempArr); 19 | 20 | // add the value in the tempArray 21 | tempArr.add(arr[index]); 22 | 23 | // do not include 24 | printSequences(arr, index + 1, tempArr); 25 | 26 | // remove the value from tempArray -- backtracking 27 | tempArr.remove(tempArr.size() - 1); 28 | } 29 | 30 | public static void main(String[] args) { 31 | int[] arr1 = { 1, 2 }; 32 | 33 | System.out.println("For the array - " + Arrays.toString(arr1)); 34 | 35 | printSequences(arr1, 0, new ArrayList()); 36 | 37 | System.out.println(); 38 | 39 | int[] arr2 = { 1, 2, 3 }; 40 | 41 | System.out.println("For the array - " + Arrays.toString(arr2)); 42 | 43 | printSequences(arr2, 0, new ArrayList()); 44 | } 45 | } --------------------------------------------------------------------------------