├── .DS_Store ├── .vscode └── settings.json ├── Assignment └── Library_management_system.java ├── Day_01_Introduction ├── Assignments │ ├── ASCIIValue.java │ ├── AddIntegers.java │ ├── AssignmentSolution6.java │ ├── Basic.java │ ├── MultiplyFloatingPoint.java │ ├── PrintInteger.java │ └── QuotientRemainder.java ├── Basic │ ├── Datatype.java │ ├── DatatypeRange.java │ ├── NamingConventions.java │ ├── TypeCasting.java │ ├── UserInput.java │ ├── UsingScannerClass.class │ ├── UsingScannerClass.java │ ├── Variable.java │ ├── Variable_01.java │ └── Variable_02.java ├── Example │ ├── Datatype_01.java │ ├── Datatype_2.java │ ├── Datatype_3.java │ ├── Datatype_4.java │ ├── Datatype_5.java │ ├── Datatype_6.java │ ├── Datatype_7.java │ ├── Example.java │ └── UserInput.java ├── README.md └── user_input │ ├── User_1.class │ └── User_1.java ├── Day_02_Operators ├── Assignments │ └── AgeCalculator.java ├── Operators │ ├── ArithmeticOperators.java │ ├── AssignmentOperators.java │ ├── BitwiseOperators.java │ ├── ConditionalTernary.java │ ├── IncrementDecrementOperators.java │ ├── LogicalOperators.java │ ├── Operator.java │ ├── RelationalOperators.class │ └── RelationalOperators.java └── README.md ├── Day_03_If_Else ├── Assignments │ ├── AlphabetCheck.java │ ├── EvenOdd.java │ ├── LargestNumber.java │ ├── LeapYear.java │ ├── NestedIfElse.java │ ├── PositiveNegative.java │ └── VowelConsonant.java ├── If_Else │ └── If_else.java ├── Interview Question.md └── README.md ├── Day_04_SwitchStatement ├── Assignments │ ├── CountryCapital.java │ ├── DayOfWeek.java │ ├── Mcq.java │ ├── PasswordChecker.java │ └── SimpleCalculator.java ├── README.md └── SwitchCase │ ├── MCQ.java │ ├── MonthName.java │ ├── SwitchCaseChar.java │ ├── WeekName.class │ └── WeekName.java ├── Day_05_Java Loop ├── Assignments │ ├── AddNumbers.java │ ├── CountDigits.java │ ├── DisplayAlphabets.java │ ├── ReverseDigits.java │ ├── ReverseNumber.java │ ├── SeriesSum.java │ └── SumOfEvenAndOdd.java ├── DoWhileLoop │ └── DoWhileLoop.java ├── ForLoop │ ├── ForLoop.java │ ├── For_loop.java │ └── OtherExample.java ├── NestedLoop │ ├── HalfPyramidAlphabets.java │ └── NestedForLoop.java ├── README.md └── WhileLoop │ └── WhileLoop.java ├── Day_06_Arrays ├── ArrayExample │ ├── CharArray.java │ ├── IntArray.java │ ├── IntArray_Single.class │ ├── IntArray_Single.java │ ├── IntUserInput.class │ ├── IntUserInput.java │ ├── OtherWay.java │ ├── StringArray.java │ └── UserInputArray.java ├── Assignments │ ├── ArrayConcatenation.java │ ├── ArrayString.java │ ├── ArraySumAverage.java │ ├── MatrixAddition.java │ ├── MatrixMultiplication.java │ ├── MatrixMultiplication_Passing_Matrix_Function.java │ └── MatrixTranspose.java ├── JavaCopyArray │ ├── ArrayCopyExample.java │ └── README.md ├── MultidimensionalArrays │ ├── MultiArray.java │ ├── MultiArrayExample.java │ ├── MultiArrayStr.java │ ├── MultidimensionalArraysInt.java │ ├── MultidimensionalArraysIntINPUT.java │ ├── README.md │ ├── ThreeDArrayExample.class │ ├── ThreeDArrayExample.java │ ├── TwoDArrayExample.class │ └── TwoDArrayExample.java ├── OneDimensionalArrays │ ├── ArrayContainsValue.java │ ├── CharArrayExample.java │ ├── ForeachLoop.java │ ├── OneDimensionalArrayExample.java │ ├── OtherWayArray.java │ ├── SingleArrayExample1.java │ ├── SingleArrayIntegers.java │ ├── SingleArrayUserInput.java │ └── StringArrayExample.java └── README.md ├── Day_07_Function ├── Function │ ├── Function1.java │ ├── Function2.java │ ├── Function3.java │ └── Function4.java ├── Function2 │ ├── NonReturnNonArguments.java │ ├── NonReturnWithArguments.java │ ├── WithReturnNonArguments.java │ └── WithReturnWithArguments.java ├── Methods.java ├── Methods │ ├── Client.java │ ├── Main_Client.java │ └── Methods_Example.java └── README.md ├── Day_08_BreakContinue ├── BreakStatementExample.java ├── ContinueStatementExample.java ├── LoopUsingBreak.java └── README.md ├── Day_09_ClassObjects ├── Example1 │ ├── Car.java │ ├── Person.java │ └── School.java ├── Example2 │ └── Books.java ├── README.md └── Shop │ ├── Client.java │ └── ClientMainClass.java ├── Day_10_Constructor ├── Constructor │ ├── Book.java │ ├── Client.java │ ├── Codeswithpankaj.java │ └── Course.java ├── Employee.java ├── EmployeeMain.java └── README.md ├── Day_11_Strings ├── JavaString │ └── StringMethodsExample.java ├── README.md └── StringBuffer.md ├── Day_12_AccessModifiers ├── AccessModifiers │ └── AccessModifiersExample.java └── README.md ├── Day_13_ThisKeyword ├── Client.java ├── ClientMain.java ├── README.md └── ThisKeyword │ ├── Students.class │ ├── Students.java │ └── p4n.java ├── Day_14_FinalKeyword ├── FianlKeyword │ └── cwp.java └── README.md ├── Day_15_Recursion_Instanceof ├── README.md └── RecursionInstanceof │ ├── Fibonacci.java │ └── InstanceofOperator.java ├── Day_16_Inheritance ├── HierarchicalInheritance │ └── HierarchicalInheritanceExample.java ├── HybridInheritance │ ├── HybridInheritanceExample.java │ ├── HybridInheritanceExample1.class │ └── HybridInheritanceExample1.java ├── MultiLevel_Inheritance │ └── MultiLevelInheritanceExample.java ├── MultipleInheritance │ ├── CWP_MultipleExample.java │ ├── Example │ │ └── Schools.java │ └── MultipleInheritanceExample.java ├── README.md └── Singleinheritance │ ├── Example │ ├── CWPShop.class │ ├── CWPShop.java │ ├── CodingBooks.class │ ├── CodingBooks.java │ ├── MainShop.class │ └── MainShop.java │ ├── PrintBill.java │ └── SingleInheritanceExample.java ├── Day_17_MethodOverriding ├── MethodOverriding │ ├── Client.class │ ├── Client.java │ └── MethodOverridingExample.java └── README.md ├── Day_18_SuperKeyword ├── README.md └── SuperKeyWord │ ├── StudyBooks.java │ └── SuperKeywordExample.java ├── Day_19_AbstractClassMethod ├── AbstractClassMethod │ └── AbstractClassExample.java └── README.md ├── Day_20_Interfaces ├── JavaInterface │ ├── InnerOrderInterface.class │ ├── InterfaceExample.java │ ├── OrderInterface.class │ └── OrderInterface.java └── README.md ├── Day_21_Polymorphism ├── JavaPolymorphism │ ├── CustomerData.class │ ├── CustomerData.java │ ├── Employee.java │ ├── Food.java │ ├── PolymorphismExample.java │ └── PolymorphismShopExample.java └── README.md ├── Day_22_Encapsulation ├── Encapsulation │ ├── Clients.java │ ├── Customers.java │ ├── CustomersMain.java │ ├── EncapsulationExample.java │ ├── MainClient.java │ ├── P4NBooks.java │ ├── Student.java │ └── shop.java └── README.md ├── Day_23_NestedClassExample ├── NestedClass │ └── NestedClassExample.java └── README.md ├── Day_24_MathUtility ├── JavaStaticClass │ ├── MathUtility.java │ └── StaticClassExample.java └── README.md ├── Day_26_AnonymousClass ├── JavaAnonymousClass │ ├── AnonymousClassExample.java │ ├── AnonymousClassExample1.java │ └── AnonymousClassExample2.java └── README.md ├── Day_27_Singleton ├── JavaSingleton │ ├── Singleton.java │ └── SingletonExample.java └── README.md ├── Day_28_Enum ├── EnumClass │ ├── EnumClassExample.java │ ├── EnumConstructorExample.java │ └── EnumStringExample.java └── README.md ├── Day_29_Reflection ├── README.md └── ReflectionJAVA │ └── ReflectionExample.java ├── Day_30_ExceptionHandling ├── Example.md ├── ExceptionHandling │ ├── CustomExceptionExample.java │ ├── Example1.java │ ├── Example2.class │ ├── Example2.java │ ├── FinallyExample.java │ ├── JavaTopicsExample.java │ └── ThrowThrowsExample.java └── README.md ├── Day_31_List ├── List │ ├── ArrayListClass.java │ ├── ArrayListExample.java │ ├── LinkedListClass.java │ ├── ListExample.java │ ├── ListString.class │ ├── ListString.java │ └── README.md └── README.md ├── Day_32_ArrayList └── ArrayList │ ├── ArrayListExample.java │ ├── ArrayListMethodsExample.java │ ├── ArrayListToArray.java │ ├── ArrayListToString.java │ ├── ArrayListWithListInterface.java │ ├── ArrayToArrayList.java │ ├── InitializeArrayList.java │ ├── README.md │ └── StringArrayListExample.java ├── Day_33_Stack └── Stack │ ├── README.md │ └── StackExample.java ├── Day_34_Vector ├── AccessElementInVector.java ├── AccessVectorElementsWithIterator.java ├── AddElementAtIndexInVector.java ├── AddElementToVector.java ├── README.md ├── VectorAllinOne.class ├── VectorAllinOne.java ├── VectorContainsExample.java ├── VectorExample.java ├── VectorSetExample.java ├── VectorSizeExample.java ├── VectorToArrayExample.java └── VectorToStringExample.java ├── Day_35_QueueInterface ├── QueueInterface │ ├── QueueExample.java │ ├── QueueExample1.class │ ├── QueueExample1.java │ └── README.md └── README.md ├── Day_36_DequeInterface ├── DequeInterface │ ├── DequeAsStackExample.java │ └── DequeMethodsExample.java └── README.md ├── Day_37_LinkedList ├── JavaLinkedList │ ├── LinkedListAdditionalMethodsExample.java │ └── LinkedListAsDequeAndQueueExample.java └── README.md ├── Day_38_ArrayDeque ├── ArrayDequeAccessExample.class ├── ArrayDequeAccessExample.java ├── ArrayDequeAddExample.java ├── ArrayDequeRemoveExample.class ├── ArrayDequeRemoveExample.java ├── ArrayDequeSizeAndEmptyExample.java └── README.md ├── Day_39_BlockingQueue ├── BlockingQueueExample.java └── README.md ├── Day_40_ArrayBlockingQueue ├── ArrayBlockingQueueExample.java ├── ArrayBlockingQueueExample1.java └── README.md ├── Day_41_LinkedBlockingQueue ├── LinkedBlockingQueueExample.java └── README.md ├── Day_42_HashMap ├── HashMap1.class ├── HashMap1.java ├── Map1.java └── README.md ├── Day_43_LinkedHashMap ├── LinkedHashMapExample.java └── README.md ├── Day_44_LinkedHashMap └── README.md ├── Day_45_EnumMap └── README.md ├── Day_46_SortedMapInterface └── README.md ├── Day_47_NavigableMapInterface └── README.md ├── Day_48_TreeMap └── README.md ├── Day_49_ConcurrentMapInterface ├── ConcurrentMapExample.java └── README.md ├── Day_50_Set_Interface ├── README.md ├── SetMethodsExample.java ├── SetOperation.class ├── SetOperations.java └── SetOperationsExample.java ├── Day_51_HashSet └── README.md ├── Day_52_EnumSet └── README.md ├── Day_53_LinkedHashSet └── README.md ├── Day_54_SortedSetInterface ├── README.md └── SortedSetExample.java ├── Day_55_NavigableSetInterface ├── NavigableSetExample.java └── README.md ├── Day_56_TreeSet ├── README.md └── TreeSetExample.java ├── Day_57_IO_Streams ├── JavaBufferedInputStream │ └── README.md ├── JavaBufferedOutputStream │ └── README.md ├── JavaByteArrayInputStream │ └── README.md ├── JavaByteArrayOutputStream │ └── README.md ├── JavaFileInputStream │ ├── FileOutputStreamExample.java │ └── README.md ├── JavaFileOutputStream │ └── README.md ├── JavaInputStream │ ├── InputStreamExample.java │ └── README.md ├── JavaObjectInputStream │ └── README.md ├── JavaObjectOutputStream │ └── README.md ├── JavaOutputStream │ ├── OutputStreamExample.java │ └── README.md ├── JavaPrintStream │ └── README.md └── README.md ├── Day_58_Java_Reader_Writer └── README.md ├── Day_59_Threading ├── AccountHolder.class ├── BankAccount.class ├── BankAccountExample.class ├── BankAccountExample.java ├── Buffer.class ├── Chef.class ├── Consumer.class ├── ExampleMultiThreads.class ├── ExampleMultiThreads.java ├── Example_singleThread.class ├── Example_singleThread.java ├── MultiThreadSum.class ├── MultiThreadSum.java ├── Order.class ├── Producer.class ├── ProducerConsumerExample.class ├── ProducerConsumerExample.java ├── README.md ├── RestaurantExample.class ├── RestaurantExample.java ├── Waiter.class ├── thread1.class └── thread2.class ├── Day_60_LambdaExpressions ├── LambdaExample.java ├── LambdaGUIExample.java ├── LambdaStreamAdvancedExample.java ├── LambdaStreamExample.java └── README.md ├── Day_61_Immutable_Objects ├── ImmutableObjects │ ├── ImmutableExample.java │ └── ImmutablePerson.java ├── MutableObjects │ ├── MutableExample.java │ ├── MutableExample1.class │ ├── MutableExample1.java │ ├── MutablePerson.class │ └── MutablePerson.java └── README.md ├── Day_62_JDBC ├── Db_jdbc.java ├── DeleteDataExample.java ├── InsertData.md ├── InsertDataExample.java ├── README.md ├── SelectDataExample.java └── UpdateDataExample.java ├── Day_63_Annotations_Base64Encoding ├── Author.class ├── Author.java ├── MyClass.java ├── README.md ├── decoded_p4n.txt ├── p4n.txt └── src │ ├── AnnotationsJava │ ├── AnnotationExample.java │ ├── Author.java │ └── MyClass.java │ ├── Base64Encoding_Decoding │ ├── Base64Decoding.java │ └── Base64Example.java │ └── Encoding_DecodingFiles │ ├── Base64Encoder.java │ └── FileBase64Example.java ├── Exam.md ├── Example00 ├── InheritanceExample.class ├── InheritanceExample.java ├── Marks.class ├── Percentage.class └── Result.class ├── InterviewQuestion ├── AgeCal.java ├── Answer-CoreJava MCQ.md ├── Array1.java ├── Basic_interview_Question.md ├── Calc.java ├── MedianOfTwoSortedArrays.java ├── README.md ├── SpellChecker.java ├── StackIndentationChecker.java ├── dictionary.txt └── p4n │ ├── ArrayComparator.java │ ├── BankAccount.java │ ├── Car.java │ ├── Employee.java │ ├── ListFilter.java │ ├── ListMerger.java │ ├── ListReverser.java │ ├── ListSearcher.java │ ├── MapPrinter.java │ ├── NumberSumCalculator.java │ └── Student.java ├── Questions.md └── README.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/.DS_Store -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "java.debug.settings.onBuildFailureProceed": true, 3 | "java.project.explorer.showNonJavaResources": false, 4 | "java.project.sourcePaths": [ 5 | "Day_61_Immutable_Objects/MutableObjects", 6 | "Day_61_Immutable_Objects/ImmutableObjects", 7 | "Day_50_Set_Interface", 8 | "Day_04_SwitchStatement/SwitchCase", 9 | "Day_01_Introduction/user_input", 10 | "Example00" 11 | ] 12 | } -------------------------------------------------------------------------------- /Day_01_Introduction/Assignments/ASCIIValue.java: -------------------------------------------------------------------------------- 1 | package Day_01_Introduction.Assignments; 2 | //Write a Program to Find ASCII Value of a character 3 | //www.codeswithpankaj.com 4 | import java.util.Scanner; 5 | 6 | public class ASCIIValue { 7 | public static void main(String[] args) { 8 | Scanner input = new Scanner(System.in); 9 | 10 | System.out.print("Enter a character: "); 11 | char character = input.next().charAt(0); 12 | 13 | int asciiValue = (int) character; 14 | System.out.println("The ASCII value of the character is: " + asciiValue); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Day_01_Introduction/Assignments/AddIntegers.java: -------------------------------------------------------------------------------- 1 | package Day_01_Introduction.Assignments; 2 | //Write a Program in java to Add Two Integers 3 | import java.util.Scanner; 4 | 5 | public class AddIntegers { 6 | public static void main(String[] args) { 7 | Scanner input = new Scanner(System.in); 8 | 9 | System.out.print("Enter the first integer: "); 10 | int number1 = input.nextInt(); 11 | 12 | System.out.print("Enter the second integer: "); 13 | int number2 = input.nextInt(); 14 | 15 | int sum = number1 + number2; 16 | System.out.println("The sum of the two integers is: " + sum); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Day_01_Introduction/Assignments/AssignmentSolution6.java: -------------------------------------------------------------------------------- 1 | package Day_01_Introduction.Assignments; 2 | //Write a Program to Swap Two Numbers 3 | //https://www.codeswithpankaj.com 4 | //https://www.p4n.in 5 | 6 | import java.util.Scanner; 7 | 8 | public class AssignmentSolution6 { 9 | public static void main(String[] args) { 10 | Scanner input = new Scanner(System.in); 11 | 12 | System.out.print("Enter the dividend: "); 13 | int dividend = input.nextInt(); 14 | 15 | System.out.print("Enter the divisor: "); 16 | int divisor = input.nextInt(); 17 | 18 | int quotient = dividend / divisor; 19 | int remainder = dividend % divisor; 20 | 21 | System.out.println("Quotient: " + quotient); 22 | System.out.println("Remainder: " + remainder); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Day_01_Introduction/Assignments/Basic.java: -------------------------------------------------------------------------------- 1 | package Day_01_Introduction.Assignments; 2 | class Basic{ 3 | 4 | public static void main(String[] arg){ 5 | 6 | // Print String 7 | System.out.println("www.codeswithpankaj.com"); 8 | // print number 9 | System.out.println(56789); 10 | 11 | System.out.println("p4n.in "+56789012); 12 | 13 | } 14 | 15 | } 16 | 17 | -------------------------------------------------------------------------------- /Day_01_Introduction/Assignments/MultiplyFloatingPoint.java: -------------------------------------------------------------------------------- 1 | package Day_01_Introduction.Assignments; 2 | //Write a Program in java to Multiply two Floating Point Numbers 3 | 4 | import java.util.Scanner; 5 | 6 | public class MultiplyFloatingPoint { 7 | public static void main(String[] args) { 8 | Scanner input = new Scanner(System.in); 9 | 10 | System.out.print("Enter the first floating-point number: "); 11 | float number1 = input.nextFloat(); 12 | 13 | System.out.print("Enter the second floating-point number: "); 14 | float number2 = input.nextFloat(); 15 | 16 | float product = number1 * number2; 17 | System.out.println("The product of the two floating-point numbers is: " + product); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Day_01_Introduction/Assignments/PrintInteger.java: -------------------------------------------------------------------------------- 1 | package Day_01_Introduction.Assignments; 2 | // Write a Program in java to Print an Integer (Entered by the User) 3 | import java.util.Scanner; 4 | 5 | public class PrintInteger { 6 | public static void main(String[] args) { 7 | Scanner input = new Scanner(System.in); 8 | 9 | System.out.print("Enter an integer: "); 10 | int number = input.nextInt(); 11 | 12 | System.out.println("The entered integer is: " + number); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Day_01_Introduction/Assignments/QuotientRemainder.java: -------------------------------------------------------------------------------- 1 | package Day_01_Introduction.Assignments; 2 | //Write a Program to Compute Quotient and Remainder 3 | // https://www.codeswithpankaj.com/ 4 | 5 | import java.util.Scanner; 6 | 7 | public class QuotientRemainder { 8 | public static void main(String[] args) { 9 | Scanner input = new Scanner(System.in); 10 | 11 | System.out.print("Enter the dividend: "); 12 | int dividend = input.nextInt(); 13 | 14 | System.out.print("Enter the divisor: "); 15 | int divisor = input.nextInt(); 16 | 17 | int quotient = dividend / divisor; 18 | int remainder = dividend % divisor; 19 | 20 | System.out.println("Quotient: " + quotient); 21 | System.out.println("Remainder: " + remainder); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Day_01_Introduction/Basic/DatatypeRange.java: -------------------------------------------------------------------------------- 1 | package Day_01_Introduction.Basic; 2 | 3 | 4 | public class DatatypeRange { 5 | 6 | public static void main(String[] args) { 7 | 8 | int number = 100; 9 | System.out.println(number); 10 | 11 | short n = 98; 12 | 13 | short minshort = Short.MIN_VALUE; 14 | short maxshort = Short.MAX_VALUE; 15 | 16 | System.out.println("Min Value of Short : "+minshort); 17 | System.out.println("Max Value of Short : "+maxshort); 18 | 19 | byte minbyte = Byte.MIN_VALUE; 20 | byte maxbyte = Byte.MAX_VALUE; 21 | 22 | System.out.println("Min Value of Byte : "+minbyte); 23 | System.out.println("Max Value of Byte : "+maxbyte); 24 | 25 | int minint = Integer.MIN_VALUE; 26 | int maxint = Integer.MAX_VALUE; 27 | 28 | System.out.println("Min Value of int : "+minint); 29 | System.out.println("Max Value of int : "+maxint); 30 | 31 | long minlong = Long.MIN_VALUE; 32 | long maxlong = Long.MAX_VALUE; 33 | 34 | System.out.println("Min Value of long : "+minlong); 35 | System.out.println("Max Value of long : "+maxlong); 36 | 37 | float minfloat = Float.MIN_VALUE; 38 | float maxfloat = Float.MAX_VALUE; 39 | 40 | System.out.println("Min Value of float : "+minfloat); 41 | System.out.println("Max Value of float : "+maxfloat); 42 | 43 | double mindouble = Double.MIN_VALUE; 44 | double maxdouble = Double.MAX_VALUE; 45 | 46 | System.out.println("Min Value of double : "+mindouble); 47 | System.out.println("Max Value of double : "+maxdouble); 48 | 49 | 50 | 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /Day_01_Introduction/Basic/NamingConventions.java: -------------------------------------------------------------------------------- 1 | package Day_01_Introduction.Basic; 2 | 3 | public class NamingConventions { 4 | 5 | // Constants should be in uppercase, with words separated by underscores 6 | 7 | public static final int MAX_COUNT = 10000; 8 | 9 | 10 | public static void main(String[] args) { 11 | 12 | // Variable names should start with a lowercase letter and use camelCase 13 | 14 | int age = 25; 15 | double salaryPerHour = 50.75; 16 | String firstName = "John"; 17 | boolean isEmployed = true; 18 | 19 | // Use meaningful names that describe the purpose of the variables 20 | int numberOfStudents = 50; 21 | double hourlyWage = 15.50; 22 | String lastName = "Doe"; 23 | boolean hasJob = false; 24 | 25 | 26 | 27 | 28 | 29 | 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Day_01_Introduction/Basic/TypeCasting.java: -------------------------------------------------------------------------------- 1 | package Day_01_Introduction.Basic; 2 | 3 | public class TypeCasting { 4 | 5 | public static void main(String[] args) { 6 | 7 | // Implicit Type Casting (Widening) 8 | 9 | int myInt = 100; 10 | 11 | long myLong = myInt; // Implicit Type Casting from int to long... 12 | 13 | float myfloat = myLong; // Implicit casting from long to float 14 | 15 | double mydouble = myfloat; // Implicit casting from float to double 16 | 17 | System.out.println("\n Implicit Type Casting \n"); 18 | System.out.println("int : "+ myInt); 19 | System.out.println("long : "+ myLong); 20 | System.out.println("float : "+ myfloat); 21 | System.out.println("double : "+ mydouble); 22 | 23 | // Explicit Type Carsting : (Narrowing) 24 | 25 | double d = 3.456; 26 | int dInt = (int) d; // Explicit casting from double to int 27 | 28 | System.out.println("\n Explicit Type Casting \n"); 29 | System.out.println("Double : "+d); 30 | System.out.println("Int "+dInt); 31 | 32 | 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Day_01_Introduction/Basic/UserInput.java: -------------------------------------------------------------------------------- 1 | package Day_01_Introduction.Basic; 2 | // codeswithpankaj.com 3 | // import JAVA Class Scanner 4 | import java.util.Scanner; 5 | 6 | public class UserInput { 7 | 8 | public static void main(String[] arg){ 9 | 10 | // create a object Scanner Class 11 | 12 | Scanner sc = new Scanner(System.in); 13 | 14 | // variable.. 15 | 16 | String Address; 17 | int age; 18 | String name; 19 | float height; 20 | char grade; 21 | 22 | System.out.println("Enter Your Address ... "); 23 | Address = sc.nextLine(); 24 | System.out.println("Enter Your name ... "); 25 | name = sc.next(); 26 | System.out.println("Enter Your age ... "); 27 | age = sc.nextInt(); 28 | System.out.println("Enter Your height ... "); 29 | height = sc.nextFloat(); 30 | System.out.println("Enter Your grade ... "); 31 | grade = sc.next().charAt(0); 32 | 33 | System.out.println("\n------output---------------\n"); 34 | 35 | System.out.println("Your Name : "+name); 36 | System.out.println("Your age : "+age); 37 | System.out.println("Your height : "+height); 38 | System.out.println("Your grade : "+grade); 39 | System.out.println("Your address : "+Address); 40 | 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /Day_01_Introduction/Basic/UsingScannerClass.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_01_Introduction/Basic/UsingScannerClass.class -------------------------------------------------------------------------------- /Day_01_Introduction/Basic/Variable.java: -------------------------------------------------------------------------------- 1 | package Day_01_Introduction.Basic; 2 | 3 | class Variable{ 4 | 5 | public static void main(String[] args) { 6 | 7 | //DataType VariableName = Value; 8 | 9 | int age = 12; 10 | 11 | System.out.println(age); 12 | 13 | age = 23; 14 | 15 | System.out.println(age); 16 | 17 | 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /Day_01_Introduction/Basic/Variable_01.java: -------------------------------------------------------------------------------- 1 | package Day_01_Introduction.Basic; 2 | 3 | 4 | public class Variable_01 { 5 | public static void main(String[] args) { 6 | //Datatype var value 7 | 8 | // int number1 = 100; 9 | // int number2 = 200; 10 | // int result = number1+number2; 11 | // System.out.println("Result is : "+result); 12 | 13 | int number1,number2,result; 14 | number1 = 90; 15 | number2 = 34; 16 | result = number1+number2; 17 | System.out.println("Result is : "+result); 18 | 19 | 20 | 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Day_01_Introduction/Basic/Variable_02.java: -------------------------------------------------------------------------------- 1 | package basic; 2 | 3 | public class Variable { 4 | 5 | public static void main(String[] arg) { 6 | 7 | // create a variable 8 | int age; 9 | String name; 10 | float height; 11 | // assign values 12 | 13 | age = 23; 14 | name = "Sahil"; 15 | height = 5.9f; 16 | 17 | System.out.println("Your Name is : "+name); 18 | System.out.println("Your Age is : "+age); 19 | System.out.println("Your Height is : "+height); 20 | 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Day_01_Introduction/Example/Datatype_01.java: -------------------------------------------------------------------------------- 1 | package dec_19_2023; 2 | 3 | public class Datatype_01 { 4 | 5 | public static void main(String[] arg) { 6 | 7 | byte b1 = 23; 8 | System.out.println(b1); 9 | 10 | byte bytemin = Byte.MIN_VALUE; 11 | byte bytemax = Byte.MAX_VALUE; 12 | 13 | System.out.println("Byte Min Value : "+bytemin); 14 | System.out.println("Byte Max Value : "+bytemax); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Day_01_Introduction/Example/Datatype_2.java: -------------------------------------------------------------------------------- 1 | package dec_19_2023; 2 | 3 | public class Datatype_2 { 4 | 5 | public static void main(String[] arg) { 6 | 7 | short b1 = 23; 8 | System.out.println(b1); 9 | 10 | short Shortmin = Short.MIN_VALUE; 11 | short Shortmax = Short.MAX_VALUE; 12 | 13 | System.out.println("short Min Value : "+Shortmin); 14 | System.out.println("short Max Value : "+Shortmax); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Day_01_Introduction/Example/Datatype_3.java: -------------------------------------------------------------------------------- 1 | package dec_19_2023; 2 | 3 | public class Datatype_3 { 4 | 5 | public static void main(String[] arg) { 6 | 7 | long b1 = 23; 8 | System.out.println(b1); 9 | 10 | long Longmin = Long.MIN_VALUE; 11 | long Longmax = Long.MAX_VALUE; 12 | 13 | System.out.println("Long Min Value : "+Longmin); 14 | System.out.println("Long Max Value : "+Longmax); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Day_01_Introduction/Example/Datatype_4.java: -------------------------------------------------------------------------------- 1 | package dec_19_2023; 2 | 3 | public class Datatype_4 { 4 | 5 | public static void main(String[] arg) { 6 | 7 | int b1 = 23; 8 | System.out.println(b1); 9 | 10 | int Integermin = Integer.MIN_VALUE; 11 | int Integermax = Integer.MAX_VALUE; 12 | 13 | System.out.println("Integer Min Value : "+Integermin); 14 | System.out.println("Integer Max Value : "+Integermax); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Day_01_Introduction/Example/Datatype_5.java: -------------------------------------------------------------------------------- 1 | package dec_19_2023; 2 | 3 | public class Datatype_5 { 4 | 5 | public static void main(String[] arg) { 6 | 7 | 8 | char ch = 'r'; 9 | 10 | System.out.println(ch); 11 | 12 | String name = "joy"; 13 | 14 | System.out.println(name); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Day_01_Introduction/Example/Datatype_6.java: -------------------------------------------------------------------------------- 1 | package dec_19_2023; 2 | 3 | public class Datatype_6 { 4 | 5 | public static void main(String[] arg) { 6 | 7 | 8 | float number = (float) 3.4; 9 | 10 | float floatmin = Float.MIN_VALUE; 11 | float floatmax = Float.MAX_VALUE; 12 | 13 | System.out.println("Float Min Value : "+floatmin); 14 | System.out.println("Float Max Value : "+floatmax); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Day_01_Introduction/Example/Datatype_7.java: -------------------------------------------------------------------------------- 1 | package dec_19_2023; 2 | 3 | public class Datatype_7 { 4 | 5 | public static void main(String[] arg) { 6 | 7 | 8 | float number = (float) 3.4; 9 | 10 | float floatmin = Float.MIN_VALUE; 11 | float floatmax = Float.MAX_VALUE; 12 | 13 | System.out.println("Float Min Value : "+floatmin); 14 | System.out.println("Float Max Value : "+floatmax); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Day_01_Introduction/Example/Example.java: -------------------------------------------------------------------------------- 1 | package dec_19_2023; 2 | 3 | public class Example { 4 | 5 | public static void main(String[] arg) { 6 | 7 | 8 | String name = "joy"; 9 | int age = 12; 10 | char ltr = 'A'; 11 | float height = 3.4f; 12 | 13 | System.out.println("Your Name is : "+name); 14 | System.out.println("Your age is : "+age); 15 | System.out.println("Your ltr is : "+ltr); 16 | System.out.println("Your height is : "+height); 17 | 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Day_01_Introduction/Example/UserInput.java: -------------------------------------------------------------------------------- 1 | package dec_19_2023; 2 | import java.util.Scanner; 3 | public class UserInput { 4 | 5 | public static void main(String[] arg) { 6 | 7 | Scanner sc = new Scanner(System.in); 8 | System.out.println("Your Name : "); 9 | String name = sc.nextLine(); 10 | System.out.println("Your Age : "); 11 | int age = sc.nextInt(); 12 | System.out.println("Your Ltr : "); 13 | char ltr = sc.next().charAt(0); 14 | System.out.println("Your height : "); 15 | float height = sc.nextFloat(); 16 | System.out.println("-----------------------"); 17 | System.out.println("Your Name is : "+name); 18 | System.out.println("Your age is : "+age); 19 | System.out.println("Your ltr is : "+ltr); 20 | System.out.println("Your height is : "+height); 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Day_01_Introduction/user_input/User_1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_01_Introduction/user_input/User_1.class -------------------------------------------------------------------------------- /Day_01_Introduction/user_input/User_1.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class User_1{ 3 | 4 | public static void main(String[] arg){ 5 | 6 | // Create a Scanner Class Object 7 | 8 | Scanner sc = new Scanner(System.in); 9 | 10 | String name; 11 | int age; 12 | char ltr; 13 | float height; 14 | 15 | System.out.println("Enter Your Name - "); 16 | name = sc.next(); 17 | System.out.println("Enter Your age - "); 18 | age = sc.nextInt(); 19 | System.out.println("Enter Your ltr - "); 20 | ltr = sc.next().charAt(0); 21 | System.out.println("Enter Your height - "); 22 | height = sc.nextFloat(); 23 | 24 | 25 | System.out.println("Your Name - "+name); 26 | System.out.println("Your age - "+age); 27 | System.out.println("Your ltr - "+ltr); 28 | System.out.println("Your height - "+height); 29 | 30 | 31 | 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /Day_02_Operators/Assignments/AgeCalculator.java: -------------------------------------------------------------------------------- 1 | 2 | // https://www.codeswithpankaj.com/ 3 | // p4n.in 4 | import java.time.LocalDate; 5 | 6 | import java.util.Scanner; 7 | 8 | public class AgeCalculator{ 9 | public static void main(String[] args) { 10 | // Create a Scanner object to read input from the user 11 | Scanner scanner = new Scanner(System.in); 12 | 13 | // Prompt the user to enter their birth year 14 | System.out.print("Enter your birth year: "); 15 | int birthYear = scanner.nextInt(); 16 | 17 | // Get the current year 18 | int currentYear = LocalDate.now().getYear(); 19 | 20 | // Calculate the age 21 | int age = currentYear - birthYear; 22 | 23 | // Display the result 24 | System.out.println("Your age is: " + age); 25 | 26 | // Close the scanner 27 | scanner.close(); 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Day_02_Operators/Operators/ArithmeticOperators.java: -------------------------------------------------------------------------------- 1 | // 1. Arithmetic Operators: 2 | // - Addition (+): Adds two operands. 3 | // - Subtraction (-): Subtracts the right operand from the left operand. 4 | // - Multiplication (*): Multiplies two operands. 5 | // - Division (/): Divides the left operand by the right operand. 6 | // - Modulus (%): Returns the remainder after division. 7 | 8 | public class ArithmeticOperators { 9 | public static void main(String[] args) { 10 | System.out.println("Arithmetic Operators + "+(45+90)); 11 | System.out.println("Arithmetic Operators - "+(45-90)); 12 | System.out.println("Arithmetic Operators * "+(45*90)); 13 | System.out.println("Arithmetic Operators / "+(4567/9)); 14 | System.out.println("Arithmetic Operators % "+(4567%9)); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Day_02_Operators/Operators/AssignmentOperators.java: -------------------------------------------------------------------------------- 1 | // 2. Assignment Operators: 2 | // - Simple Assignment (=): Assigns a value to a variable. 3 | // - Compound Assignment Operators (+=, -=, *=, /=, %=): Performs an arithmetic operation and assigns the result to the left operand. 4 | 5 | public class AssignmentOperators { 6 | public static void main(String[] args) { 7 | 8 | int num = 10; // Assigns value into num variable using " = " 9 | // num = num + 10 10 | num += 10; 11 | System.out.println(num); 12 | // num = num - 10 13 | num -= 10; 14 | System.out.println(num); 15 | // num = num / 10 16 | num /= 10; 17 | System.out.println(num); 18 | // num = num * 10 19 | num *= 10; 20 | System.out.println(num); 21 | 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Day_02_Operators/Operators/BitwiseOperators.java: -------------------------------------------------------------------------------- 1 | public class BitwiseOperators { 2 | public static void main(String[] args) { 3 | // Bitwise AND (&): 4 | 5 | int a = 5; // 101 in binary 6 | int b = 3; // 011 in binary 7 | int result = a & b; // Bitwise AND operation 8 | System.out.println(result); // Output: 1 (001 in binary) 9 | 10 | // Bitwise OR (|): 11 | 12 | int a1 = 5; // 101 in binary 13 | int b1 = 3; // 011 in binary 14 | int result1 = a1 | b1; // Bitwise OR operation 15 | System.out.println(result1); // Output: 7 (111 in binary) 16 | 17 | // Bitwise XOR (^): 18 | 19 | int a2 = 5; // 101 in binary 20 | int b2 = 3; // 011 in binary 21 | int result2 = a2 ^ b2; // Bitwise XOR operation 22 | System.out.println(result2); // Output: 6 (110 in binary) 23 | 24 | //Bitwise NOT (~): 25 | 26 | int a3 = 5; // 101 in binary 27 | int result3 = ~a3; // Bitwise NOT operation 28 | System.out.println(result3); // Output: -6 (complement of 5 in two's complement representation) 29 | 30 | // Left Shift (<<): 31 | 32 | int a4 = 5; // 101 in binary 33 | int result4 = a4 << 2; // Left shift by 2 positions 34 | System.out.println(result4); // Output: 20 (10100 in binary) 35 | 36 | // Right Shift (>>): 37 | 38 | int a5 = 20; // 10100 in binary 39 | int result5 = a5 >> 2; // Right shift by 2 positions 40 | System.out.println(result5); // Output: 5 (101 in binary) 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Day_02_Operators/Operators/ConditionalTernary.java: -------------------------------------------------------------------------------- 1 | public class ConditionalTernary { 2 | 3 | public static void main(String[] args) { 4 | int number = 9; 5 | String result = (number % 2 == 0) ? "Even" : "Odd"; 6 | System.out.println(result); 7 | 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Day_02_Operators/Operators/IncrementDecrementOperators.java: -------------------------------------------------------------------------------- 1 | public class IncrementDecrementOperators { 2 | public static void main(String[] args) { 3 | int number = 100; 4 | //Increment (++) 5 | number++; 6 | System.out.println(number); 7 | //Decrement (--): 8 | number--; 9 | System.out.println(number); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Day_02_Operators/Operators/LogicalOperators.java: -------------------------------------------------------------------------------- 1 | // 5. Logical Operators: 2 | // - Logical AND (&&): Returns true if both operands are true. 3 | // - Logical OR (||): Returns true if either operand is true. 4 | // - Logical NOT (!): Reverses the logical state of an operand. 5 | 6 | 7 | public class LogicalOperators { 8 | 9 | public static void main(String[] args) { 10 | // and && 11 | // left side | right side = result 12 | // T | T = T 13 | // T | F = F 14 | // F | T = F 15 | // F | F = F 16 | System.out.println(56 < 90 && 676 <= 78 ); // output F 17 | 18 | // or || 19 | // left side | right side = result 20 | // T | T = T 21 | // T | F = T 22 | // F | T = T 23 | // F | F = F 24 | System.out.println(56 < 90 || 676 <= 78 ); // output T 25 | 26 | // not ! 27 | System.out.println(45 != 78 ); // output F 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Day_02_Operators/Operators/RelationalOperators.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_02_Operators/Operators/RelationalOperators.class -------------------------------------------------------------------------------- /Day_02_Operators/Operators/RelationalOperators.java: -------------------------------------------------------------------------------- 1 | // 4. Comparison Operators / Relational Operators: 2 | // - Equal to (==): Checks if two operands are equal. 3 | // - Not equal to (!=): Checks if two operands are not equal. 4 | // - Greater than (>), 5 | // - Less than (<), 6 | // - Greater than or equal to (>=), 7 | // - Less than or equal to (<=) : Perform comparison between operands. 8 | 9 | public class RelationalOperators { 10 | 11 | public static void main(String[] args) { 12 | 13 | System.out.println("Relational Operators Less than (<) :"+(45 < 89)); 14 | System.out.println("Relational Operators Greater than (>) :"+(45 > 89)); 15 | System.out.println("Relational Operators Less than or equal to (<=) :"+(45 <= 89)); 16 | System.out.println("Relational Operators Greater than or equal to (>=) :"+(45 >= 89)); 17 | System.out.println("Relational Operators Equal to (==) :"+(45 == 89)); 18 | System.out.println("Relational Operators Not equal to (!=) :"+(45 != 89)); 19 | 20 | 21 | 22 | 23 | } 24 | } 25 | 26 | // Output 27 | // Relational Operators Less than (<) :true 28 | // Relational Operators Greater than (>) :false 29 | // Relational Operators Less than or equal to (<=) :true 30 | // Relational Operators Greater than or equal to (>=) :false 31 | // Relational Operators Equal to (==) :false 32 | // Relational Operators Not equal to (!=) :true -------------------------------------------------------------------------------- /Day_03_If_Else/Assignments/AlphabetCheck.java: -------------------------------------------------------------------------------- 1 | // Program to Check Whether a Character is Alphabet or Not: 2 | // https://www.codeswithpankaj.com 3 | 4 | import java.util.Scanner; 5 | 6 | public class AlphabetCheck { 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | System.out.print("Enter a character: "); 10 | char ch = scanner.next().charAt(0); 11 | 12 | if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) { 13 | System.out.println(ch + " is an alphabet."); 14 | } else { 15 | System.out.println(ch + " is not an alphabet."); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Day_03_If_Else/Assignments/EvenOdd.java: -------------------------------------------------------------------------------- 1 | // Write a Program to Check Whether a Number is Even or Odd 2 | import java.util.Scanner; 3 | 4 | public class EvenOdd { 5 | public static void main(String[] args) { 6 | Scanner input = new Scanner(System.in); 7 | 8 | System.out.print("Enter a number: "); 9 | int number = input.nextInt(); 10 | 11 | if (number % 2 == 0) { 12 | System.out.println(number + " is even."); 13 | } else { 14 | System.out.println(number + " is odd."); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Day_03_If_Else/Assignments/LargestNumber.java: -------------------------------------------------------------------------------- 1 | // Write a Program to Find the Largest Among Three Numbers(user input) 2 | // https://www.codeswithpankaj.com/ 3 | 4 | import java.util.Scanner; 5 | 6 | public class LargestNumber { 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | System.out.print("Enter the first number: "); 10 | int num1 = scanner.nextInt(); 11 | System.out.print("Enter the second number: "); 12 | int num2 = scanner.nextInt(); 13 | System.out.print("Enter the third number: "); 14 | int num3 = scanner.nextInt(); 15 | 16 | int largest = num1; 17 | 18 | if (num2 > largest) { 19 | largest = num2; 20 | } 21 | 22 | if (num3 > largest) { 23 | largest = num3; 24 | } 25 | 26 | System.out.println("The largest number is: " + largest); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Day_03_If_Else/Assignments/LeapYear.java: -------------------------------------------------------------------------------- 1 | // Write a Program to Check Leap Year(user input) 2 | // https://www.codeswithpankaj.com 3 | 4 | import java.util.Scanner; 5 | 6 | public class LeapYear { 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | System.out.print("Enter a year: "); 10 | int year = scanner.nextInt(); 11 | 12 | boolean isLeapYear = false; 13 | 14 | if (year % 4 == 0) { 15 | if (year % 100 == 0) { 16 | if (year % 400 == 0) { 17 | isLeapYear = true; 18 | } 19 | } else { 20 | isLeapYear = true; 21 | } 22 | } 23 | 24 | if (isLeapYear) { 25 | System.out.println(year + " is a leap year."); 26 | } else { 27 | System.out.println(year + " is not a leap year."); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Day_03_If_Else/Assignments/NestedIfElse.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class NestedIfElse{ 4 | 5 | public static void main(String[] args) { 6 | 7 | // create a scanner class object 8 | 9 | Scanner sc = new Scanner(System.in); 10 | 11 | int num1, num2, num3; 12 | 13 | System.out.println("\n Enter Number 1 \n"); 14 | num1 = sc.nextInt(); 15 | System.out.println("\n Enter Number 2 \n"); 16 | num2 = sc.nextInt(); 17 | System.out.println("\n Enter Number 3 \n"); 18 | num3 = sc.nextInt(); 19 | 20 | if(num1 < num2 && num1 < num3) { 21 | 22 | System.out.println("number 1 is smallest .. " +num1); 23 | }else { 24 | 25 | 26 | if(num2 < num1 && num2 < num3) { 27 | 28 | System.out.println("number 2 is smallest .. " +num2); 29 | }else { 30 | 31 | System.out.println("number 3 is smallest .. " +num3); 32 | 33 | } 34 | 35 | } 36 | 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /Day_03_If_Else/Assignments/PositiveNegative.java: -------------------------------------------------------------------------------- 1 | // https://www.codeswithpankaj.com/ 2 | // Program to Check Whether a Number is Positive or Negative: 3 | import java.util.Scanner; 4 | 5 | public class PositiveNegative { 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | System.out.print("Enter a number: "); 9 | int number = scanner.nextInt(); 10 | 11 | if (number > 0) { 12 | System.out.println(number + " is positive."); 13 | } else if (number < 0) { 14 | System.out.println(number + " is negative."); 15 | } else { 16 | System.out.println("The number is zero."); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Day_03_If_Else/Assignments/VowelConsonant.java: -------------------------------------------------------------------------------- 1 | // Write a Program to Check Whether an Alphabet is Vowel or Consonant(user input) 2 | // https://www.codeswithpankaj.com/ 3 | 4 | import java.util.Scanner; 5 | 6 | public class VowelConsonant { 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | System.out.print("Enter an alphabet: "); 10 | char alphabet = scanner.next().charAt(0); 11 | 12 | if (alphabet == 'a' || alphabet == 'e' || alphabet == 'i' || alphabet == 'o' || alphabet == 'u' 13 | || alphabet == 'A' || alphabet == 'E' || alphabet == 'I' || alphabet == 'O' || alphabet == 'U') { 14 | System.out.println(alphabet + " is a vowel."); 15 | } else { 16 | System.out.println(alphabet + " is a consonant."); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Day_03_If_Else/If_Else/If_else.java: -------------------------------------------------------------------------------- 1 | 2 | public class If_else { 3 | 4 | public static void main(String[] args) { 5 | 6 | // find smallest number 7 | int num1, num2; 8 | num1 = 10; 9 | num2 = 8; 10 | 11 | if(num1 < num2) { 12 | //t 13 | System.out.println(" number 1 is smallest.."); 14 | }else { 15 | //f 16 | System.out.println(" number 1 not is smallest.."); 17 | } 18 | 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Day_04_SwitchStatement/Assignments/DayOfWeek.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner;; 2 | 3 | public class DayOfWeek{ 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner sc = new Scanner(System.in); 8 | 9 | System.out.println("Enter Day of week number"); 10 | int DayOfWeek = sc.nextInt(); 11 | 12 | // switch case statment 13 | 14 | switch(DayOfWeek){ 15 | 16 | case 1: System.out.println("Monday"); 17 | break; 18 | case 2: System.out.println("Tuesday"); 19 | break; 20 | case 3: System.out.println("Wednesday"); 21 | break; 22 | case 4: System.out.println("Thursday"); 23 | break; 24 | case 5: System.out.println("Friday"); 25 | break; 26 | case 6: System.out.println("Saturday"); 27 | break; 28 | case 7: System.out.println("Sunday"); 29 | break; 30 | default : System.out.println(" Invaild Day of week."); 31 | break; 32 | } 33 | 34 | 35 | } 36 | 37 | 38 | } -------------------------------------------------------------------------------- /Day_04_SwitchStatement/Assignments/Mcq.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class Mcq{ 3 | 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner sc = new Scanner(System.in); 8 | // Question 1. 9 | // Pollination by Bat is called : 10 | // (a) Omithorphily 11 | // (b) Entemophily 12 | // (c) Cheropterophily 13 | // (d) Hydrophily 14 | 15 | System.out.println("\nQuestion 1.\n"); 16 | System.out.println("Pollination by Bat is called :"); 17 | System.out.println("(a) Omithorphily"); 18 | System.out.println("(b) Entemophily"); 19 | System.out.println("(c) Cheropterophily"); 20 | System.out.println("(d) Hydrophily"); 21 | 22 | System.out.println(" \nSelect One Option ---- \n"); 23 | 24 | String option = sc.next(); 25 | 26 | String answer = "Please Select One"; 27 | option = option.toLowerCase(); 28 | switch(option.toLowerCase()){ 29 | 30 | case "a" : answer = "Omithorphily"; 31 | System.out.println("Worng Answer"); 32 | break; 33 | case "b" : answer = "Entemophily"; 34 | System.out.println("Worng Answer"); 35 | break; 36 | case "c" : answer = "Cheropterophily"; 37 | break; 38 | case "d" : answer = "Hydrophily"; 39 | System.out.println("Worng Answer"); 40 | break; 41 | default : System.out.println("Not include into option Select Again..."); 42 | 43 | } 44 | 45 | System.out.println("Answer: "+answer); 46 | 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /Day_04_SwitchStatement/Assignments/SimpleCalculator.java: -------------------------------------------------------------------------------- 1 | //Write a Program to Make a Simple Calculator Using switch...case 2 | //https://www.codeswithpankaj.com/ 3 | 4 | import java.util.Scanner; 5 | 6 | public class SimpleCalculator { 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | 10 | System.out.print("Enter the first number: "); 11 | int num1 = sc.nextInt(); 12 | 13 | System.out.print("Enter the second number: "); 14 | int num2 = sc.nextInt(); 15 | 16 | System.out.println("Available operations:"); 17 | System.out.println("1. Addition (+)"); 18 | System.out.println("2. Subtraction (-)"); 19 | System.out.println("3. Multiplication (*)"); 20 | System.out.println("4. Division (/)"); 21 | 22 | System.out.print("Enter your choice (1-4): "); 23 | char choice = sc.next().charAt(0); 24 | 25 | int result = 0; 26 | 27 | switch(choice){ 28 | case '+' : result = num1 + num2; 29 | break; 30 | case '-' : result = num1 - num2; 31 | break; 32 | case '*' : result = num1 * num2; 33 | break; 34 | case '/' : result = num1 / num2; 35 | break; 36 | default : System.out.println("Select Only + , - , * , / "); 37 | break; 38 | } 39 | 40 | System.out.println("Your Result is : = "+result); 41 | 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Day_04_SwitchStatement/SwitchCase/MCQ.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class MCQ { 4 | 5 | public static void main(String[] agr){ 6 | 7 | // object of Scanner class 8 | Scanner sc = new Scanner(System.in); 9 | System.out.println("1. Who invented Java Programming?\r\n" + // 10 | "a) Guido van Rossum\r\n" + // 11 | "b) James Gosling\r\n" + // 12 | "c) Dennis Ritchie\r\n" + // 13 | "d) Bjarne Stroustrup\n"); 14 | 15 | char option = sc.next().charAt(0); 16 | 17 | switch (option) { 18 | case 'a': System.out.println("Wrong Answer"); 19 | break; 20 | case 'b': System.out.println("Answer: b \r\n" + // 21 | "Explanation: Java programming was developed by James Gosling at Sun Microsystems in 1995. James Gosling is well known as the father of Java."); 22 | break; 23 | case 'c': System.out.println("Wrong Answer"); 24 | break; 25 | case 'd': System.out.println("Wrong Answer"); 26 | break; 27 | default : 28 | System.out.println("select only a,b,c,d"); 29 | 30 | } 31 | 32 | 33 | 34 | 35 | 36 | } 37 | 38 | 39 | } -------------------------------------------------------------------------------- /Day_04_SwitchStatement/SwitchCase/MonthName.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | public class MonthName { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner sc = new Scanner(System.in); 8 | int Day; 9 | System.out.println("Enter Month Day Number 1 - 12"); 10 | Day = sc.nextInt(); 11 | 12 | switch (Day) { 13 | 14 | case 1 : System.out.println("January"); 15 | break; 16 | case 2 : System.out.println("February"); 17 | break; 18 | case 3 : System.out.println("March"); 19 | break; 20 | case 4 : System.out.println("April"); 21 | break; 22 | case 5 : System.out.println("May"); 23 | break; 24 | case 6 : System.out.println("June"); 25 | break; 26 | case 7 : System.out.println("July"); 27 | break; 28 | case 8 : System.out.println("August"); 29 | break; 30 | case 9 : System.out.println("September"); 31 | break; 32 | case 10 : System.out.println("October"); 33 | break; 34 | case 11 : System.out.println("November"); 35 | break; 36 | case 12 : System.out.println("December"); 37 | break; 38 | default : 39 | System.out.println("Plz Enter only between 1 to 12 "); 40 | 41 | } 42 | 43 | 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /Day_04_SwitchStatement/SwitchCase/SwitchCaseChar.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | import static java.lang.Character.toLowerCase; 4 | 5 | public class SwitchCaseChar { 6 | // Check Whether an Alphabet is Vowel or Consonant(user input) 7 | public static void main(String[] args) { 8 | // Scanner class object 9 | Scanner sc = new Scanner(System.in); 10 | // user input char 11 | System.out.println("Enter Alphabet "); 12 | char Alphabet; 13 | Alphabet = sc.next().charAt(0); 14 | 15 | Alphabet = toLowerCase(Alphabet); 16 | 17 | switch (Alphabet){ 18 | 19 | case 'a' : 20 | System.out.println("Alphabet is Vowel"); 21 | break; 22 | case 'e': 23 | System.out.println("Alphabet is Vowel"); 24 | break; 25 | case 'i': 26 | System.out.println("Alphabet is Vowel"); 27 | break; 28 | case 'o': 29 | System.out.println("Alphabet is Vowel"); 30 | break; 31 | case 'u': 32 | System.out.println("Alphabet is Vowel"); 33 | break; 34 | default: 35 | System.out.println("Alphabet is Consonant"); 36 | } 37 | 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /Day_04_SwitchStatement/SwitchCase/WeekName.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_04_SwitchStatement/SwitchCase/WeekName.class -------------------------------------------------------------------------------- /Day_04_SwitchStatement/SwitchCase/WeekName.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class WeekName{ 3 | 4 | public static void main(String[] args) { 5 | 6 | Scanner sc = new Scanner(System.in); 7 | 8 | System.out.println("Enter Day Number : 1 Monday, 2 Tuesday, 3 Wednesday, 4 Thursday, 5 Friday, 6 Saturday, and 7 Sunday."); 9 | 10 | int day = sc.nextInt(); 11 | switch (day) { 12 | 13 | case 1: System.out.println("the Day is Monday : "); 14 | break; 15 | case 2: System.out.println("the Day is Tuesday : "); 16 | break; 17 | case 3: System.out.println("the Day is Wednesday : "); 18 | break; 19 | case 4: System.out.println("the Day is Thursday : "); 20 | break; 21 | case 5: System.out.println("the Day is Friday : "); 22 | break; 23 | case 6: System.out.println("the Day is Saturday : "); 24 | break; 25 | case 7: System.out.println("the Day is Sunday : "); 26 | default: 27 | System.out.println("Enter only 1 - 7 : "); 28 | } 29 | 30 | 31 | } 32 | 33 | 34 | } -------------------------------------------------------------------------------- /Day_05_Java Loop/Assignments/AddNumbers.java: -------------------------------------------------------------------------------- 1 | // Program with a do-while loop that adds two numbers and asks the user whether to repeat: 2 | // https://www.codeswithpankaj.com/ 3 | // https://www.p4n.in/ 4 | 5 | import java.util.Scanner; 6 | 7 | public class AddNumbers { 8 | public static void main(String[] args) { 9 | Scanner scanner = new Scanner(System.in); 10 | char choice; 11 | 12 | do { 13 | System.out.print("Enter the first number: "); 14 | int num1 = scanner.nextInt(); 15 | 16 | System.out.print("Enter the second number: "); 17 | int num2 = scanner.nextInt(); 18 | 19 | int sum = num1 + num2; 20 | System.out.println("Sum: " + sum); 21 | 22 | System.out.print("Do you want to perform the operation again? (Y/N): "); 23 | choice = scanner.next().charAt(0); 24 | } while (choice == 'Y' || choice == 'y'); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Day_05_Java Loop/Assignments/CountDigits.java: -------------------------------------------------------------------------------- 1 | // Java Program to Count the Number of Digits in an Integer: 2 | // https://www.codeswithpankaj.com/ 3 | // https://www.p4n.in/ 4 | 5 | import java.util.Scanner; 6 | 7 | public class CountDigits { 8 | public static void main(String[] args) { 9 | Scanner scanner = new Scanner(System.in); 10 | System.out.print("Enter an integer: "); 11 | int number = scanner.nextInt(); 12 | int count = 0; 13 | 14 | while (number != 0) { 15 | number /= 10; 16 | count++; 17 | } 18 | 19 | System.out.println("Number of digits: " + count); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Day_05_Java Loop/Assignments/DisplayAlphabets.java: -------------------------------------------------------------------------------- 1 | // Java Program to Display Alphabets (A to Z) using a loop: 2 | // https://www.codeswithpankaj.com/ 3 | // https://www.p4n.in/ 4 | 5 | public class DisplayAlphabets { 6 | public static void main(String[] args) { 7 | char ch; 8 | for(ch = 'A'; ch <= 'Z'; ch++) { 9 | System.out.print(ch + " "); 10 | } 11 | } 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /Day_05_Java Loop/Assignments/ReverseDigits.java: -------------------------------------------------------------------------------- 1 | // Program to reverse the digits of a number: 2 | // https://www.codeswithpankaj.com/ 3 | // https://www.p4n.in/ 4 | 5 | import java.util.Scanner; 6 | 7 | public class ReverseDigits { 8 | public static void main(String[] args) { 9 | Scanner scanner = new Scanner(System.in); 10 | System.out.print("Enter an integer: "); 11 | int number = scanner.nextInt(); 12 | int reversedNumber = 0; 13 | 14 | while (number != 0) { 15 | int digit = number % 10; 16 | reversedNumber = reversedNumber * 10 + digit; 17 | number /= 10; 18 | } 19 | 20 | System.out.println("Reversed number: " + reversedNumber); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Day_05_Java Loop/Assignments/ReverseNumber.java: -------------------------------------------------------------------------------- 1 | // Java Program to Reverse a Number: 2 | // https://www.codeswithpankaj.com/ 3 | // https://www.p4n.in/ 4 | 5 | import java.util.Scanner; 6 | 7 | public class ReverseNumber { 8 | public static void main(String[] args) { 9 | Scanner scanner = new Scanner(System.in); 10 | System.out.print("Enter an integer: "); 11 | int number = scanner.nextInt(); 12 | int reversedNumber = 0; 13 | 14 | while (number != 0) { 15 | int digit = number % 10; 16 | reversedNumber = reversedNumber * 10 + digit; 17 | number /= 10; 18 | } 19 | 20 | System.out.println("Reversed number: " + reversedNumber); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Day_05_Java Loop/Assignments/SeriesSum.java: -------------------------------------------------------------------------------- 1 | // Program to calculate the sum of the series 1 + 1/2 + 1/3 + 1/4 + 1/5 + ... + 1/n: 2 | // https://www.codeswithpankaj.com 3 | // https://www.p4n.in 4 | 5 | import java.util.Scanner; 6 | 7 | public class SeriesSum { 8 | public static void main(String[] args) { 9 | Scanner scanner = new Scanner(System.in); 10 | System.out.print("Enter the value of n: "); 11 | int n = scanner.nextInt(); 12 | double sum = 0; 13 | 14 | for (int i = 1; i <= n; i++) { 15 | sum += 1.0 / i; 16 | } 17 | 18 | System.out.println("Sum of the series: " + sum); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Day_05_Java Loop/Assignments/SumOfEvenAndOdd.java: -------------------------------------------------------------------------------- 1 | // Program to read a set of integers and print the sum of even and odd integers: 2 | // https://www.codeswithpankaj.com/ 3 | // https://www.p4n.in/ 4 | 5 | import java.util.Scanner; 6 | 7 | public class SumOfEvenAndOdd { 8 | public static void main(String[] args) { 9 | Scanner scanner = new Scanner(System.in); 10 | System.out.print("Enter a set of integers (0 to stop): "); 11 | 12 | int evenSum = 0; 13 | int oddSum = 0; 14 | int number; 15 | 16 | while ((number = scanner.nextInt()) != 0) { 17 | if (number % 2 == 0) { 18 | evenSum += number; 19 | } else { 20 | oddSum += number; 21 | } 22 | } 23 | 24 | System.out.println("Sum of even integers: " + evenSum); 25 | System.out.println("Sum of odd integers: " + oddSum); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Day_05_Java Loop/DoWhileLoop/DoWhileLoop.java: -------------------------------------------------------------------------------- 1 | public class DoWhileLoop{ 2 | 3 | // 1 . initialization 4 | // 2 . Code to be executed in each iteration 5 | // 3 . iteration 6 | // 4 . condition 7 | 8 | 9 | 10 | public static void main(String[] args) { 11 | int a = 1; 12 | 13 | do{ 14 | 15 | System.out.println("a = "+a); 16 | a++; 17 | 18 | }while(a<=10); 19 | } 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Day_05_Java Loop/ForLoop/ForLoop.java: -------------------------------------------------------------------------------- 1 | 2 | public class ForLoop{ 3 | 4 | public static void main(String[] args) { 5 | 6 | // for (initialization; condition; iteration ++ , --) { 7 | // Code to be executed in each iteration 8 | // } 9 | 10 | // start (initialization) a = 1 11 | // end (condition) a <= 10 12 | // ++ , -- (+1)(-1) (iteration) 13 | // output loop body 14 | 15 | // Example: 16 | 17 | //1,2,3,4,5,6.... 18 | 19 | for(int a = 1 ; a <= 10 ; a++ ){ 20 | System.out.println(a*10); 21 | System.out.println(a+" = p4n.in"); 22 | } 23 | 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /Day_05_Java Loop/ForLoop/For_loop.java: -------------------------------------------------------------------------------- 1 | 2 | public class For_loop { 3 | 4 | public static void main(String[] args) { 5 | 6 | // for (initialExpression; testExpression; updateExpression) { 7 | // body of the loop 8 | // } 9 | 10 | // start point = initialExpression 11 | // end point = testExpression 12 | // ++ / -- [+1] [-1] = updateExpression 13 | 14 | for(int a = 1 ; a <=10; a++){ 15 | 16 | //System.out.println(a+" - p4n.in"); 17 | System.out.println(a*2); 18 | } 19 | 20 | 21 | 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Day_05_Java Loop/ForLoop/OtherExample.java: -------------------------------------------------------------------------------- 1 | public class OtherExample { 2 | 3 | public static void main(String[] args) { 4 | 5 | for (int i = 0; i < 10; i++) { 6 | 7 | if(i <= 5){ 8 | System.out.println(i+" *********** "); 9 | continue; 10 | }else{ 11 | System.out.println(i+" ----------- "); 12 | } 13 | 14 | } 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Day_05_Java Loop/NestedLoop/HalfPyramidAlphabets.java: -------------------------------------------------------------------------------- 1 | // Program to print a half pyramid using alphabets: 2 | // https://www.codeswithpankaj.com/ 3 | // https://www.p4n.in/ 4 | 5 | import java.util.Scanner; 6 | 7 | public class HalfPyramidAlphabets { 8 | public static void main(String[] args) { 9 | Scanner scanner = new Scanner(System.in); 10 | System.out.print("Enter the number of rows: "); 11 | int rows = scanner.nextInt(); 12 | int alphabet = 65; 13 | 14 | for (int i = 1; i <= rows; i++) { 15 | for (int j = 1; j <= i; j++) { 16 | System.out.print((char) alphabet + " "); 17 | } 18 | alphabet++; 19 | System.out.println(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Day_05_Java Loop/NestedLoop/NestedForLoop.java: -------------------------------------------------------------------------------- 1 | public class NestedForLoop { 2 | public static void main(String[] args) { 3 | 4 | for (int i = 0; i <= 10; i++) { 5 | for (int j = 0; j < i; j++) { 6 | System.out.print(" X "); 7 | } 8 | System.out.println(); 9 | } 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Day_05_Java Loop/WhileLoop/WhileLoop.java: -------------------------------------------------------------------------------- 1 | public class WhileLoop { 2 | 3 | // 1 . initialization 4 | // 2 . condition 5 | // 4 . Code to be executed in each iteration 6 | // 3 . iteration 7 | 8 | public static void main(String[] args) { 9 | int a = 1; 10 | 11 | while(a<=10){ 12 | System.out.println("a = "+a); 13 | a++; 14 | } 15 | } 16 | 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Day_06_Arrays/ArrayExample/CharArray.java: -------------------------------------------------------------------------------- 1 | package ArrayExample; 2 | 3 | public class CharArray { 4 | public static void main(String[] args) { 5 | //Datatype ArrayName[] = new Datatype[size] 6 | 7 | char data[] = new char[4]; 8 | 9 | // insert data into array 10 | 11 | data[0] = 'j'; 12 | data[1] = 'c'; 13 | data[2] = 'c'; 14 | data[3] = 'r'; 15 | 16 | // access data from array item 17 | 18 | //System.out.println(data[1]); 19 | 20 | // access all data 21 | 22 | for (int i = 0; i < data.length; i++) { 23 | 24 | System.out.println((i+1)+" = "+data[i]); 25 | 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Day_06_Arrays/ArrayExample/IntArray.java: -------------------------------------------------------------------------------- 1 | package ArrayExample; 2 | 3 | class IntArray{ 4 | 5 | public static void main(String[] args) { 6 | 7 | 8 | //Datatype ArrayName[] = new Datatype[size] 9 | 10 | int data[] = new int[4]; 11 | 12 | // insert data into array 13 | 14 | data[0] = 11; 15 | data[1] = 12; 16 | data[2] = 13; 17 | data[3] = 14; 18 | 19 | // access data from array item 20 | 21 | //System.out.println(data[1]); 22 | 23 | // access all data 24 | 25 | for (int i = 0; i < data.length; i++) { 26 | 27 | System.out.println(data[i]); 28 | 29 | } 30 | 31 | 32 | 33 | 34 | 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /Day_06_Arrays/ArrayExample/IntArray_Single.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_06_Arrays/ArrayExample/IntArray_Single.class -------------------------------------------------------------------------------- /Day_06_Arrays/ArrayExample/IntArray_Single.java: -------------------------------------------------------------------------------- 1 | public class IntArray_Single { 2 | 3 | 4 | public static void main(String[] args) { 5 | 6 | 7 | // array of integers 8 | 9 | int data[] = new int[4]; 10 | 11 | // assigning values to array 12 | 13 | data[0] = 21; 14 | data[1] = 45; 15 | data[2] = 67; 16 | data[3] = 89; 17 | 18 | // printing single item from array 19 | 20 | // System.out.println("this is element of array : "+data[2]); 21 | 22 | // print all item from array 23 | 24 | for (int i = 0; i < data.length; i++) { 25 | 26 | System.out.println("Item from array : "+data[i]); 27 | 28 | } 29 | 30 | 31 | 32 | 33 | 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /Day_06_Arrays/ArrayExample/IntUserInput.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_06_Arrays/ArrayExample/IntUserInput.class -------------------------------------------------------------------------------- /Day_06_Arrays/ArrayExample/IntUserInput.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class IntUserInput { 4 | 5 | public static void main(String[] args) { 6 | Scanner scanner = new Scanner(System.in); 7 | 8 | // Prompt the user to enter a size of array 9 | 10 | int size; 11 | 12 | System.out.println("Enter Array size .... "); 13 | size = scanner.nextInt(); 14 | 15 | int [] array = new int[size]; 16 | 17 | 18 | 19 | for (int i = 0; i < size; i++) { 20 | System.out.println("Enter Array elements .... ["+i+"] = "); 21 | array[i] = scanner.nextInt(); 22 | } 23 | 24 | 25 | // print all element of array 26 | System.out.println("Array elements are : "); 27 | for (int i = 0; i < size; i++) { 28 | System.out.println("Array elements are : "+"["+i+"] = "+array[i]); 29 | } 30 | 31 | } 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Day_06_Arrays/ArrayExample/OtherWay.java: -------------------------------------------------------------------------------- 1 | package ArrayExample; 2 | 3 | public class OtherWay { 4 | public static void main(String[] args) { 5 | 6 | String course[] = {"c++","java","python","go"}; 7 | 8 | //System.out.println(course[2]); 9 | 10 | for (int i = 0; i < course.length; i++) { 11 | 12 | System.out.println(course[i]); 13 | 14 | } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Day_06_Arrays/ArrayExample/StringArray.java: -------------------------------------------------------------------------------- 1 | package ArrayExample; 2 | 3 | public class StringArray { 4 | public static void main(String[] args) { 5 | //Datatype ArrayName[] = new Datatype[size] 6 | 7 | String data[] = new String[4]; 8 | 9 | // insert data into array 10 | 11 | data[0] = "java"; 12 | data[1] = "c++"; 13 | data[2] = "c"; 14 | data[3] = "ruby"; 15 | 16 | // access data from array item 17 | 18 | //System.out.println(data[1]); 19 | 20 | // access all data 21 | 22 | for (int i = 0; i < data.length; i++) { 23 | 24 | System.out.println((i+1)+" = "+data[i]); 25 | 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Day_06_Arrays/ArrayExample/UserInputArray.java: -------------------------------------------------------------------------------- 1 | package ArrayExample; 2 | // import class Scanner 3 | import java.util.Scanner; 4 | public class UserInputArray { 5 | 6 | 7 | public static void main(String[] args) { 8 | // Create a Object 9 | Scanner sc = new Scanner(System.in); 10 | // Size of array 11 | System.out.println("Enter Array Size ... "); 12 | int size; 13 | size = sc.nextInt(); 14 | 15 | String Course[] = new String[size]; 16 | 17 | for (int i = 0; i < Course.length; i++) { 18 | 19 | System.out.println("Enter Course Name = "+(i+1)); 20 | Course[i] = sc.next(); 21 | 22 | } 23 | 24 | System.out.println("------output-------------"); 25 | for (int i = 0; i < Course.length; i++) { 26 | System.out.println((i+1)+" = "+Course[i]); 27 | } 28 | 29 | 30 | 31 | } 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Day_06_Arrays/Assignments/ArrayConcatenation.java: -------------------------------------------------------------------------------- 1 | // Java Program to Concatenate Two Arrays 2 | // p4n.in 3 | // codeswithpankaj.com 4 | 5 | import java.util.Arrays; 6 | 7 | public class ArrayConcatenation { 8 | public static void main(String[] args) { 9 | // Define the arrays 10 | int[] array1 = {1, 2, 3}; 11 | int[] array2 = {4, 5, 6}; 12 | 13 | // Concatenate the arrays 14 | int[] concatenatedArray = concatenateArrays(array1, array2); 15 | 16 | // Display the result 17 | System.out.println("Concatenated Array: " + Arrays.toString(concatenatedArray)); 18 | } 19 | 20 | public static int[] concatenateArrays(int[] array1, int[] array2) { 21 | int length1 = array1.length; 22 | int length2 = array2.length; 23 | int[] result = new int[length1 + length2]; 24 | 25 | System.arraycopy(array1, 0, result, 0, length1); 26 | System.arraycopy(array2, 0, result, length1, length2); 27 | 28 | return result; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Day_06_Arrays/Assignments/ArrayString.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | public class ArrayString { 4 | 5 | public static void main(String[] args) { 6 | 7 | // Step 1 Declare an array of integers 8 | 9 | String website[] = new String[4]; 10 | 11 | // Step 2 Initialize the array with values 12 | 13 | website[0] = "www.p4n.in"; 14 | website[1] = "www.codeswithpankaj.com"; 15 | website[2] = "www.p4n.store"; 16 | website[3] = "www.pn2.in"; 17 | 18 | // Step 3 Access all and print array elements 19 | 20 | // System.out.println(website[2]); 21 | 22 | System.out.println("======= website list =========="); 23 | 24 | for (int i = 0; i < website.length; i++) { 25 | System.out.println((i+1)+" - "+website[i]); 26 | } 27 | 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Day_06_Arrays/Assignments/ArraySumAverage.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ArraySumAverage { 4 | public static void main(String[] args) { 5 | // Create a Scanner object for user input 6 | Scanner scanner = new Scanner(System.in); 7 | 8 | // Get the size of the array from the user 9 | System.out.print("Enter the size of the array: "); 10 | int size = scanner.nextInt(); 11 | 12 | // Declare the array based on the user input 13 | int[] numbers = new int[size]; 14 | 15 | // Get values for the array from the user 16 | System.out.println("Enter the elements of the array:"); 17 | for (int i = 0; i < size; i++) { 18 | System.out.print("Element " + (i + 1) + ": "); 19 | numbers[i] = scanner.nextInt(); 20 | } 21 | 22 | // Calculate the sum of array elements 23 | int sum = 0; 24 | for (int i = 0; i < size; i++) { 25 | sum += numbers[i]; 26 | } 27 | 28 | // Calculate the average of array elements 29 | double average = (double) sum / size; 30 | 31 | // Print the sum and average 32 | System.out.println("Sum: " + sum); 33 | System.out.println("Average: " + average); 34 | 35 | // Close the Scanner 36 | scanner.close(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Day_06_Arrays/Assignments/MatrixAddition.java: -------------------------------------------------------------------------------- 1 | // p4n.in 2 | // codeswithpankaj.com 3 | 4 | public class MatrixAddition { 5 | public static void main(String[] args) { 6 | // Define the matrices 7 | int[][] matrix1 = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; 8 | int[][] matrix2 = {{9, 8, 7}, {6, 5, 4}, {3, 2, 1}}; 9 | 10 | // Perform matrix addition 11 | int[][] sumMatrix = addMatrices(matrix1, matrix2); 12 | 13 | // Display the result 14 | System.out.println("Sum of the matrices:"); 15 | displayMatrix(sumMatrix); 16 | } 17 | 18 | public static int[][] addMatrices(int[][] matrix1, int[][] matrix2) { 19 | int rows = matrix1.length; 20 | int columns = matrix1[0].length; 21 | int[][] result = new int[rows][columns]; 22 | 23 | for (int i = 0; i < rows; i++) { 24 | for (int j = 0; j < columns; j++) { 25 | result[i][j] = matrix1[i][j] + matrix2[i][j]; 26 | } 27 | } 28 | 29 | return result; 30 | } 31 | 32 | public static void displayMatrix(int[][] matrix) { 33 | int rows = matrix.length; 34 | int columns = matrix[0].length; 35 | 36 | for (int i = 0; i < rows; i++) { 37 | for (int j = 0; j < columns; j++) { 38 | System.out.print(matrix[i][j] + " "); 39 | } 40 | System.out.println(); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Day_06_Arrays/Assignments/MatrixTranspose.java: -------------------------------------------------------------------------------- 1 | // Java Program to Find Transpose of a Matrix 2 | // p4n.in 3 | // codeswithpankaj.com 4 | 5 | public class MatrixTranspose { 6 | public static void main(String[] args) { 7 | // Define the matrix 8 | int[][] matrix = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; 9 | 10 | // Find the transpose 11 | int[][] transposeMatrix = findTranspose(matrix); 12 | 13 | // Display the result 14 | System.out.println("Original Matrix:"); 15 | displayMatrix(matrix); 16 | 17 | System.out.println("\nTranspose of the Matrix:"); 18 | displayMatrix(transposeMatrix); 19 | } 20 | 21 | public static int[][] findTranspose(int[][] matrix) { 22 | int rows = matrix.length; 23 | int columns = matrix[0].length; 24 | int[][] transposeMatrix = new int[columns][rows]; 25 | 26 | for (int i = 0; i < rows; i++) { 27 | for (int j = 0; j < columns; j++) { 28 | transposeMatrix[j][i] = matrix[i][j]; 29 | } 30 | } 31 | 32 | return transposeMatrix; 33 | } 34 | 35 | public static void displayMatrix(int[][] matrix) { 36 | int rows = matrix.length; 37 | int columns = matrix[0].length; 38 | 39 | for (int i = 0; i < rows; i++) { 40 | for (int j = 0; j < columns; j++) { 41 | System.out.print(matrix[i][j] + " "); 42 | } 43 | System.out.println(); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Day_06_Arrays/JavaCopyArray/ArrayCopyExample.java: -------------------------------------------------------------------------------- 1 | package JavaCopyArray; 2 | // p4n.in 3 | // codeswithpankaj.com 4 | // example that demonstrates how to copy arrays using different methods in Java: 5 | import java.util.Arrays; 6 | 7 | public class ArrayCopyExample { 8 | public static void main(String[] args) { 9 | // Source array 10 | int[] sourceArray = {1, 2, 3, 4, 5}; 11 | 12 | // Method 1: Using a Loop 13 | int[] copyUsingLoop = new int[sourceArray.length]; 14 | for (int i = 0; i < sourceArray.length; i++) { 15 | copyUsingLoop[i] = sourceArray[i]; 16 | } 17 | System.out.println("Copy using loop: " + Arrays.toString(copyUsingLoop)); 18 | 19 | // Method 2: Using System.arraycopy() 20 | int[] copyUsingArrayCopy = new int[sourceArray.length]; 21 | System.arraycopy(sourceArray, 0, copyUsingArrayCopy, 0, sourceArray.length); 22 | System.out.println("Copy using System.arraycopy(): " + Arrays.toString(copyUsingArrayCopy)); 23 | 24 | // Method 3: Using Arrays.copyOf() 25 | int[] copyUsingCopyOf = Arrays.copyOf(sourceArray, sourceArray.length); 26 | System.out.println("Copy using Arrays.copyOf(): " + Arrays.toString(copyUsingCopyOf)); 27 | 28 | // Method 4: Using Arrays.copyOfRange() 29 | int[] copyUsingCopyOfRange = Arrays.copyOfRange(sourceArray, 0, sourceArray.length); 30 | System.out.println("Copy using Arrays.copyOfRange(): " + Arrays.toString(copyUsingCopyOfRange)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Day_06_Arrays/MultidimensionalArrays/MultiArray.java: -------------------------------------------------------------------------------- 1 | package MultidimensionalArrays; 2 | class MultiArray{ 3 | 4 | public static void main(String[] args) { 5 | 6 | //Datatype[][] ArrayName = new DataType[size][size] 7 | 8 | int[][] data = new int[3][3] ; 9 | 10 | data[0][0] = 21; 11 | data[0][1] = 22; 12 | data[0][2] = 23; 13 | 14 | data[1][0] = 24; 15 | data[1][1] = 25; 16 | data[1][2] = 26; 17 | 18 | data[2][0] = 27; 19 | data[2][1] = 28; 20 | data[2][2] = 29; 21 | 22 | //System.out.println(data[1][1]); 23 | 24 | for (int i = 0; i < 3; i++) { 25 | for (int j = 0; j < 3; j++) { 26 | System.out.print(data[i][j]+" "); 27 | } 28 | System.out.println(); 29 | } 30 | 31 | 32 | } 33 | 34 | 35 | } -------------------------------------------------------------------------------- /Day_06_Arrays/MultidimensionalArrays/MultiArrayExample.java: -------------------------------------------------------------------------------- 1 | package MultidimensionalArrays; 2 | class MultiArrayExample{ 3 | public static void main(String[] args) { 4 | 5 | int[][] data = new int[3][3]; 6 | 7 | data[0][0] = 21; 8 | data[1][0] = 22; 9 | data[2][0] = 23; 10 | 11 | data[0][1] = 24; 12 | data[1][1] = 25; 13 | data[2][1] = 26; 14 | 15 | data[0][2] = 27; 16 | data[1][2] = 28; 17 | data[2][2] = 29; 18 | 19 | for (int i = 0; i < data.length; i++) { 20 | 21 | for (int j = 0; j < data.length; j++) { 22 | 23 | System.out.print(" "+data[i][j]); 24 | 25 | } 26 | System.out.println(); 27 | } 28 | 29 | } 30 | } -------------------------------------------------------------------------------- /Day_06_Arrays/MultidimensionalArrays/MultiArrayStr.java: -------------------------------------------------------------------------------- 1 | package MultidimensionalArrays; 2 | class multiArrayStr{ 3 | 4 | public static void main(String[] args) { 5 | 6 | String data[][] = new String[3][3]; 7 | 8 | data[0][0] = "JAVA"; 9 | data[1][0] = "JSP"; 10 | data[2][0] = "GO"; 11 | 12 | data[0][1] = "JSF"; 13 | data[1][1] = "RUBY"; 14 | data[2][1] = "C"; 15 | 16 | data[0][2] = "C++"; 17 | data[1][2] = "PYTHON"; 18 | data[2][2] = "R"; 19 | 20 | //System.out.println(data[0][2]); 21 | for (int i = 0; i < 3; i++) { 22 | for (int j = 0; j < 3; j++){ 23 | System.out.print(i+""+j+" "); 24 | } 25 | System.out.println(); 26 | } 27 | 28 | 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /Day_06_Arrays/MultidimensionalArrays/MultidimensionalArraysInt.java: -------------------------------------------------------------------------------- 1 | package MultidimensionalArrays; 2 | class MultidimensionalArraysInt{ 3 | 4 | 5 | public static void main(String[] args) { 6 | 7 | int[][] data = new int[3][3]; 8 | 9 | data[0][0] = 23; 10 | data[0][1] = 24; 11 | data[0][2] = 25; 12 | 13 | data[1][0] = 26; 14 | data[1][1] = 27; 15 | data[1][2] = 28; 16 | 17 | data[2][0] = 29; 18 | data[2][1] = 30; 19 | data[2][2] = 31; 20 | 21 | 22 | //System.out.println(data[2][2]); 23 | 24 | for (int i = 0; i < data.length; i++) { 25 | for (int j = 0; j < data.length; j++) { 26 | System.out.print(" "+data[i][j]); 27 | } 28 | System.out.println(); 29 | } 30 | 31 | 32 | 33 | } 34 | 35 | 36 | } -------------------------------------------------------------------------------- /Day_06_Arrays/MultidimensionalArrays/MultidimensionalArraysIntINPUT.java: -------------------------------------------------------------------------------- 1 | package MultidimensionalArrays; 2 | import java.util.Scanner;; 3 | class MultidimensionalArraysIntINPUT{ 4 | 5 | 6 | public static void main(String[] args) { 7 | 8 | Scanner sc = new Scanner(System.in); 9 | 10 | int row,col; 11 | 12 | System.out.println("Enter col number : \n"); 13 | col = sc.nextInt(); 14 | System.out.println("Enter row number : \n"); 15 | row = sc.nextInt(); 16 | 17 | int[][] data = new int[row][col]; 18 | 19 | for (int i = 0; i < row; i++) { 20 | for (int j = 0; j < col; j++) { 21 | 22 | System.out.print("Enter row and col - "+i+j+"\n"); 23 | data[i][j] = sc.nextInt(); 24 | 25 | } 26 | 27 | System.out.println(); 28 | } 29 | 30 | System.out.println("-------------------"); 31 | for (int i = 0; i < row; i++) { 32 | for (int j = 0; j < col; j++) { 33 | 34 | System.out.print(" "+data[i][j]); 35 | 36 | 37 | } 38 | 39 | System.out.println(); 40 | } 41 | 42 | 43 | 44 | } 45 | 46 | 47 | } -------------------------------------------------------------------------------- /Day_06_Arrays/MultidimensionalArrays/ThreeDArrayExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_06_Arrays/MultidimensionalArrays/ThreeDArrayExample.class -------------------------------------------------------------------------------- /Day_06_Arrays/MultidimensionalArrays/TwoDArrayExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_06_Arrays/MultidimensionalArrays/TwoDArrayExample.class -------------------------------------------------------------------------------- /Day_06_Arrays/OneDimensionalArrays/ArrayContainsValue.java: -------------------------------------------------------------------------------- 1 | package OneDimensionalArrays; 2 | 3 | // Java Program to Check if An Array Contains a Given Value 4 | // p4n.in 5 | // codeswithpankaj.com 6 | 7 | public class ArrayContainsValue { 8 | public static void main(String[] args) { 9 | // Define the array 10 | int[] array = {1, 2, 3, 4, 5}; 11 | 12 | // Check if the array contains a given value 13 | int targetValue = 3; 14 | boolean containsValue = contains(array, targetValue); 15 | 16 | // Display the result 17 | if (containsValue) { 18 | System.out.println("The array contains the value " + targetValue); 19 | } else { 20 | System.out.println("The array does not contain the value " + targetValue); 21 | } 22 | } 23 | 24 | public static boolean contains(int[] array, int targetValue) { 25 | for (int element : array) { 26 | if (element == targetValue) { 27 | return true; 28 | } 29 | } 30 | return false; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Day_06_Arrays/OneDimensionalArrays/CharArrayExample.java: -------------------------------------------------------------------------------- 1 | package OneDimensionalArrays; 2 | 3 | public class CharArrayExample { 4 | 5 | public static void main(String[] args) { 6 | // Declare and create an array of characters 7 | char[] letters = new char[5]; 8 | // Initialize array elements 9 | letters[0] = 'A'; 10 | letters[1] = 'B'; 11 | letters[2] = 'C'; 12 | letters[3] = 'D'; 13 | letters[4] = 'E'; 14 | 15 | // Access and print array elements 16 | 17 | for (int i = 0; i < letters.length; i++) { 18 | System.out.println(i+1+" - "+letters[i]); 19 | } 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Day_06_Arrays/OneDimensionalArrays/ForeachLoop.java: -------------------------------------------------------------------------------- 1 | package OneDimensionalArrays; 2 | 3 | public class ForeachLoop { 4 | 5 | public static void main(String[] args) { 6 | String students[] = {"Vinit","Deepak","Rohit","Joy"}; 7 | 8 | for (String std : students) { 9 | 10 | System.out.println(std); 11 | } 12 | } 13 | 14 | 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Day_06_Arrays/OneDimensionalArrays/OneDimensionalArrayExample.java: -------------------------------------------------------------------------------- 1 | package OneDimensionalArrays; 2 | public class OneDimensionalArrayExample{ 3 | public static void main(String[] args) { 4 | // Declare an array of integers 5 | // dataType[] arrayName = new dataType[arrayLength]; 6 | int[] numbers = new int[5]; 7 | // int[5] = create an array of size 5 8 | 9 | // Initialize the array elements 10 | numbers[0] = 10; 11 | numbers[1] = 20; 12 | numbers[2] = 30; 13 | numbers[3] = 40; 14 | numbers[4] = 50; 15 | 16 | // access and print array elements 17 | // System.out.println(numbers[1]); // output 20 18 | 19 | System.out.println("--------- Array elements -------- "); 20 | 21 | for(int i = 0 ; i < numbers.length ; i++){ 22 | //print elements 23 | System.out.println("Elements at index " + i + " : " + numbers[i]); 24 | } 25 | 26 | } 27 | } -------------------------------------------------------------------------------- /Day_06_Arrays/OneDimensionalArrays/OtherWayArray.java: -------------------------------------------------------------------------------- 1 | package OneDimensionalArrays; 2 | 3 | public class OtherWayArray { 4 | 5 | public static void main(String[] args) { 6 | int data[] = {1200,1300,1400,1500}; 7 | 8 | for (int i = 0; i < data.length; i++) { 9 | 10 | System.out.println("Data - "+data[i]); 11 | } 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Day_06_Arrays/OneDimensionalArrays/SingleArrayExample1.java: -------------------------------------------------------------------------------- 1 | package OneDimensionalArrays; 2 | // p4n.in 3 | // codeswithpankaj.com 4 | public class SingleArrayExample1{ 5 | public static void main(String[] args) { 6 | // Declare and initialize an array of strings 7 | String[] names = {"Alice", "Bob", "Charlie", "David", "Emily"}; 8 | 9 | // Access and print array elements 10 | System.out.println("Array elements:"); 11 | for (int i = 0; i < names.length; i++) { 12 | System.out.println(names[i]); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Day_06_Arrays/OneDimensionalArrays/SingleArrayIntegers.java: -------------------------------------------------------------------------------- 1 | package OneDimensionalArrays; 2 | //@p4n.in 3 | // codeswithpankaj.com 4 | public class SingleArrayIntegers{ 5 | public static void main(String[] args) { 6 | // Declare an array of integers 7 | int[] numbers = new int[5]; 8 | 9 | // Initialize the array with values 10 | numbers[0] = 10; 11 | numbers[1] = 20; 12 | numbers[2] = 30; 13 | numbers[3] = 40; 14 | numbers[4] = 50; 15 | 16 | // Access and print array elements 17 | System.out.println("Array elements:"); 18 | 19 | for (int i = 0; i < numbers.length; i++) { 20 | System.out.println(numbers[i]); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Day_06_Arrays/OneDimensionalArrays/SingleArrayUserInput.java: -------------------------------------------------------------------------------- 1 | package OneDimensionalArrays; 2 | import java.util.Scanner; 3 | //p4n.in 4 | //codeswithpankaj.com 5 | public class SingleArrayUserInput { 6 | public static void main(String[] args) { 7 | // Create a Scanner object for user input 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | // Get the size of the array from the user 11 | System.out.print("Enter the size of the array: "); 12 | int size = scanner.nextInt(); 13 | 14 | // Declare the array based on the user input 15 | int[] numbers = new int[size]; 16 | 17 | // Get values for the array from the user 18 | System.out.println("Enter the elements of the array:"); 19 | for (int i = 0; i < size; i++) { 20 | System.out.print("Element " + (i + 1) + ": "); 21 | numbers[i] = scanner.nextInt(); 22 | } 23 | 24 | // Access and print array elements 25 | System.out.println("Array elements:"); 26 | for (int i = 0; i < size; i++) { 27 | System.out.println(numbers[i]); 28 | } 29 | 30 | // Close the Scanner 31 | scanner.close(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Day_06_Arrays/OneDimensionalArrays/StringArrayExample.java: -------------------------------------------------------------------------------- 1 | package OneDimensionalArrays; 2 | 3 | public class StringArrayExample { 4 | // Declare and create an array of strings 5 | 6 | public static void main(String[] args) { 7 | // dataType[] arrayName = new dataType[arrayLength]; 8 | String[] subject = new String[5]; 9 | 10 | subject[0] = "java"; 11 | subject[1] = "c++"; 12 | subject[2] = "python"; 13 | subject[3] = "ruby"; 14 | subject[4] = "servlet"; 15 | 16 | // print all elements 17 | for (int i = 0; i < subject.length; i++) { 18 | System.out.println("Subject - "+(i+1)+" : "+subject[i]); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Day_07_Function/Function/Function1.java: -------------------------------------------------------------------------------- 1 | package Day_07_Function.Function; 2 | 3 | class Function1{ 4 | // Non Return type and Non Arguments 5 | 6 | static void info(){ 7 | 8 | // function body 9 | System.out.println("@codeswithpankaj.com"); 10 | } 11 | 12 | public static void main(String[] agr){ 13 | // call static function 14 | info(); 15 | info(); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /Day_07_Function/Function/Function2.java: -------------------------------------------------------------------------------- 1 | package Day_07_Function.Function; 2 | 3 | class Function2{ 4 | // Non Return type and With Arguments 5 | 6 | static void info(String Website){ 7 | 8 | // function body 9 | System.out.println("Your Website Name : "+Website); 10 | } 11 | 12 | static void intro(String name , int age , float height){ 13 | System.out.println("Name : "+name); 14 | System.out.println("Age : "+age); 15 | System.out.println("Height : "+height); 16 | } 17 | 18 | public static void main(String[] agr){ 19 | // call static function 20 | info("@p4n.in"); 21 | info("@codeswithpankaj.com"); 22 | 23 | intro("Joy",12,3.4f); 24 | intro("Toy",22,6.7f); 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /Day_07_Function/Function/Function3.java: -------------------------------------------------------------------------------- 1 | package Day_07_Function.Function; 2 | 3 | class Function3{ 4 | // - With Return type and Non Arguments 5 | 6 | static int getnumber(){ 7 | return 900; 8 | } 9 | 10 | static float getfloatnumber(){ 11 | return 3.4f; 12 | } 13 | static String getname(){ 14 | return "@p4n.in"; 15 | } 16 | 17 | public static void main(String[] agr){ 18 | // call static function 19 | System.out.println(getnumber()); 20 | System.out.println(getname()); 21 | System.out.println(getfloatnumber()); 22 | 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /Day_07_Function/Function/Function4.java: -------------------------------------------------------------------------------- 1 | package Day_07_Function.Function; 2 | 3 | class Function4{ 4 | // - With Return type and With Arguments 5 | 6 | static int tax(int price, int gst){ 7 | gst = (price * gst)/100; 8 | int final_price = gst+price; 9 | return final_price; 10 | } 11 | 12 | 13 | public static void main(String[] agr){ 14 | // call static function 15 | 16 | int mrp = tax(1200, 18); 17 | System.out.println(mrp+20); 18 | 19 | 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /Day_07_Function/Function2/NonReturnNonArguments.java: -------------------------------------------------------------------------------- 1 | package Day_07_Function.Function2; 2 | 3 | class NonReturnNonArguments{ 4 | 5 | // Non-Return Type and Non-Arguments 6 | 7 | static void getinfo(){ 8 | 9 | System.out.println("Website : codewithpankaj.com "); 10 | System.out.println("Course Name : JAVA Development "); 11 | 12 | } 13 | 14 | public static void main(String[] args) { 15 | // Calling a method with no return type and no arguments 16 | 17 | getinfo(); 18 | 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /Day_07_Function/Function2/NonReturnWithArguments.java: -------------------------------------------------------------------------------- 1 | package Day_07_Function.Function2; 2 | 3 | public class NonReturnWithArguments { 4 | // Non-Return Type and With Arguments 5 | 6 | static void getinfo(String name, int age ,float height){ 7 | 8 | System.out.println("Your Name is : "+name); 9 | System.out.println("Your age is : "+age); 10 | System.out.println("Your height is : "+height); 11 | 12 | } 13 | 14 | public static void main(String[] args) { 15 | // Calling a method with no return type and with arguments 16 | 17 | getinfo("Neha", 21, 4.9f); 18 | getinfo("Tejal", 18, 4.7f); 19 | getinfo("Piyush", 20, 5.7f); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Day_07_Function/Function2/WithReturnNonArguments.java: -------------------------------------------------------------------------------- 1 | package Day_07_Function.Function2; 2 | 3 | public class WithReturnNonArguments { 4 | // With Return Type and Non-Arguments 5 | 6 | static int getage(){ 7 | return 45; 8 | } 9 | static String getname(){ 10 | return "Neha"; 11 | } 12 | static float getheight(){ 13 | return 4.5f; 14 | } 15 | 16 | public static void main(String[] args) { 17 | // Calling a method with a return type and no arguments 18 | 19 | String name = getname(); 20 | int age = getage(); 21 | float height = getheight(); 22 | 23 | System.out.println("Your Name is : "+name); 24 | System.out.println("Your age is : "+age); 25 | System.out.println("Your height is : "+height); 26 | } 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Day_07_Function/Function2/WithReturnWithArguments.java: -------------------------------------------------------------------------------- 1 | package Day_07_Function.Function2; 2 | 3 | public class WithReturnWithArguments { 4 | // With Return Type and With Arguments 5 | 6 | static double tax(long price, double gst){ 7 | 8 | long GstAmount = (long) (price*gst)/100; 9 | long Final_Price = price+GstAmount; 10 | 11 | return Final_Price; 12 | 13 | } 14 | 15 | public static void main(String[] args) { 16 | // Calling a method with a return type and with arguments 17 | 18 | long mrp = (long) tax(12000, 18.5); 19 | 20 | long final_mrp = mrp-10; 21 | 22 | System.out.println("Your Final Price : "+final_mrp); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Day_07_Function/Methods.java: -------------------------------------------------------------------------------- 1 | package Day_07_Function; 2 | 3 | public class Methods { 4 | void info(){ 5 | System.out.println("codeswithpankaj"); 6 | } 7 | 8 | public static void main(String[] arg){ 9 | //className ObjectName = new ClassName(); 10 | Methods obj = new Methods(); 11 | obj.info(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Day_07_Function/Methods/Client.java: -------------------------------------------------------------------------------- 1 | package Methods; 2 | 3 | public class Client { 4 | 5 | // - Non Return type and Non Arguments 6 | void get_info() { 7 | 8 | System.out.println("codeswithpankaj.com"); 9 | System.out.println(" this is java tutorial...."); 10 | System.out.println("client info : name : joy "); 11 | } 12 | // - Non Return type and With Arguments 13 | 14 | void getresult(int price,int qt) { 15 | 16 | int mrp = price*qt; 17 | 18 | System.out.println("MRP : "+mrp); 19 | } 20 | 21 | // - With Return type and Non Arguments 22 | 23 | int mrp() { 24 | 25 | return 900; 26 | } 27 | 28 | // - With Return type and With Aruments 29 | 30 | long tax(long price,int gst) { 31 | 32 | long gst_price = (price*gst)/100; 33 | long total_amount = gst_price+price; 34 | 35 | return total_amount; 36 | } 37 | 38 | 39 | 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /Day_07_Function/Methods/Main_Client.java: -------------------------------------------------------------------------------- 1 | package Methods; 2 | import java.util.*; 3 | public class Main_Client { 4 | 5 | public static void main(String[] args) { 6 | 7 | //create object 8 | 9 | // className objectName = new className(); 10 | 11 | Client cl = new Client(); 12 | cl.get_info(); 13 | cl.getresult(1200, 18); 14 | System.out.println(cl.mrp()+900); 15 | 16 | long mrp = cl.tax(465465465435l, 56); 17 | 18 | System.out.println("MRP : ---- "+mrp); 19 | 20 | 21 | 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Day_07_Function/Methods/Methods_Example.java: -------------------------------------------------------------------------------- 1 | package Methods; 2 | 3 | public class Methods_Example { 4 | 5 | //static methods 6 | 7 | static void info() { 8 | 9 | System.out.println("codeswithpankaj.com"); 10 | } 11 | 12 | 13 | 14 | public static void main(String[] args) { 15 | 16 | // calling methods 17 | 18 | info(); 19 | info(); 20 | 21 | 22 | 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Day_08_BreakContinue /BreakStatementExample.java: -------------------------------------------------------------------------------- 1 | // p4n.in 2 | // codeswithpankaj.com 3 | package Day_09; 4 | public class BreakStatementExample { 5 | public static void main(String[] args) { 6 | int[] numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; 7 | int searchValue = 6; 8 | 9 | // Iterate through the array to find the search value 10 | for (int number : numbers) { 11 | if (number == searchValue) { 12 | System.out.println("Value found!"); 13 | break; 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Day_08_BreakContinue /ContinueStatementExample.java: -------------------------------------------------------------------------------- 1 | package Day_09; 2 | // p4n.in 3 | // codeswithpankaj.com 4 | 5 | public class ContinueStatementExample { 6 | public static void main(String[] args) { 7 | // Iterate through numbers from 1 to 10 8 | for (int i = 1; i <= 10; i++) { 9 | // Skip printing even numbers 10 | if (i % 2 == 0) { 11 | continue; 12 | } 13 | System.out.println(i); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Day_08_BreakContinue /LoopUsingBreak.java: -------------------------------------------------------------------------------- 1 | package Day_09; 2 | 3 | public class LoopUsingBreak { 4 | 5 | public static void main(String[] args) { 6 | 7 | for (int i = 0; i <= 10; i++) { 8 | 9 | if(i < 5){ 10 | System.out.println("Done ... "+i); 11 | continue; 12 | }else{ 13 | System.out.println("************ "+i); 14 | } 15 | 16 | } 17 | 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Day_09_ClassObjects/Example1/School.java: -------------------------------------------------------------------------------- 1 | package Day_09_ClassObjects.Example1; 2 | public class School { 3 | String StudentName; 4 | int RollNumber; 5 | void info(){ 6 | System.out.println("Student Name : "+StudentName); 7 | System.out.println("Student RollNumber : "+RollNumber); 8 | } 9 | } 10 | class MainSchool { 11 | 12 | public static void main(String[] args) { 13 | // Create a object 14 | School sc = new School(); 15 | sc.RollNumber = 1002; 16 | sc.StudentName = "Mumtaz"; 17 | 18 | sc.info(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Day_09_ClassObjects/Example2/Books.java: -------------------------------------------------------------------------------- 1 | package Day_09_ClassObjects.Example2; 2 | public class Books { 3 | 4 | void GetBooksInfo(){ 5 | System.out.println("Codeswithpankaj- java hub"); 6 | } 7 | 8 | void GetBooksPrice(int price){ 9 | System.out.println("Books Price -- "+price); 10 | } 11 | 12 | public static void main(String[] args) { 13 | //ClassName ObjectName = new ClassName(); 14 | Books obj = new Books(); 15 | obj.GetBooksInfo(); 16 | obj.GetBooksPrice(1300); 17 | } 18 | } -------------------------------------------------------------------------------- /Day_09_ClassObjects/Shop/Client.java: -------------------------------------------------------------------------------- 1 | package Day_09_ClassObjects.Shop; 2 | 3 | public class Client { 4 | String name; 5 | long mobile; 6 | void info(){ 7 | System.out.println("Client Name - "+name); 8 | System.out.println("Mobile Number - "+mobile); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Day_09_ClassObjects/Shop/ClientMainClass.java: -------------------------------------------------------------------------------- 1 | package Day_09_ClassObjects.Shop; 2 | 3 | import java.util.Scanner; 4 | public class ClientMainClass { 5 | public static void main(String[] args) { 6 | // create a object 7 | Scanner sc = new Scanner(System.in); 8 | // ClassName ObjectName = new ClassName(); 9 | Client cl = new Client(); 10 | System.out.println("Enter Client Name : "); 11 | String name = sc.next(); 12 | System.out.println("Enter Client Mobile number : "); 13 | long mobile = sc.nextLong(); 14 | 15 | cl.name = name; 16 | cl.mobile = mobile; 17 | cl.info(); 18 | 19 | // cl.name = "Toy"; 20 | // cl.mobile = 7897541230l; 21 | // cl.info(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Day_10_Constructor/Constructor/Book.java: -------------------------------------------------------------------------------- 1 | public class Book { 2 | // Instance variables 3 | private String title; 4 | private String author; 5 | private int yearPublished; 6 | 7 | // Constructor with parameters 8 | public Book(String title, String author, int yearPublished) { 9 | this.title = title; 10 | this.author = author; 11 | this.yearPublished = yearPublished; 12 | } 13 | 14 | // Method to display book details 15 | public void displayDetails() { 16 | System.out.println("Title: " + title); 17 | System.out.println("Author: " + author); 18 | System.out.println("Year Published: " + yearPublished); 19 | } 20 | 21 | public static void main(String[] args) { 22 | // Create two book objects using the constructor 23 | Book book1 = new Book("The Catcher in the Rye", "J.D. Salinger", 1951); 24 | Book book2 = new Book("To Kill a Mockingbird", "Harper Lee", 1960); 25 | 26 | // Call the displayDetails method to show the book details 27 | System.out.println("Book 1 Details:"); 28 | book1.displayDetails(); 29 | 30 | System.out.println("\nBook 2 Details:"); 31 | book2.displayDetails(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Day_10_Constructor/Constructor/Client.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | public class Client 4 | { 5 | //Default constructor 6 | Client(){ 7 | System.out.println("welcome... p4n.in"); 8 | } 9 | // Constructor with parameters 10 | Client(String name){ 11 | System.out.println("welcome - "+name); 12 | } 13 | public static void main(String[] args) { 14 | Client obj1 = new Client(); 15 | Client obj = new Client("www.p4n.in"); 16 | 17 | } 18 | 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Day_10_Constructor/Constructor/Codeswithpankaj.java: -------------------------------------------------------------------------------- 1 | public class Codeswithpankaj { 2 | // Instance variables 3 | private String courseName; 4 | private int courseDuration; 5 | 6 | // Constructor with two parameters 7 | public Codeswithpankaj(String name, int duration) { 8 | courseName = name; 9 | courseDuration = duration; 10 | } 11 | 12 | // Method to display course details 13 | public void displayCourseDetails() { 14 | System.out.println("Course Name: " + courseName); 15 | System.out.println("Course Duration (in weeks): " + courseDuration); 16 | } 17 | 18 | public static void main(String[] args) { 19 | // Create an object using the constructor 20 | Codeswithpankaj course = new Codeswithpankaj("Java Programming", 12); 21 | 22 | // Call the displayCourseDetails method to show the course details 23 | course.displayCourseDetails(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Day_10_Constructor/Constructor/Course.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | public class Course { 4 | 5 | // default Constructor 6 | Course(){ 7 | System.out.println("www.p4n.in"); 8 | } 9 | Course(String web){ 10 | System.out.println("this is website : "+web); 11 | } 12 | public static void main(String[] args) { 13 | // Create a object 14 | Course course = new Course(); 15 | Course course1 = new Course("www.codeswithpankaj.com"); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Day_10_Constructor/Employee.java: -------------------------------------------------------------------------------- 1 | package jan_11_2023; 2 | 3 | public class Employee { 4 | 5 | int number = 100; 6 | String website; 7 | Employee(){ 8 | 9 | System.out.println("JAVA tutorial...."); 10 | System.out.println("Number 1 "+number); 11 | 12 | } 13 | 14 | Employee(String web){ 15 | website = web; 16 | System.out.println("website name is : "+web); 17 | } 18 | 19 | void getnumber() { 20 | System.out.println("Number 1 "+number); 21 | System.out.println("website name is : "+website); 22 | } 23 | } 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Day_10_Constructor/EmployeeMain.java: -------------------------------------------------------------------------------- 1 | package jan_11_2023; 2 | 3 | public class EmployeeMain { 4 | 5 | public static void main(String[] args) { 6 | 7 | Employee em = new Employee(); 8 | em.number = 900; 9 | Employee em1 = new Employee("codeswithpankaj.com"); 10 | Employee em2 = new Employee(); 11 | em.getnumber(); 12 | em1.getnumber(); 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Day_13_ThisKeyword/Client.java: -------------------------------------------------------------------------------- 1 | package jan_18_2024; 2 | 3 | public class Client { 4 | 5 | 6 | String Client_Name; 7 | int Client_Id; 8 | 9 | public Client(String Client_Name, int Client_Id) { 10 | this.Client_Name = Client_Name; 11 | this.Client_Id = Client_Id; 12 | 13 | } 14 | 15 | void info() { 16 | 17 | if(Client_Name != null) { 18 | 19 | System.out.println("Customer Name "+Client_Name); 20 | System.out.println("Customer ID "+Client_Id); 21 | }else { 22 | System.out.println("Data Not Found..."); 23 | } 24 | } 25 | 26 | 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Day_13_ThisKeyword/ClientMain.java: -------------------------------------------------------------------------------- 1 | package jan_18_2024; 2 | 3 | public class ClientMain { 4 | 5 | public static void main(String[] args) { 6 | 7 | Client cl = new Client("Nishant",23); 8 | cl.info(); 9 | 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Day_13_ThisKeyword/ThisKeyword/Students.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_13_ThisKeyword/ThisKeyword/Students.class -------------------------------------------------------------------------------- /Day_13_ThisKeyword/ThisKeyword/Students.java: -------------------------------------------------------------------------------- 1 | class Students{ 2 | String Name; 3 | void GetInfo(String Name){ 4 | this.Name = Name; 5 | System.out.println("My Name is : "+Name); 6 | } 7 | 8 | void GetBooks(String Book){ 9 | System.out.println("The Books Name is : "+Book); 10 | System.out.println("Student Name : "+Name); 11 | } 12 | 13 | public static void main(String[] args) { 14 | Students st = new Students(); 15 | 16 | st.GetInfo("Neha"); 17 | st.GetBooks("JAVA SE"); 18 | } 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /Day_13_ThisKeyword/ThisKeyword/p4n.java: -------------------------------------------------------------------------------- 1 | package Day_13_ThisKeyword.ThisKeyword; 2 | public class p4n { 3 | private int number; 4 | 5 | // Constructor that initializes the number field 6 | public p4n(int number) { 7 | this.number = number; // Use 'this' to refer to the instance variable 8 | } 9 | 10 | // Method to display the number 11 | public void displayNumber() { 12 | System.out.println("Number: " + this.number); // 'this' is optional here 13 | } 14 | 15 | // Another constructor that calls the parameterized constructor 16 | public p4n() { 17 | this(42); // Call the parameterized constructor with a default number of 42 18 | } 19 | 20 | public static void main(String[] args) { 21 | // Create p4n objects using different constructors 22 | p4n obj1 = new p4n(20); 23 | p4n obj2 = new p4n(); 24 | 25 | // Display the numbers 26 | System.out.println("Object 1 Number:"); 27 | obj1.displayNumber(); 28 | 29 | System.out.println("\nObject 2 Number:"); 30 | obj2.displayNumber(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Day_14_FinalKeyword /FianlKeyword/cwp.java: -------------------------------------------------------------------------------- 1 | package Day_15; 2 | 3 | public class cwp { 4 | // Final variable (constant) 5 | final double PI = 3.14159; 6 | 7 | // Final method that cannot be overridden 8 | final void displayPI() { 9 | System.out.println("The value of PI is: " + PI); 10 | } 11 | 12 | public static void main(String[] args) { 13 | cwp example = new cwp(); 14 | 15 | // Access the final variable and method 16 | System.out.println("Accessing the final variable PI: " + example.PI); 17 | example.displayPI(); 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Day_15_Recursion_Instanceof/RecursionInstanceof/Fibonacci.java: -------------------------------------------------------------------------------- 1 | package Day_15_Recursion_Instanceof.RecursionInstanceof; 2 | 3 | public class Fibonacci { 4 | public static int fibonacci(int n) { 5 | // Base cases: Fibonacci of 0 is 0 and Fibonacci of 1 is 1 6 | if (n == 0) { 7 | return 0; 8 | } else if (n == 1) { 9 | return 1; 10 | } 11 | // Recursive case: Fibonacci of n is the sum of the previous two Fibonacci numbers 12 | else { 13 | return fibonacci(n - 1) + fibonacci(n - 2); 14 | } 15 | } 16 | 17 | public static void main(String[] args) { 18 | int number = 7; 19 | int result = fibonacci(number); 20 | System.out.println("Fibonacci number at position " + number + " is: " + result); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Day_16_Inheritance/HierarchicalInheritance/HierarchicalInheritanceExample.java: -------------------------------------------------------------------------------- 1 | package Day_16_Inheritance.HierarchicalInheritance; 2 | 3 | // Superclass 4 | class Animal { 5 | void eat() { 6 | System.out.println("The animal is eating."); 7 | } 8 | } 9 | 10 | // Subclass 1 inheriting from Animal 11 | class Dog extends Animal { 12 | void bark() { 13 | System.out.println("The dog is barking."); 14 | } 15 | } 16 | 17 | // Subclass 2 inheriting from Animal 18 | class Cat extends Animal { 19 | void meow() { 20 | System.out.println("The cat is meowing."); 21 | } 22 | } 23 | 24 | public class HierarchicalInheritanceExample { 25 | public static void main(String[] args) { 26 | Dog myDog = new Dog(); 27 | Cat myCat = new Cat(); 28 | 29 | // Both Dog and Cat classes inherit the eat() method from Animal 30 | myDog.eat(); 31 | myCat.eat(); 32 | 33 | // Each subclass has its own unique methods 34 | myDog.bark(); 35 | myCat.meow(); 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /Day_16_Inheritance/HybridInheritance/HybridInheritanceExample.java: -------------------------------------------------------------------------------- 1 | package Day_16_Inheritance.HybridInheritance; 2 | 3 | // Interface for swimming behavior 4 | interface Swimmer { 5 | void swim(); 6 | } 7 | 8 | // Superclass 9 | class Animal { 10 | void eat() { 11 | System.out.println("The animal is eating."); 12 | } 13 | } 14 | 15 | // Subclass 1 inheriting from Animal and implementing Swimmer interface 16 | class Fish extends Animal implements Swimmer { 17 | @Override 18 | public void swim() { 19 | System.out.println("The fish is swimming."); 20 | } 21 | } 22 | 23 | // Subclass 2 inheriting from Animal 24 | class Dog extends Animal { 25 | void bark() { 26 | System.out.println("The dog is barking."); 27 | } 28 | } 29 | 30 | public class HybridInheritanceExample { 31 | public static void main(String[] args) { 32 | Fish myFish = new Fish(); 33 | Dog myDog = new Dog(); 34 | 35 | // Fish inherits eat() from Animal and implements swim() from Swimmer 36 | myFish.eat(); 37 | myFish.swim(); 38 | 39 | // Dog inherits eat() from Animal and has its own method bark() 40 | myDog.eat(); 41 | myDog.bark(); 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /Day_16_Inheritance/HybridInheritance/HybridInheritanceExample1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_16_Inheritance/HybridInheritance/HybridInheritanceExample1.class -------------------------------------------------------------------------------- /Day_16_Inheritance/HybridInheritance/HybridInheritanceExample1.java: -------------------------------------------------------------------------------- 1 | package Day_16_Inheritance.HybridInheritance; 2 | 3 | //Animal0 4 | //Swimmer0 5 | //Dog0 6 | //Fish0 7 | 8 | class Animal0{ 9 | void eat() { 10 | System.out.println("The animal is eating."); 11 | } 12 | } 13 | interface Swimmer0{ 14 | public void swim(); 15 | } 16 | interface Run0{ 17 | public void Runer(); 18 | } 19 | class Dog0 extends Animal0 implements Run0{ 20 | void bark() { 21 | System.out.println("The dog is barking."); 22 | } 23 | 24 | public void Runer() { 25 | 26 | } 27 | } 28 | class Fish0 extends Animal0 implements Swimmer0{ 29 | public void swim(){ 30 | 31 | } 32 | } 33 | 34 | 35 | 36 | 37 | 38 | 39 | public class HybridInheritanceExample1 { 40 | 41 | public static void main(String[] arg){ 42 | 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Day_16_Inheritance/MultiLevel_Inheritance/MultiLevelInheritanceExample.java: -------------------------------------------------------------------------------- 1 | package Day_16_Inheritance.MultiLevel_Inheritance; 2 | 3 | // Superclass 4 | class Animal { 5 | void eat() { 6 | System.out.println("The animal is eating."); 7 | } 8 | } 9 | 10 | // Subclass inheriting from Animal 11 | class Dog extends Animal { 12 | void bark() { 13 | System.out.println("The dog is barking."); 14 | } 15 | } 16 | 17 | // Subclass inheriting from Dog 18 | class GermanShepherd extends Dog { 19 | void guard() { 20 | System.out.println("The German Shepherd is guarding."); 21 | } 22 | } 23 | 24 | public class MultiLevelInheritanceExample { 25 | public static void main(String[] args) { 26 | GermanShepherd myDog = new GermanShepherd(); 27 | 28 | // The GermanShepherd class inherits the eat() and bark() methods 29 | myDog.eat(); 30 | myDog.bark(); 31 | 32 | // It also has its own method guard() 33 | myDog.guard(); 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /Day_16_Inheritance/MultipleInheritance/CWP_MultipleExample.java: -------------------------------------------------------------------------------- 1 | package Day_16_Inheritance.MultipleInheritance; 2 | 3 | 4 | class student{ 5 | void GetStudentInfo(){ 6 | System.out.println("Student : Mumtaz"); 7 | System.out.println("Student : Joy"); 8 | } 9 | } 10 | class books extends student{ 11 | void GetBooks(){ 12 | System.out.println("JAVA Development"); 13 | System.out.println("Python development"); 14 | } 15 | } 16 | class Subject extends student{ 17 | void GetSubejct(){ 18 | System.out.println("Inheritance...."); 19 | System.out.println("Numpy...."); 20 | } 21 | } 22 | 23 | 24 | public class CWP_MultipleExample { 25 | public static void main(String[] args) { 26 | 27 | 28 | books book = new books(); 29 | book.GetBooks(); 30 | book.GetStudentInfo(); 31 | 32 | Subject subjects = new Subject(); 33 | subjects.GetSubejct(); 34 | subjects.GetStudentInfo(); 35 | 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Day_16_Inheritance/MultipleInheritance/Example/Schools.java: -------------------------------------------------------------------------------- 1 | package Day_16_Inheritance.MultipleInheritance.Example; 2 | 3 | interface Teacher{ 4 | 5 | public void getTeacherName(); 6 | 7 | } 8 | class Notes{ 9 | 10 | void getNotes(){ 11 | System.out.println("Java Development Course Notes.."); 12 | } 13 | 14 | } 15 | class Students extends Notes implements Teacher{ 16 | 17 | public void getTeacherName(){ 18 | System.out.println("Your Teacher Name Neha"); 19 | } 20 | 21 | } 22 | 23 | 24 | public class Schools { 25 | public static void main(String[] args) { 26 | Students students = new Students(); 27 | students.getNotes(); 28 | students.getTeacherName(); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Day_16_Inheritance/MultipleInheritance/MultipleInheritanceExample.java: -------------------------------------------------------------------------------- 1 | package Day_16_Inheritance.MultipleInheritance; 2 | 3 | // First interface 4 | interface Swimmer { 5 | void swim(); 6 | } 7 | 8 | // Second interface 9 | interface Flyer { 10 | void fly(); 11 | } 12 | 13 | // Class implementing both interfaces 14 | class Bird implements Swimmer, Flyer { 15 | @Override 16 | public void swim() { 17 | System.out.println("The bird is swimming."); 18 | } 19 | 20 | @Override 21 | public void fly() { 22 | System.out.println("The bird is flying."); 23 | } 24 | 25 | void sing() { 26 | System.out.println("The bird is singing."); 27 | } 28 | } 29 | 30 | public class MultipleInheritanceExample { 31 | public static void main(String[] args) { 32 | Bird bird = new Bird(); 33 | 34 | // Call methods from both interfaces 35 | bird.swim(); 36 | bird.fly(); 37 | 38 | // Call a method specific to the Bird class 39 | bird.sing(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Day_16_Inheritance/Singleinheritance/Example/CWPShop.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_16_Inheritance/Singleinheritance/Example/CWPShop.class -------------------------------------------------------------------------------- /Day_16_Inheritance/Singleinheritance/Example/CWPShop.java: -------------------------------------------------------------------------------- 1 | 2 | class CWPShop extends CodingBooks{ 3 | 4 | void getShopInfo(){ 5 | System.out.println("Shop Name : CWP - Books Store"); 6 | System.out.println("Shop Address : Andheri West Near Bank"); 7 | System.out.println("Shop Mobile No. : 9875544662"); 8 | } 9 | 10 | } -------------------------------------------------------------------------------- /Day_16_Inheritance/Singleinheritance/Example/CodingBooks.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_16_Inheritance/Singleinheritance/Example/CodingBooks.class -------------------------------------------------------------------------------- /Day_16_Inheritance/Singleinheritance/Example/CodingBooks.java: -------------------------------------------------------------------------------- 1 | class CodingBooks{ 2 | 3 | void getBooksInfo(){ 4 | System.out.println("Books 1 : JAVA Developments"); 5 | System.out.println("Books 2 : IOS Developments"); 6 | System.out.println("Books 3 : Web Developments"); 7 | } 8 | 9 | } -------------------------------------------------------------------------------- /Day_16_Inheritance/Singleinheritance/Example/MainShop.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_16_Inheritance/Singleinheritance/Example/MainShop.class -------------------------------------------------------------------------------- /Day_16_Inheritance/Singleinheritance/Example/MainShop.java: -------------------------------------------------------------------------------- 1 | class MainShop{ 2 | public static void main(String[] args) { 3 | 4 | CWPShop cwpShop = new CWPShop(); 5 | cwpShop.getShopInfo(); 6 | cwpShop.getBooksInfo(); 7 | 8 | } 9 | } -------------------------------------------------------------------------------- /Day_16_Inheritance/Singleinheritance/PrintBill.java: -------------------------------------------------------------------------------- 1 | package Day_16_Inheritance.Singleinheritance; 2 | 3 | class tax{ 4 | 5 | void gst(){ 6 | System.out.println("18 %"); 7 | } 8 | } 9 | class product extends tax{ 10 | void ProductPrice(){ 11 | System.out.println("300/-"); 12 | } 13 | } 14 | 15 | class PrintBill{ 16 | 17 | public static void main(String[] args) { 18 | product p = new product(); 19 | p.ProductPrice();; 20 | p.gst(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Day_16_Inheritance/Singleinheritance/SingleInheritanceExample.java: -------------------------------------------------------------------------------- 1 | package Day_16_Inheritance.Singleinheritance; 2 | // Superclass 3 | class Animal { 4 | void eat() { 5 | System.out.println("The animal is eating."); 6 | } 7 | } 8 | 9 | // Subclass inheriting from Animal 10 | class Dog extends Animal { 11 | void bark() { 12 | System.out.println("The dog is barking."); 13 | } 14 | } 15 | 16 | public class SingleInheritanceExample { 17 | public static void main(String[] args) { 18 | Dog myDog = new Dog(); 19 | 20 | // The Dog class inherits the eat() method from its superclass (Animal) 21 | myDog.eat(); 22 | 23 | // It also has its own method bark() 24 | myDog.bark(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Day_17_MethodOverriding/MethodOverriding/Client.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_17_MethodOverriding/MethodOverriding/Client.class -------------------------------------------------------------------------------- /Day_17_MethodOverriding/MethodOverriding/Client.java: -------------------------------------------------------------------------------- 1 | package Day_17_MethodOverriding.MethodOverriding; 2 | 3 | public class Client { 4 | 5 | void info(){ 6 | System.out.println("Client Name : Kavita ji"); 7 | } 8 | 9 | void info(int age){ 10 | System.out.println("Client Age : "+age); 11 | } 12 | void info(float height){ 13 | System.out.println("Client Height : "+height); 14 | } 15 | void info(String Address){ 16 | System.out.println("Client Address : "+Address); 17 | } 18 | 19 | public static void main(String[] arg){ 20 | Client obj = new Client(); 21 | obj.info(); 22 | obj.info(42); 23 | obj.info(4.6f); 24 | obj.info("Barivali"); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Day_17_MethodOverriding/MethodOverriding/MethodOverridingExample.java: -------------------------------------------------------------------------------- 1 | package Day_17_MethodOverriding.MethodOverriding; 2 | 3 | class Animal { 4 | void makeSound() { 5 | System.out.println("Animal makes a sound"); 6 | } 7 | } 8 | 9 | class Dog extends Animal { 10 | @Override 11 | void makeSound() { 12 | System.out.println("Dog barks"); 13 | } 14 | } 15 | 16 | class Cat extends Animal { 17 | @Override 18 | void makeSound() { 19 | System.out.println("Cat meows"); 20 | } 21 | } 22 | 23 | public class MethodOverridingExample { 24 | public static void main(String[] args) { 25 | Animal animal1 = new Dog(); 26 | Animal animal2 = new Cat(); 27 | 28 | animal1.makeSound(); // Calls the makeSound method of Dog 29 | animal2.makeSound(); // Calls the makeSound method of Cat 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Day_18_SuperKeyword/SuperKeyWord/StudyBooks.java: -------------------------------------------------------------------------------- 1 | 2 | class JavaBook{ 3 | 4 | void getinfo(){ 5 | System.out.println("Book name is CWP - JAVA developments"); 6 | } 7 | 8 | } 9 | 10 | class TopicJava extends JavaBook{ 11 | void getinfo(){ 12 | super.getinfo(); 13 | System.out.println("Topic 1 - Intro"); 14 | System.out.println("Topic 2 - Variable"); 15 | System.out.println("Topic 3 - Operators"); 16 | } 17 | } 18 | 19 | 20 | public class StudyBooks { 21 | public static void main(String[] args) { 22 | TopicJava tj = new TopicJava(); 23 | tj.getinfo(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Day_18_SuperKeyword/SuperKeyWord/SuperKeywordExample.java: -------------------------------------------------------------------------------- 1 | 2 | class Animal { 3 | String name; 4 | 5 | Animal(String name) { 6 | this.name = name; 7 | } 8 | 9 | void eat() { 10 | System.out.println(name + " is eating."); 11 | } 12 | } 13 | 14 | class Dog extends Animal { 15 | String breed; 16 | 17 | Dog(String name, String breed) { 18 | super(name); // Calling the constructor of the superclass 'Animal' 19 | this.breed = breed; 20 | } 21 | 22 | void bark() { 23 | System.out.println(name + " is barking."); 24 | } 25 | 26 | void displayInfo() { 27 | super.eat(); // Calling the 'eat' method of the superclass 28 | System.out.println(name + " is a " + breed); 29 | } 30 | } 31 | 32 | public class SuperKeywordExample { 33 | public static void main(String[] args) { 34 | Dog myDog = new Dog("Buddy", "Golden Retriever"); 35 | 36 | myDog.displayInfo(); // Calls 'eat' using 'super' and displays information 37 | myDog.bark(); // Calls 'bark' method of the Dog class 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Day_19_AbstractClassMethod/AbstractClassMethod/AbstractClassExample.java: -------------------------------------------------------------------------------- 1 | package Day_19_AbstractClassMethod.AbstractClassMethod; 2 | 3 | abstract class p4n { 4 | // Abstract method without implementation 5 | abstract void printInfo(); 6 | 7 | // Regular (concrete) method with implementation 8 | void displayMessage() { 9 | System.out.println("This is a message from p4n."); 10 | } 11 | } 12 | 13 | class ConcreteSubclass extends p4n { 14 | // Implementation of the abstract method 15 | @Override 16 | void printInfo() { 17 | System.out.println("This is an implementation of printInfo() in ConcreteSubclass."); 18 | } 19 | } 20 | 21 | public class AbstractClassExample { 22 | public static void main(String[] args) { 23 | ConcreteSubclass obj = new ConcreteSubclass(); 24 | 25 | // Call the abstract method and the concrete method 26 | obj.printInfo(); 27 | obj.displayMessage(); 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Day_20_Interfaces/JavaInterface/InnerOrderInterface.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_20_Interfaces/JavaInterface/InnerOrderInterface.class -------------------------------------------------------------------------------- /Day_20_Interfaces/JavaInterface/InterfaceExample.java: -------------------------------------------------------------------------------- 1 | 2 | // Define an interface named 'Drawable' 3 | interface Drawable { 4 | void draw(); // Abstract method 5 | } 6 | 7 | // Implement the 'Drawable' interface in a class 'Circle' 8 | class Circle implements Drawable { 9 | private int radius; 10 | 11 | public Circle(int radius) { 12 | this.radius = radius; 13 | } 14 | 15 | @Override 16 | public void draw() { 17 | System.out.println("Drawing a circle with radius " + radius); 18 | } 19 | } 20 | 21 | // Implement the 'Drawable' interface in a class 'Rectangle' 22 | class Rectangle implements Drawable { 23 | private int width; 24 | private int height; 25 | 26 | public Rectangle(int width, int height) { 27 | this.width = width; 28 | this.height = height; 29 | } 30 | 31 | @Override 32 | public void draw() { 33 | System.out.println("Drawing a rectangle with width " + width + " and height " + height); 34 | } 35 | } 36 | 37 | public class InterfaceExample { 38 | public static void main(String[] args) { 39 | Drawable circle = new Circle(5); 40 | Drawable rectangle = new Rectangle(8, 6); 41 | 42 | // Polymorphic method invocation 43 | circle.draw(); // Calls draw() in Circle class 44 | rectangle.draw(); // Calls draw() in Rectangle class 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /Day_20_Interfaces/JavaInterface/OrderInterface.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_20_Interfaces/JavaInterface/OrderInterface.class -------------------------------------------------------------------------------- /Day_20_Interfaces/JavaInterface/OrderInterface.java: -------------------------------------------------------------------------------- 1 | /** 2 | * InnerOrderInterface 3 | */ 4 | interface InnerOrderInterface{ 5 | 6 | public void getOrderID(); //methods... 7 | public void getQTid(); //methods... 8 | 9 | } 10 | 11 | public class OrderInterface implements InnerOrderInterface{ 12 | 13 | public void getOrderID(){ 14 | System.out.println("ORDER ID 10001"); 15 | } 16 | 17 | public void getQTid(){ 18 | System.out.println("QT ID A0099"); 19 | } 20 | public static void main(String[] agr){ 21 | OrderInterface oi = new OrderInterface(); 22 | oi.getOrderID(); 23 | oi.getQTid(); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Day_21_Polymorphism/JavaPolymorphism/CustomerData.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_21_Polymorphism/JavaPolymorphism/CustomerData.class -------------------------------------------------------------------------------- /Day_21_Polymorphism/JavaPolymorphism/CustomerData.java: -------------------------------------------------------------------------------- 1 | public class CustomerData { 2 | 3 | // Constructor 4 | CustomerData(){ 5 | System.out.println("Customer Order ID : A001"); 6 | } 7 | CustomerData(int id){ 8 | System.out.println("Customer QT ID : "+id); 9 | } 10 | // methods 11 | void GetInfo(){ 12 | System.out.println("Welcome To p4n"); 13 | } 14 | void GetInfo(String name){ 15 | System.out.println("Customer Name : "+name); 16 | } 17 | void GetInfo(int age){ 18 | System.out.println("Customer Age : "+age); 19 | } 20 | void GetInfo(String Address, long mobile){ 21 | System.out.println("Customer Address : "+Address); 22 | System.out.println("Customer Mobile : "+mobile); 23 | } 24 | 25 | public static void main(String[] arg){ 26 | CustomerData cd = new CustomerData(); 27 | CustomerData cd1 = new CustomerData(4004); 28 | cd.GetInfo(); 29 | cd.GetInfo("Esha"); 30 | cd.GetInfo(22); 31 | cd.GetInfo("Andheri",7894561231l); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Day_21_Polymorphism/JavaPolymorphism/Employee.java: -------------------------------------------------------------------------------- 1 | package Day_21_Polymorphism.JavaPolymorphism; 2 | 3 | public class Employee { 4 | 5 | public Employee(){ 6 | System.out.println("Employee Company Name Codes With Pankaj"); 7 | } 8 | public Employee(String address){ 9 | System.out.println("Complay Address : "+address); 10 | } 11 | public Employee(long mobile){ 12 | System.out.println("Company Mobile Number : "+mobile); 13 | } 14 | 15 | void info(){ 16 | System.out.println("Employee Info - IT Development"); 17 | } 18 | 19 | void info(String name){ 20 | System.out.println("Employee Name : "+name); 21 | } 22 | 23 | void info(String dept,int DevelopmentID){ 24 | System.out.println("Employee DEPT : "+dept); 25 | System.out.println("Employee Development ID "+DevelopmentID); 26 | } 27 | 28 | public static void main(String[] args) { 29 | Employee emp = new Employee(); 30 | Employee emp1 = new Employee("Andheri West ..."); 31 | Employee emp2 = new Employee(787874512121l); 32 | emp.info(); 33 | emp.info("Neha"); 34 | emp.info("IOS Development",101); 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /Day_21_Polymorphism/JavaPolymorphism/Food.java: -------------------------------------------------------------------------------- 1 | package codeswithpankaj.com.Polymorphism; 2 | 3 | public class Food { 4 | // Overloading 5 | void info(){ 6 | System.out.println("Food Name - 1 Samosa"); 7 | System.out.println("Food Name - 2 kachori"); 8 | System.out.println("Food Name - 3 fafda"); 9 | } 10 | void info(int price){ 11 | System.out.println("Food Price - "+price); 12 | } 13 | 14 | void info(int price , int gst){ 15 | System.out.println("MRP : - "+(price+gst)); 16 | } 17 | 18 | public static void main(String[] args) { 19 | Food food = new Food(); 20 | food.info(); 21 | food.info(1200); 22 | food.info(1200,18); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Day_21_Polymorphism/JavaPolymorphism/PolymorphismExample.java: -------------------------------------------------------------------------------- 1 | package Day_21_Polymorphism.JavaPolymorphism; 2 | 3 | class Animal { 4 | void makeSound() { 5 | System.out.println("Animal makes a sound."); 6 | } 7 | } 8 | 9 | class Dog extends Animal { 10 | @Override 11 | void makeSound() { 12 | System.out.println("Dog barks."); 13 | } 14 | } 15 | 16 | class Cat extends Animal { 17 | @Override 18 | void makeSound() { 19 | System.out.println("Cat meows."); 20 | } 21 | } 22 | 23 | public class PolymorphismExample { 24 | public static void main(String[] args) { 25 | Animal myAnimal1 = new Dog(); // Polymorphic reference to a Dog object 26 | Animal myAnimal2 = new Cat(); // Polymorphic reference to a Cat object 27 | 28 | myAnimal1.makeSound(); // Calls the 'makeSound' method of Dog 29 | myAnimal2.makeSound(); // Calls the 'makeSound' method of Cat 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /Day_22_Encapsulation/Encapsulation/Clients.java: -------------------------------------------------------------------------------- 1 | package Day_22_Encapsulation.Encapsulation; 2 | class Clients{ 3 | 4 | String name; 5 | int age; 6 | Clients(String name, int age){ 7 | this.name = name; 8 | this.age = age; 9 | } 10 | 11 | void setname(String name){ 12 | this.name = name; 13 | } 14 | void setage(int age){ 15 | this.age = age; 16 | } 17 | 18 | String getname(){ 19 | return name; 20 | } 21 | 22 | int getage(){ 23 | return age; 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /Day_22_Encapsulation/Encapsulation/Customers.java: -------------------------------------------------------------------------------- 1 | 2 | class Customers{ 3 | 4 | String name; 5 | int age; 6 | float height; 7 | 8 | public Customers(String name, int age, float height){ 9 | this.name = name; 10 | this.age = age; 11 | this.height = height; 12 | } 13 | 14 | void setname(String name){ 15 | this.name = name; 16 | } 17 | 18 | void setage(int age){ 19 | this.age = age; 20 | } 21 | 22 | void setheight(float height){ 23 | this.height = height; 24 | } 25 | 26 | String getname(){ 27 | return name; 28 | } 29 | 30 | int getage(){ 31 | return age; 32 | } 33 | float getheight(){ 34 | return height; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /Day_22_Encapsulation/Encapsulation/CustomersMain.java: -------------------------------------------------------------------------------- 1 | public class CustomersMain { 2 | public static void main(String[] args) { 3 | 4 | Customers obj = new Customers("esha",22,5.6f); 5 | System.out.println("Name : "+obj.getname()); 6 | System.out.println("Age : "+obj.getage()); 7 | System.out.println("Height : "+obj.getheight()); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Day_22_Encapsulation/Encapsulation/EncapsulationExample.java: -------------------------------------------------------------------------------- 1 | package Day_22_Encapsulation.Encapsulation; 2 | 3 | public class EncapsulationExample { 4 | public static void main(String[] args) { 5 | // Create a Student object 6 | Student student = new Student("Alice", 20); 7 | 8 | // Access and modify the student's information using getter and setter methods 9 | System.out.println("Name: " + student.getName()); 10 | System.out.println("Age: " + student.getAge()); 11 | 12 | student.setName("Bob"); 13 | student.setAge(25); 14 | 15 | System.out.println("Updated Name: " + student.getName()); 16 | System.out.println("Updated Age: " + student.getAge()); 17 | 18 | // Attempt to set an invalid age 19 | student.setAge(-5); 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Day_22_Encapsulation/Encapsulation/MainClient.java: -------------------------------------------------------------------------------- 1 | package Day_22_Encapsulation.Encapsulation; 2 | class MainClient{ 3 | 4 | public static void main(String[] args) { 5 | Clients clients = new Clients("neha",21); 6 | clients.setname("Rohit"); 7 | String name_m = clients.getname(); 8 | int age_m = clients.getage(); 9 | System.out.println("My Name is : "+name_m); 10 | System.out.println("My Age is : "+age_m); 11 | } 12 | 13 | } -------------------------------------------------------------------------------- /Day_22_Encapsulation/Encapsulation/P4NBooks.java: -------------------------------------------------------------------------------- 1 | package Day_22_Encapsulation.Encapsulation; 2 | 3 | 4 | class DBook{ 5 | 6 | int price; 7 | int qt; 8 | String bookName; 9 | 10 | public DBook(int price, int qt, String bookName) { 11 | this.price = price; 12 | this.qt = qt; 13 | this.bookName = bookName; 14 | } 15 | 16 | public int getPrice() { 17 | return price; 18 | } 19 | 20 | public int getQt() { 21 | return qt; 22 | } 23 | 24 | public String getBookName() { 25 | return bookName; 26 | } 27 | 28 | public void setPrice(int price) { 29 | this.price = price; 30 | } 31 | 32 | public void setQt(int qt) { 33 | this.qt = qt; 34 | } 35 | 36 | public void setBookName(String bookName) { 37 | this.bookName = bookName; 38 | } 39 | } 40 | 41 | 42 | public class P4NBooks { 43 | 44 | 45 | public static void main(String[] args) { 46 | 47 | DBook db = new DBook(450, 12, "codeswithpankaj"); 48 | 49 | System.out.println("Book Name : "+db.getBookName()); 50 | int total_price = db.getPrice()*db.getQt(); 51 | System.out.println("Total Price Name : "+total_price); 52 | 53 | db.setPrice(750); 54 | db.setQt(56); 55 | System.out.println("New price : - "+db.getPrice()); 56 | int total_price1 = db.getPrice()*db.getQt(); 57 | System.out.println("Total Price Name : "+total_price1); 58 | 59 | 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /Day_22_Encapsulation/Encapsulation/Student.java: -------------------------------------------------------------------------------- 1 | package Day_22_Encapsulation.Encapsulation; 2 | 3 | public class Student { 4 | private String name; // Private data member 5 | private int age; // Private data member 6 | 7 | // Constructor to initialize name and age 8 | public Student(String name, int age) { 9 | this.name = name; 10 | this.age = age; 11 | } 12 | 13 | // Getter method to retrieve the name 14 | public String getName() { 15 | return name; 16 | } 17 | 18 | // Setter method to modify the name 19 | public void setName(String name) { 20 | this.name = name; 21 | } 22 | 23 | // Getter method to retrieve the age 24 | public int getAge() { 25 | return age; 26 | } 27 | 28 | // Setter method to modify the age with validation 29 | public void setAge(int age) { 30 | if (age >= 0) { 31 | this.age = age; 32 | } else { 33 | System.out.println("Invalid age. Age cannot be negative."); 34 | } 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /Day_22_Encapsulation/Encapsulation/shop.java: -------------------------------------------------------------------------------- 1 | 2 | class customers{ 3 | int order; 4 | String name; 5 | 6 | void setOrder(int order){ 7 | this.order = order; 8 | } 9 | void setName(String name){ 10 | this.name = name; 11 | } 12 | int getOrder(){ 13 | return order; 14 | } 15 | String getName(){ 16 | return name; 17 | } 18 | } 19 | class HelloWorld { 20 | public static void main(String[] args) { 21 | 22 | customers cut = new customers(); 23 | cut.setName("kavita ji"); 24 | cut.setOrder(500); 25 | 26 | System.out.println("\n Customer Order : "+cut.getOrder()); 27 | System.out.println(" \n Customer Name : "+cut.getName()); 28 | 29 | cut.setName("mumtaz ji"); 30 | cut.setOrder(960); 31 | 32 | System.out.println("\n Customer Order : "+cut.getOrder()); 33 | System.out.println(" \n Customer Name : "+cut.getName()); 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Day_24_MathUtility/JavaStaticClass/MathUtility.java: -------------------------------------------------------------------------------- 1 | package Day_24_MathUtility.JavaStaticClass; 2 | 3 | public class MathUtility { 4 | // Static constant (final) field 5 | public static final double PI = 3.14159265359; 6 | 7 | // Static method to calculate the square of a number 8 | public static double square(double number) { 9 | return number * number; 10 | } 11 | 12 | // Static method to calculate the factorial of a number 13 | public static int factorial(int n) { 14 | if (n == 0) { 15 | return 1; 16 | } 17 | return n * factorial(n - 1); 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Day_24_MathUtility/JavaStaticClass/StaticClassExample.java: -------------------------------------------------------------------------------- 1 | package Day_24_MathUtility.JavaStaticClass; 2 | 3 | public class StaticClassExample { 4 | public static void main(String[] args) { 5 | double radius = 5.0; 6 | double area = MathUtility.PI * MathUtility.square(radius); 7 | System.out.println("Area of a circle with radius " + radius + " is " + area); 8 | 9 | int number = 5; 10 | int factorial = MathUtility.factorial(number); 11 | System.out.println("Factorial of " + number + " is " + factorial); 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /Day_26_AnonymousClass/JavaAnonymousClass/AnonymousClassExample.java: -------------------------------------------------------------------------------- 1 | public class AnonymousClassExample { 2 | public static void main(String[] args) { 3 | // Creating an anonymous class that implements a simple interface 4 | MyInterface myInterface = new MyInterface() { 5 | @Override 6 | public void myMethod() { 7 | System.out.println("Anonymous class implementing MyInterface."); 8 | } 9 | }; 10 | 11 | // Calling the method of the anonymous class 12 | myInterface.myMethod(); 13 | } 14 | } 15 | 16 | // A simple interface 17 | interface MyInterface { 18 | void myMethod(); 19 | } 20 | -------------------------------------------------------------------------------- /Day_26_AnonymousClass/JavaAnonymousClass/AnonymousClassExample1.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | public class AnonymousClassExample1 { 4 | public static void main(String[] args) { 5 | // Creating and starting a new thread using an anonymous class 6 | Thread thread = new Thread(new Runnable() { 7 | @Override 8 | public void run() { 9 | for (int i = 1; i <= 5; i++) { 10 | System.out.println("Anonymous Thread: Count " + i); 11 | try { 12 | Thread.sleep(1000); // Sleep for 1 second 13 | } catch (InterruptedException e) { 14 | e.printStackTrace(); 15 | } 16 | } 17 | } 18 | }); 19 | 20 | thread.start(); // Start the thread 21 | 22 | // Main thread 23 | for (int i = 1; i <= 5; i++) { 24 | System.out.println("Main Thread: Count " + i); 25 | try { 26 | Thread.sleep(1000); // Sleep for 1 second 27 | } catch (InterruptedException e) { 28 | e.printStackTrace(); 29 | } 30 | } 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Day_26_AnonymousClass/JavaAnonymousClass/AnonymousClassExample2.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | import java.awt.event.ActionEvent; 6 | import java.awt.event.ActionListener; 7 | 8 | public class AnonymousClassExample2 { 9 | public static void main(String[] args) { 10 | // Create a simple JFrame with a button 11 | JFrame frame = new JFrame("Anonymous Class Example"); 12 | JButton button = new JButton("Click Me"); 13 | frame.setLayout(new FlowLayout()); 14 | frame.add(button); 15 | frame.setSize(300, 100); 16 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 17 | frame.setVisible(true); 18 | 19 | // Add an ActionListener using an anonymous class 20 | button.addActionListener(new ActionListener() { 21 | @Override 22 | public void actionPerformed(ActionEvent e) { 23 | JOptionPane.showMessageDialog(null, "Button clicked!", "Message", JOptionPane.INFORMATION_MESSAGE); 24 | } 25 | }); 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Day_27_Singleton/JavaSingleton/Singleton.java: -------------------------------------------------------------------------------- 1 | package Day_27_Singleton.JavaSingleton; 2 | 3 | public class Singleton { 4 | // Private static instance variable 5 | private static Singleton instance; 6 | 7 | // Private constructor to prevent external instantiation 8 | private Singleton() { 9 | // Initialization code, if needed 10 | } 11 | 12 | // Public static method to get the Singleton instance 13 | public static Singleton getInstance() { 14 | if (instance == null) { 15 | instance = new Singleton(); 16 | } 17 | return instance; 18 | } 19 | 20 | // Other methods and attributes of the Singleton class 21 | public void showMessage() { 22 | System.out.println("Hello, I am a Singleton!"); 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /Day_27_Singleton/JavaSingleton/SingletonExample.java: -------------------------------------------------------------------------------- 1 | package Day_27_Singleton.JavaSingleton; 2 | 3 | public class SingletonExample { 4 | public static void main(String[] args) { 5 | // Get the Singleton instance 6 | Singleton singleton = Singleton.getInstance(); 7 | 8 | // Call a method on the Singleton instance 9 | singleton.showMessage(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Day_28_Enum/EnumClass/EnumConstructorExample.java: -------------------------------------------------------------------------------- 1 | enum Color { 2 | RED(255, 0, 0), 3 | GREEN(0, 255, 0), 4 | BLUE(0, 0, 255), 5 | WHITE(255, 255, 255), 6 | BLACK(0, 0, 0); 7 | 8 | private int red; 9 | private int green; 10 | private int blue; 11 | 12 | // Constructor for Color enum 13 | private Color(int red, int green, int blue) { 14 | this.red = red; 15 | this.green = green; 16 | this.blue = blue; 17 | } 18 | 19 | // Getter methods to access RGB values 20 | public int getRed() { 21 | return red; 22 | } 23 | 24 | public int getGreen() { 25 | return green; 26 | } 27 | 28 | public int getBlue() { 29 | return blue; 30 | } 31 | } 32 | 33 | public class EnumConstructorExample { 34 | public static void main(String[] args) { 35 | Color myColor = Color.RED; 36 | System.out.println("My color is RGB(" + 37 | myColor.getRed() + ", " + 38 | myColor.getGreen() + ", " + 39 | myColor.getBlue() + ")"); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Day_28_Enum/EnumClass/EnumStringExample.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | enum Day { 4 | SUNDAY("Sunday"), 5 | MONDAY("Monday"), 6 | TUESDAY("Tuesday"), 7 | WEDNESDAY("Wednesday"), 8 | THURSDAY("Thursday"), 9 | FRIDAY("Friday"), 10 | SATURDAY("Saturday"); 11 | 12 | private String displayName; 13 | 14 | private Day(String displayName) { 15 | this.displayName = displayName; 16 | } 17 | 18 | public String getDisplayName() { 19 | return displayName; 20 | } 21 | } 22 | 23 | public class EnumStringExample { 24 | public static void main(String[] args) { 25 | Day today = Day.FRIDAY; 26 | System.out.println("Today is " + today.getDisplayName()); // Output: Today is Friday 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Day_30_ExceptionHandling/ExceptionHandling/CustomExceptionExample.java: -------------------------------------------------------------------------------- 1 | // Custom Exception 2 | class CustomException extends Exception { 3 | public CustomException(String message) { 4 | super(message); 5 | } 6 | } 7 | 8 | // Main class to demonstrate the custom exception 9 | public class CustomExceptionExample { 10 | 11 | // Method that throws the custom exception 12 | public static void demonstrateCustomException(int value) throws CustomException { 13 | if (value < 0) { 14 | throw new CustomException("Negative value provided: " + value); 15 | } 16 | System.out.println("Value is: " + value); 17 | } 18 | 19 | public static void main(String[] args) { 20 | try { 21 | demonstrateCustomException(10); // This will print the value 22 | demonstrateCustomException(-5); // This will throw the custom exception 23 | } catch (CustomException e) { 24 | System.out.println("Caught CustomException: " + e.getMessage()); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Day_30_ExceptionHandling/ExceptionHandling/Example1.java: -------------------------------------------------------------------------------- 1 | package codeswithpankaj.com.ExceptionHandling; 2 | import java.util.InputMismatchException; 3 | import java.util.Scanner; 4 | public class Example1 { 5 | public static void main(String[] args) { 6 | try { 7 | Scanner sc = new Scanner(System.in); 8 | int age; 9 | int height; 10 | System.out.println("enter age"); 11 | age = sc.nextInt(); 12 | System.out.println("enter height"); 13 | height = sc.nextInt(); 14 | 15 | System.out.println("age : "+age); 16 | System.out.println("height : "+height); 17 | int bmi = age/height; 18 | System.out.println("BMI : "+bmi); 19 | }catch (InputMismatchException e){ 20 | System.out.println("Enter only number..."); 21 | }catch (ArithmeticException e){ 22 | System.out.println("plz do not enter zero..."); 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Day_30_ExceptionHandling/ExceptionHandling/Example2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_30_ExceptionHandling/ExceptionHandling/Example2.class -------------------------------------------------------------------------------- /Day_30_ExceptionHandling/ExceptionHandling/Example2.java: -------------------------------------------------------------------------------- 1 | import java.util.InputMismatchException; 2 | import java.util.Scanner; 3 | class Example2{ 4 | public static void main(String[] args) { 5 | try{ 6 | Scanner sc = new Scanner(System.in); 7 | System.out.println("Enter Your Name : "); 8 | String Name = sc.next(); 9 | System.out.println("Enter Your Age : "); 10 | int age = sc.nextInt(); 11 | System.out.println("Enter Your Height : "); 12 | int height = sc.nextInt(); 13 | 14 | System.out.println("Your Name : "+Name); 15 | System.out.println("Your Age : "+age); 16 | int BMI = age/height; 17 | System.out.println(" Your BMI = "+BMI); 18 | }catch(InputMismatchException e){ 19 | System.out.println("Enter Only Number ... "); 20 | }catch(ArithmeticException e){ 21 | System.out.println("do not enter : "); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Day_30_ExceptionHandling/ExceptionHandling/FinallyExample.java: -------------------------------------------------------------------------------- 1 | public class FinallyExample { 2 | 3 | public static void main(String[] args) { 4 | try { 5 | int result = 10 / 0; // This will throw an ArithmeticException 6 | } catch (ArithmeticException e) { 7 | System.out.println("Caught ArithmeticException: " + e.getMessage()); 8 | } finally { 9 | System.out.println("This block always executes, regardless of exception."); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Day_30_ExceptionHandling/ExceptionHandling/ThrowThrowsExample.java: -------------------------------------------------------------------------------- 1 | // Custom Exception 2 | class CustomException extends Exception { 3 | public CustomException(String message) { 4 | super(message); 5 | } 6 | } 7 | 8 | public class ThrowThrowsExample { 9 | 10 | // Method that throws the custom exception 11 | public static void riskyMethod(int value) throws CustomException { 12 | if (value < 0) { 13 | throw new CustomException("Negative value provided: " + value); 14 | } 15 | System.out.println("Value is: " + value); 16 | } 17 | 18 | public static void main(String[] args) { 19 | try { 20 | riskyMethod(10); // This will print the value 21 | riskyMethod(-5); // This will throw the custom exception 22 | } catch (CustomException e) { 23 | System.out.println("Caught CustomException: " + e.getMessage()); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Day_31_List/List/ArrayListClass.java: -------------------------------------------------------------------------------- 1 | import java.util.List; 2 | import java.util.ArrayList; 3 | // www.codeswithpankaj.com 4 | class ArrayListClass{ 5 | 6 | public static void main(String[] args) { 7 | // Creating list using the ArrayList class 8 | // classname object = new classname(); 9 | List numbers = new ArrayList(); 10 | 11 | // Add elements to the list 12 | numbers.add(11); 13 | numbers.add(21); 14 | numbers.add(31); 15 | System.out.println("List: " + numbers); 16 | 17 | // Access element from the list 18 | int number = numbers.get(2); 19 | System.out.println("Accessed Element: " + number); 20 | 21 | // Remove element from the list 22 | int removedNumber = numbers.remove(1); 23 | System.out.println("Removed Element: " + removedNumber); 24 | } 25 | } -------------------------------------------------------------------------------- /Day_31_List/List/LinkedListClass.java: -------------------------------------------------------------------------------- 1 | import java.util.List; 2 | import java.util.LinkedList; 3 | // www.codeswithpankaj.com 4 | class LinkedListClass{ 5 | 6 | public static void main(String[] args) { 7 | // Creating list using the LinkedList class 8 | List numbers = new LinkedList<>(); 9 | 10 | // Add elements to the list 11 | numbers.add(1); 12 | numbers.add(2); 13 | numbers.add(3); 14 | System.out.println("List: " + numbers); 15 | 16 | // Access element from the list 17 | int number = numbers.get(2); 18 | System.out.println("Accessed Element: " + number); 19 | 20 | // Using the indexOf() method 21 | int index = numbers.indexOf(2); 22 | System.out.println("Position of 3 is " + index); 23 | 24 | // Remove element from the list 25 | int removedNumber = numbers.remove(1); 26 | System.out.println("Removed Element: " + removedNumber); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Day_31_List/List/ListString.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_31_List/List/ListString.class -------------------------------------------------------------------------------- /Day_31_List/List/ListString.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | /** 3 | * ListString 4 | */ 5 | public class ListString { 6 | 7 | public static void main(String[] args) { 8 | 9 | List data = new ArrayList(); 10 | 11 | // adding data into list 12 | data.add("java"); 13 | data.add("C++"); 14 | data.add("jsp"); 15 | data.add("servlet"); 16 | 17 | // get all data 18 | System.out.println("data : "+data); 19 | 20 | // access data by index 21 | System.out.println("data at index 0 : "+data.get(1)); 22 | 23 | // remove data by index 24 | data.remove(1); 25 | System.out.println("data after remove : "+data); 26 | 27 | 28 | // add all data 29 | List data2 = new ArrayList(); 30 | data2.add("python"); 31 | data2.add("java script"); 32 | 33 | data.addAll(data2); 34 | System.out.println("data after add all : "+data); 35 | 36 | // iterator() 37 | Iterator it = data.iterator(); 38 | while(it.hasNext()){ 39 | System.out.println(it.next()); 40 | } 41 | 42 | // for each 43 | 44 | for(String d : data){ 45 | System.out.println(d); 46 | } 47 | 48 | //using set()-- update data 49 | 50 | data.set(2, "ruby"); 51 | System.out.println("data after set : "+data); 52 | 53 | 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /Day_32_ArrayList/ArrayList/ArrayListToArray.java: -------------------------------------------------------------------------------- 1 | package Day_32_ArrayList.ArrayList; 2 | // www.codeswithpankaj.com 3 | import java.util.ArrayList; 4 | 5 | public class ArrayListToArray { 6 | public static void main(String[] args) { 7 | // Create an ArrayList 8 | ArrayList arrayList = new ArrayList<>(); 9 | arrayList.add("Apple"); 10 | arrayList.add("Banana"); 11 | arrayList.add("Cherry"); 12 | 13 | // Convert ArrayList to an array of the same type 14 | String[] array = arrayList.toArray(new String[arrayList.size()]); 15 | 16 | // Print the elements of the array 17 | for (String fruit : array) { 18 | System.out.println(fruit); 19 | } 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Day_32_ArrayList/ArrayList/ArrayListToString.java: -------------------------------------------------------------------------------- 1 | package Day_32_ArrayList.ArrayList; 2 | // www.codeswithpankaj.com 3 | import java.util.ArrayList; 4 | 5 | public class ArrayListToString { 6 | public static void main(String[] args) { 7 | // Create an ArrayList of strings 8 | ArrayList fruits = new ArrayList<>(); 9 | fruits.add("Apple"); 10 | fruits.add("Banana"); 11 | fruits.add("Cherry"); 12 | 13 | // Convert the ArrayList to a String with a delimiter 14 | String delimiter = ", "; // Define your desired delimiter 15 | StringBuilder sb = new StringBuilder(); 16 | for (String fruit : fruits) { 17 | sb.append(fruit).append(delimiter); 18 | } 19 | 20 | // Remove the trailing delimiter 21 | String fruitsString = sb.toString().replaceAll(delimiter + "$", ""); 22 | 23 | // Print the resulting String 24 | System.out.println("Fruits: " + fruitsString); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Day_32_ArrayList/ArrayList/ArrayListWithListInterface.java: -------------------------------------------------------------------------------- 1 | package Day_32_ArrayList.ArrayList; 2 | // www.codeswithpankaj.com 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class ArrayListWithListInterface { 7 | public static void main(String[] args) { 8 | // Create an ArrayList using the List interface 9 | List fruitsList = new ArrayList<>(); 10 | 11 | // Add elements to the ArrayList 12 | fruitsList.add("Apple"); 13 | fruitsList.add("Banana"); 14 | fruitsList.add("Cherry"); 15 | 16 | // Print the elements of the ArrayList 17 | for (String fruit : fruitsList) { 18 | System.out.println(fruit); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Day_32_ArrayList/ArrayList/ArrayToArrayList.java: -------------------------------------------------------------------------------- 1 | package Day_32_ArrayList.ArrayList; 2 | // www.codeswithpankaj.com 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | public class ArrayToArrayList { 8 | public static void main(String[] args) { 9 | // Create an array 10 | String[] fruitsArray = {"Apple", "Banana", "Cherry"}; 11 | 12 | // Convert the array to an ArrayList 13 | List fruitsList = new ArrayList<>(Arrays.asList(fruitsArray)); 14 | 15 | // Print the elements of the ArrayList 16 | for (String fruit : fruitsList) { 17 | System.out.println(fruit); 18 | } 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /Day_32_ArrayList/ArrayList/InitializeArrayList.java: -------------------------------------------------------------------------------- 1 | package Day_32_ArrayList.ArrayList; 2 | // www.codeswithpankaj.com 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | public class InitializeArrayList { 8 | public static void main(String[] args) { 9 | // Create and initialize an ArrayList in a single line 10 | ArrayList fruits = new ArrayList<>(Arrays.asList("Apple", "Banana", "Cherry")); 11 | 12 | // Print the elements of the ArrayList 13 | for (String fruit : fruits) { 14 | System.out.println(fruit); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Day_32_ArrayList/ArrayList/StringArrayListExample.java: -------------------------------------------------------------------------------- 1 | package p4n; 2 | import java.util.ArrayList; 3 | public class Array_List01 { 4 | 5 | public static void main(String[] args) { 6 | 7 | // create a object 8 | ArrayList data = new ArrayList(); 9 | 10 | // insert data in list 11 | // add() 12 | data.add("Java"); 13 | data.add("C++"); 14 | data.add("C#"); 15 | data.add("Servlet"); 16 | data.add("JSP"); 17 | data.add("Python"); 18 | 19 | System.out.println(data); 20 | // print data from array 21 | // for(String item : data){ 22 | // System.out.println(item); 23 | // } 24 | 25 | // insert element at position 2 26 | 27 | data.add(2,"Pandas"); 28 | 29 | System.out.println(data); 30 | 31 | // get the element from the arraylist 32 | 33 | System.out.println("Element from index 1 : "+data.get(1)); 34 | 35 | // change the element of the array list 36 | data.set(2, "JavaScript"); 37 | System.out.println("Modified ArrayList: " + data); 38 | 39 | // remove element from index 3 40 | String str = data.remove(3); 41 | System.out.println("Updated ArrayList: " + data); 42 | System.out.println("Removed Element: " + str); 43 | 44 | // iterate using for-each loop 45 | System.out.println("Accessing individual Course : "); 46 | 47 | for (String language : data ) { 48 | System.out.println(language); 49 | 50 | } 51 | 52 | 53 | 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /Day_34_Vector/AccessElementInVector.java: -------------------------------------------------------------------------------- 1 | package Day_34_Vector; 2 | // www.codeswithpankaj.com 3 | import java.util.Vector; 4 | 5 | public class AccessElementInVector { 6 | public static void main(String[] args) { 7 | // Create a Vector of strings 8 | Vector colors = new Vector<>(); 9 | colors.add("Red"); 10 | colors.add("Green"); 11 | colors.add("Blue"); 12 | 13 | // Access elements in the Vector by index 14 | String firstColor = colors.get(0); 15 | String secondColor = colors.get(1); 16 | String thirdColor = colors.get(2); 17 | 18 | // Print the accessed elements 19 | System.out.println("First color: " + firstColor); 20 | System.out.println("Second color: " + secondColor); 21 | System.out.println("Third color: " + thirdColor); 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /Day_34_Vector/AccessVectorElementsWithIterator.java: -------------------------------------------------------------------------------- 1 | package Day_34_Vector; 2 | // www.codeswithpankaj.com 3 | import java.util.Iterator; 4 | import java.util.Vector; 5 | 6 | public class AccessVectorElementsWithIterator { 7 | public static void main(String[] args) { 8 | // Create a Vector of integers 9 | Vector numbers = new Vector<>(); 10 | numbers.add(10); 11 | numbers.add(20); 12 | numbers.add(30); 13 | 14 | // Obtain an iterator to access Vector elements 15 | Iterator iterator = numbers.iterator(); 16 | 17 | // Use the iterator to sequentially access and print elements 18 | System.out.print("Vector elements: "); 19 | while (iterator.hasNext()) { 20 | Integer number = iterator.next(); 21 | System.out.print(number + " "); 22 | } 23 | System.out.println(); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /Day_34_Vector/AddElementAtIndexInVector.java: -------------------------------------------------------------------------------- 1 | package Day_34_Vector; 2 | // www.codeswithpankaj.com 3 | import java.util.Vector; 4 | 5 | public class AddElementAtIndexInVector { 6 | public static void main(String[] args) { 7 | // Create a Vector of strings 8 | Vector fruits = new Vector<>(); 9 | 10 | // Add elements to the Vector 11 | fruits.add("Apple"); 12 | fruits.add("Banana"); 13 | 14 | // Add an element at a specific position (index 1) 15 | fruits.add(1, "Cherry"); 16 | 17 | // Print the Vector 18 | System.out.println("Vector: " + fruits); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Day_34_Vector/AddElementToVector.java: -------------------------------------------------------------------------------- 1 | package Day_34_Vector; 2 | // www.codeswithpankaj.com 3 | import java.util.Vector; 4 | 5 | public class AddElementToVector { 6 | public static void main(String[] args) { 7 | // Create a Vector of integers 8 | Vector numbers = new Vector<>(); 9 | 10 | // Add elements to the Vector 11 | numbers.add(10); 12 | numbers.add(20); 13 | numbers.add(30); 14 | 15 | // Print the Vector 16 | System.out.println("Vector: " + numbers); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Day_34_Vector/VectorAllinOne.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_34_Vector/VectorAllinOne.class -------------------------------------------------------------------------------- /Day_34_Vector/VectorAllinOne.java: -------------------------------------------------------------------------------- 1 | // package Day_34_Vector; 2 | 3 | import java.util.Vector; 4 | 5 | class VectorAllinOne{ 6 | public static void main(String[] args) { 7 | // Create a Vector of strings 8 | 9 | Vector data = new Vector<>(); 10 | 11 | // Add elements to the Vector 12 | data.add("JAVA"); 13 | data.add("C++"); 14 | data.add("Python"); 15 | data.add("Ruby"); 16 | data.add("Go"); 17 | 18 | // Print the Vector 19 | System.out.println("Data : "+data); 20 | 21 | // Add all elements of vector2 to vector1 22 | 23 | Vector data1 = new Vector<>(); 24 | data1.add("Core JAVA"); 25 | data1.add("Advance JAVA"); 26 | 27 | data.addAll(data1); 28 | 29 | System.out.println("New Vector : "+data); 30 | 31 | // Access elements in the Vector by index 32 | 33 | // System.out.println("Access data item : "+data.get(2)); 34 | 35 | // Change an element in the Vector 36 | 37 | data.set(3, "Swift"); 38 | System.out.println("Update Vector Data : "+data); 39 | 40 | // Print the size of the Vector 41 | System.out.println("Size of Vector Data : "+data.size()); 42 | 43 | // print using loop 44 | 45 | for (String item : data) { 46 | System.out.println("Data = : "+item); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /Day_34_Vector/VectorContainsExample.java: -------------------------------------------------------------------------------- 1 | package Day_34_Vector; 2 | // www.codeswithpankaj.com 3 | import java.util.Vector; 4 | 5 | public class VectorContainsExample { 6 | public static void main(String[] args) { 7 | // Create a Vector of integers 8 | Vector numbers = new Vector<>(); 9 | numbers.add(10); 10 | numbers.add(20); 11 | numbers.add(30); 12 | 13 | // Check if the Vector contains a specific element 14 | boolean containsTwenty = numbers.contains(20); 15 | 16 | // Print the result 17 | System.out.println("Vector contains 20: " + containsTwenty); 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Day_34_Vector/VectorExample.java: -------------------------------------------------------------------------------- 1 | package Day_34_Vector; 2 | // www.codeswithpankaj.com 3 | import java.util.Vector; 4 | 5 | public class VectorExample { 6 | public static void main(String[] args) { 7 | // Create a Vector of strings 8 | Vector names = new Vector<>(); 9 | 10 | // Add elements to the Vector 11 | names.add("Alice"); 12 | names.add("Bob"); 13 | names.add("Charlie"); 14 | 15 | // Access elements in the Vector 16 | String firstPerson = names.get(0); 17 | System.out.println("First person: " + firstPerson); 18 | 19 | // Iterating over the Vector using a for-each loop 20 | System.out.print("Names: "); 21 | for (String name : names) { 22 | System.out.print(name + " "); 23 | } 24 | System.out.println(); 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /Day_34_Vector/VectorSetExample.java: -------------------------------------------------------------------------------- 1 | package Day_34_Vector; 2 | // www.codeswithpankaj.com 3 | import java.util.Vector; 4 | 5 | public class VectorSetExample { 6 | public static void main(String[] args) { 7 | // Create a Vector of integers 8 | Vector numbers = new Vector<>(); 9 | numbers.add(10); 10 | numbers.add(20); 11 | numbers.add(30); 12 | 13 | // Change an element in the Vector 14 | numbers.set(1, 25); 15 | 16 | // Print the updated Vector 17 | System.out.println("Updated Vector: " + numbers); 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Day_34_Vector/VectorSizeExample.java: -------------------------------------------------------------------------------- 1 | package Day_34_Vector; 2 | // www.codeswithpankaj.com 3 | import java.util.Vector; 4 | 5 | public class VectorSizeExample { 6 | public static void main(String[] args) { 7 | // Create a Vector of strings 8 | Vector fruits = new Vector<>(); 9 | fruits.add("Apple"); 10 | fruits.add("Banana"); 11 | fruits.add("Cherry"); 12 | 13 | // Get the size of the Vector 14 | int size = fruits.size(); 15 | 16 | // Print the size of the Vector 17 | System.out.println("Size of the Vector: " + size); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Day_34_Vector/VectorToArrayExample.java: -------------------------------------------------------------------------------- 1 | package Day_34_Vector; 2 | // www.codeswithpankaj.com 3 | import java.util.Vector; 4 | 5 | public class VectorToArrayExample { 6 | public static void main(String[] args) { 7 | // Create a Vector of integers 8 | Vector numbers = new Vector<>(); 9 | numbers.add(10); 10 | numbers.add(20); 11 | numbers.add(30); 12 | 13 | // Convert the Vector to an array 14 | Integer[] numbersArray = numbers.toArray(new Integer[numbers.size()]); 15 | 16 | // Print the array 17 | System.out.print("Array: "); 18 | for (Integer number : numbersArray) { 19 | System.out.print(number + " "); 20 | } 21 | System.out.println(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Day_34_Vector/VectorToStringExample.java: -------------------------------------------------------------------------------- 1 | package Day_34_Vector; 2 | // www.codeswithpankaj.com 3 | import java.util.Vector; 4 | 5 | public class VectorToStringExample { 6 | public static void main(String[] args) { 7 | // Create a Vector of strings 8 | Vector colors = new Vector<>(); 9 | colors.add("Red"); 10 | colors.add("Green"); 11 | colors.add("Blue"); 12 | 13 | // Convert the Vector to a String 14 | String colorsString = colors.toString(); 15 | 16 | // Print the String representation 17 | System.out.println("Vector as String: " + colorsString); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Day_35_QueueInterface/QueueInterface/QueueExample1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_35_QueueInterface/QueueInterface/QueueExample1.class -------------------------------------------------------------------------------- /Day_36_DequeInterface /DequeInterface/DequeAsStackExample.java: -------------------------------------------------------------------------------- 1 | package Day_36; 2 | 3 | import java.util.ArrayDeque; 4 | import java.util.Deque; 5 | 6 | public class DequeAsStackExample { 7 | public static void main(String[] args) { 8 | // Create a Deque to implement a stack 9 | Deque stack = new ArrayDeque<>(); 10 | 11 | // 1. push() - Add elements to the beginning of the deque (top of the stack) 12 | stack.push(10); 13 | stack.push(20); 14 | stack.push(30); 15 | 16 | // Display the stack after pushing elements 17 | System.out.println("Stack after push operations: " + stack); 18 | 19 | // 2. pop() - Remove elements from the beginning of the deque (top of the stack) 20 | int poppedElement1 = stack.pop(); 21 | int poppedElement2 = stack.pop(); 22 | 23 | // Display the popped elements and the updated stack 24 | System.out.println("Popped element 1: " + poppedElement1); 25 | System.out.println("Popped element 2: " + poppedElement2); 26 | System.out.println("Stack after pop operations: " + stack); 27 | 28 | // 3. peek() - Peek at the top element without removing it 29 | int topElement = stack.peek(); 30 | 31 | // Display the top element 32 | System.out.println("Top element (peek): " + topElement); 33 | 34 | // Display the final stack 35 | System.out.println("Final Stack: " + stack); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Day_38_ArrayDeque/ArrayDequeAccessExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_38_ArrayDeque/ArrayDequeAccessExample.class -------------------------------------------------------------------------------- /Day_38_ArrayDeque/ArrayDequeRemoveExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_38_ArrayDeque/ArrayDequeRemoveExample.class -------------------------------------------------------------------------------- /Day_38_ArrayDeque/ArrayDequeSizeAndEmptyExample.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayDeque; 2 | import java.util.Deque; 3 | 4 | public class ArrayDequeSizeAndEmptyExample { 5 | public static void main(String[] args) { 6 | // Create an ArrayDeque of integers 7 | Deque deque = new ArrayDeque<>(); 8 | 9 | // Checking if the deque is empty 10 | boolean isEmpty = deque.isEmpty(); 11 | System.out.println("Is the ArrayDeque empty? " + isEmpty); 12 | 13 | // Adding elements to the deque 14 | deque.add(10); 15 | deque.add(20); 16 | deque.add(30); 17 | System.out.println("ArrayDeque after adding elements: " + deque); 18 | 19 | // Checking the size of the deque 20 | int size = deque.size(); 21 | System.out.println("Size of the ArrayDeque: " + size); 22 | 23 | // Adding more elements 24 | deque.add(40); 25 | deque.add(50); 26 | 27 | // Checking if the deque is empty again 28 | isEmpty = deque.isEmpty(); 29 | System.out.println("Is the ArrayDeque empty now? " + isEmpty); 30 | 31 | // Removing elements from the deque 32 | deque.removeFirst(); 33 | deque.removeLast(); 34 | 35 | // Checking the size after removal 36 | size = deque.size(); 37 | System.out.println("Size of the ArrayDeque after removal: " + size); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Day_40_ArrayBlockingQueue/ArrayBlockingQueueExample.java: -------------------------------------------------------------------------------- 1 | import java.util.concurrent.ArrayBlockingQueue; 2 | import java.util.concurrent.BlockingQueue; 3 | 4 | public class ArrayBlockingQueueExample { 5 | public static void main(String[] args) { 6 | // Create an ArrayBlockingQueue with a capacity of 3 7 | BlockingQueue blockingQueue = new ArrayBlockingQueue<>(3); 8 | 9 | // Producer thread 10 | Thread producerThread = new Thread(() -> { 11 | try { 12 | for (int i = 1; i <= 5; i++) { 13 | // Put items into the queue 14 | blockingQueue.put(i); 15 | System.out.println("Produced: " + i); 16 | } 17 | } catch (InterruptedException e) { 18 | Thread.currentThread().interrupt(); 19 | } 20 | }); 21 | 22 | // Consumer thread 23 | Thread consumerThread = new Thread(() -> { 24 | try { 25 | while (true) { 26 | // Take items from the queue 27 | int value = blockingQueue.take(); 28 | System.out.println("Consumed: " + value); 29 | } 30 | } catch (InterruptedException e) { 31 | Thread.currentThread().interrupt(); 32 | } 33 | }); 34 | 35 | // Start the producer and consumer threads 36 | producerThread.start(); 37 | consumerThread.start(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Day_42_HashMap/HashMap1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_42_HashMap/HashMap1.class -------------------------------------------------------------------------------- /Day_42_HashMap/HashMap1.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | import java.util.Map; 3 | 4 | public class HashMap1 { 5 | 6 | public static void main(String[] args) { 7 | // Create a HashMap with Integer keys and String values 8 | Map data = new HashMap(); 9 | // Add key-value pairs to the HashMap 10 | 11 | data.put(101, "Samosa"); 12 | data.put(102, "Kachori"); 13 | data.put(103, "Fafda"); 14 | data.put(104, "Jalebi"); 15 | data.put(105, "Dhokla"); 16 | data.put(106, "pav"); 17 | data.put(107, "pav bhaji"); 18 | 19 | System.out.println("Data : "+data); 20 | 21 | // Accessing 22 | 23 | System.out.println("Food : "+data.get(105)); 24 | 25 | // Modifying HashMap 26 | data.put(104, "Vada Pav1"); 27 | data.put(106, "Pav Bhaji1"); 28 | // System.out.println("Update Data Item :"+data); 29 | 30 | // Removing Elements from HashMap 31 | data.remove(102); 32 | System.out.println("After Remove Items Data : "+data); 33 | 34 | // Iterating Over HashMap (fetch/show/display data using loop) 35 | 36 | for(Map.Entry food : data.entrySet()){ 37 | 38 | System.out.println(food.getKey()+" = "+food.getValue()); 39 | } 40 | 41 | 42 | 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Day_43_LinkedHashMap/LinkedHashMapExample.java: -------------------------------------------------------------------------------- 1 | import java.util.LinkedHashMap; 2 | import java.util.Map; 3 | 4 | public class LinkedHashMapExample { 5 | public static void main(String[] args) { 6 | // Create a LinkedHashMap in insertion-order mode 7 | LinkedHashMap linkedHashMap = new LinkedHashMap<>(); 8 | 9 | // Add elements to the map 10 | linkedHashMap.put("One", 1); 11 | linkedHashMap.put("Two", 2); 12 | linkedHashMap.put("Three", 3); 13 | 14 | // Iterate over the elements (in insertion order) 15 | for (Map.Entry entry : linkedHashMap.entrySet()) { 16 | System.out.println(entry.getKey() + ": " + entry.getValue()); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Day_50_Set_Interface/SetOperation.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_50_Set_Interface/SetOperation.class -------------------------------------------------------------------------------- /Day_50_Set_Interface/SetOperations.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class SetOperation{ 3 | 4 | public static void main(String[] args) { 5 | 6 | // Set Operations 7 | Set x = new HashSet<>(Arrays.asList(1, 2, 3, 4)); 8 | Set y = new HashSet<>(Arrays.asList(3, 4, 5, 6)); 9 | 10 | // Union 11 | Set union = new HashSet<>(x); 12 | union.addAll(y); 13 | System.out.println("Union of x and y: " + union); 14 | 15 | // Intersection 16 | Set intersection = new HashSet<>(x); 17 | intersection.retainAll(y); 18 | System.out.println("Intersection of x and y: " + intersection); 19 | 20 | // Subset 21 | boolean isSubset = y.containsAll(x); 22 | System.out.println("Is x a subset of y? " + isSubset); 23 | 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /Day_50_Set_Interface/SetOperationsExample.java: -------------------------------------------------------------------------------- 1 | package Day_50_Set_Interface; 2 | import java.util.HashSet; 3 | import java.util.Set; 4 | 5 | public class SetOperationsExample { 6 | public static void main(String[] args) { 7 | // Create two sets 8 | Set set1 = new HashSet<>(); 9 | Set set2 = new HashSet<>(); 10 | 11 | // Add elements to set1 12 | set1.add(1); 13 | set1.add(2); 14 | set1.add(3); 15 | 16 | // Add elements to set2 17 | set2.add(3); 18 | set2.add(4); 19 | set2.add(5); 20 | 21 | // Union - Combine elements from both sets (remove duplicates) 22 | Set union = new HashSet<>(set1); 23 | union.addAll(set2); 24 | System.out.println("Union of Set 1 and Set 2: " + union); 25 | 26 | // Intersection - Keep only the common elements between sets 27 | Set intersection = new HashSet<>(set1); 28 | intersection.retainAll(set2); 29 | System.out.println("Intersection of Set 1 and Set 2: " + intersection); 30 | 31 | // Subset - Check if Set 1 is a subset of Set 2 32 | boolean isSubset = set2.containsAll(set1); 33 | System.out.println("Is Set 1 a subset of Set 2? " + isSubset); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Day_57_IO_Streams/JavaFileInputStream/FileOutputStreamExample.java: -------------------------------------------------------------------------------- 1 | package Day_57_IO_Streams.JavaFileInputStream; 2 | 3 | import java.io.FileOutputStream; 4 | import java.io.IOException; 5 | import java.io.OutputStream; 6 | 7 | public class FileOutputStreamExample{ 8 | public static void main(String[] args) { 9 | String fileName = "output.txt"; 10 | String data = "Hello, World!"; 11 | 12 | try { 13 | // Create a FileOutputStream for the specified file 14 | OutputStream outputStream = new FileOutputStream(fileName); 15 | 16 | // Convert the data to bytes and write it to the file 17 | byte[] byteData = data.getBytes(); 18 | outputStream.write(byteData); 19 | 20 | // Close the output stream to release resources 21 | outputStream.close(); 22 | 23 | System.out.println("Data has been written to " + fileName); 24 | } catch (IOException e) { 25 | e.printStackTrace(); 26 | } 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Day_57_IO_Streams/JavaInputStream/InputStreamExample.java: -------------------------------------------------------------------------------- 1 | package Day_57_IO_Streams.JavaInputStream; 2 | import java.io.FileInputStream; 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | public class InputStreamExample { 7 | public static void main(String[] args) { 8 | try { 9 | // Create an InputStream for reading from a file 10 | InputStream inputStream = new FileInputStream("example.txt"); 11 | 12 | // Read and process data from the file 13 | int data; 14 | while ((data = inputStream.read()) != -1) { 15 | // Convert the integer data to a character and print it 16 | char character = (char) data; 17 | System.out.print(character); 18 | } 19 | 20 | // Close the input stream to release resources 21 | inputStream.close(); 22 | } catch (IOException e) { 23 | e.printStackTrace(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Day_57_IO_Streams/JavaOutputStream/OutputStreamExample.java: -------------------------------------------------------------------------------- 1 | package Day_57_IO_Streams.JavaOutputStream; 2 | 3 | import java.io.FileOutputStream; 4 | import java.io.IOException; 5 | import java.io.OutputStream; 6 | 7 | public class OutputStreamExample { 8 | public static void main(String[] args) { 9 | try { 10 | // Create an OutputStream for writing to a file 11 | OutputStream outputStream = new FileOutputStream("output.txt"); 12 | 13 | // Data to write to the file 14 | String data = "Hello, World!"; 15 | 16 | // Convert the data to bytes and write it to the file 17 | byte[] byteData = data.getBytes(); 18 | outputStream.write(byteData); 19 | 20 | // Close the output stream to release resources 21 | outputStream.close(); 22 | 23 | System.out.println("Data has been written to output.txt"); 24 | } catch (IOException e) { 25 | e.printStackTrace(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Day_58_Java_Reader_Writer/README.md: -------------------------------------------------------------------------------- 1 | # Byte Streams 2 | 3 | Programs use byte streams to perform input and output of 8-bit bytes. All byte stream classes are descended from InputStream and OutputStream. 4 | 5 | There are many byte stream classes. To demonstrate how byte streams work, we'll focus on the file I/O byte streams, FileInputStream and FileOutputStream. Other kinds of byte streams are used in much the same way; they differ mainly in the way they are constructed. 6 | 7 | Using Byte Streams 8 | We'll explore FileInputStream and FileOutputStream by examining an example program named CopyBytes, which uses byte streams to copy xanadu.txt, one byte at a time. 9 | ```java 10 | import java.io.FileInputStream; 11 | import java.io.FileOutputStream; 12 | import java.io.IOException; 13 | 14 | public class CopyBytes { 15 | public static void main(String[] args) throws IOException { 16 | 17 | FileInputStream in = null; 18 | FileOutputStream out = null; 19 | 20 | try { 21 | in = new FileInputStream("xanadu.txt"); 22 | out = new FileOutputStream("outagain.txt"); 23 | int c; 24 | 25 | while ((c = in.read()) != -1) { 26 | out.write(c); 27 | } 28 | } finally { 29 | if (in != null) { 30 | in.close(); 31 | } 32 | if (out != null) { 33 | out.close(); 34 | } 35 | } 36 | } 37 | } 38 | ``` 39 | -------------------------------------------------------------------------------- /Day_59_Threading/AccountHolder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_59_Threading/AccountHolder.class -------------------------------------------------------------------------------- /Day_59_Threading/BankAccount.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_59_Threading/BankAccount.class -------------------------------------------------------------------------------- /Day_59_Threading/BankAccountExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_59_Threading/BankAccountExample.class -------------------------------------------------------------------------------- /Day_59_Threading/Buffer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_59_Threading/Buffer.class -------------------------------------------------------------------------------- /Day_59_Threading/Chef.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_59_Threading/Chef.class -------------------------------------------------------------------------------- /Day_59_Threading/Consumer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_59_Threading/Consumer.class -------------------------------------------------------------------------------- /Day_59_Threading/ExampleMultiThreads.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_59_Threading/ExampleMultiThreads.class -------------------------------------------------------------------------------- /Day_59_Threading/ExampleMultiThreads.java: -------------------------------------------------------------------------------- 1 | class thread1 extends Thread{ 2 | 3 | public void run(){ 4 | 5 | try{ 6 | for (int i = 0; i <= 10; i++) { 7 | 8 | System.out.println("Welcome to Thread 1 --- No. "+i); 9 | Thread.sleep(1000); 10 | 11 | } 12 | }catch(Exception e){ 13 | System.err.println(e); 14 | } 15 | 16 | } 17 | 18 | } 19 | 20 | class thread2 extends Thread{ 21 | 22 | public void run(){ 23 | 24 | try{ 25 | for (int i = 0; i <= 10; i++) { 26 | 27 | System.out.println("Welcome to Thread 2 ****** No. "+i); 28 | Thread.sleep(1000); 29 | 30 | } 31 | }catch(Exception e){ 32 | System.err.println(e); 33 | } 34 | 35 | } 36 | 37 | } 38 | 39 | 40 | public class ExampleMultiThreads { 41 | public static void main(String[] args) { 42 | 43 | //Thread th = new Thread(); 44 | //th.start(); 45 | 46 | thread1 th1 = new thread1(); 47 | thread2 th2 = new thread2(); 48 | th1.start(); 49 | th2.start(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Day_59_Threading/Example_singleThread.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_59_Threading/Example_singleThread.class -------------------------------------------------------------------------------- /Day_59_Threading/Example_singleThread.java: -------------------------------------------------------------------------------- 1 | class Example_singleThread implements Runnable{ 2 | 3 | 4 | public void run(){ 5 | 6 | try{ 7 | for (int i = 0; i <= 10; i++) { 8 | 9 | System.out.println("Welcome to Thread 1 --- No. "+i); 10 | Thread.sleep(2000); 11 | 12 | } 13 | }catch(Exception e){ 14 | System.err.println(e); 15 | } 16 | 17 | } 18 | 19 | 20 | public static void main(String[] args) { 21 | 22 | Example_singleThread est = new Example_singleThread(); 23 | est.run(); 24 | 25 | 26 | } 27 | 28 | 29 | } -------------------------------------------------------------------------------- /Day_59_Threading/MultiThreadSum.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_59_Threading/MultiThreadSum.class -------------------------------------------------------------------------------- /Day_59_Threading/Order.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_59_Threading/Order.class -------------------------------------------------------------------------------- /Day_59_Threading/Producer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_59_Threading/Producer.class -------------------------------------------------------------------------------- /Day_59_Threading/ProducerConsumerExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_59_Threading/ProducerConsumerExample.class -------------------------------------------------------------------------------- /Day_59_Threading/RestaurantExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_59_Threading/RestaurantExample.class -------------------------------------------------------------------------------- /Day_59_Threading/Waiter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_59_Threading/Waiter.class -------------------------------------------------------------------------------- /Day_59_Threading/thread1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_59_Threading/thread1.class -------------------------------------------------------------------------------- /Day_59_Threading/thread2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_59_Threading/thread2.class -------------------------------------------------------------------------------- /Day_60_LambdaExpressions/LambdaGUIExample.java: -------------------------------------------------------------------------------- 1 | package Day_60_LambdaExpressions; 2 | 3 | import javax.swing.JButton; 4 | import javax.swing.JFrame; 5 | import javax.swing.JLabel; 6 | import javax.swing.JPanel; 7 | import javax.swing.SwingUtilities; 8 | 9 | public class LambdaGUIExample { 10 | 11 | public static void main(String[] args) { 12 | SwingUtilities.invokeLater(() -> { 13 | JFrame frame = new JFrame("Lambda GUI Example"); 14 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 15 | 16 | JPanel panel = new JPanel(); 17 | 18 | JLabel label = new JLabel("Click the button!"); 19 | 20 | JButton button = new JButton("Click Me"); 21 | button.addActionListener(e -> label.setText("Button Clicked!")); 22 | 23 | panel.add(label); 24 | panel.add(button); 25 | 26 | frame.getContentPane().add(panel); 27 | frame.setSize(300, 200); 28 | frame.setLocationRelativeTo(null); 29 | frame.setVisible(true); 30 | }); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Day_61_Immutable_Objects/ImmutableObjects/ImmutableExample.java: -------------------------------------------------------------------------------- 1 | public class ImmutableExample { 2 | public static void main(String[] args) { 3 | // Creating an instance of ImmutablePerson 4 | ImmutablePerson person = new ImmutablePerson("Nishant Chouhan", 30); 5 | 6 | // Accessing the information 7 | System.out.println("Name: " + person.getName()); 8 | System.out.println("Age: " + person.getAge()); 9 | 10 | // Attempting to modify the state of the object will result in a compilation error 11 | // person.setName("Jane Doe"); // Compilation error 12 | 13 | // Creating a new instance with modified information 14 | ImmutablePerson newPerson = new ImmutablePerson("Pankaj Chouhan", 32); 15 | System.out.println("New Person - Name: " + newPerson.getName()); 16 | System.out.println("New Person - Age: " + newPerson.getAge()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Day_61_Immutable_Objects/ImmutableObjects/ImmutablePerson.java: -------------------------------------------------------------------------------- 1 | public final class ImmutablePerson { 2 | private final String name; 3 | private final int age; 4 | 5 | public ImmutablePerson(String name, int age) { 6 | this.name = name; 7 | this.age = age; 8 | } 9 | 10 | public String getName() { 11 | return name; 12 | } 13 | 14 | public int getAge() { 15 | return age; 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /Day_61_Immutable_Objects/MutableObjects/MutableExample.java: -------------------------------------------------------------------------------- 1 | public class MutableExample { 2 | public static void main(String[] args) { 3 | // Creating a mutable StringBuilder 4 | StringBuilder mutableString = new StringBuilder("Hello"); 5 | 6 | // Accessing and modifying the StringBuilder 7 | System.out.println("Original String: " + mutableString); 8 | 9 | // Appending to the StringBuilder 10 | mutableString.append(", World!"); 11 | System.out.println("Modified String (Appended): " + mutableString); 12 | 13 | // Modifying the state of the StringBuilder 14 | mutableString.replace(0, 5, "Greetings"); 15 | System.out.println("Updated String: " + mutableString); 16 | 17 | // Inserting into the StringBuilder 18 | mutableString.insert(9, " Java"); 19 | System.out.println("String after Insertion: " + mutableString); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Day_61_Immutable_Objects/MutableObjects/MutableExample1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_61_Immutable_Objects/MutableObjects/MutableExample1.class -------------------------------------------------------------------------------- /Day_61_Immutable_Objects/MutableObjects/MutableExample1.java: -------------------------------------------------------------------------------- 1 | public class MutableExample1 { 2 | public static void main(String[] args) { 3 | // Creating an instance of MutablePerson 4 | MutablePerson person = new MutablePerson("Pankaj Chouhan", 25); 5 | 6 | // Printing the initial state 7 | System.out.println("Initial Person: " + person); 8 | 9 | // Modifying the state using setter methods 10 | person.setName("Pankaj Chouhan"); 11 | person.setAge(30); 12 | 13 | // Printing the updated state 14 | System.out.println("Updated Person: " + person); 15 | 16 | // Creating a new instance with modified information 17 | MutablePerson newPerson = new MutablePerson("Nishant", 28); 18 | 19 | // Printing the new person 20 | System.out.println("New Person: " + newPerson); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Day_61_Immutable_Objects/MutableObjects/MutablePerson.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_61_Immutable_Objects/MutableObjects/MutablePerson.class -------------------------------------------------------------------------------- /Day_61_Immutable_Objects/MutableObjects/MutablePerson.java: -------------------------------------------------------------------------------- 1 | public class MutablePerson { 2 | private String name; 3 | private int age; 4 | 5 | public MutablePerson(String name, int age) { 6 | this.name = name; 7 | this.age = age; 8 | } 9 | 10 | // Getter methods 11 | public String getName() { 12 | return name; 13 | } 14 | 15 | public int getAge() { 16 | return age; 17 | } 18 | 19 | // Setter methods for modifying the state 20 | public void setName(String name) { 21 | this.name = name; 22 | } 23 | 24 | public void setAge(int age) { 25 | this.age = age; 26 | } 27 | 28 | @Override 29 | public String toString() { 30 | return "MutablePerson{" + 31 | "name='" + name + '\'' + 32 | ", age=" + age + 33 | '}'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Day_62_JDBC/Db_jdbc.java: -------------------------------------------------------------------------------- 1 | package codeswithpankaj.com.JDBC; 2 | import java.sql.*; 3 | public class Db_jdbc { 4 | 5 | public static void main(String[] args) { 6 | String JDBC_URL = "jdbc:mysql://localhost:3306/p4n"; 7 | String JDBC_USERNAME = "root"; 8 | String JDBC_PASSWORD = "admin"; 9 | try { 10 | Class.forName("com.mysql.jdbc.Driver"); 11 | Connection con = DriverManager.getConnection(JDBC_URL, JDBC_USERNAME, JDBC_PASSWORD); 12 | Statement stmt = con.createStatement(); 13 | ResultSet rs = stmt.executeQuery("select * from student"); 14 | //step number 5th get all data from database... 15 | while(rs.next()) 16 | System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3)); 17 | con.close(); 18 | }catch(Exception e){ 19 | System.out.println(e); 20 | } 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /Day_63_Annotations_Base64Encoding/Author.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Day_63_Annotations_Base64Encoding/Author.class -------------------------------------------------------------------------------- /Day_63_Annotations_Base64Encoding/Author.java: -------------------------------------------------------------------------------- 1 | package Day_63_Annotations_Base64Encoding; 2 | import java.lang.annotation.ElementType; 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.RetentionPolicy; 5 | import java.lang.annotation.Target; 6 | 7 | @Retention(RetentionPolicy.RUNTIME) // Annotation is available at runtime 8 | 9 | @Target({ElementType.TYPE, ElementType.METHOD}) // Can be used on classes and methods 10 | 11 | public @interface Author { 12 | 13 | String name(); 14 | 15 | String date(); 16 | 17 | } -------------------------------------------------------------------------------- /Day_63_Annotations_Base64Encoding/MyClass.java: -------------------------------------------------------------------------------- 1 | package Day_63_Annotations_Base64Encoding; 2 | 3 | @Author(name = "Pankaj", date = "2024-09-02") 4 | 5 | public class MyClass { 6 | 7 | @Author(name = "Pankaj", date = "2024-09-02") 8 | 9 | public void myMethod() { 10 | 11 | System.out.println("This method is annotated!"); 12 | 13 | } 14 | 15 | } -------------------------------------------------------------------------------- /Day_63_Annotations_Base64Encoding/decoded_p4n.txt: -------------------------------------------------------------------------------- 1 | QW5ub3RhdGlvbnMgaGVscCBhZGQgZXh0cmEgaW5mb3JtYXRpb24gdG8geW91ciBjb2RlLCBtYWtpbmcgaXQgZWFzaWVyIHRvIG1hbmFnZSBhbmQgdW5kZXJzdGFuZC4gQmFzZTY0IGVuY29kaW5nIGlzIGEgdXNlZnVsIHRvb2wgZm9yIGNvbnZlcnRpbmcgZGF0YSBpbnRvIGEgZm9ybWF0IHRoYXQgY2FuIGJlIGVhc2lseSBzaGFyZWQgb3Igc3RvcmVkLg== 2 | -------------------------------------------------------------------------------- /Day_63_Annotations_Base64Encoding/p4n.txt: -------------------------------------------------------------------------------- 1 | we learned about Annotations and Base64 Encoding in Java. Annotations help add extra information to your code, making it easier to manage and understand. Base64 encoding is a useful tool for converting data into a format that can be easily shared or stored. -------------------------------------------------------------------------------- /Day_63_Annotations_Base64Encoding/src/AnnotationsJava/AnnotationExample.java: -------------------------------------------------------------------------------- 1 | package AnnotationsJava; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | public class AnnotationExample { 6 | 7 | public static void main(String[] args) { 8 | 9 | // Check if the class has the @Author annotation 10 | 11 | if (MyClass.class.isAnnotationPresent(Author.class)) { 12 | 13 | Author author = MyClass.class.getAnnotation(Author.class); 14 | 15 | System.out.println("Class Author: " + author.name() + ", Date: " + author.date()); 16 | 17 | } 18 | 19 | // Check if the method has the @Author annotation 20 | 21 | try { 22 | 23 | Method method = MyClass.class.getMethod("myMethod"); 24 | 25 | if (method.isAnnotationPresent(Author.class)) { 26 | 27 | Author author = method.getAnnotation(Author.class); 28 | 29 | System.out.println("Method Author: " + author.name() + ", Date: " + author.date()); 30 | 31 | } 32 | 33 | } catch (NoSuchMethodException e) { 34 | 35 | e.printStackTrace(); 36 | 37 | } 38 | 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /Day_63_Annotations_Base64Encoding/src/AnnotationsJava/Author.java: -------------------------------------------------------------------------------- 1 | package AnnotationsJava; 2 | import java.lang.annotation.ElementType; 3 | 4 | import java.lang.annotation.Retention; 5 | 6 | import java.lang.annotation.RetentionPolicy; 7 | 8 | import java.lang.annotation.Target; 9 | 10 | @Retention(RetentionPolicy.RUNTIME) // Annotation is available at runtime 11 | 12 | @Target({ElementType.TYPE, ElementType.METHOD}) // Can be used on classes and methods 13 | 14 | public @interface Author { 15 | 16 | String name(); 17 | 18 | String date(); 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /Day_63_Annotations_Base64Encoding/src/AnnotationsJava/MyClass.java: -------------------------------------------------------------------------------- 1 | package AnnotationsJava; 2 | 3 | @Author(name = "Pankaj", date = "2024-09-02") 4 | 5 | public class MyClass { 6 | 7 | @Author(name = "Pankaj", date = "2024-09-02") 8 | 9 | public void myMethod() { 10 | 11 | System.out.println("This method is annotated!"); 12 | 13 | } 14 | 15 | } -------------------------------------------------------------------------------- /Day_63_Annotations_Base64Encoding/src/Base64Encoding_Decoding/Base64Decoding.java: -------------------------------------------------------------------------------- 1 | package Base64Encoding_Decoding; 2 | 3 | import java.util.Base64; 4 | 5 | public class Base64Decoding{ 6 | 7 | public static void main(String[] args) { 8 | 9 | String encodedString = "Y29kZXMgd2l0aCBwYW5rYWo="; 10 | 11 | byte[] decodedBytes = Base64.getDecoder().decode(encodedString); 12 | 13 | String decodedString = new String(decodedBytes); 14 | 15 | System.out.println("Encoded String: " + encodedString); 16 | 17 | System.out.println("Decoded String: " + decodedString); 18 | 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /Day_63_Annotations_Base64Encoding/src/Base64Encoding_Decoding/Base64Example.java: -------------------------------------------------------------------------------- 1 | package Base64Encoding_Decoding; 2 | import java.util.Base64; 3 | 4 | public class Base64Example { 5 | 6 | public static void main(String[] args) { 7 | 8 | String originalString = "codes with pankaj"; 9 | 10 | String encodedString = Base64.getEncoder().encodeToString(originalString.getBytes()); 11 | 12 | System.out.println("Original String: " + originalString); 13 | 14 | System.out.println("Encoded String: " + encodedString); 15 | 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /Day_63_Annotations_Base64Encoding/src/Encoding_DecodingFiles/Base64Encoder.java: -------------------------------------------------------------------------------- 1 | package Encoding_DecodingFiles; 2 | 3 | import java.util.Base64; 4 | 5 | public class Base64Encoder { 6 | public static void main(String[] args) { 7 | String originalText = "Annotations help add extra information to your code, making it easier to manage and understand. Base64 encoding is a useful tool for converting data into a format that can be easily shared or stored."; 8 | 9 | // Convert the string into a byte array 10 | byte[] bytes = originalText.getBytes(); 11 | 12 | // Encode the byte array to a Base64 string 13 | String encodedText = Base64.getEncoder().encodeToString(bytes); 14 | 15 | // Print the encoded string 16 | System.out.println("Encoded Text: " + encodedText); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Day_63_Annotations_Base64Encoding/src/Encoding_DecodingFiles/FileBase64Example.java: -------------------------------------------------------------------------------- 1 | package Encoding_DecodingFiles; 2 | 3 | import java.util.Base64; 4 | 5 | import java.nio.file.Files; 6 | 7 | import java.nio.file.Paths; 8 | 9 | import java.io.IOException; 10 | 11 | public class FileBase64Example { 12 | 13 | public static void main(String[] args) { 14 | 15 | try { 16 | 17 | // Read file and encode it to Base64 18 | 19 | byte[] fileContent = Files.readAllBytes(Paths.get("p4n.txt")); 20 | 21 | String encodedString = Base64.getEncoder().encodeToString(fileContent); 22 | 23 | System.out.println("Encoded File String: " + encodedString); 24 | 25 | // Decode Base64 string back to file 26 | 27 | byte[] decodedBytes = Base64.getDecoder().decode(encodedString); 28 | 29 | Files.write(Paths.get("decoded_p4n.txt"), decodedBytes); 30 | 31 | System.out.println("File successfully decoded!"); 32 | 33 | } catch (IOException e) { 34 | 35 | e.printStackTrace(); 36 | 37 | } 38 | 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /Example00/InheritanceExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Example00/InheritanceExample.class -------------------------------------------------------------------------------- /Example00/Marks.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Example00/Marks.class -------------------------------------------------------------------------------- /Example00/Percentage.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Example00/Percentage.class -------------------------------------------------------------------------------- /Example00/Result.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pankaj-Str/JAVA-SE-Tutorial-codeswithpankaj/48f603446a26d7b8fe8cffd2a97397ec10910dfc/Example00/Result.class -------------------------------------------------------------------------------- /InterviewQuestion/p4n/BankAccount.java: -------------------------------------------------------------------------------- 1 | package p4n; 2 | 3 | public class BankAccount{ 4 | 5 | private String accountNumber; 6 | private double balance; 7 | 8 | 9 | public BankAccount(String accountNumber, double balance) { 10 | this.accountNumber = accountNumber; 11 | this.balance = balance; 12 | } 13 | 14 | 15 | public String getAccountNumber() { 16 | return accountNumber; 17 | } 18 | 19 | 20 | public void setAccountNumber(String accountNumber) { 21 | this.accountNumber = accountNumber; 22 | } 23 | 24 | 25 | public double getBalance() { 26 | return balance; 27 | } 28 | 29 | 30 | public void setBalance(double balance) { 31 | this.balance = balance; 32 | } 33 | 34 | public static void main(String[] args) { 35 | // Creating a BankAccount object 36 | BankAccount account = new BankAccount("123456789", 1000.0); 37 | 38 | // Accessing and modifying instance variables using getter and setter methods 39 | System.out.println("Initial Account Number: " + account.getAccountNumber()); 40 | System.out.println("Initial Balance: " + account.getBalance()); 41 | 42 | account.setAccountNumber("987654321"); 43 | account.setBalance(1500.0); 44 | 45 | System.out.println("Updated Account Number: " + account.getAccountNumber()); 46 | System.out.println("Updated Balance: " + account.getBalance()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /InterviewQuestion/p4n/ListFilter.java: -------------------------------------------------------------------------------- 1 | package p4n; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | import java.util.function.Predicate; 7 | 8 | public class ListFilter { 9 | 10 | // Generic method to filter elements based on a predicate 11 | public static List filterList(List list, Predicate predicate) { 12 | List filteredList = new ArrayList<>(); 13 | 14 | for (T element : list) { 15 | if (predicate.test(element)) { 16 | filteredList.add(element); 17 | } 18 | } 19 | 20 | return filteredList; 21 | } 22 | 23 | public static void main(String[] args) { 24 | List integerList = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); 25 | List stringList = Arrays.asList("samosa", "kachori", "fafda", "jalebi", "vadapav"); 26 | 27 | 28 | Predicate isEven = num -> num % 2 == 0; 29 | Predicate containsE = str -> str.contains("e"); 30 | 31 | 32 | List evenNumbers = filterList(integerList, isEven); 33 | List stringsWithE = filterList(stringList, containsE); 34 | 35 | 36 | System.out.println("Even Numbers: " + evenNumbers); 37 | System.out.println("Strings Containing 'e': " + stringsWithE); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /InterviewQuestion/p4n/ListMerger.java: -------------------------------------------------------------------------------- 1 | package p4n; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | public class ListMerger{ 8 | 9 | // Generic method to merge two lists by alternating elements 10 | public static List mergeLists(List list1, List list2) { 11 | List mergedList = new ArrayList<>(); 12 | int maxSize = Math.max(list1.size(), list2.size()); 13 | 14 | for (int i = 0; i < maxSize; i++) { 15 | if (i < list1.size()) { 16 | mergedList.add(list1.get(i)); 17 | } 18 | if (i < list2.size()) { 19 | mergedList.add(list2.get(i)); 20 | } 21 | } 22 | 23 | return mergedList; 24 | } 25 | 26 | public static void main(String[] args) { 27 | List integerList1 = Arrays.asList(1, 3, 5); 28 | List integerList2 = Arrays.asList(2, 4, 6, 8, 10); 29 | 30 | List stringList1 = Arrays.asList("a", "c", "e"); 31 | List stringList2 = Arrays.asList("b", "d", "f", "g"); 32 | 33 | List mergedIntegerList = mergeLists(integerList1, integerList2); 34 | List mergedStringList = mergeLists(stringList1, stringList2); 35 | 36 | System.out.println("Merged Integer List: " + mergedIntegerList); 37 | System.out.println("Merged String List: " + mergedStringList); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /InterviewQuestion/p4n/ListReverser.java: -------------------------------------------------------------------------------- 1 | package p4n; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | import java.util.Collections; 7 | 8 | public class ListReverser { 9 | 10 | 11 | public static List reverseList(List list) { 12 | 13 | List reversedList = new ArrayList<>(list); 14 | 15 | 16 | Collections.reverse(reversedList); 17 | 18 | return reversedList; 19 | } 20 | 21 | public static void main(String[] args) { 22 | List integerList = Arrays.asList(1, 2, 3, 4, 5); 23 | List stringList = Arrays.asList("apple", "banana", "cherry", "date"); 24 | 25 | List reversedIntegerList = reverseList(integerList); 26 | List reversedStringList = reverseList(stringList); 27 | 28 | System.out.println("Original integerList: " + integerList); 29 | System.out.println("Reversed integerList: " + reversedIntegerList); 30 | 31 | System.out.println("Original stringList: " + stringList); 32 | System.out.println("Reversed stringList: " + reversedStringList); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /InterviewQuestion/p4n/ListSearcher.java: -------------------------------------------------------------------------------- 1 | package p4n; 2 | 3 | import java.util.List; 4 | import java.util.Arrays; 5 | 6 | public class ListSearcher { 7 | 8 | public static int indexOfElement(List list, T target) { 9 | if (list == null || target == null) { 10 | return -1; 11 | } 12 | 13 | for (int i = 0; i < list.size(); i++) { 14 | if (target.equals(list.get(i))) { 15 | return i; 16 | } 17 | } 18 | 19 | return -1; 20 | } 21 | 22 | public static void main(String[] args) { 23 | List integerList = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); 24 | List stringList = Arrays.asList("apple", "banana", "cherry", "date", "elderberry"); 25 | 26 | int intIndex = indexOfElement(integerList, 5); 27 | int strIndex = indexOfElement(stringList, "cherry"); 28 | int notFoundIndex = indexOfElement(stringList, "fig"); 29 | 30 | System.out.println("Index of 5 in integerList: " + intIndex); // Should print 4 31 | System.out.println("Index of 'cherry' in stringList: " + strIndex); // Should print 2 32 | System.out.println("Index of 'fig' in stringList: " + notFoundIndex); // Should print -1 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /InterviewQuestion/p4n/MapPrinter.java: -------------------------------------------------------------------------------- 1 | package p4n; 2 | 3 | import java.util.Map; 4 | import java.util.HashMap; 5 | 6 | public class MapPrinter { 7 | 8 | 9 | public static void printMap(Map map) { 10 | for (Map.Entry entry : map.entrySet()) { 11 | System.out.println("Key: " + entry.getKey() + ", Value: " + entry.getValue()); 12 | } 13 | } 14 | 15 | public static void main(String[] args) { 16 | 17 | Map integerStringMap = new HashMap<>(); 18 | integerStringMap.put(1, "One"); 19 | integerStringMap.put(2, "Two"); 20 | integerStringMap.put(3, "Three"); 21 | 22 | 23 | Map stringDoubleMap = new HashMap<>(); 24 | stringDoubleMap.put("A", 1.1); 25 | stringDoubleMap.put("B", 2.2); 26 | stringDoubleMap.put("C", 3.3); 27 | 28 | 29 | System.out.println("Integer to String Map:"); 30 | printMap(integerStringMap); 31 | 32 | System.out.println("\nString to Double Map:"); 33 | printMap(stringDoubleMap); 34 | } 35 | } 36 | --------------------------------------------------------------------------------