{"id":19606743,"url":"https://github.com/learnwithfair/java-documentation","last_synced_at":"2025-02-26T16:44:00.446Z","repository":{"id":237391783,"uuid":"794437378","full_name":"learnwithfair/java-documentation","owner":"learnwithfair","description":"java (OOP) documentation with  [learnwithfair, Learn with fair, Rahatul Rabbi, Md Rahatul Rabbi ,rahatulrabbi]","archived":false,"fork":false,"pushed_at":"2024-05-03T14:54:37.000Z","size":18081,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-09T09:24:24.327Z","etag":null,"topics":["documentation","java","jdbc","learn-with-fair","learnwithfair","oop","oop-in-java","rahatul-rabbi","rahatulrabbi"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/learnwithfair.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-01T06:47:54.000Z","updated_at":"2024-09-05T16:32:15.000Z","dependencies_parsed_at":"2025-01-10T08:32:40.438Z","dependency_job_id":null,"html_url":"https://github.com/learnwithfair/java-documentation","commit_stats":null,"previous_names":["learnwithfair/java-documentation"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/learnwithfair%2Fjava-documentation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/learnwithfair%2Fjava-documentation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/learnwithfair%2Fjava-documentation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/learnwithfair%2Fjava-documentation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/learnwithfair","download_url":"https://codeload.github.com/learnwithfair/java-documentation/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240894607,"owners_count":19874842,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["documentation","java","jdbc","learn-with-fair","learnwithfair","oop","oop-in-java","rahatul-rabbi","rahatulrabbi"],"created_at":"2024-11-11T10:07:05.966Z","updated_at":"2025-02-26T16:44:00.425Z","avatar_url":"https://github.com/learnwithfair.png","language":null,"readme":"# JAVA-DOCUMENTATION\n\n[![Youtube][youtube-shield]][youtube-url]\n[![Facebook][facebook-shield]][facebook-url]\n[![Instagram][instagram-shield]][instagram-url]\n[![LinkedIn][linkedin-shield]][linkedin-url]\n\nThanks for visiting my GitHub account!\n\n\u003cimg src =\"https://cdn.iconscout.com/icon/free/png-256/free-java-60-1174953.png\" height = \"200px\" width = \"180px\"/\u003e **Java** is a popular OOP language. It is used to develop mobile apps, web apps, desktop apps, games, and much more. [See More](https://www.w3schools.com/java/)\n\n|                                                                              |\n| :--------------------------------------------------------------------------: |\n|                                   Features                                   |\n| ![features](https://github.com/learnwithfair/java/blob/main/images/oops.png) |\n|                    ![features](images/java-features.jpg)                     |\n\n### [Code-Example](https://github.com/learnwithfair/java)\n\n## Source Code (Download)\n\n- [Documentation](https://mega.nz/folder/RGFiUApD#PoKIVCwF8IkQhE2PHw1XxQ)\n- [Source-code](https://mega.nz/folder/ROF1WBTS#klvFbstilMZrMg_z1JeRhg)\n\n## Overview of JAVA\n\n[![overview](images/java-overview.png)](https://fb.watch/rQIa_O6OT-/)\n\n## Table of Contents\n\n1. [Basic Java](#1-basic-java)\n\n   - [Introduction to Java](#11-introduction-to-java)\n   - [First Java Application](#12-first-java-application)\n   - [Escape sequences](#13-escape-sequences--backslash-characters)\n   - [Types of Comments](#14-types-of-comments)\n   - [Java program's Phases](#15-java-programs-phases)\n   - [Variable \u0026 Data types](#16-variable--data-types)\n   - [Format specifiers](#17-format-specifiers)\n   - [Getting user inputs](#18-getting-user-input)\n   - [Operators, Operands, Expression](#19-operators-operands-expression)\n   - [Control Statement](#110-control-statements)\n     - [Conditional control statement](#1101-conditional-control-statements)\n     - [Loop control statement](#1102-looping-control-statements)\n     - [Jump control statement](#1103-jump-control-statements)\n   - [Control Statement](#110-control-statements)\n   - [Arrays and ArrayList](#111-arrays-and-arraylist)\n   - [String Manipulation](#112-string-manipulation)\n   - [Object Oriented Programming](#113-object-oriented-programming)\n     - [Classes, Object, Constructor](#classes-object-constructor)\n     - [static variable, method and block](#static-variable-static-method-and-static-block)\n     - [OOP Key Feature 1: Encapsulation](#oop-key-feature-1-encapsulation)\n     - [OOP Key Feature 2: Inheritance](#oop-key-feature-2-inheritance)\n     - [super, this, final keyword](#super-this-final-keyword)\n   - [Object Oriented Programming](#113-object-oriented-programming)\n\n2. Intermediate\n3. All assignments\n\n   - [Assignment 1 (Print User Information)](#assigment-1-print-your-information)\n   - [Assignment 2 (Variable and Data type)](#assignment-2-variable-and-data-type)\n   - [Assignment 3 (User Input)](#assignment-3-user-input)\n   - [Assignment 4 (installment amount for per month)](#assignment-4-installment-amount-for-per-month)\n   - [Assignment 5 (valid voter using if else)](#assignment-5-valid-voter-using-if-else)\n   - [Assignment 6 (Digit spelling using if else)](#assignment-6-digit-spelling-using-if-else)\n   - [Assignment 7 (logical OR operators and if else)](#assignment-7-logical-operators-and-if-else)\n   - [Assignment 8 (Logical AND assignment and if-else)](#assignment-8-logical-and-assignment-and-if-else)\n   - [Assignment 9 (Call center using switch)](#assignment-9-call-center-using-switch)\n   - [Assignment 10 (find sum of 1-10 using for loop)](#assignment-10-find-sum-of-1-10-using-for-loop)\n   - [Assignment 11 (find factorial of n)](#assignment-11-find-factorial-of-n)\n   - [Assignment 12 (print sum of odd numbers from m-n)](#assignment-12-print-sum-of-odd-numbers-from-m-n)\n   - [Assignment 13 (find nth fibonacci number)](#assignment-13-find-nth-fibonacci-number)\n   - [Assignment 14 (Palindrome number)](#assignment-14-palindrome-number)\n   - [Assignment 15 (Armstrong number)](#assignment-15-armstrong-number)\n   - [Assignment 16 (find nth fibonacci number)](#assignment-16---find-nth-fibonacci-number)\n   - [Assignment 17 (Pattern program)](#assignment-17-pattern-program)\n   - [Assignment 18 (Print the day name)](#assignment-18-print-the-day-name)\n\n## Compiling and Running JAVA Programs\n\nThis section explains how to compile and run a JAVA application from the command line. For information on compiling and running a JAVA application using NetBeans IDE, see Running Tutorial Examples in NetBeans IDE. Here are the steps you need to follow:\n\n- Install the latest release of the Java SE platform, if you haven't already done so (JDK).\n- Setup Environment variable for JDk\n- Install IDE such as NetBeans, Eclipse\n- Create a program that uses Swing components.\n- Compile the program.\n- Run the program.\n\n```diff\n- Note: File name and class name must be the same.\n\n```\n\n## Environment variable Setup\n\n--- To set java path ---\n\n1. Right-click on \"My computer\" and click on properties\n2. Click on \"Advanced system settings\"\n3. Click on \"Environment variables\"\n4. Click on the new tab of a user variable\n5. Write the path in a variable name\n6. Copy the path of the bin folder ( `C:\\Program Files\\Java\\jdk-21\\bin`)\n7. Paste the path of the bin folder in the variable value\n8. Click OK\n9. For Check, write the command in the CMD `java -version` Or, `javac -version`\n\n[See More](https://stackoverflow.com/questions/1672281/how-to-set-the-environment-variables-for-java-in-windows)\n\n## Required Software (Download)\n\n- JDK, Download-\u003e https://www.oracle.com/java/technologies/downloads/#jdk21-windows\n- NetBeans, Download-\u003e https://netbeans.apache.org/front/main/download/nb122/nb122/\n- Or, Eclipse, Download-\u003e https://www.eclipse.org/downloads/download.php?file=/oomph/epp/2023-12/R/eclipse-inst-jre-win64.exe\n\n## For Advance, Connect Database (JDBC)\n\n- Connect MS Access database, visit-\u003e https://www.youtube.com/watch?v=MbDoMexPcYc\n\n## Required Software (Download)\n\n- UCanAccess, Download-\u003e https://sourceforge.net/projects/ucanaccess/\n- WindowBuilder, Download-\u003e https://download.eclipse.org/windowbuilder/updates/release/latest/\n\n## Enable TCP_IP Error\n\n1. Go to Manage by clicking on Desktop Computer\n2. Go to Service and Applications\n3. Go to SQL Server Configuration Manager\n4. Go to SQL Server Network Configuration\n5. Go to Protocol for MSSQLSERVER\n6. Then TCP/IP Enable.\n7. Go to SQL Server Services Restart All (Example...Sql server browser, SQL server(MSS..))\n\n## Programs\n\n- Operators\n\n  - calculator programs - area, temperature\n  - days to time converter program: 10 days = seconds?\n\n- Control statement\n\n  - conditional control statement: if, else if, else, switch\n    - Even/odd program\n    - Pass/Fail program\n    - valid voter program\n    - Positive/Negative/Zero program\n    - Digit spelling program\n    - Large/small program\n    - Leap year program\n    - Vowel/Consonant program\n    - small/capital letter\n    - assignments\n  - Loop control statement: for, while, do while\n  - Jump control statement: break, continue, return\n\n    - print 1-100 using for, while, do while loop\n    - print a-z\n    - print 2,4,...100 / even numbers from 1-100\n    - print 1,3,...99 / odd numbers from 1-100\n    - print sum of 1-n numbers\n    - print sum of even numbers from 1-100\n    - print sum of odd numbers from 1-100\n    - factorial of n\n    - series related program: 1+2+3+ ... + n\n    - series related program: 1^2+2^2+3^2+ ... + n^2\n    - Fibonacci series\n    - multiplication table\n    - nested related problems\n    - prime numbers\n    - prime numbers from 1 to n\n    - sum of digits\n    - reverse a number\n    - palindrome number\n    - Armstrong number\n    - user is valid or not by checking username,password\n    - Pattern related program\n\n- Data structure\n  - Array\n    - introduction to array\n    - sum and average\n    - maximum and minimum\n    - for each in array\n    - 2d array\n    - array matrix\n    - sum of diagonal, upper triangle, lower triangle elements of a matrix\n    - array output test\n    - array sorting\n  - ArrayList\n  - LinkedList\n  - HashMap\n  - HashSet\n- String\n  - String\n  - StringBuffer\n  - StringBuilder\n- Date \u0026 Time\n\n## Project Overview\n\n|                                                                                            |\n| :----------------------------------------------------------------------------------------: |\n|                                          Primary                                           |\n|      ![Primary](https://github.com/learnwithfair/java/blob/main/images/overview.png)       |\n|                                          Advances                                          |\n|      ![Advances](https://github.com/learnwithfair/java/blob/main/images/advance.png)       |\n|                                    JDBC, Socket, Thread                                    |\n| ![Advances](https://github.com/learnwithfair/java/blob/main/images/jdbc-socket-thread.png) |\n\n## 1. Basic Java\n\n### 1.1 Introduction to Java\n\n- What is Java?\n  - Java is a high level; OOP (Object Oriented Programming) language originally developed by sun microsystem but currenly owned by Oracle.\n- Why Should we learn Java / Features of Java?\n  - Platform Independent - WORA (Write Once Run Anywhere)\n  - Object Oriented\n  - Support web based application\n  - Robust (example - exception handling)\n  - Multi-threaded\n- What does platform independent means?\n  - Test.java -\u003e javac -\u003e Test.class (ByteCode) -\u003e Any JVM in any OS can run the ByteCode\n- History of Java\n  - C++ was not platform independent and could not support netwrok programming so sun microsystem took a project called \"green project\" in 1990 to sort out this issue.\n  - James Gosling (Father of Java), Patrick Naughton and Mike Sheridan was working in this project.\n  - At first it was names as Oak programming language but in 1994 they named it as Java.\n  - Java was officially released in 1995.\n- Java Certifications\n  ![oracle certification](images/oracle-java-certification-path.jpg)\n  ![oracle certification2](images/Java_Certification_Path.gif)\n- Java Versions\n  ![java-versions](images/java-versions.png)\n- Environment Setup\n\n  - JDK: Java Development Kit is a software development environment used for developinh java applications and applets. It includes Java Runtimne Environment (JRE), an interpreter / loader (java), a compiler (javac), a document generator (javadoc) and other toold needed in java development. Check JDK is installed or not by using this command `java -version` in your terminal\n    ![jdk](images/JDK_JRE_JVM-1.jpg)\n  - IDE: Integrated Development Environment. An Integrated Development Environment (IDE) is a software application that provides comprehensive tools and features to facilitate software development. Examples of IDE's: Eclipse, NetBeans, Visual Studio Code, JDeveloper, IntelliJ IDEA, Programiz Java Compiler. Here are some reasons why developers use IDEs:\n\n    1. Code Editing: IDEs offer advanced code editing capabilities such as syntax highlighting, code completion, and error checking. These features help developers write code more efficiently and with fewer mistakes.\n\n    2. Debugging: IDEs provide debugging tools that allow developers to step through their code, set breakpoints, and inspect variables. Debugging tools help identify and fix issues in the code during development.\n\n    3. Build and Compilation: IDEs integrate with build systems and compilers, making it easier to build, compile, and run the code. They can automate repetitive tasks such as compiling, packaging, and deploying the application.\n\n    4. Project Management: IDEs provide project management features that help organize and manage code files, libraries, and resources. They offer features like code navigation, search, and refactoring tools, making it easier to work with large codebases.\n\n    5. Version Control Integration: IDEs often have built-in support for version control systems like Git. They provide features to commit, update, and manage code changes, making collaboration with other developers smoother.\n\n    6. Code Templates and Snippets: IDEs offer code templates and snippets that help speed up development by providing predefined code structures or commonly used code snippets.\n\n    7. Testing and Profiling: IDEs may include tools for writing and running tests, as well as performance profiling to identify bottlenecks in the code and optimize performance.\n\n    8. Integration with Frameworks and Libraries: Many IDEs provide integration with popular frameworks and libraries, offering features like code generation, automated configuration, and easy access to documentation.\n\n### 1.2 First Java Application\n\n- File Extension .java\n- Every java application must have a class. class name must start with a capital letter.\n- A package is a folder which holds collection of classes and interfaces. package names are typically written in lowercase letters.\n\n```java\n\n// A program to print your info\n// Understand the program flow\n// keywords in Java - Keywords are reserved words and also in small letters\n// How to create a class, function\n// How to print in Java - use System.out.Println() or print()\n// what is string? printing string in quotation\n// printing numeric value does not require double quotation\nclass Program1 {\n  public static void main(String[] args) {\n    System.out.print(\"Product Infos\");\n    System.out.println(\"Product: iphone 14\");\n    System.out.println(\"Price: $1300\");\n    System.out.println(\"Quantity: 14\");\n  }\n}\n```\n\n#### Assigment 1 (print your information)\n\n### 1.3 Escape sequences / Backslash characters\n\n```java\n// Escape sequence - a special character followed by backslash. sometimes it is called as backshalsh character\n// example -\u003e \\b, \\t, \\n, \\\", \\', \\\\\n\nclass Test {\n  public static void main(String[] args) {\n    System.out.print(\"\\\"Product Infos\\\"\\n\");\n    System.out.println(\"Product:\\t iphone 14\");\n    System.out.println(\"Price:\\t\\t $1300\");\n    System.out.println(\"Quantity:\\t 14\");\n  }\n}\n```\n\n### 1.4 Types of Comments\n\n- Comments are used to add explanatory notes or annotations within the source code. It is good practice to add meaningful comments to your code to enhance its understandability and maintainability. Comments can help you and other developers understand the purpose of the code, clarify complex logic, or provide reminders for future modifications.\n  Java supports three types of comments:\n\n  1. Single-line comments: Single-line comments begin with two forward slashes (`//`) and extend to the end of the line. They are used for short comments or explanations on a single line.\n\n  ```java\n  // This is a single-line comment\n  int age = 25; // Variable representing the age\n  ```\n\n  2. Multi-line comments: Multi-line comments, also known as block comments, begin with a forward slash followed by an asterisk (`/*`) and end with an asterisk followed by a forward slash (`*/`). They can span multiple lines and are often used for longer explanations or comment blocks.\n\n  ```java\n  /*\n  This is a multi-line comment\n  It can span multiple lines\n  Used for longer explanations or comment blocks\n  */\n  ```\n\n  3. Javadoc comments: Javadoc comments are a special type of comment used for generating documentation from the source code. They begin with a forward slash followed by two asterisks (`/**`) and end with an asterisk followed by a forward slash (`*/`). Javadoc comments are used to describe classes, methods, and fields and can include tags for specifying parameters, return values, exceptions, and more.\n\n  ```java\n  /**\n    * This is a Javadoc comment.\n    * It can be used to generate documentation.\n    * @param name the name of the person\n    * @return a greeting message\n    */\n  public String greet(String name) {\n      return \"Hello, \" + name + \"!\";\n  }\n  ```\n\n### 1.5 Java program's Phases\n\n- Edit -\u003e Compile -\u003e Load -\u003e Verify -\u003e Execute\n  ![java-compilation-process](images/java-compilation-process.jpeg)\n\n### 1.6 Variable \u0026 Data types\n\n- A variable is a container for storing data. When declaring variables in Java, there are certain rules and conventions to follow. syntax: data-type variable-name;\n  Here are the key rules for variable declarations:\n\n1. Variable Names:\n\n   - Must start with a letter, underscore (\\_), or dollar sign ($).\n   - Can include letters, digits, underscores, and dollar signs.\n   - Cannot be a reserved word (e.g., keywords like \"int\", \"class\", \"public\").\n   - Follow camelCase convention (start with a lowercase letter, capitalize each subsequent word).\n\n2. Variable Types:\n   ![data type](images/datatypesinjava.png)\n   ![memory size for data types](images/memory-size.jpeg)\n   ![primtive-non-primitive](images/primitive-reference-type.jpeg)\n3. Initialization:\n\n   - Variables can be initialized at the time of declaration or later in the code.\n   - Uninitialized local variables cannot be used until they are assigned a value.\n\n4. Scope:\n\n   - Variables have different scopes, such as local scope, method scope, or class scope.\n   - Local variables are declared within a block of code and are only accessible within that block.\n   - Class variables (also known as static variables) are shared across instances of a class.\n   - Instance variables belong to a specific instance of a class.\n\n5. Constants:\n\n   - Constants are declared using the `final` keyword to indicate that their value cannot be changed.\n   - Constant variable names are typically written in uppercase with underscores for word separation (e.g., final int MAX_VALUE = 100).\n\n6. Naming Conventions:\n\n   - Use meaningful and descriptive names for variables.\n   - Follow camelCase convention for variable names (e.g., firstName, numItems).\n   - Avoid using single-character variable names (except for loop counters or temporary variables).\n   - Choose names that are easy to understand and maintain.\n\n7. Declaration and Assignment:\n   - Declare variables before using them in the code.\n   - Variables should be assigned values appropriate to their data type.\n   - Variables can be assigned new values using the assignment operator (=).\n\nHere's an example that illustrates these rules:\n\n```java\nclass Test {\n  public static void main(String[] args) {\n    String productName = \"iphone 14\";\n    double productPrice = 1300;\n    int productQuantity = 14;\n    final double PRODUCT_DISCOUNT = 10.133;\n    System.out.println(\"Product Infos\");\n    System.out.println(\"Product:  \" + productName);\n    System.out.println(\"Price: $\" + productPrice);\n    System.out.println(\"Quantity: \" + productQuantity);\n    System.out.println(\"Discount: \" + PRODUCT_DISCOUNT);\n  }\n}\n\n/*\n * Learning outcomes\n * variable declaration\n * variable initalization\n * dynamic initialization\n * data types\n */\npublic class Program4 {\n  public static void main(String[] args) {\n\n    // declaring variables for a student\n    String name;\n    int id, age;\n    double gpa;\n    boolean isRegisted;\n\n    // initializing variables for a student\n    name = \"Anisul Islam\";\n    id = 1302020017;\n    age = 25;\n    gpa = 3.92;\n    isRegisted = true;\n\n    // printing variables\n    System.out.println(\"Student Information\");\n    System.out.println(\"--------------------\");\n    System.out.println(\"Name: \"+name);\n    System.out.println(\"ID: \"+id);\n    System.out.println(\"Age: \"+age);\n    System.out.println(\"GPA: \"+gpa);\n    System.out.println(\"Registered: \"+isRegisted);\n  }\n}\n```\n\nBy following these rules and conventions, you can write clean, readable, and maintainable code in Java.\n\n#### Assignment-2 (Variable and Data type)\n\n```java\n  /*\n  * Assignment-2 (Variable and Data type)\n  * step 1: create a class called Product\n  * step 2: create a main method\n  * step 3: declare variables: id, title, price, description, category\n  * step 4: assign the following data in main method\n  101,iphone15,1895 euros,perfect product with best image quality, phone,\n  * step 5: print the data\n*/\n```\n\n### 1.7 Format specifiers\n\n- Format specifiers in Java are used to control the formatting of values when outputting them using methods like System.out.printf() or String.format(). They provide a way to specify how a value should be displayed, including its width, precision, alignment, and data type.\n\n```java\n/*\n * Learning outcomes\n * format specifiers\n */\npublic class Program5 {\n  public static void main(String[] args) {\n\n    // declaring variables for a student\n    String name;\n    int id, age;\n    double gpa;\n    boolean isRegisted;\n\n    // initializing variables for a student\n    name = \"Anisul Islam\";\n    id = 1302020017;\n    age = 25;\n    gpa = 3.92;\n    isRegisted = true;\n\n    // printing variables\n    System.out.println(\"Student Information\");\n    System.out.println(\"--------------------\");\n    System.out.printf(\"Name: \"+name);\n    System.out.printf(\"Name: %s\\n\",name);\n    System.out.printf(\"ID : %d: \\n\",id);\n    System.out.printf(\"Age: %d\\n\",age);\n    System.out.printf(\"GPA: %.2f\\n\",gpa);\n    System.out.printf(\"Registered: %b\\n\",isRegisted);\n  }\n}\n```\n\n### 1.8 Getting User Input\n\n```java\nimport java.util.Scanner;\n\nclass Test {\n  public static void main(String[] args) {\n    try (Scanner input = new Scanner(System.in)) {\n      // String productName = input.next(); // does not count anything after space\n      System.out.print(\"Enter Product Name: \");\n      String productName = input.nextLine();\n\n      System.out.print(\"Enter Product Price: \");\n      double productPrice = input.nextDouble();\n\n      System.out.print(\"Enter Product Quantity: \");\n      int productQuantity = input.nextInt();\n\n      final double PRODUCT_DISCOUNT = 10.133;\n      System.out.println(\"Product Infos\");\n      System.out.println(\"Product:  \" + productName);\n      System.out.println(\"Price: $\" + productPrice);\n      System.out.println(\"Quantity: \" + productQuantity);\n      System.out.println(\"Discount: \" + PRODUCT_DISCOUNT);\n    }\n  }\n}\n\n/*\nLearning outcome\nhow to get user input\nRead a byte - nextByte()\nRead a short - nextShort()\nRead an int - nextInt()\nRead a long - nextLong()\nRead a float - nextFloat()\nRead a double - nextDouble()\nRead a boolean - nextBoolean()\nRead a complete line - nextLine()\nRead a word - next()\n */\nimport java.util.Scanner;\n\npublic class Program6 {\n  public static void main(String[] args) {\n    Scanner input = new Scanner(System.in);\n\n    // declaring variables for a student\n    String name;\n    int id, age;\n    double gpa;\n    boolean isRegisted;\n\n    // getting inputs for a student\n    System.out.print(\"Enter student name: \");\n    name = input.nextLine();\n\n    System.out.print(\"Enter student id: \");\n    id =  input.nextInt();\n\n    System.out.print(\"Enter student age: \");\n    age =  input.nextInt();\n\n    System.out.print(\"Enter student gpa: \");\n    gpa =  input.nextDouble();\n\n    System.out.print(\"Enter student is isregistered? true/false : \");\n    isRegisted =  input.nextBoolean();\n\n    // printing variables\n    System.out.println(\"Student Information\");\n    System.out.println(\"--------------------\");\n    System.out.println(\"Name: \"+name);\n    System.out.println(\"ID: \"+id);\n    System.out.println(\"Age: \"+age);\n    System.out.println(\"GPA: \"+gpa);\n    System.out.println(\"Registered: \"+isRegisted);\n  }\n}\n```\n\n#### Assignment-3 (User Input)\n\n```java\n/*\n * Assignment-3 (User Input)\n * step 1: create a class called Product\n * step 2: create a main method\n * step 3: declare variables: id, title, price, description, category\n * step 4: get user input for each variables\n* step 5: print the variables\n */\n\n```\n\n### 1.9 Operators, Operands, Expression\n\n- In Java, operators are symbols or characters that perform specific operations on operands (variables, literals, or expressions). They are used to manipulate and process data within expressions and statements. Here are the different types of operators in Java:\n\n1. Arithmetic Operators:\n\n   - Addition: `+`\n   - Subtraction: `-`\n   - Multiplication: `*`\n   - Division: `/`\n   - Modulus (remainder): `%`\n   - Increment: `++`\n   - Decrement: `--`\n\n   ```java\n   // Example of Arithmetic operators\n   import java.util.Scanner;\n\n   public class Program7 {\n     public static void main(String[] args) {\n       int number1, number2, result;\n       Scanner input = new Scanner(System.in);\n\n       System.out.print(\"number1 = \");\n       number1 = input.nextInt();\n       System.out.print(\"number2 = \");\n       number2 = input.nextInt();\n\n       result = number1 + number2;\n       System.out.println(number1 +\" + \"+number2 + \" = \"+result);\n\n       result = number1 - number2;\n       System.out.println(number1 +\" - \"+number2 + \" = \"+result);\n\n       result = number1 * number2;\n       System.out.println(number1 +\" * \"+number2 + \" = \"+result);\n\n       // type casting\n       double result2 = (double)number1 / number2;\n       System.out.println(number1 +\" / \"+number2 + \" = \"+result2);\n\n       result = number1 % number2;\n       System.out.println(number1 +\" % \"+number2 + \" = \"+result);\n\n     }\n   }\n   ```\n\n   ```java\n      // Example of Unary Operators\n     /*\n     * Unary Operator\n     * Unary Plus, minus\n     * increment -\u003e prefix increment, postfix increment\n     * decrement -\u003e prefix decrement, postfix decrement\n     */\n     public class Program10 {\n       public static void main(String[] args) {\n         int x = 10;\n         System.out.println(+x);\n         System.out.println(-x);\n         System.out.println(x++);\n         System.out.println(++x);\n         System.out.println(x);\n         System.out.println(x--);\n         System.out.println(--x);\n       }\n     }\n\n   ```\n\n2. Assignment Operators:\n\n   - Assignment: `=`\n   - Addition assignment: `+=`\n   - Subtraction assignment: `-=`\n   - Multiplication assignment: `*=`\n   - Division assignment: `/=`\n   - Modulus assignment: `%=`\n\n   ```java\n   // Example of Assignment operators\n   public class Program8 {\n     public static void main(String[] args) {\n     int x = 10;\n     x += 1;\n     System.out.println(\"x = \"+x);\n     x -= 1;\n     System.out.println(\"x = \"+x);\n     x *= 1;\n     System.out.println(\"x = \"+x);\n     x /= 1;\n     System.out.println(\"x = \"+x);\n     x %= 1;\n     System.out.println(\"x = \"+x);\n     }\n   }\n   ```\n\n3. Comparison Operators:\n\n   - Equal to: `==`\n   - Not equal to: `!=`\n   - Greater than: `\u003e`\n   - Less than: `\u003c`\n   - Greater than or equal to: `\u003e=`\n   - Less than or equal to: `\u003c=`\n\n4. Logical Operators:\n\n   - Logical AND: `\u0026\u0026`\n   - Logical OR: `||`\n   - Logical NOT: `!`\n\n5. Bitwise Operators:\n\n   - Bitwise AND: `\u0026`\n   - Bitwise OR: `|`\n   - Bitwise XOR: `^`\n   - Bitwise NOT: `~`\n   - Left shift: `\u003c\u003c`\n   - Right shift: `\u003e\u003e`\n   - Unsigned right shift: `\u003e\u003e\u003e`\n\n   ```java\n    // Example of bitwise operators\n   ```\n\n6. Conditional (Ternary) Operator:\n\n   - The conditional operator (`?:`) is used to assign a value based on a condition. It has the form `condition ? expression1 : expression2`. If the condition is true, `expression1` is evaluated and assigned; otherwise, `expression2` is evaluated and assigned.\n\n   ```java\n      // ternary/conditional operator exp1 ? exp2 : exp3\n      public class Program16 {\n        public static void main(String[] args) {\n          int number = 20;\n          String result = number%2==0 ? \"even\" : \"odd\";\n          System.out.println(result);\n        }\n      }\n   ```\n\n7. Instanceof Operator:\n\n   - The instanceof operator is used to check if an object belongs to a particular class or implements an interface. It has the form `object instanceof type`.\n\n8. Other Operators:\n   - Dot Operator (`.`): Used to access members of a class or object.\n   - Comma Operator (`,`): Used to separate expressions in a statement.\n   - Parentheses (`()`): Used to group expressions and specify evaluation order.\n   - Square Brackets (`[]`): Used for array indexing.\n   - New Operator: Used to create objects with the `new` keyword.\n\n#### Assignment-4 (installment amount for per month)\n\n```java\nimport java.util.Scanner;\n// Create a program to calculate installment amount for per month\npublic class Assignment4 {\n  public static void main(String[] args) {\n\n    (Scanner input = new Scanner(System.in)) {\n      int phonePrice = 1800; // 1800 euros\n      int numberOfInstallment, installmentPerMonth;\n\n      System.out.print(\"Number of installments? \");\n      // get number of installments from user\n\n\n      // calculate  installment amount for per month\n\n\n        System.out.println(\"Monthly installment Amount: \"+installmentPerMonth + \" euros\");\n    }\n\n  }\n}\n```\n\n#### Area of Triangle Program\n\n```java\n// Area of Triangle Program\nimport java.util.Scanner;\npublic class Program9 {\n  public static void main(String[] args) {\n    double base, height, area;\n\n    Scanner input = new Scanner(System.in);\n\n    System.out.print(\"Enter Base = \");\n    base = input.nextInt();\n\n    System.out.print(\"Enter Height = \");\n    height = input.nextInt();\n\n    area = 0.5 * base * height;\n\n    System.out.println(\"Area of Triangle = \"+area);\n  }\n}\n\n```\n\n#### Temperature Converter\n\n```java\n\n// Temperature convert\n// F = 9/5 C + 32\nimport java.util.Scanner;\n\nclass Test {\n\n  public static void main(String[] args) {\n    try (Scanner input = new Scanner(System.in)) {\n      System.out.print(\"Enter Celsisu : \");\n      double celsius = input.nextDouble();\n\n      double fahrenheit = 9 / 5.0 * celsius + 32;\n      System.out.println(\"Fahrenheit: \" + fahrenheit);\n    }\n  }\n}\n```\n\n### 1.10 Control statements\n\n- There are 3 types of control statements: Conditional, loop, jump control statements.\n\n#### 1.10.1 Conditional Control Statements\n\n- if Statement: It executes a block of code if a certain condition is true.\n- if-else Statement: It executes one block of code if the condition is true and another block if the condition is false.\n- if-else-if Ladder: It allows multiple conditions to be checked one after another, and the corresponding block of code is executed based on the first condition that evaluates to true.\n- switch Statement: It checks a variable against multiple possible values and executes the code block associated with the matching value.\n\n  - Positive, Negative Program - if, else if, else\n\n    ```java\n        // Positive, Negative Program - if, else if, else\n        public class Program12 {\n          public static void main(String[] args) {\n            int number = 12;\n            if(number\u003e0){\n              System.out.println(\"Positive\");\n            }else if(number\u003c0){\n              System.out.println(\"Negative\");\n            }else{\n              System.out.println(\"Zero\");\n            }\n          }\n        }\n    ```\n\n  - Switch: Day of week\n\n  ```java\n      // Switch: Day of week\n      public class Program12 {\n        public static void main(String[] args) {\n            int dayOfWeek = 3;\n            switch (dayOfWeek) {\n                case 1:\n                    System.out.println(\"Monday\");\n                    break;\n                case 2:\n                    System.out.println(\"Tuesday\");\n                    break;\n                case 3:\n                    System.out.println(\"Wednesday\");\n                    break;\n                default:\n                    System.out.println(\"Unknown day\");\n            }\n        }\n      }\n  ```\n\n  - vowel or consonant program\n\n  ```java\n      // vowel or consonant program\n      import java.util.Scanner;\n\n      public class Program13 {\n        public static void main(String[] args) {\n          try (Scanner input = new Scanner(System.in)) {\n            System.out.print(\"Enter a letter: \");\n            char ch = input.next().charAt(0);\n\n            if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {\n              System.out.println(\"Vowel\");\n            } else {\n              System.out.println(\"Consonant\");\n            }\n          }\n        }\n      }\n\n  ```\n\n  - small /capital letter\n\n  ```java\n\n   // small /capital letter\n   import java.util.Scanner;\n\n   public class Program14 {\n     public static void main(String[] args) {\n       try (Scanner input = new Scanner(System.in)) {\n         System.out.print(\"Enter a letter: \");\n         char ch = input.next().charAt(0);\n\n         if (ch \u003e= 'a' \u0026\u0026 ch \u003c= 'z') {\n           System.out.println(\"Small letter\");\n         } else if (ch \u003e= 'A' \u0026\u0026 ch \u003c= 'Z') {\n           System.out.println(\"Capital letter\");\n         } else {\n           System.out.println(\"Not a letter\");\n         }\n\n       }\n\n     }\n   }\n\n  ```\n\n#### Assignment-5 (valid voter using if else)\n\n```java\n   /*\n   * valid voter program using if,else\n   * step 1: ask for a person age\n   * step 2: if age is equal or more than 18 than print valid voter\n   * step 3: else print invalid voter\n   */\n   public class Assignment5 {\n     public static void main(String[] args) {\n\n     }\n   }\n```\n\n#### Assignment-6 (Digit spelling using if else)\n\n```java\n   /*\n     * Digit spelling program using if,else if, else\n     * step 1: ask for a digit between 0-9\n     * step 2: check the digit and print it by spelling. example if user input is 0 then print Zero\n     * step 3: if the digit is not among 0-9 then print Invalid digit\n     */\n     public class Assignment6 {\n       public static void main(String[] args) {\n\n       }\n     }\n\n```\n\n#### Assignment-7 (logical operators and if else)\n\n```java\n   // Logical or assignment\n   // step 1: Print \"Do you love java? \"\n   // step 2: take user input y / Y / n / N\n   // step 3: if user input y / Y then print you are a java lover\n   // step 4: if user input n / N then print you are not a java lover\n   public class Assignment7 {\n     public static void main(String[] args) {\n\n     }\n   }\n```\n\n#### Assignment-8 (Logical AND assignment and if-else)\n\n```java\n   // Logical AND assignment\n   // Check eligible candidate\n   // Step 1: Ask the candidate have you completed your masters? y/n\n   // Step 2: Ask the candidate are you fulent in English? y/n\n   // Step 3: if the candidate has passed masters and also have fluent english skill then print you are eligible to for the job interview\n   // Step 4: else print Sorry. you are not eligible to for the job interview\n   public class Assignment8 {\n     public static void main(String[] args) {\n\n     }\n   }\n\n```\n\n#### Assignment-9 (Call center using switch)\n\n```java\n   // switch assignment: call center\n   // if user select option 1 then set language bengali\n   // if user select option 2 then set language hindi\n   // if user select option 3 then set language urdu\n   // for any other option set language english\n   public class Assignment9 {\n     public static void main(String[] args) {\n       // get the OPTION from user\n       // use switch, case, break and default\n\n       // Selected language is Bengali\n       // Selected language is Hindi\n       // Selected language is Urdu\n       // Selected language is English\n     }\n   }\n\n```\n\n#### 1.10.2 Looping Control Statements\n\n- while Loop: It repeatedly executes a block of code as long as a condition is true.\n- do-while Loop: It executes a block of code at least once and then repeatedly executes it as long as a condition is true.\n- for Loop: It allows you to specify the initialization, condition, and iteration in a single line and repeatedly executes a block of code based on the condition.\n- for-each Loop: It is used to iterate over elements of an array or a collection.\n\n  - Example of for, while, do while, for each loop\n\n  ```java\n   // print 1-10 using loop control statements\n\n   System.out.println(\"Using for loop:\");\n   for (int i = 1; i \u003c= 10; i++) {\n       System.out.println(i);\n   }\n\n   System.out.println(\"Using while loop:\");\n   int i = 1;\n   while (i \u003c= 10) {\n       System.out.println(i);\n       i++;\n   }\n\n   System.out.println(\"Using do-while loop:\");\n   int i = 1;\n   do {\n       System.out.println(i);\n       i++;\n   } while (i \u003c= 10);\n\n   System.out.println(\"Using for-each loop:\");\n   int[] numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};\n   for (int number : numbers) {\n       System.out.println(number);\n   }\n  ```\n\n  - Sum of digits Program\n\n  ```java\n    import java.util.Scanner;\n\n    class Test {\n      public static void main(String[] args) {\n        try (Scanner input = new Scanner(System.in)) {\n          System.out.print(\"Enter a number: \");\n          int number = input.nextInt();\n          int temp = number;\n          int remainder, sum = 0;\n          while (temp != 0) {\n            remainder = temp % 10;\n            sum = sum + remainder;\n            temp = temp / 10;\n          }\n          System.out.println(\"The sum of digits of \" + number + \" = \" + sum);\n        } catch (Exception e) {\n          System.out.println(e);\n        }\n      }\n    }\n  ```\n\n  - Reverse number Program\n\n  ```java\n      import java.util.Scanner;\n\n      class Test {\n        public static void main(String[] args) {\n          try (Scanner input = new Scanner(System.in)) {\n            System.out.print(\"Enter a number: \");\n            int number = input.nextInt();\n            int temp = number;\n            int remainder, reverse = 0;\n            while (temp != 0) {\n              remainder = temp % 10;\n              reverse = (reverse * 10) + remainder;\n              temp = temp / 10;\n            }\n            System.out.println(\"The reverse of \" + number + \" = \" + reverse);\n          } catch (Exception e) {\n            System.out.println(e);\n          }\n        }\n      }\n  ```\n\n  - Palindrome number Program\n\n  ```java\n    import java.util.Scanner;\n\n    class Test {\n      public static void main(String[] args) {\n        try (Scanner input = new Scanner(System.in)) {\n          System.out.print(\"Enter a number: \");\n          int number = input.nextInt();\n          int temp = number;\n          int remainder, reverse = 0;\n          while (temp != 0) {\n            remainder = temp % 10;\n            reverse = (reverse * 10) + remainder;\n            temp = temp / 10;\n          }\n          if (number == reverse) {\n            System.out.println(number + \" is a Palindrome number\");\n          } else {\n            System.out.println(number + \" is not a Palindrome number\");\n          }\n\n        } catch (Exception e) {\n          System.out.println(e);\n        }\n      }\n    }\n  ```\n\n  - Armstrong number Program\n\n  ```java\n      import java.util.Scanner;\n\n      public class Program30 {\n        public static void main(String[] args) {\n          try (Scanner input = new Scanner(System.in)) {\n            System.out.print(\"Enter any postive integer: \");\n            int number = input.nextInt();\n            int temp = number;\n            int sum = 0;\n            while(temp!=0){\n                int r = temp % 10;\n                sum = sum + r*r*r;\n                temp = temp / 10;\n            }\n          if(number == sum){\n            System.out.println(\"Armstrong number\");\n          }\n          else{\n            System.out.println(\"Not a Armstrong number\");\n          }\n          }\n        }\n      }\n\n  ```\n\n  - Series program 1+2+3+ ... + n\n\n  ```java\n\n  ```\n\n  - Fibonacci series Program 0 1 1 2 3 5 ... n\n\n  ```java\n    import java.util.Scanner;\n\n    public class Program26 {\n      public static void main(String[] args) {\n        try (Scanner input = new Scanner(System.in)) {\n\n          System.out.print(\"How many fibonacci numbers? \");\n          int n = input.nextInt();\n\n          int first = 0;\n          int second = 1;\n\n          for(int i=1; i\u003c=n; i++){\n            if(i\u003c=2){\n              System.out.print(\" \"+ (i-1));\n            }else{\n              int fibo =  first + second;\n              System.out.print(\" \"+fibo);\n              first = second;\n              second = fibo;\n            }\n          }\n\n        }\n      }\n    }\n\n  ```\n\n  - Lucas series Program 2 1 3 4 7 ... n\n\n  ```java\n    public class LucasSeries {\n      public static void main(String[] args) {\n          int limit = 10; // Define the limit of the Lucas series\n\n          System.out.println(\"Lucas series up to \" + limit + \":\");\n          generateLucasSeries(limit);\n      }\n\n      public static void generateLucasSeries(int limit) {\n          int first = 2; // First number in the Lucas series\n          int second = 1; // Second number in the Lucas series\n\n          // Print the first two numbers\n          System.out.print(first + \" \" + second + \" \");\n\n          // Generate subsequent numbers in the Lucas series\n          for (int i = 3; i \u003c= limit; i++) {\n              int next = first + second;\n              System.out.print(next + \" \");\n\n              // Update values for the next iteration\n              first = second;\n              second = next;\n          }\n\n          System.out.println(); // Print a new line after the series\n      }\n    }\n  ```\n\n  - Pattern related program\n\n  ```java\n      // 1\n      // 1 2\n      // 1 2 3\n      import java.util.Scanner;\n\n      public class Program31 {\n        public static void main(String[] args) {\n          try (Scanner input = new Scanner(System.in)) {\n            System.out.print(\"Enter n = \");\n            int n= input.nextInt();\n            for(int row=1; row\u003c=n; row++){\n              for (int col=1; col\u003c=row; col++){\n                System.out.print(\" \"+col);\n              }\n              System.out.println();\n            }\n          }\n\n        }\n      }\n\n  ```\n\n#### Assignment 10 (find sum of 1-10 using for loop)\n\n```java\n// find sum of 1-10 using for loop\npublic class Assignment10 {\n  public static void main(String[] args) {\n\n  }\n}\n```\n\n#### Assignment 11 (find factorial of n)\n\n```java\n// find factorial of n\npublic class Assignment11 {\n  public static void main(String[] args) {\n\n  }\n}\n\n```\n\n#### Assignment 12 (print sum of odd numbers from m-n)\n\n```java\n// print sum of odd numbers from m-n\npublic class Assignment12 {\n  public static void main(String[] args) {\n\n  }\n}\n\n```\n\n#### Assignment 13 (find nth fibonacci number)\n\n```java\n// find nth fibonacci number\nimport java.util.Scanner;\npublic class Assignment13 {\n  public static void main(String[] args) {\n    try (Scanner input = new Scanner(System.in)) {\n\n      System.out.print(\"which fibonacci number you want to see? \");\n      int n = input.nextInt();\n\n\n    }\n  }\n}\n```\n\n#### Assignment 14 (Palindrome number)\n\n```java\n// 1. generate and print palindrome numbers from m-n\n// 2. count and print number of palindrome numbers\nimport java.util.Scanner;\npublic class Assignment14 {\n   public static void main(String[] args) {\n    try (Scanner input = new Scanner(System.in)) {\n      System.out.print(\"start number: \");\n      int m = input.nextInt();\n\n      System.out.print(\"end number: \");\n      int n = input.nextInt();\n\n      int totalPalindromeNumber=0;\n\n\n     System.out.println(\"Total Palindrome numbers : \"+totalPalindromeNumber);\n    }\n  }\n}\n\n```\n\n#### Assignment 15 (Armstrong number)\n\n```java\n// 1. generate and print armstrong numbers from m-n\n// 2. count and print number of armstrong numbers\nimport java.util.Scanner;\npublic class Assignment15 {\n   public static void main(String[] args) {\n    try (Scanner input = new Scanner(System.in)) {\n      System.out.print(\"start number: \");\n      int m = input.nextInt();\n\n      System.out.print(\"end number: \");\n      int n = input.nextInt();\n\n      int totalArmstrongNumber=0;\n\n\n     System.out.println(\"Total armstrong numbers : \"+totalArmstrongNumber);\n    }\n  }\n}\n\n```\n\n#### Assignment 17 (Pattern program)\n\n```java\n// Create a pattern like following one if n=4\n/*\n 1\n 1 0\n 1 0 1\n 1 0 1 0\n */\npublic class Assignment17 {\n  public static void main(String[] args) {\n\n  }\n}\n\n```\n\n#### 1.10.3 Jump Control Statements\n\n- break Statement: It terminates the current loop or switch statement and transfers control to the statement following the loop or switch.\n- continue Statement: It skips the rest of the current iteration of a loop and moves to the next iteration.\n- return Statement: It terminates the execution of a method and returns control to the caller.\n- throw Statement: It is used to explicitly throw an exception to handle exceptional situations.\n\n  - break and continue example\n\n    ```java\n      // break Statement\n      for (int i = 0; i \u003c 5; i++) {\n          if (i == 3) {\n              break;\n          }\n          System.out.println(\"i: \" + i);\n      }\n\n      // continue Statement\n      for (int i = 0; i \u003c 5; i++) {\n          if (i == 2) {\n              continue;\n          }\n          System.out.println(\"i: \" + i);\n      }\n    ```\n\n  - Prime number Program\n\n  ```java\n      import java.util.Scanner;\n      public class Test {\n        public static void main(String[] args) {\n          try (Scanner input = new Scanner(System.in)) {\n            System.out.print(\"Enter a positive integer: \");\n            int number = input.nextInt();\n            int count = 0;\n\n            if (number \u003c 2) {\n              System.out.println(\"Not Prime number\");\n            } else {\n              for (int i = 2; i \u003c= Math.sqrt(number); i++) {\n                if (number % i == 0) {\n                  count++;\n                  break;\n                }\n              }\n              if (count == 0) {\n                System.out.println(\"Prime number\");\n              } else {\n                System.out.println(\"Not Prime number\");\n              }\n\n            }\n          } catch (Exception e) {\n            System.out.println(\"Invalid input\");\n          }\n        }\n      }\n  ```\n\n  - Prime number Program using function\n\n  ```java\n    import java.util.Scanner;\n\n    public class PrimeProgram {\n        public static void main(String[] args) {\n            try (Scanner input = new Scanner(System.in)) {\n                System.out.print(\"Enter a positive integer: \");\n                int number = input.nextInt();\n\n                if (isPrime(number)) {\n                    System.out.println(\"Prime number\");\n                } else {\n                    System.out.println(\"Not Prime number\");\n                }\n            } catch (Exception e) {\n                System.out.println(\"Invalid input\");\n            }\n        }\n\n        private static boolean isPrime(int number) {\n            if (number \u003c 2) {\n                return false;\n            }\n            for (int i = 2; i \u003c= Math.sqrt(number); i++) {\n                if (number % i == 0) {\n                    return false;\n                }\n            }\n            return true;\n        }\n    }\n  ```\n\n  - Total Prime number from m to n program\n\n  ```java\n    import java.util.Scanner;\n\n    class Program25 {\n      public static void main(String args[]) {\n        try (Scanner input = new Scanner(System.in)) {\n          int m, n;\n          int count = 0;\n          int totalprime = 0;\n          System.out.print(\"Enter initial number:\");\n          m = input.nextInt();\n          System.out.print(\"Enter last number: \");\n          n = input.nextInt();\n\n          for (int i = m; i \u003c= n; i++) {\n            if (i \u003c 2) {\n              continue;\n            } else {\n              for (int j = 2; j \u003c i; j++) {\n                if (i % j == 0) {\n                  count++;\n                  break;\n                }\n              }\n              if (count == 0) {\n                System.out.println(i);\n                totalprime++;\n              }\n              count = 0;\n            }\n          }\n          System.out.println(\"total prime:\" + totalprime);\n        }\n      }\n    }\n  ```\n\n#### Assignment 16 - find nth fibonacci number\n\n```java\n// validate user based on username and password\n// input username and password until username==\"anis\" and password==\"123456\"\n// if username and password does not match print \"username/password is incorrect. Please try again\"\n// if username and password does not match print \"welcome to the system\"\n```\n\n### 1.11 Arrays and ArrayList\n\n- Array: In Java, an array is a data structure that allows you to store a fixed-size collection of elements of the same type. It provides a convenient way to work with groups of related data. Arrays provide a way to store and manipulate collections of elements in a concise and efficient manner. They are widely used in Java to represent lists of items, collections of data, and matrices. Understanding arrays is fundamental for many programming tasks and algorithms. Here's an explanation of arrays in Java:\n\n1. Declaration and Initialization:\n\n   - To declare an array, you specify the type of elements it will hold, followed by square brackets `[]`, and then the name of the array. For example: `int[] numbers;`\n   - To initialize an array, you can assign it a new array object using the `new` keyword, followed by the type and the size of the array. For example: `numbers = new int[5];`\n   - Alternatively, you can declare and initialize an array in a single line: `int[] numbers = new int[5];`\n\n2. Accessing Elements:\n\n   - Array elements are accessed using an index, which starts at 0 for the first element. For example: `int firstElement = numbers[0];`\n   - You can assign values to array elements using the index: `numbers[0] = 10;`\n\n3. Length:\n\n   - The length of an array is determined by the number of elements it can hold. You can retrieve the length of an array using the `length` property: `int size = numbers.length;`\n\n4. Iterating Over an Array:\n\n   - You can use a loop, such as the `for` loop, to iterate over the elements of an array. For example:\n\n     ```java\n     for (int i = 0; i \u003c numbers.length; i++) {\n         int element = numbers[i];\n         // Do something with the element\n     }\n     ```\n\n5. Array Initialization with Values:\n\n   - You can initialize an array with values at the time of declaration using an initializer list. For example: `int[] numbers = {1, 2, 3, 4, 5};`\n\n6. Multidimensional Arrays:\n\n   - Java also supports multidimensional arrays, where each element is itself an array. For example: `int[][] matrix = new int[3][4];`\n   - we can only assign row size and later the column.\n\n   ```java\n   int[][] numbers = new int[4][];\n   numbers[0] = new int[1];\n   numbers[1] = new int[2];\n   numbers[2] = new int[3];\n   numbers[3] = new int[4];\n   ```\n\n7. Array Copying:\n   - Java provides the `System.arraycopy()` method and the `Arrays.copyOf()` method to copy the elements of one array to another.\n\n- one dimensional array example\n\n```java\npublic class Program32 {\n  public static void main(String[] args) {\n    int[] numbers; // array declaration\n    numbers = new int[5]; //array creation\n\n    numbers[0] = 10;\n    numbers[1] = 20;\n    numbers[2] = 30;\n    numbers[3] = 40;\n    numbers[4] = 50;\n\n    int sum=0;\n    for(int x=0; x\u003cnumbers.length;x++){\n      sum+=numbers[x];\n    }\n\n    int max=numbers[0];\n    int min=numbers[0];\n    for(int x=1;x\u003cnumbers.length; x++){\n      if(max\u003cnumbers[x]){\n        max=numbers[x];\n      }\n      if(min\u003enumbers[x]){\n        min=numbers[x];\n      }\n    }\n    System.out.println(\"Sum of Array = \"+sum);\n    System.out.println(\"Average of Array = \"+((float)sum/numbers.length));\n     System.out.println(\"Maximum number of Array = \"+max);\n     System.out.println(\"Minimum number of Array = \"+min);\n\n  }\n}\n```\n\n- one dimensional string array example\n\n```java\n // for each or enhanched for loop\nimport java.util.Scanner;\n\npublic class Program33 {\n  public static void main(String[] args) {\n\n       try (Scanner input = new Scanner(System.in)) {\n\n        String[] countries = {\"Bangladesh\", \"Pakistan\", \"England\", \"India\"};\n\n        for (String country : countries) {\n          System.out.println(country);\n        }\n\n      }\n  }\n}\n\n```\n\n- Two dimensional array example\n\n```java\npublic class Program34 {\n  public static void main(String[] args) {\n    int [][] numbers = new int[3][3]; // 3 rows x 3 columns = 9 items\n\n    // first row\n    numbers[0][0] = 1;\n    numbers[0][1] = 2;\n    numbers[0][2] = 3;\n\n    // second row\n    numbers[1][0] = 4;\n    numbers[1][1] = 5;\n    numbers[1][2] = 6;\n\n    // third row\n    numbers[2][0] = 7;\n    numbers[2][1] = 8;\n    numbers[2][2] = 9;\n\n    // printing 2d array\n    for(int row=0; row\u003cnumbers.length; row++){\n      for(int col=0; col\u003cnumbers[row].length; col++){\n        System.out.print(numbers[row][col]);\n      }\n      System.out.println();\n    }\n  }\n}\n```\n\n- Array Matrix Sum Example\n\n```java\nimport java.util.Scanner;\n\n// Matrix Program\n// A + B = ?\npublic class Program35 {\n\n  static void printMatrix(int[][] number) {\n    for (int row = 0; row \u003c number.length; row++) {\n      for (int column = 0; column \u003c number[row].length; column++) {\n        System.out.print(\" \" + number[row][column]);\n      }\n      System.out.println();\n    }\n  }\n\n  public static void main(String[] args) {\n    int[][] A = new int[2][3];\n    int[][] B = new int[2][3];\n    int[][] C = new int[2][3];\n\n    try (Scanner input = new Scanner(System.in)) {\n\n      System.out.println(\"Input for A Matrix\");\n      for (int row = 0; row \u003c A.length; row++) {\n        for (int column = 0; column \u003c A[row].length; column++) {\n          System.out.printf(\"A[%d][%d] = \", row, column);\n          A[row][column] = input.nextInt();\n        }\n      }\n\n      System.out.println(\"Printing A Matrix\");\n      printMatrix(A);\n\n      System.out.println(\"Input for B Matrix\");\n      for (int row = 0; row \u003c B.length; row++) {\n        for (int column = 0; column \u003c B[row].length; column++) {\n          System.out.printf(\"B[%d][%d] = \", row, column);\n          B[row][column] = input.nextInt();\n        }\n      }\n\n      System.out.println(\"Printing B Matrix\");\n      printMatrix(B);\n\n      // calculating C=A+B\n      for (int row = 0; row \u003c B.length; row++) {\n        for (int column = 0; column \u003c B[row].length; column++) {\n          C[row][column] = A[row][column] + B[row][column];\n        }\n      }\n\n      System.out.println(\"Printing C Matrix\");\n      printMatrix(C);\n    }\n\n  }\n}\n```\n\n- Array Matrix Multiplication Example\n\n```java\n\n```\n\n- Array Diagonal Matrix Example\n\n```java\n\n```\n\n- Create programs based on Array output examples\n\n```java\n/**\n * 0 1 2 3 4\n * 5 6 7 8 9\n * 10 11 12 13 14\n * 15 16 17 18 19\n*/\npublic class Test {\n  public static void main(String[] args) {\n    int[][] A = new int[4][5];\n    int count = 0;\n\n    // assign values to the 2d array\n    for (int i = 0; i \u003c 4; i++) {\n      for (int j = 0; j \u003c 5; j++) {\n        A[i][j] = count++;\n      }\n    }\n\n    // print values to the 2d array\n    for (int i = 0; i \u003c 4; i++) {\n      for (int j = 0; j \u003c 5; j++) {\n        System.out.print(A[i][j] + \" \");\n      }\n      System.out.println();\n    }\n  }\n}\n```\n\n```java\n/**\n * 0\n * 1 2\n * 3 4 5\n * 6 7 8 9\n*/\n\npublic class Test {\n  public static void main(String[] args) {\n    int[][] A = new int[4][];\n    A[0] = new int[1];\n    A[1] = new int[2];\n    A[2] = new int[3];\n    A[3] = new int[4];\n    int count = 0;\n\n    // assign values to the 2d array\n    for (int i = 0; i \u003c A.length; i++) {\n      for (int j = 0; j \u003c i + 1; j++) {\n        A[i][j] = count++;\n      }\n    }\n\n    // print values to the 2d array\n    for (int i = 0; i \u003c A.length; i++) {\n      for (int j = 0; j \u003c i + 1; j++) {\n        System.out.print(A[i][j] + \" \");\n      }\n      System.out.println();\n    }\n  }\n}\n```\n\n- Array sorting (Ascending and descending)\n\n```java\nimport java.util.Arrays;\n\npublic class Test {\n  public static void main(String[] args) {\n    int[] numbers = { 10, 4, 32, 45, 99, 2 };\n\n    Arrays.sort(numbers);\n\n    System.out.print(\"Ascending order: \");\n    for (int i = 0; i \u003c numbers.length; i++) {\n      System.out.print(\" \" + numbers[i]);\n    }\n    System.out.println();\n\n    System.out.print(\"Descending order: \");\n    for (int i = numbers.length - 1; i \u003e= 0; i--) {\n      System.out.print(\" \" + numbers[i]);\n    }\n    System.out.println();\n\n    String[] names = { \"Pinky\", \"Anisul\", \"Liton\", \"Sweety\" };\n    Arrays.sort(names);\n    // we can sort the array just like last time\n  }\n}\n\n```\n\n#### Assignment 18 (Print the day name)\n\n```java\nimport java.util.Scanner;\n\n/*\n * Assigment 18 (Print the day name)\n * declare an array of weekdays\n * User will give a day number you have to print the equivalent day name\n *\n * Example 1\n * input-\u003e Enter day number (1-7) : 1\n * output-\u003e Monday\n *\n * Example 2\n * input-\u003e Enter day number (1-7) : 3\n * output-\u003e Wednesday\n */\n\npublic class Assignment18 {\n  public static void main(String[] args) {\n\n       try (Scanner input = new Scanner(System.in)) {\n\n\n      }\n  }\n}\n\n```\n\n#### Assignment 19 (Array Operations)\n\n- Assignment: Array Operations\n\nWrite a Java program that performs various operations on an array of integers. Your program should implement the following functionality:\n\n1. Initialization: Initialize an array of integers with the following values: {5, 10, 15, 20, 25}.\n\n2. Sum of Elements: Calculate and print the sum of all elements in the array.\n\n3. Largest Element: Find and print the largest element in the array.\n\n4. Smallest Element: Find and print the smallest element in the array.\n\n5. Average: Calculate and print the average value of all elements in the array.\n\n6. Search: Prompt the user to enter a number to search in the array. Check if the number exists in the array and print an appropriate message.\n\n7. Reverse Order: Reverse the order of elements in the array and print the reversed array.\n\nYou can structure your program with appropriate methods for each operation and a main method to run the program. Make sure to provide clear output and handle any necessary user input.\n\nHere's a skeleton code for the assignment:\n\n```java\nimport java.util.Scanner;\n\npublic class ArrayOperations {\n    public static void main(String[] args) {\n        int[] numbers = {5, 10, 15, 20, 25};\n\n        // Call the methods for each operation\n        int sum = calculateSum(numbers);\n        System.out.println(\"Sum of elements: \" + sum);\n\n        int largest = findLargest(numbers);\n        System.out.println(\"Largest element: \" + largest);\n\n        int smallest = findSmallest(numbers);\n        System.out.println(\"Smallest element: \" + smallest);\n\n        double average = calculateAverage(numbers);\n        System.out.println(\"Average: \" + average);\n\n        Scanner input = new Scanner(System.in);\n        System.out.print(\"Enter a number to search: \");\n        int searchNumber = input.nextInt();\n        boolean found = searchNumber(numbers, searchNumber);\n        if (found) {\n            System.out.println(searchNumber + \" exists in the array.\");\n        } else {\n            System.out.println(searchNumber + \" does not exist in the array.\");\n        }\n\n        int[] reversed = reverseArray(numbers);\n        System.out.println(\"Reversed array: \");\n        for (int num : reversed) {\n            System.out.print(num + \" \");\n        }\n        System.out.println();\n    }\n\n    public static int calculateSum(int[] arr) {\n        // Calculate the sum of elements\n        // Implement your logic here\n    }\n\n    public static int findLargest(int[] arr) {\n        // Find the largest element\n        // Implement your logic here\n    }\n\n    public static int findSmallest(int[] arr) {\n        // Find the smallest element\n        // Implement your logic here\n    }\n\n    public static double calculateAverage(int[] arr) {\n        // Calculate the average of elements\n        // Implement your logic here\n    }\n\n    public static boolean searchNumber(int[] arr, int target) {\n        // Search for the target number in the array\n        // Implement your logic here\n    }\n\n    public static int[] reverseArray(int[] arr) {\n        // Reverse the order of elements in the array\n        // Implement your logic here\n    }\n}\n```\n\nYou need to complete the implementation of each method by adding the appropriate logic to perform the operations. Once you have completed the code, you can run the program to see the results of each operation on the given array of integers.\n\nFeel free to customize or extend the assignment according to your needs. Good luck!\n\n- ArrayList: Array is static or fixed where ArrayList is dynamic and resizeable. Array supports for and for each loop where ArrayList supports for each loop and iterator. Array is faster than ArrayList. Array.length vs ArrayList.size(). some common methods are - size(), add(), addAll(),remove(), set(), get(), clear(), isEmpty(), contains(), indexOf(), equals()\n\n  - Example of ArrayList\n\n  ```java\n    import java.util.ArrayList;\n    import java.util.Arrays;\n    import java.util.Collections;\n    import java.util.Iterator;\n\n    public class Test {\n      public static void main(String[] args) {\n        ArrayList\u003cString\u003e fruits = new ArrayList\u003c\u003e();\n\n        // Add elements to the ArrayList\n        fruits.add(\"Apple\");\n        fruits.add(\"Banana\");\n        fruits.add(\"Orange\");\n        fruits.add(3, \"Mango\");\n\n        // remove elements from the ArrayList\n        fruits.remove(3);\n        System.out.println(\"After removing:  \" + fruits);\n        // fruits.removeAll();\n        // fruits.clear();\n\n        // set elements\n        fruits.set(2, \"Mango\");\n        System.out.println(\"After setting new item:  \" + fruits);\n\n        // Access elements\n        System.out.println(\"First fruit: \" + fruits.get(0));\n\n        // Iterate over elements\n        for (String fruit : fruits) {\n          System.out.println(fruit);\n        }\n\n        // Size of the ArrayList\n        System.out.println(\"Size: \" + fruits.size());\n\n        // Check the ArrayList is empty or not\n        System.out.println(\"isEmpty: \" + fruits.isEmpty());\n\n        // Check the ArrayList contains an item or not\n        System.out.println(\"contains Mango: \" + fruits.contains(\"Mango\"));\n\n        // Check the index of an item\n        System.out.println(\"index of Mango: \" + fruits.indexOf(\"Mango\"));\n\n        // print ArrayList using iterator\n        Iterator itr = fruits.iterator();\n        while (itr.hasNext()) {\n          System.out.println(itr.next());\n        }\n\n        ArrayList\u003cInteger\u003e numbers = new ArrayList\u003c\u003e(Arrays.asList(1, 2, 3, 4, 5));\n        System.out.println(numbers);\n\n        Collections.sort(numbers);\n        System.out.println(\"After sorting in Ascending order: \" + numbers);\n\n        Collections.reverse(numbers);\n        System.out.println(\"After sorting in Descending order: \" + numbers);\n      }\n    }\n  ```\n\n### 1.12 String Manipulation\n\nIn Java, the `String` class is a built-in class that represents a sequence of characters. It is used to store and manipulate textual data. Strings in Java are immutable, meaning that their values cannot be changed once created. When you perform operations on strings, such as concatenation or substring extraction, new string objects are created.\n\nThe Java String class offers a wide range of methods and functionalities for working with strings efficiently. You can refer to the Java documentation for a comprehensive list of methods available in the `String` class.\n\nHere are some key features and operations related to strings in Java:\n\n1. String Declaration and Initialization:\n\n   - Strings can be declared and initialized using the `String` class. For example:\n\n     ```java\n     String str1 = \"Hello\";  // Using string literal\n     String str2 = new String(\"World\");  // Using the constructor\n     ```\n\n2. String Concatenation:\n\n   - Strings can be concatenated using the `+` operator or the `concat()` method. For example:\n\n     ```java\n     String greeting = str1 + \" \" + str2;\n     String fullGreeting = str1.concat(\" \").concat(str2);\n     ```\n\n3. String Length:\n\n   - The length of a string can be obtained using the `length()` method. For example:\n\n     ```java\n     int length = greeting.length();\n     ```\n\n4. Accessing Characters:\n\n   - Individual characters within a string can be accessed using the `charAt()` method. The index starts at 0. For example:\n\n     ```java\n     char firstChar = greeting.charAt(0);\n     ```\n\n5. Substrings:\n\n   - Substrings can be extracted from a string using the `substring()` method. For example:\n\n     ```java\n     String substring = greeting.substring(6, 10); // Extracts \"World\"\n     ```\n\n6. String Comparison:\n\n   - String equality can be checked using the `equals()` method or the `==` operator. For example:\n\n     ```java\n     boolean isEqual = str1.equals(str2);\n     boolean isSameObject = str1 == str2;\n     ```\n\n7. String Manipulation:\n\n   - The `String` class provides various methods for manipulating strings, such as converting case (e.g., `toUpperCase()`, `toLowerCase()`), removing whitespace (e.g., `trim()`), replacing characters or substrings (e.g., `replace()`, `replaceAll()`), and more.\n\n8. Conversion between String and Primitive Data type:\n\n   ```java\n      // other types to String\n      int number = 100;\n      String s = Integer.toString(number);\n      System.out.println(s);\n\n      double number2 = 100;\n      String s1 = Double.toString(number2);\n      System.out.println(s1);\n\n      boolean b = true;\n      String s2 = Boolean.toString(b);\n      System.out.println(s2);\n\n      // String to other types\n      String n = \"32\";\n      System.out.println(Integer.parseInt(n));\n      System.out.println(Double.parseDouble(n));\n      System.out.println(Double.valueOf(n));\n\n   ```\n\n9. Wrapper Class - Autoboxing, unboxing\n\nAutoboxing and unboxing are features in Java that automatically convert between primitive types and their corresponding wrapper classes. These features were introduced to simplify the code and provide a more intuitive way of working with primitive types and their object counterparts.\n\n- Autoboxing is the automatic conversion of a primitive type to its corresponding wrapper class. - When you assign a primitive value to a variable of the corresponding wrapper class, autoboxing automatically wraps the primitive value into an object of the wrapper class.\n\n  ```java\n  int number = 42;\n  Integer wrappedNumber = number; // Autoboxing from int to Integer\n  ```\n\n- Unboxing is the automatic conversion of a wrapper class object to its corresponding primitive type.\n\n  - When you assign a wrapper class object to a variable of the corresponding primitive type, unboxing automatically extracts the primitive value from the object.\n  - Example:\n\n    ```java\n    Integer wrappedNumber = 42;\n    int number = wrappedNumber; // Unboxing from Integer to int\n    ```\n\n- Autoboxing and Unboxing in Expressions:\n\n  - Autoboxing and unboxing also apply to expressions involving primitive types and their corresponding wrapper classes.\n\n  - Example:\n\n    ```java\n    Integer a = 5; // Autoboxing\n    Integer b = 10;\n    int sum = a + b; // Unboxing, addition, and autoboxing\n    ```\n\n  Autoboxing and unboxing provide a convenient way to work with both primitive types and their object counterparts without requiring explicit conversions. They simplify code readability and reduce the need for manual conversions between primitive types and wrapper classes.\n\n  However, it's important to note that autoboxing and unboxing can have performance implications in certain scenarios, as they involve object creation and method calls. Care should be taken when using autoboxing and unboxing in performance-critical code or in situations where memory usage needs to be optimized.\n\n- Random number generator\n\n```java\nimport java.util.Random;\n\npublic class RandomGeneratorExample {\n    public static void main(String[] args) {\n        Random random = new Random();\n\n        // Generating random integers\n        int randomInt = random.nextInt();\n        System.out.println(\"Random Integer: \" + randomInt);\n\n        // Generating random integers within a specific range\n        int randomInRange = random.nextInt(100); // Generates integers from 0 to 99\n        System.out.println(\"Random Integer in Range: \" + randomInRange);\n\n        // Generating random doubles\n        double randomDouble = random.nextDouble();\n        System.out.println(\"Random Double: \" + randomDouble);\n\n        // Generating random booleans\n        boolean randomBoolean = random.nextBoolean();\n        System.out.println(\"Random Boolean: \" + randomBoolean);\n    }\n}\n\n```\n\n### 1.13 Object Oriented Programming\n\n- Object-Oriented Programming (OOP) is a programming paradigm that organizes code into objects, which represent real-world entities. Java is an object-oriented programming language that fully supports OOP principles. OOP key concepts: Inheritance, Encapsulation, Abstraction, Polymorphism\n\n#### Classes, Object, Constructor\n\n- Class: A class is a template from which individual object is created. A class is a blueprint for creating objects. It defines the properties (attributes) and behaviors (methods) that objects of that class will have.\n\n  ```java\n  public class Car {\n      // Properties\n      String brand;\n      String color;\n      int year;\n\n      // Behaviors\n      void startEngine() {\n          System.out.println(\"Engine started!\");\n      }\n\n      void drive() {\n          System.out.println(\"Car is driving.\");\n      }\n  }\n  ```\n\n- Object: Any class type variable is known as object. An object is an instance of a class. It represents a specific entity based on the class blueprint. Objects are created using the new keyword and the class constructor.\n\n  ```java\n  public class Main {\n      public static void main(String[] args) {\n          // Create Car objects\n          Car car1 = new Car();\n          Car car2 = new Car();\n\n          // Set object properties\n          car1.brand = \"Toyota\";\n          car1.color = \"Red\";\n          car1.year = 2020;\n\n          car2.brand = \"Honda\";\n          car2.color = \"Blue\";\n          car2.year = 2019;\n\n          // Invoke object behaviors\n          car1.startEngine();\n          car1.drive();\n          car2.startEngine();\n          car2.drive();\n\n          // priniting cars details\n          System.out.println(\"Car1 details: \");\n          System.out.println(\"Brand: \" + car1.brand);\n          System.out.println(\"Color: \" + car1.color);\n          System.out.println(\"Year: \" + car1.year);\n\n          System.out.println(\"Car2 details: \");\n          System.out.println(\"Brand: \" + car2.brand);\n          System.out.println(\"Color: \" + car2.color);\n          System.out.println(\"Year: \" + car2.year);\n      }\n  }\n  ```\n\n- Introducing parametrized methods inside the car class\n\n  ```java\n  class Car {\n    // properties\n    String brand, color;\n    int year;\n\n    // behaviours\n    void startEngine() {\n      System.out.println(\"Engine started\");\n    }\n\n    void drive() {\n      System.out.println(\"Car is driving\");\n    }\n\n    void setDetails(String brandName, String colorName, int manufactureYear) {\n      brand = brandName;\n      color = colorName;\n      year = manufactureYear;\n    }\n\n    void printDetails() {\n      System.out.println(\"Car details: \");\n      System.out.println(\"---------------\");\n      System.out.println(\"Brand: \" + brand);\n      System.out.println(\"Color: \" + color);\n      System.out.println(\"Year: \" + year);\n      System.out.println();\n    }\n\n  }\n\n  class Test {\n    public static void main(String[] args) {\n      // create Car objets\n      Car car1 = new Car();\n      Car car2 = new Car();\n\n      // set object properties\n      car1.setDetails(\"Toyota\", \"red\", 2016);\n      car2.setDetails(\"Honda\", \"blue\", 2019);\n\n      // priniting cars details\n      car1.printDetails();\n      car2.printDetails();\n\n      // Invoke object behaviors\n      car1.startEngine();\n      car1.drive();\n      car2.startEngine();\n      car2.drive();\n    }\n  }\n  ```\n\n- Constructor: Constructor is a special type of method which can help us to initialize object. Constructor does not need to be called. The constructor has the same name as the class it belongs to. It does not have a return type, not even void. types: default and parametrized constructor\n\n  - Constructor example\n\n  ```java\n  class Car {\n    // properties\n    String brand, color;\n    int year;\n\n    // constructor - same name as the class it belongs to and no return type not even void\n    Car(String brand, String color, int year) {\n      this.brand = brand;\n      this.color = color;\n      this.year = year;\n    }\n\n    // behaviours\n    void startEngine() {\n      System.out.println(\"Engine started\");\n    }\n\n    void drive() {\n      System.out.println(\"Car is driving\");\n    }\n\n    void printDetails() {\n      System.out.println(\"Car details: \");\n      System.out.println(\"---------------\");\n      System.out.println(\"Brand: \" + brand);\n      System.out.println(\"Color: \" + color);\n      System.out.println(\"Year: \" + year);\n      System.out.println();\n    }\n\n  }\n\n  class Test {\n    public static void main(String[] args) {\n      // create Car objets\n      Car car1 = new Car(\"Toyota\", \"red\", 2016);\n      Car car2 = new Car(\"Honda\", \"blue\", 2019);\n\n      // priniting cars details\n      car1.printDetails();\n      car2.printDetails();\n\n      // Invoke object behaviors\n      car1.startEngine();\n      car1.drive();\n      car2.startEngine();\n      car2.drive();\n    }\n  }\n  ```\n\n  - Overloading Constructors where we have constructors with same name but the parameter numbers are different.\n\n  ```java\n  class Car {\n    // properties\n    String brand, color;\n    int year;\n\n    // constructor - same name as the class it belongs to and no return type not even void\n    Car(String brand, String color, int year) {\n      this.brand = brand;\n      this.color = color;\n      this.year = year;\n    }\n\n    // constructor overloading: same name different parameters\n     Car(String brand, String color) {\n      this.brand = brand;\n      this.color = color;\n    }\n\n    Car() {\n      System.out.println(\"Default constructor\");\n    }\n\n    // behaviours\n    void startEngine() {\n      System.out.println(\"Engine started\");\n    }\n\n    void drive() {\n      System.out.println(\"Car is driving\");\n    }\n\n    void printDetails() {\n      System.out.println(\"Car details: \");\n      System.out.println(\"---------------\");\n      System.out.println(\"Brand: \" + brand);\n      System.out.println(\"Color: \" + color);\n      System.out.println(\"Year: \" + year);\n      System.out.println();\n    }\n\n  }\n\n  class Test {\n    public static void main(String[] args) {\n      // create Car objets\n      Car car1 = new Car(\"Toyota\", \"red\", 2016);\n      Car car2 = new Car(\"Honda\", \"blue\", 2019);\n      Car car3 = new Car(\"Peugeot\", \"black\");\n      Car car4 = new Car();\n\n      // priniting cars details\n      car1.printDetails();\n      car2.printDetails();\n\n      // Invoke object behaviors\n      car1.startEngine();\n      car1.drive();\n      car2.startEngine();\n      car2.drive();\n    }\n  }\n  ```\n\n- Differences between the constructor and method\n\n#### static variable, static method and static block\n\n- static keyword is used for memory management. It saves memory by sharing variables with different objects. It's important to note that static members belong to the class and are not specific to any object. They can be accessed using the class name followed by the member name, such as `ClassName.staticMember`.\n\n1. Static Variables:\n\n   - Static variables, also known as class variables, are shared among all instances of a class. They are declared using the `static` keyword and have a single copy that is shared by all objects of the class.\n   - Example:\n\n     ```java\n     public class Counter {\n         static int count; // Static variable\n\n         public Counter() {\n             count++; // Increment count in the constructor\n         }\n     }\n     ```\n\n2. Static Block:\n\n   - A static block is a static initializer block that is used to initialize static variables or perform any other one-time initialization tasks for the class.\n   - It is executed only once when the class is loaded into memory, before any object of that class is created or any static method is called. static block is called even before main method.\n   - Example:\n\n     ```java\n     public class StaticBlockExample {\n        static int id;\n        static String name;\n\n         static {\n             // Static block\n             id = 101;\n             name = \"Anisul\";\n             System.out.println(\"Static block executed!\");\n         }\n\n         static void display(){\n            System.out.println(\"Id: \"+id);\n            System.out.println(\"Name: \"+name);\n         }\n\n         public static void main(String[] args) {\n             System.out.println(\"Main method executed!\");\n             StaticBlockExample.display();\n         }\n     }\n     ```\n\n3. Static Methods:\n\n   - Static methods are associated with the class itself, rather than with individual objects of the class. They are declared using the `static` keyword and can be called directly using the class name, without creating an object. The main method is the most common example of static method.\n   - Static methods cannot access instance variables or call instance methods directly, as they are not associated with any specific object.\n   - Example:\n\n     ```java\n     public class StaticMethod {\n         public int add(int a, int b) {\n             return a + b;\n         }\n\n         public static int multiply(int a, int b) {\n             return a * b;\n         }\n     }\n     public class Test{\n        public static void main(String[] args){\n          int result = StaticMethod.multiply(20,30);\n           System.out.println(result);\n\n           StaicMethod sm = new StaticMethod();\n           result = sm.add(20,30);\n           System.out.println(result);\n        }\n     }\n     ```\n\n     - static method can't use non static members. this and super can not be used.\n\n     ```java\n         public class StaticMethod {\n            public int add(int a, int b) {\n                return a + b;\n            }\n\n            public static int multiply(int a, int b) {\n                int x = add(20,30); // error here\n                return a * b;\n            }\n        }\n     ```\n\n- variable types: local (variable is decalred inside a method/constructor/block), instance variables (decalred inside class but outside the method and not decared as static) and class/static variable.\n\n#### OOP Key Feature 1: Encapsulation\n\n- Encapsulation is the practice of bundling related properties and behaviors within a class and providing access to them through methods. It helps in data hiding and protects the internal state of objects. 4 types of access modifiers: private, default, protected, public.\n\n  ```java\n  public class Car {\n      private String brand;\n      private String color;\n      private int year;\n\n      // Getter methods\n      public String getBrand() {\n          return brand;\n      }\n\n      public String getColor() {\n          return color;\n      }\n\n      public int getYear() {\n          return year;\n      }\n\n      // Setter methods\n      public void setBrand(String brand) {\n          this.brand = brand;\n      }\n\n      public void setColor(String color) {\n          this.color = color;\n      }\n\n      public void setYear(int year) {\n          this.year = year;\n      }\n  }\n\n  ```\n\n#### OOP Key Feature 2: Inheritance\n\n- Inheritance allows creating new classes (child classes / sub classes / dervied classes) based on existing classes (parent classes /super classes /base classes). Child classes inherit the properties and behaviors of their parent classes, enabling code reuse and creating a hierarchical structure. For method overriding and make parent child relationship we need inheritance.\n\n  ```java\n  public class ElectricCar extends Car {\n      private int batteryCapacity;\n\n      // Additional behavior\n      void chargeBattery() {\n          System.out.println(\"Battery is charging.\");\n      }\n  }\n  ```\n\n  - More simple inheritance example\n\n  ```java\n    //\n    class Person {\n        String name;\n        int age;\n\n        public void printDetails1() {\n          System.out.println(\"Name: \" + name);\n          System.out.println(\"Age: \" + age);\n        }\n      }\n\n      class Teacher extends Person {\n        double salary;\n\n        public void printDetails2() {\n          System.out.println(\"Name: \" + name);\n          System.out.println(\"Age: \" + age);\n          System.out.println(\"salary: \" + salary);\n        }\n      }\n\n      class Test {\n        public static void main(String[] args) {\n            Teacher t1 = new Teacher();\n            Teacher t2 = new Teacher();\n\n            t1.name = \"Anisul Islam\";\n            t1.age = 33;\n            t1.salary = 4.500;\n            t1.printDetails2();\n\n            t2.name = \"Emraj Chowdhury\";\n            t2.age = 29;\n            t2.salary = 2.500;\n            t2.printDetails2();\n        }\n      }\n  ```\n\n  - Inheriting private members is not possible but we can create public getter and setter methods to use private members of a class.\n\n  ```java\n      class Person {\n        private String name;\n        private int age;\n\n        public void setName(String name) {\n          this.name = name;\n        }\n\n        public void setAge(int age) {\n          this.age = age;\n        }\n\n        public String getName() {\n          return name;\n        }\n\n        public int getAge() {\n          return age;\n        }\n\n        public void printDetails1() {\n          System.out.println(\"Name: \" + name);\n          System.out.println(\"Age: \" + age);\n        }\n      }\n\n      class Teacher extends Person {\n        private double salary;\n\n        public void setSalary(double salary) {\n          this.salary = salary;\n        }\n\n        public double getSalary() {\n          return salary;\n        }\n\n        public void printDetails2() {\n          System.out.println(\"Name: \" + getName());\n          System.out.println(\"Age: \" + getAge());\n          System.out.println(\"salary: \" + getSalary());\n        }\n      }\n\n      class Test {\n        public static void main(String[] args) {\n          Person p = new Person();\n          Teacher t1 = new Teacher();\n\n          // instanceof operator\n          System.out.println(p instanceof Person);\n          System.out.println(p instanceof Teacher);\n\n\n          t1.setName(\"Anisul Islam\");\n          t1.setAge(33);\n          t1.setSalary(4.500);\n          t1.printDetails2();\n\n          Teacher t2 = new Teacher();\n          t2.setName(\"Anisul Islam\");\n          t2.setAge(33);\n          t2.setSalary(4.500);\n          t2.printDetails2();\n        }\n\n    }\n  ```\n\n  - Types of Inheritance: Single Inheritane (A\u003c- B), multilevel inheritance (A \u003c- B \u003c- C), Hierarchical Inheritance (A\u003c-B, A\u003c-C, A\u003c-D multiple sub class is dervied from single subclass), Multiple Inheritance (dimand shape A\u003c-B, A\u003c-C, B\u003c-D, C\u003c-D one subclass trying to derive 2 superclasses)\n\n- method overriding\n\n  - method overriding is a process of declaring a method in subclass which is already present in superclass. It helps us to do code reuse.\n\n  ```java\n    class Person {\n        private String name;\n        private int age;\n\n        public void setName(String name) {\n          this.name = name;\n        }\n\n        public void setAge(int age) {\n          this.age = age;\n        }\n\n        public String getName() {\n          return name;\n        }\n\n        public int getAge() {\n          return age;\n        }\n\n        public void printDetails() {\n          System.out.println(\"Name: \" + name);\n          System.out.println(\"Age: \" + age);\n        }\n      }\n\n      class Teacher extends Person {\n        private double salary;\n\n        public void setSalary(double salary) {\n          this.salary = salary;\n        }\n\n        public double getSalary() {\n          return salary;\n        }\n\n        public void printDetails() {\n          System.out.println(\"Name: \" + getName());\n          System.out.println(\"Age: \" + getAge());\n          System.out.println(\"salary: \" + getSalary());\n        }\n      }\n  ```\n\n- method overloading vs overriding\n\n  - Can you override static method? No, cause static method bound to the class not to object.\n  - Can you override java main method?: No, because main is a static method.\n\n    Overloading:\n\n    1. Definition: Overloading occurs when multiple methods in the same class have the same name but different parameters (either different types or different numbers of parameters).\n    2. Purpose: Overloading is used to provide multiple methods with the same name but different behaviors or functionalities.\n    3. Occurrence: Overloading happens within the same class.\n    4. Inheritance: Overloading is not related to inheritance.\n    5. Signature: Overloaded methods must have a different method signature, which includes the method name and parameter list.\n    6. Return Type: Overloaded methods may or may not have the same return type.\n    7. Example:\n\n    ```java\n    public class Calculator {\n        public int add(int a, int b) {\n            return a + b;\n        }\n\n        public int add(int a, int b, int c) {\n            return a + b + c;\n        }\n    }\n    ```\n\n    Overriding:\n\n    1. Definition: Overriding occurs when a subclass provides its own implementation of a method that is already defined in its superclass.\n    2. Purpose: Overriding is used to modify or extend the behavior of an inherited method in a subclass.\n    3. Occurrence: Overriding happens in a subclass that extends a superclass.\n    4. Inheritance: Overriding is related to inheritance.\n    5. Signature: Overridden methods must have the same method signature, including the method name, parameter list, and return type.\n    6. Annotation: The `@Override` annotation is used to indicate that a method is intended to override a superclass method (optional but recommended).\n    7. Example:\n\n    ```java\n    public class Animal {\n        public void makeSound() {\n            System.out.println(\"Animal makes a sound.\");\n        }\n    }\n\n    public class Cat extends Animal {\n        @Override\n        public void makeSound() {\n            System.out.println(\"Cat meows.\");\n        }\n    }\n    ```\n\n    In summary, overloading is about providing multiple methods with the same name but different parameters within the same class, while overriding is about providing a new implementation of an inherited method in a subclass. Overloading is determined at compile-time based on the method's signature, while overriding is determined at runtime based on the actual object type.\n\n- Why Java does not support multiple inheritance?\n\n#### super, this, final keyword\n\n- super keyword is used to access super class members such as properties, behaviours, constructors. super.variable, super.method(), super(param1,param2) for constructor. It has to be the first statement in method.\n\n  - super keyword example\n\n  ```java\n  class Animal {\n      protected String name;\n\n      public Animal(String name) {\n          this.name = name;\n      }\n\n      public void eat() {\n          System.out.println(\"The animal is eating.\");\n      }\n  }\n\n  class Dog extends Animal {\n      private String breed;\n\n      public Dog(String name, String breed) {\n          super(name); // Calling the superclass constructor using super()\n          this.breed = breed;\n      }\n\n      public void displayInfo() {\n          System.out.println(\"Name: \" + super.name); // Accessing the superclass variable using super\n          super.eat(); // Invoking the superclass method using super\n          System.out.println(\"Breed: \" + this.breed);\n      }\n  }\n\n  public class Main {\n      public static void main(String[] args) {\n          Dog dog = new Dog(\"Buddy\", \"Labrador\");\n          dog.displayInfo();\n      }\n  }\n\n  // Another example\n      class Person {\n        private String name;\n        private int age;\n\n        public Person(String name, int age) {\n          this.name = name;\n          this.age = age;\n        }\n\n        public String getName() {\n          return name;\n        }\n\n        public int getAge() {\n          return age;\n        }\n\n        public void printDetails() {\n          System.out.println(\"Name: \" + name);\n          System.out.println(\"Age: \" + age);\n        }\n    }\n\n    class Teacher extends Person {\n      private double salary;\n\n      public Teacher(String name, int age, double salary) {\n        super(name, age);\n        this.salary = salary;\n      }\n\n      public void setSalary(double salary) {\n        this.salary = salary;\n      }\n\n      public double getSalary() {\n        return salary;\n      }\n\n      public void printDetails() {\n        super.printDetails();\n        System.out.println(\"salary: \" + getSalary());\n      }\n    }\n\n    class Test {\n      public static void main(String[] args) {\n        Person p = new Person(\"Anisul Islam\", 33);\n        Teacher t1 = new Teacher(\"Anisul Islam\", 33, 4.500);\n\n        System.out.println(p instanceof Person);\n        System.out.println(p instanceof Teacher);\n\n        t1.setSalary(4.500);\n        t1.printDetails();\n\n        Teacher t2 = new Teacher(\"Emraj\", 30, 4200);\n        t2.printDetails();\n      }\n    }\n  ```\n\n- this keyword: this keyword is a reference to the current instance of a class. It is primarily used to refer to the instance variables and methods of the current object. Here's an example to illustrate the usage of the this keyword:\n\n  - this keyword example\n\n  ```java\n  class Person {\n      private String name;\n      private int age;\n\n      public Person(String name, int age) {\n          this.name = name; // Assigning the name parameter to the instance variable using this\n          this.age = age; // Assigning the age parameter to the instance variable using this\n      }\n\n      public void displayInfo() {\n          System.out.println(\"Name: \" + this.name); // Accessing the instance variable using this\n          System.out.println(\"Age: \" + this.age); // Accessing the instance variable using this\n          this.sayHello(); // Invoking the instance method using this\n      }\n\n      public void sayHello() {\n          System.out.println(\"Hello, I'm \" + this.name); // Accessing the instance variable using this\n      }\n  }\n\n  public class Main {\n      public static void main(String[] args) {\n          Person person = new Person(\"John\", 25);\n          person.displayInfo();\n      }\n  }\n  ```\n\n- final keyword: In Java, the `final` keyword is used to declare a variable, method, or class as unchangeable or unextendable, depending on its usage. Final variables maintain constant values, final methods cannot be overridden, and final classes cannot be subclassed. Here are examples of how the `final` keyword can be used:\n\n  1. Final Variables: In this example, the PI variable is declared as final, indicating that its value cannot be changed.\n\n     ```java\n     public class Circle {\n         private final double PI = 3.14159; // Declaring a final variable\n\n         public double calculateArea(double radius) {\n             final double area = PI * radius * radius; // Using a final variable\n             return area;\n         }\n     }\n     ```\n\n  2. Final Methods: In the following example, the stop method is declared as final, which means it cannot be overridden by any subclass. The start method, on the other hand, can be overridden in a subclass.\n\n     ```java\n     public class Vehicle {\n         public void start() {\n             // Code to start the vehicle\n         }\n\n         public final void stop() {\n             // Code to stop the vehicle\n         }\n     }\n     ```\n\n  3. Final Classes: In this example, the `MathUtils` class is declared as `final`, indicating that it cannot be extended by any other class. It prevents inheritance and ensures that the class remains unchanged.\n\n     ```java\n     public final class MathUtils {\n         // Class implementation\n     }\n     ```\n\n#### OOP Key Feature 3: Polymorphism\n\n- Polymorphism (poly greek word means many and morphism greek word means form = many forms) refers to the ability of objects to take on multiple forms. It allows a child class to override or extend the behaviors of its parent class, enabling dynamic binding of methods at runtime. There are 2 types of polymorphism - Compile time (static polymorphism - method/constructor overloadin) and run time polymorphism (dynamic polymorphism - method overriding).\n\n  ```java\n  class Person {\n    private String name;\n    private int age;\n\n    public Person(String name, int age) {\n      this.name = name;\n      this.age = age;\n    }\n\n    public String getName() {\n      return name;\n    }\n\n    public int getAge() {\n      return age;\n    }\n\n    public void printDetails() {\n      System.out.println(\"Name: \" + name);\n      System.out.println(\"Age: \" + age);\n    }\n  }\n\n  class Teacher extends Person {\n    private double salary;\n\n    public Teacher(String name, int age, double salary) {\n      super(name, age);\n      this.salary = salary;\n    }\n\n    public void setSalary(double salary) {\n      this.salary = salary;\n    }\n\n    public double getSalary() {\n      return salary;\n    }\n\n    @Override\n    public void printDetails() {\n      super.printDetails();\n      System.out.println(\"salary: \" + getSalary());\n    }\n  }\n\n  class Student extends Person {\n    double gpa;\n\n    Student(String name, int age, double gpa) {\n      super(name, age);\n      this.gpa = gpa;\n    }\n\n    @Override\n    public void printDetails() {\n      super.printDetails();\n      System.out.println(\"GPA: \" + gpa);\n    }\n  }\n\n  class Test {\n    public static void main(String[] args) {\n      Person p = new Person(\"Anisul Islam\", 33);\n      p.printDetails();\n\n      // super class object is used here as reference variable and its taking\n      // different forms based on the object that we are assigning\n      p = new Teacher(\"Anisul Islam\", 33, 4.500);\n      p.printDetails();\n\n      p = new Student(\"Anisul Islam\", 33, 3.5);\n      p.printDetails();\n      // Teacher t = new Teacher(\"Anisul Islam\", 33, 4.500);\n      // Student s = new Student(\"Anisul Islam\", 33, 3.5);\n\n    }\n\n  }\n  ```\n\n  - Another example of polymorphism\n\n  ```java\n    class Shape {\n      double dim1, dim2;\n\n      Shape(double dim1, double dim2) {\n        this.dim1 = dim1;\n        this.dim2 = dim2;\n      }\n\n      double area() {\n        return 0;\n      }\n    }\n\n    class Rectangle extends Shape {\n\n      Rectangle(double dim1, double dim2) {\n        super(dim1, dim2);\n      }\n\n      double area() {\n        return dim1 * dim2;\n      }\n    }\n\n    class Triangle extends Shape {\n\n      Triangle(double dim1, double dim2) {\n        super(dim1, dim2);\n      }\n\n      double area() {\n        return 0.5 * dim1 * dim2;\n      }\n    }\n\n    class Test {\n      public static void main(String[] args) {\n        Shape s = new Shape(0, 0);\n        System.out.println(\"Shape Area: \" + s.area());\n\n        s = new Rectangle(10, 20);\n        System.out.println(\"Rectangle Area: \" + s.area());\n\n        s = new Triangle(10, 20);\n        System.out.println(\"Triangle Area: \" + s.area());\n      }\n    }\n  ```\n\n#### OOP Key Feature 4: Abstraction\n\n- Abstraction focuses on hiding the implementation details of a class and providing a simplified interface for interacting with objects. Abstract classes and interfaces are used to achieve abstraction.\n\n```java\npublic abstract class Vehicle {\n    // Abstract method\n    abstract void startEngine();\n\n    // Concrete method\n    void stopEngine() {\n        System.out.println(\"Engine stopped!\");\n    }\n}\n```\n\n- interface\n\n### 1.14 Exception Handling\n\n## 2. Intermediate Java\n\n### 2.1 Collections Framework\n\n![collection](images/ClassificationofDataStructure.jpeg)\n![data structure and api in java](images/data-structures-and-java-apis2.jpg)\n\n## Follow Me\n\n[\u003cimg src='https://cdn.jsdelivr.net/npm/simple-icons@3.0.1/icons/github.svg' alt='github' height='40'\u003e](https://github.com/learnwithfair) [\u003cimg src='https://cdn.jsdelivr.net/npm/simple-icons@3.0.1/icons/facebook.svg' alt='facebook' height='40'\u003e](https://www.facebook.com/learnwithfair/) [\u003cimg src='https://cdn.jsdelivr.net/npm/simple-icons@3.0.1/icons/instagram.svg' alt='instagram' height='40'\u003e](https://www.instagram.com/learnwithfair/) [\u003cimg src='https://cdn.jsdelivr.net/npm/simple-icons@3.0.1/icons/twitter.svg' alt='twitter' height='40'\u003e](https://www.twiter.com/learnwithfair/) [\u003cimg src='https://cdn.jsdelivr.net/npm/simple-icons@3.0.1/icons/youtube.svg' alt='YouTube' height='40'\u003e](https://www.youtube.com/@learnwithfair)\n\n\u003c!-- MARKDOWN LINKS \u0026 IMAGES --\u003e\n\n[youtube-shield]: https://img.shields.io/badge/-Youtube-black.svg?style=flat-square\u0026logo=youtube\u0026color=555\u0026logoColor=white\n[youtube-url]: https://youtube.com/@learnwithfair\n[facebook-shield]: https://img.shields.io/badge/-Facebook-black.svg?style=flat-square\u0026logo=facebook\u0026color=555\u0026logoColor=white\n[facebook-url]: https://facebook.com/learnwithfair\n[instagram-shield]: https://img.shields.io/badge/-Instagram-black.svg?style=flat-square\u0026logo=instagram\u0026color=555\u0026logoColor=white\n[instagram-url]: https://instagram.com/learnwithfair\n[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=flat-square\u0026logo=linkedin\u0026colorB=555\n[linkedin-url]: https://linkedin.com/company/learnwithfair\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flearnwithfair%2Fjava-documentation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flearnwithfair%2Fjava-documentation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flearnwithfair%2Fjava-documentation/lists"}