├── .deepsource.toml ├── Collections ├── ArrayList_class.java ├── LinkedList_class.java ├── _Stack.java ├── _hashSet.java ├── _queue.java └── hashMap.java ├── LICENSE ├── OOPS ├── Class_Object.java ├── MultilevelInheritance.java ├── README.MD ├── SingleInheritance.java ├── abstraction.java ├── encapsulation.java ├── hierarchical.java ├── instance_and_static.java ├── interface_class.java ├── methodOverLoading.java ├── methodOverRiding.java ├── multiple_inheritance.java ├── private_constructor.java ├── super_keyword.java └── this_keyword.java ├── README.md ├── _basic ├── Access_Modifier.java ├── Calculator_switch.java ├── Fastest_IO.java ├── FileHandling.java ├── README.MD ├── ReadData.java ├── Ternary_Operator.java ├── bitwise.java ├── bufferedReader_output.java ├── bufferedWriter.java ├── do_while.java ├── for_each.java ├── multiThreading.java ├── multithreading_2nd.java ├── string.java ├── tryCatch.java └── type_casting.java └── _recursion ├── Fibonacci.java ├── GeomatricSum.java ├── PairStar.java ├── QuickSort.java ├── README.MD ├── StringToInt.java ├── TowerOfHanoi.java ├── binarySearch.java ├── checkNumber_in_Array.java ├── countZeros_recursive.java ├── count_digits.java ├── first_index.java ├── isPalindrome.java ├── isSortedArray.java ├── is_fibonacci.java ├── lastIndex.java ├── mergeSort.java ├── multiplyTwoIntegers.java ├── power_n.java ├── print_n_num.java ├── removeConsecutiveDuplicate.java ├── remove_X.java ├── replacePI.java ├── sumOfDigits.java └── sum_array.java /.deepsource.toml: -------------------------------------------------------------------------------- 1 | version = 1 2 | 3 | [[analyzers]] 4 | name = "java" 5 | enabled = true 6 | 7 | [analyzers.meta] 8 | runtime_version = "17" -------------------------------------------------------------------------------- /Collections/ArrayList_class.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | 4 | 5 | //the ArrayList class is a resizeable array, 6 | 7 | //arraylist has a regular array inside it 8 | //whenever array size is out of bound new array with 9 | // bigger size of array replaced with old array 10 | // implementation of new array: [currentSize + (currentSize/2)] 11 | 12 | 13 | class ArrayList_class{ 14 | 15 | public static void main(String[] args) { 16 | 17 | ArrayList cars = new ArrayList<>(); 18 | 19 | cars.add("Volvo"); //add item 20 | cars.add("BMW"); 21 | cars.add("Ford"); 22 | cars.add("Mazda"); 23 | cars.add("Tata"); 24 | cars.add("Suzuki"); 25 | cars.add("Hyundai"); 26 | System.out.println(cars); 27 | 28 | 29 | System.out.println(cars.get(4)); //access item 30 | 31 | cars.set(3, "Honda"); //change item 32 | 33 | 34 | cars.remove("Ford"); //remove item 35 | cars.remove(2); // 36 | System.out.println(cars); 37 | 38 | 39 | 40 | cars.clear(); //removes all items 41 | System.out.println(cars); 42 | 43 | 44 | System.out.println("Length of the ArrayList is " +cars.size()); //length of ArrayList 45 | 46 | } 47 | } -------------------------------------------------------------------------------- /Collections/LinkedList_class.java: -------------------------------------------------------------------------------- 1 | import java.util.LinkedList; 2 | 3 | 4 | //LinkedList stores its items in containers, the list has link 5 | // to the first container & each containers has link to the next 6 | 7 | 8 | 9 | public class LinkedList_class { 10 | 11 | 12 | public static void main(String[] args) { 13 | 14 | LinkedList cars = new LinkedList<>(); 15 | 16 | 17 | 18 | cars.add("Volvo"); //add item 19 | cars.add("BMW"); 20 | cars.add("Ford"); 21 | cars.add("Mazda"); 22 | cars.add("Tata"); 23 | cars.add("Suzuki"); 24 | cars.add("Hyundai"); 25 | cars.add("Honda"); 26 | cars.add("Lamborghini"); 27 | 28 | 29 | 30 | 31 | 32 | // linkedlist has same fatures like 33 | // arraylist some extra features are 34 | 35 | cars.addFirst("Ferrari"); //adds item to first 36 | cars.addLast("Tesla"); //adds items to last 37 | 38 | 39 | System.out.println(cars.getFirst()); //gets first item 40 | System.out.println(cars.getLast()); //gets last item 41 | 42 | 43 | 44 | System.out.println(cars); 45 | 46 | cars.removeFirst(); //removes first item 47 | cars.removeLast(); //removes last item 48 | 49 | 50 | System.out.println(cars); 51 | 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Collections/_Stack.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.util.Stack; 3 | 4 | class _Stack{ 5 | 6 | static Scanner sc = new Scanner(System.in); 7 | public static void main(String[] args) { 8 | 9 | 10 | 11 | Stack stack = new Stack<>(); 12 | 13 | for (int i=0;i<15;i++){ 14 | 15 | int n = sc.nextInt(); 16 | stack.push(n); 17 | } 18 | 19 | System.out.println(stack); 20 | 21 | // stack.pop(); 22 | 23 | // System.out.println(stack); 24 | 25 | System.out.println("size of the stack " + stack.capacity()); 26 | 27 | System.out.println("is empty: "+ stack.empty()); 28 | 29 | System.out.println("contains: "+stack.contains(8)); 30 | 31 | System.out.println("peek of the stack: " + stack.peek()); 32 | System.out.println("index of: " + stack.indexOf(9)); 33 | System.out.println("search: "+ stack.search(5)); 34 | 35 | System.out.println("first element: "+stack.firstElement()); 36 | System.out.println("last element: " + stack.lastElement()); 37 | 38 | System.out.println("equals: " + stack.equals(15)); 39 | 40 | System.out.println("element at: " + stack.elementAt(5)); 41 | System.out.println("get: " + stack.get(5)); 42 | 43 | stack.clear(); 44 | System.out.println(stack); 45 | } 46 | } -------------------------------------------------------------------------------- /Collections/_hashSet.java: -------------------------------------------------------------------------------- 1 | // HashSet is class which does not contain 2 | // duplicate values like array, linkedlist 3 | 4 | 5 | import java.util.HashSet; 6 | import java.util.Iterator; 7 | 8 | 9 | 10 | 11 | public class _hashSet { 12 | 13 | public static void main(String[] args) { 14 | 15 | HashSet set = new HashSet(); 16 | 17 | set.add("Volvo"); 18 | set.add("volvo"); // HashSet is case sensitive means 'Volvo' & 'volvo' treated as two value 19 | 20 | set.add("honda"); 21 | set.add("honda"); 22 | 23 | set.add("Lamborghini"); 24 | set.add("vaspa"); 25 | set.add("null"); 26 | 27 | 28 | set.add("bmw"); 29 | set.add("bmw"); 30 | 31 | System.out.println(set); 32 | 33 | set.remove("vaspa"); //element can be removed by name 34 | System.out.println(set); 35 | 36 | 37 | // set.remove(2); //element can't be removed with index 38 | // System.out.println(set); 39 | 40 | 41 | // set.clear(); //clears out all elements 42 | // System.out.println(set); 43 | 44 | 45 | Iterator itr = set.iterator(); //iterator carries the reference 46 | 47 | while(itr.hasNext()) 48 | System.out.println(itr.next()); //itr.next() is used to call next element from HashSet 49 | 50 | 51 | } 52 | } 53 | 54 | 55 | 56 | 57 | // there's so many cool functions in HashSet, one must explore 58 | // thanks 59 | -------------------------------------------------------------------------------- /Collections/_queue.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayDeque; 2 | import java.util.Queue; 3 | 4 | public class _queue { 5 | 6 | public static void main(String[] args) { 7 | 8 | ArrayDeque android = new ArrayDeque<>(); 9 | 10 | android.add("samsung"); 11 | System.out.println(android); 12 | 13 | android.addFirst("realme"); 14 | System.out.println(android); 15 | 16 | android.addLast("redmi"); 17 | System.out.println(android); 18 | 19 | System.out.println("contains: " + android.contains("nokia")); 20 | 21 | android.offerFirst("vivo"); 22 | android.offerLast("poco"); 23 | System.out.println(android); 24 | 25 | System.out.println("poll: "+ android.poll()); 26 | 27 | System.out.println("peek: " + android.peek()); 28 | 29 | // System.out.println(android.stream()); 30 | 31 | System.out.println("length: " + android.size()); 32 | android.pop(); 33 | System.out.println("after pop: " + android); 34 | 35 | 36 | System.out.println( android.remove("apple")); 37 | 38 | 39 | System.out.println("get first: " + android.getFirst()); 40 | System.out.println("get last: " + android.getLast()); 41 | 42 | System.out.println("is empty: " + android.isEmpty()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Collections/hashMap.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | 3 | public class hashMap { 4 | 5 | 6 | public static void main(String[] args) { 7 | 8 | // creating an empty hashmap object of 9 | // strings & integer type 10 | HashMap map1 = new HashMap<>(); 11 | 12 | //adding elements to the map 13 | //using standard put method 14 | map1.put("Kayach", 455); 15 | map1.put("Dibakar", 566); 16 | map1.put("Souvik", 420); 17 | map1.put("Gourmani", 430); 18 | map1.put("Ratnadip", 484); 19 | 20 | int n = map1.size(); 21 | System.out.println(n); 22 | 23 | // map1. 24 | 25 | //printing the map1 object elements 26 | System.out.println(map1); 27 | 28 | 29 | System.out.println("marks obtained by kayach is: "+ map1.get("Dibakar")); 30 | 31 | 32 | //checking if a key is present 33 | // then print its value 34 | 35 | if (map1.containsKey("hemant")){ 36 | 37 | 38 | // get method will return value 39 | // of a key from map object 40 | 41 | System.out.println("student attended exam"); 42 | } 43 | else{ 44 | System.out.println("absent"); 45 | } 46 | 47 | } 48 | } 49 | 50 | 51 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Bikash Nath 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /OOPS/Class_Object.java: -------------------------------------------------------------------------------- 1 | public class Class_Object { 2 | int age = 25; 3 | int height = 164; 4 | int weight = 60; 5 | String color = "Brwon"; 6 | 7 | void sleep(){ 8 | System.out.println("Currently i m sleeping around 2 to 3 am mostly.."); 9 | } 10 | 11 | void eating() 12 | { 13 | System.out.println("breakfast:10 - 12, lunch:2.30 - 3.30, dinner:8 - 9.30"); 14 | } 15 | 16 | 17 | public static void main(String[] args) { 18 | 19 | Class_Object person = new Class_Object(); 20 | // System.out.println("My current age is "+person.age); 21 | // System.out.println("My height is "+person.height+" cm"); 22 | // System.out.println("My current weight is "+person.weight+" kg"); 23 | // System.out.println(person.color); 24 | // person.sleep(); 25 | // person.eating(); 26 | 27 | 28 | constru prsn = new constru(); //default constructor 29 | // prsn.person(); 30 | 31 | 32 | 33 | //parameterized constructor 34 | param_const ref = new param_const(95,"Gourmani"); 35 | ref.print(); 36 | 37 | 38 | //copy constructor 39 | copy_const ref2 = new copy_const(); 40 | 41 | 42 | } 43 | } 44 | 45 | 46 | 47 | // Constructor 48 | class constru{ 49 | 50 | int a; String name; 51 | 52 | constru(){ //default constructor 53 | a = 25; name = "Bikash"; 54 | } 55 | 56 | 57 | void person() 58 | { 59 | System.out.println("Age is "+ a+" name is " + name); 60 | } 61 | } 62 | 63 | class param_const{ 64 | int x; String str; 65 | 66 | param_const(int a, String s){ //parameterized constructor 67 | str = s; 68 | x = a; 69 | 70 | } 71 | 72 | 73 | void print (){ 74 | System.out.println("Marks obtained by "+str+" is: " + x); 75 | } 76 | } 77 | 78 | 79 | 80 | class copy_const{ 81 | int a; String s; 82 | 83 | copy_const(){ //default constructor 84 | a = 90; 85 | s = "Kayach"; 86 | System.out.println("Marks obtained by "+ s+ " is: " +a); 87 | } 88 | 89 | copy_const(copy_const ref){ //copy_constructor 90 | ref.a = a; 91 | ref.s = s; 92 | System.out.println("Marks obtained by "+ s+" is: "+ a); 93 | } 94 | } -------------------------------------------------------------------------------- /OOPS/MultilevelInheritance.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | //multi-level inheritance is the involvement 4 | // of atleast two or more than two class 5 | 6 | 7 | //one class inherits the propierties of one parent class 8 | //then newly created sub-class becomes the base-class for 9 | // another new class 10 | 11 | 12 | public class MultilevelInheritance { 13 | 14 | public static void main(String[] args) { 15 | 16 | System.out.println("Multi-level Inheritance program: "); 17 | 18 | Calculator fst = new Calculator(); 19 | 20 | fst.input(); 21 | fst.add(); 22 | fst.sub(); 23 | fst.multi(); 24 | fst.div(); 25 | fst.rem(); 26 | 27 | } 28 | 29 | } 30 | 31 | class addition{ 32 | 33 | Scanner s = new Scanner(System.in); 34 | 35 | int a, b; 36 | 37 | void add(){ 38 | System.out.println("Addition class: Addition of "+a + " & "+ b + " is "+(a+b)); 39 | } 40 | } 41 | 42 | 43 | class Subtraction extends addition{ 44 | 45 | 46 | 47 | void sub(){ 48 | System.out.println("Subtraction class: Subtraction of "+b + " from "+ a + " is "+(a-b)); 49 | } 50 | } 51 | 52 | class division extends Subtraction{ 53 | 54 | void div(){ 55 | System.out.println("Division class: Division of "+a + " by "+ b + " is "+(a/b)); 56 | } 57 | } 58 | 59 | 60 | class multiplication extends division{ 61 | 62 | void multi(){ 63 | System.out.println("Multiplication class: Multiplication of "+a + " with "+ b + " is "+(a*b)); 64 | } 65 | } 66 | 67 | 68 | class remainder extends multiplication{ 69 | 70 | void rem(){ 71 | System.out.println("Remainder class: Remainder of "+a + " % "+ b + " is "+(a%b)); 72 | } 73 | 74 | } 75 | 76 | 77 | class Calculator extends remainder{ 78 | 79 | void input(){ 80 | 81 | System.out.println("This is Calculator\n" + "Enter two numbers: "); 82 | 83 | 84 | 85 | a = s.nextInt(); 86 | b = s.nextInt(); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /OOPS/README.MD: -------------------------------------------------------------------------------- 1 | # Object Oriented Programming System (OOPS) 2 | 3 | OOPS in java is to improve code readability and reusability by defining a java program efficiently. 4 | 5 | ## The main principles of OOPS in java are: 6 | Classes/Objects 7 | Encapsulation/data-hidding 8 | Abstraction/interfaces 9 | Inheritance 10 | Polymorphism 11 | 12 | 13 | 14 | 15 | # Encapsulation 16 | It is the process by which data(variables) and the code acts upon them(methods) are integreted as a single unit. other class can not acces the data of a class, only methods can accessed 17 | 18 | 19 | 20 | # Abstraction 21 | abstraction class in java is the process of hiding the intricate code implementation from the user and just provides the user with necessary information 22 | 23 | 24 | 25 | # Inheritance 26 | inheritance in java is a concept that acquires all the propierties from one class to another class, the class which inherits is called sub-class/child-class and from which class child class inherits the propierties is called super-class/parent-class 27 | 28 | 29 | 30 | # Polymorphism 31 | polymorphism means 'many forms' and it occurs when we have many classes related to each other by inheritance 32 | -------------------------------------------------------------------------------- /OOPS/SingleInheritance.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | 4 | //single inheritance is the simplest type of inheritance 5 | //in this, a class inherits propierties from a single class 6 | 7 | 8 | 9 | class SingleInheritance{ 10 | 11 | public static void main(String[] args) { 12 | 13 | std_id pn = new std_id(); 14 | 15 | 16 | pn.input(); 17 | pn.disp(); 18 | } 19 | 20 | } 21 | 22 | 23 | class students{ 24 | static Scanner s = new Scanner(System.in); 25 | int roll, marks; 26 | String name; 27 | protected int id; 28 | 29 | void input(){ 30 | 31 | System.out.println("What is you'r name? "); 32 | name = s.next(); 33 | System.out.println("roll no: "); 34 | roll = s.nextInt(); 35 | System.out.println("Enter marks: "); 36 | marks = s.nextInt(); 37 | 38 | } 39 | } 40 | 41 | 42 | class std_id extends students{ 43 | 44 | void disp(){ 45 | System.out.println(marks + " marks obtained by "+name+ " & roll no is "+roll); 46 | } 47 | } -------------------------------------------------------------------------------- /OOPS/abstraction.java: -------------------------------------------------------------------------------- 1 | 2 | //data abstraction is a process of hiding 3 | //some info and showing only essential info to user 4 | 5 | 6 | 7 | 8 | public class abstraction { 9 | 10 | public static void main(String[] args) { 11 | 12 | rabbit rb = new rabbit(); 13 | rb.eat();rb.sound();rb.legs();rb.height();rb.colour(); 14 | 15 | 16 | 17 | dog dg = new dog(); 18 | dg.eat();dg.sound();dg.legs();dg.height(); 19 | 20 | 21 | 22 | cow cw = new cow(); 23 | cw.eat();cw.sound();cw.legs();cw.height(); 24 | 25 | } 26 | 27 | } 28 | 29 | 30 | 31 | //abstract class 32 | abstract class animal{ 33 | 34 | void legs(){ 35 | System.out.println("have 4 legs"); 36 | } 37 | 38 | abstract void sound(); 39 | abstract void eat(); 40 | abstract void height(); 41 | } 42 | 43 | class rabbit extends animal{ 44 | @Override 45 | void sound(){ 46 | System.out.println("Rabbits does not make sound"); 47 | } 48 | 49 | void eat(){ 50 | System.out.println("Rabbits use to eat carrot"); 51 | } 52 | 53 | void height(){ 54 | System.out.println("Rabbits height are less than 2-feet"); 55 | } 56 | 57 | void colour(){ 58 | System.out.println("Rabbit can be white, black or mixed Color"); 59 | } 60 | } 61 | 62 | 63 | class dog extends animal{ 64 | 65 | @Override 66 | void sound(){ 67 | System.out.println("Dog sounds like Bow Bow.."); 68 | } 69 | 70 | void eat(){ 71 | System.out.println("Dogs loves to meat"); 72 | } 73 | 74 | void height(){ 75 | System.out.println("Dogs are less than 3-feet height");; 76 | } 77 | 78 | 79 | 80 | } 81 | 82 | 83 | class cow extends animal{ 84 | 85 | @Override 86 | void sound(){ 87 | System.out.println("Cows sounds like Awwww Awwww.."); 88 | } 89 | 90 | void eat(){ 91 | System.out.println("Cows eats grass"); 92 | } 93 | 94 | void height(){ 95 | System.out.println("Cows are less than 4-feet height"); 96 | } 97 | } 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /OOPS/encapsulation.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | 4 | //Encapsulation in java refers to integrating 5 | //data(variables) and code(methods) into a single unit 6 | // 7 | //in encapsulation data variables are hidden from other class's 8 | //& can only be accessed by the methods in which thy are found 9 | 10 | class bank{ 11 | 12 | static Scanner sc = new Scanner(System.in); 13 | 14 | private int bal=5000; int pwd; 15 | 16 | 17 | 18 | public void check_balance(int pwd){ 19 | 20 | if (pwd==12345678) 21 | System.out.println("You'r bank balance is: " + bal); 22 | 23 | else 24 | System.out.println("Invalid Credential!"); 25 | } 26 | 27 | 28 | 29 | 30 | public void deposit(int pwd){ 31 | 32 | if (pwd==12345678){ 33 | System.out.println("How much money u want to deposit: "); 34 | int wtd = sc.nextInt(); 35 | bal += wtd; 36 | System.out.println("Balance after deposit of "+ wtd + " is: " + bal); 37 | } 38 | 39 | else 40 | System.out.println("Invalid Credential!"); 41 | } 42 | 43 | 44 | 45 | public void withdraw(int pwd){ 46 | 47 | if (pwd==12345678){ 48 | System.out.println("How much money u want to withdraw: "); 49 | int depo = sc.nextInt(); 50 | bal -= depo; 51 | System.out.println("Balance after withdraw of " + depo+" is: " + bal); 52 | } 53 | 54 | else 55 | System.out.println("Invalid Credential!"); 56 | 57 | } 58 | 59 | 60 | } 61 | 62 | 63 | 64 | class customer { 65 | 66 | static Scanner sc = new Scanner(System.in); 67 | 68 | public void customer() { 69 | bank cust = new bank(); 70 | 71 | System.out.print("1.Check balance\n2.Withdraw\n3.Deposit\nEnter you'r choice: "); 72 | int ch = sc.nextInt(); 73 | 74 | System.out.print("Enter you'r current password: "); 75 | int pwd = sc.nextInt(); 76 | 77 | 78 | switch(ch){ 79 | case 1:cust.check_balance(pwd); 80 | break; 81 | 82 | case 2:cust.withdraw(pwd); 83 | break; 84 | 85 | case 3:cust.deposit(pwd); 86 | break; 87 | 88 | default:System.out.println("Invalid choice!"); 89 | } 90 | } 91 | } 92 | 93 | 94 | public class encapsulation{ 95 | public static void main(String[] args) { 96 | 97 | customer cust = new customer(); 98 | 99 | cust.customer(); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /OOPS/hierarchical.java: -------------------------------------------------------------------------------- 1 | // when multiple sub classes inherit methods & paropierties of one 2 | // parent class then it is called hierarchical inheritance 3 | 4 | 5 | class hierarchical{ 6 | 7 | public static void main(String[] args) { 8 | 9 | programmer p = new programmer(); 10 | p.salary(); 11 | 12 | java_developer jd = new java_developer(); 13 | jd.salary(); 14 | 15 | system_designer sd = new system_designer(); 16 | sd.salary(); 17 | 18 | } 19 | } 20 | 21 | 22 | 23 | class employee{ 24 | float salary = 40000; 25 | 26 | 27 | } 28 | 29 | 30 | class programmer extends employee{ 31 | int bonus = 10000; 32 | 33 | void salary(){ 34 | System.out.println("Programmer salary is "+(salary+bonus)); 35 | } 36 | } 37 | 38 | class java_developer extends employee{ 39 | int bonus = 12000; 40 | 41 | void salary(){ 42 | System.out.println("Java-Developer salary is "+(salary+bonus)); 43 | } 44 | } 45 | 46 | 47 | class system_designer extends employee{ 48 | int bonus = 15000; 49 | 50 | void salary(){ 51 | System.out.println("System designer salary is "+(salary+bonus)); 52 | } 53 | } -------------------------------------------------------------------------------- /OOPS/instance_and_static.java: -------------------------------------------------------------------------------- 1 | public class instance_and_static { 2 | int b = 5; 3 | static int a=2; 4 | 5 | instance_and_static(){ 6 | System.out.println("Inside default constructor.."); 7 | } 8 | 9 | 10 | //instance block 11 | { 12 | 13 | // instance deals with object 14 | 15 | 16 | //object is must needed to access instance block 17 | 18 | //instance block calls before constructor 19 | // 20 | 21 | System.out.println("Inside instance block"); 22 | 23 | 24 | //instance block can access both static 25 | // and non-static variable 26 | 27 | System.out.println(a+" "+b); 28 | 29 | } 30 | 31 | 32 | 33 | static{ 34 | 35 | // static deals with class 36 | 37 | 38 | //static block runs when program compiled 39 | // no need for object initiation 40 | // static runs even before instance block 41 | 42 | System.out.print("Inside static block "); 43 | 44 | 45 | 46 | // static block can only access static variable 47 | System.out.println(a); 48 | } 49 | 50 | 51 | public static void main(String[] args) { 52 | 53 | instance_and_static ref = new instance_and_static(); 54 | } 55 | 56 | 57 | } 58 | -------------------------------------------------------------------------------- /OOPS/interface_class.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | public class interface_class { 4 | public static void main(String[] args) { 5 | 6 | tvs cst = new tvs(); 7 | cst.start();cst.stop();cst.speed(); 8 | cst.color(); 9 | 10 | 11 | honda hnd = new honda(); 12 | hnd.start();hnd.stop();hnd.speed();hnd.color(); 13 | 14 | } 15 | } 16 | 17 | 18 | 19 | //in class name instead abstract keyword interface used 20 | interface vehicle{ 21 | 22 | String model = "TVS"; //public + static + final 23 | 24 | void start(); //public + abstract method without abstract key 25 | 26 | void stop(); //public + abstract method without abstract key 27 | 28 | 29 | // default method in interface introduced after jdk v-1.8 30 | default void speed(){ 31 | System.out.println("TVS model speed is 100 KM/H"); 32 | } 33 | 34 | 35 | //static methods also can be implemented 36 | static void wheel(){ 37 | System.out.println("TVS bikes have 2 vehicle, lol!"); 38 | } 39 | 40 | 41 | } 42 | 43 | 44 | 45 | //in interface instead of extends keyword implements used 46 | class tvs implements vehicle{ 47 | 48 | @Override // annotation 49 | public void start(){ 50 | System.out.println("start(): insert key & press accelarator"); 51 | } 52 | 53 | @Override 54 | public void stop(){ 55 | System.out.println("stop(): exit key"); 56 | } 57 | 58 | static void color(){ 59 | System.out.println("TVS model color is Red"); 60 | } 61 | 62 | } 63 | 64 | 65 | 66 | class honda implements vehicle{ 67 | @Override 68 | public void start(){ 69 | System.out.println("start(): insert key & press accelarator"); 70 | } 71 | 72 | @Override 73 | public void stop(){ 74 | System.out.println("stop(): Exit key"); 75 | } 76 | 77 | void color(){ 78 | System.out.println("Honda color is blue and red"); 79 | } 80 | 81 | @Override 82 | public void speed(){ 83 | System.out.println("Honda speed is 125 Km/H"); 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /OOPS/methodOverLoading.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | 4 | //the term method overloading allows us to have more 5 | //methods with same name, since this process executed 6 | // in compile time it is called as compile time polymorphism 7 | 8 | public class methodOverLoading extends student { 9 | 10 | public static void main(String[] args) { 11 | 12 | student std = new student(); 13 | 14 | std.student(); 15 | 16 | 17 | } 18 | 19 | } 20 | 21 | 22 | class student{ 23 | 24 | static Scanner Sc = new Scanner(System.in); 25 | 26 | 27 | void student(){ 28 | 29 | System.out.println("\nEnter you'r Id: "); 30 | int id = Sc.nextInt(); 31 | 32 | System.out.println("Id: " + id); 33 | student(id); 34 | 35 | 36 | } 37 | 38 | void student(int id){ 39 | 40 | String name=""; 41 | 42 | switch(id){ 43 | case 1:name = "Kayach";break; 44 | case 2:name = "Dibakar";break; 45 | case 3:name = "Ratnadip";break; 46 | case 4:name = "Piklu";break; 47 | case 5:name = "Shubhankar";break; 48 | case 6:name = "Gourmani";break; 49 | case 7:name = "Souvik";break; 50 | case 8:name = "Sandip";break; 51 | case 9:name = "Naveen";break; 52 | case 10:name = "Ashish";break; 53 | case 11:name = "Hemant";break; 54 | default:System.out.println("Invalid Id.."); 55 | } 56 | 57 | student(name); 58 | } 59 | 60 | 61 | void student(String name){ 62 | 63 | int marks=0 ; 64 | 65 | switch(name){ 66 | case "Kayach": marks = 77;break; 67 | case "Dibakar": marks = 88;break; 68 | case "Ratnadip": marks = 91;break; 69 | case "Piklu": marks = 69;break; 70 | case "Shubhankar": marks = 80;break; 71 | case "Gourmani": marks = 79;break; 72 | case "Souvik": marks = 96;break; 73 | case "Sandip": marks = 63;break; 74 | case "Naveen": marks = 98;break; 75 | case "Ashish": marks = 93;break; 76 | case "Hemant": marks = 99;break; 77 | 78 | } 79 | 80 | student(name, marks); 81 | } 82 | 83 | void student(String name, int marks){ 84 | 85 | System.out.println("Name: "+ name + "\nMarks: " + marks); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /OOPS/methodOverRiding.java: -------------------------------------------------------------------------------- 1 | // runtime polymorphism or dynamic method dispatch is a process 2 | // to resolve a call to an overridden method at runtime 3 | 4 | 5 | 6 | /*RunTime Polymorphism */ 7 | 8 | 9 | public class methodOverRiding { 10 | 11 | public static void main(String[] args) { 12 | 13 | shape shp = new square(); 14 | shp.show(); // will call only overridden method 15 | 16 | 17 | shape sp = new round(); 18 | // sp.show(); //will call both parent & sub class method 19 | 20 | 21 | shape sp1 = new rectangle(); 22 | // sp1.show(); // will call sub class method 23 | 24 | } 25 | } 26 | 27 | 28 | class shape{ 29 | 30 | void show(){ 31 | System.out.println("Unkown Shape"); 32 | } 33 | } 34 | 35 | class rectangle extends shape{ 36 | 37 | void show(){ 38 | System.out.println("Rectangle Shape"); 39 | } 40 | 41 | } 42 | 43 | 44 | 45 | //overridden method is runtime polymorphism 46 | class square extends shape{ 47 | 48 | @Override // annotation ensures that the succeeding method must overridden 49 | void show(){ 50 | System.out.println("Square Shape"); 51 | } 52 | } 53 | 54 | class round extends shape{ 55 | 56 | void show(){ 57 | super.show(); 58 | System.out.println("Round Shape"); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /OOPS/multiple_inheritance.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | 4 | //multiple inheritance is the capability of creating 5 | // a single class with multiple super classes 6 | 7 | 8 | //unlike other popular OOPs languages java does 9 | // not support multiple inheritance but we can achive 10 | // it through interface because interface only provides 11 | // abstract method which implementation provided by 12 | // the sub classes 13 | 14 | 15 | interface sum{ 16 | static Scanner scn = new Scanner(System.in); 17 | 18 | void add(); 19 | } 20 | 21 | interface subtracts{ 22 | 23 | void sub(); 24 | } 25 | 26 | 27 | interface multiply{ 28 | 29 | void multi(); 30 | } 31 | 32 | 33 | interface divide{ 34 | 35 | void div(); 36 | } 37 | 38 | interface remain{ 39 | void rem(); 40 | } 41 | 42 | 43 | 44 | public class multiple_inheritance implements sum, subtracts, multiply, divide, remain{ 45 | 46 | int a, b; 47 | 48 | void input(){ 49 | 50 | System.out.println("Enter two numbers: "); 51 | a = scn.nextInt(); 52 | b = scn.nextInt(); 53 | } 54 | 55 | public void add(){ 56 | 57 | System.out.println("Addition of "+ a + " & " + b +" is " + (a+b)); 58 | } 59 | 60 | 61 | public void sub(){ 62 | System.out.println("Subtraction of "+ b + " from " + a +" is " + (a-b)); 63 | } 64 | 65 | 66 | public void multi(){ 67 | System.out.println("Multiplication of "+ a + " with " + b +" is " + (a*b)); 68 | } 69 | 70 | 71 | public void div(){ 72 | System.out.println("Division of "+ a + " by " + b +" is " + (a/b)); 73 | } 74 | 75 | 76 | public void rem(){ 77 | System.out.println("Remainder of "+ a+" % "+ b + " is " + (a%b)); 78 | } 79 | 80 | 81 | public static void main(String[] args) { 82 | 83 | multiple_inheritance Calcu = new multiple_inheritance(); 84 | 85 | System.out.println("Multiple Inheritance program:"); 86 | 87 | Calcu.input(); 88 | Calcu.add(); 89 | Calcu.sub(); 90 | Calcu.multi(); 91 | Calcu.div(); 92 | Calcu.rem(); 93 | } 94 | 95 | 96 | } 97 | -------------------------------------------------------------------------------- /OOPS/private_constructor.java: -------------------------------------------------------------------------------- 1 | public class private_constructor { 2 | int a; String str; 3 | 4 | 5 | private private_constructor(){ // private constructor cant accessed from other class 6 | a=78; 7 | str = "Dibakar"; 8 | System.out.println("Marks obtained by "+str+" is: " + a); 9 | } 10 | 11 | 12 | public static void main(String[] args) { 13 | private_constructor pv = new private_constructor(); 14 | } 15 | } 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /OOPS/super_keyword.java: -------------------------------------------------------------------------------- 1 | class super_class { 2 | 3 | int x = 82; String str = "Shubankar"; 4 | 5 | super_class(){ 6 | System.out.println("Super class constructor"); 7 | } 8 | 9 | void print(){ 10 | System.out.println("Learn anywhere"); 11 | } 12 | 13 | } 14 | 15 | class sub_class extends super_class{ 16 | 17 | 18 | int x=89; String str= "Shubam"; 19 | 20 | sub_class(){ 21 | 22 | // super class constructor will run by default 23 | //but for parameterized constructor we must 24 | // call super constructor & pass the params 25 | 26 | System.out.println("Sub class constructor"); 27 | } 28 | 29 | void show(){ 30 | System.out.println("Marks obtained by "+str+" is: " + x); 31 | 32 | //super keyword is used to call variable from super class 33 | System.out.println("Marks obtained by "+super.str+" is: " + super.x); 34 | } 35 | 36 | 37 | void print(){ 38 | 39 | super.print(); //super will run print method from super class 40 | System.out.println("& Improve skills.."); 41 | } 42 | } 43 | 44 | 45 | class super_keyword{ 46 | 47 | public static void main(String[] args) { 48 | sub_class ref = new sub_class(); 49 | 50 | ref.show(); 51 | ref.print(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /OOPS/this_keyword.java: -------------------------------------------------------------------------------- 1 | // this keyword is the reference variable of class 2 | 3 | 4 | public class this_keyword { 5 | 6 | 7 | //calling parameterized constructor 8 | this_keyword(){ 9 | this(200); 10 | } 11 | 12 | this_keyword(int x){ 13 | System.out.println("Score is " + x); 14 | } 15 | 16 | 17 | 18 | 19 | 20 | //calling default constructor 21 | // this_keyword(){ 22 | // System.out.println("Hello Coder!"); 23 | // } 24 | 25 | // this_keyword(int x){ 26 | // this(); 27 | // System.out.println(x); 28 | // } 29 | 30 | 31 | 32 | 33 | 34 | //refering current object 35 | // int rollno; String name; float fee; 36 | 37 | // this_keyword(int rollno, String name, float fee){ 38 | 39 | // // this.rollno = rollno; 40 | // // this.name = name; 41 | // // this.fee = fee; 42 | // } 43 | 44 | 45 | 46 | // void display(){ 47 | // System.out.println(rollno+" "+name + " "+ fee); 48 | // } 49 | 50 | 51 | public static void main(String[] args) { 52 | 53 | // this_keyword ref = new this_keyword(01, "Anhkit", 4000f); 54 | // ref.display(); 55 | 56 | 57 | this_keyword ref = new this_keyword(); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Classification of Data Structure: 2 | 1.Linear Data Structure: 3 | i. Static Data Structure: Array 4 | 5 | ii.Dynamic Data Structure: 6 | * Queue 7 | * Linked List 8 | * Stack 9 | 10 | 2.Non-Linear Data Structure: 11 | * Tree 12 | * Graph 13 | 14 | 15 | 16 | 17 | 18 | # java-coding 19 | 20 | 21 | ### Notes to remind of: 22 | * embedded: portable, reuseable, reliable with embedded systems 23 | * secure: compile code into a binary byte interpreted on JVM 24 | * robust: utilizes strong memory management by bypassing security dilemmas 25 | * architecture neutral: 4 bits of memory for both 32 & 64 bit architeure 26 | * high performance: byte code is close to native code 27 | * distributed: facilitates users to create distributed apps (RMI & EJB) 28 | * multi-threaded: doesn't occupy memory for each thread, shares a common memory area 29 | * dynamic: classes are loaded on demand also supports functions from native languages i.e. C, C++ 30 | 31 | 32 | ### Reserved Keywords 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /_basic/Access_Modifier.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | // access modifier in java specifies the accessibilty 5 | // or scope of a field, method, constructor or class 6 | 7 | 8 | 9 | public class Access_Modifier { 10 | 11 | private void private_func(){ 12 | System.out.println("private method only accessible within class"); 13 | } 14 | 15 | 16 | void default_func(){ 17 | System.out.println("default method can accessed outside class"); 18 | } 19 | 20 | 21 | protected void protected_func(){ 22 | System.out.println("except outside package, protected method can accessible anywhere"); 23 | } 24 | 25 | 26 | public void public_func(){ 27 | System.out.println("public method can accessible anywhere"); 28 | } 29 | 30 | 31 | public static void main(String[] args) { 32 | 33 | Access_Modifier am = new Access_Modifier(); 34 | 35 | am.private_func(); 36 | am.default_func(); 37 | am.protected_func(); 38 | am.public_func(); 39 | 40 | } 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /_basic/Calculator_switch.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Calculator_switch { 4 | 5 | 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | System.out.println("Enter 1st Num: "); 9 | int n1 = sc.nextInt(); 10 | System.out.println("Enter 2nd Num: "); 11 | int n2 = sc.nextInt(); 12 | System.out.println("Enter Choice: + - * / %"); 13 | char c= sc.next().charAt(0); 14 | 15 | switch(c){ 16 | case '+': 17 | System.out.println("Addition of " + n1+ " and " +n2 +" is = " + (n1+n2)); 18 | break; 19 | case '-': 20 | System.out.println("Subtraction of " + n2 +" from "+n1 + " is = "+ (n1 - n2)); 21 | break; 22 | case '*': 23 | System.out.println("Multiplication of " + +n1 +" with " + n2 + " is = " + (n1*n2)); 24 | break; 25 | case '/': 26 | System.out.println("Division of "+ n1 + " by " + n2 + " is = " + (n1/n2)); 27 | break; 28 | case '%': 29 | System.out.println(n1 + " Modulo "+ n2 + " is = " + (n1%n2)); 30 | break; 31 | default: 32 | System.out.println("Invalid Choice.."); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /_basic/Fastest_IO.java: -------------------------------------------------------------------------------- 1 | import java.io.DataInputStream; 2 | import java.io.FileInputStream; 3 | import java.io.IOException; 4 | import java.sql.Time; 5 | import java.util.Scanner; 6 | 7 | class Fastest_IO{ 8 | 9 | static class Reader { 10 | final private int BUFFER_SIZE = 1 << 16; 11 | private DataInputStream din; 12 | private byte[] buffer; 13 | private int bufferPointer, bytesRead; 14 | 15 | public Reader() 16 | { 17 | din = new DataInputStream(System.in); 18 | buffer = new byte[BUFFER_SIZE]; 19 | bufferPointer = bytesRead = 0; 20 | } 21 | 22 | public Reader(String file_name) throws IOException 23 | { 24 | din = new DataInputStream( 25 | new FileInputStream(file_name)); 26 | buffer = new byte[BUFFER_SIZE]; 27 | bufferPointer = bytesRead = 0; 28 | } 29 | 30 | public String readLine() throws IOException 31 | { 32 | byte[] buf = new byte[64]; // line length 33 | int cnt = 0, c; 34 | while ((c = read()) != -1) { 35 | if (c == '\n') { 36 | if (cnt != 0) { 37 | break; 38 | } 39 | else { 40 | continue; 41 | } 42 | } 43 | buf[cnt++] = (byte)c; 44 | } 45 | return new String(buf, 0, cnt); 46 | } 47 | 48 | public int nextInt() throws IOException 49 | { 50 | int ret = 0; 51 | byte c = read(); 52 | while (c <= ' ') { 53 | c = read(); 54 | } 55 | boolean neg = (c == '-'); 56 | if (neg) 57 | c = read(); 58 | do { 59 | ret = ret * 10 + c - '0'; 60 | } while ((c = read()) >= '0' && c <= '9'); 61 | 62 | if (neg) 63 | return -ret; 64 | return ret; 65 | } 66 | 67 | public long nextLong() throws IOException 68 | { 69 | long ret = 0; 70 | byte c = read(); 71 | while (c <= ' ') 72 | c = read(); 73 | boolean neg = (c == '-'); 74 | if (neg) 75 | c = read(); 76 | do { 77 | ret = ret * 10 + c - '0'; 78 | } while ((c = read()) >= '0' && c <= '9'); 79 | if (neg) 80 | return -ret; 81 | return ret; 82 | } 83 | 84 | public double nextDouble() throws IOException 85 | { 86 | double ret = 0, div = 1; 87 | byte c = read(); 88 | while (c <= ' ') 89 | c = read(); 90 | boolean neg = (c == '-'); 91 | if (neg) 92 | c = read(); 93 | 94 | do { 95 | ret = ret * 10 + c - '0'; 96 | } while ((c = read()) >= '0' && c <= '9'); 97 | 98 | if (c == '.') { 99 | while ((c = read()) >= '0' && c <= '9') { 100 | ret += (c - '0') / (div *= 10); 101 | } 102 | } 103 | 104 | if (neg) 105 | return -ret; 106 | return ret; 107 | } 108 | 109 | private void fillBuffer() throws IOException 110 | { 111 | bytesRead = din.read(buffer, bufferPointer = 0, 112 | BUFFER_SIZE); 113 | if (bytesRead == -1) 114 | buffer[0] = -1; 115 | } 116 | 117 | private byte read() throws IOException 118 | { 119 | if (bufferPointer == bytesRead) 120 | fillBuffer(); 121 | return buffer[bufferPointer++]; 122 | } 123 | 124 | public void close() throws IOException 125 | { 126 | if (din == null) 127 | return; 128 | din.close(); 129 | } 130 | } 131 | 132 | public static void main(String[] args) throws IOException { 133 | 134 | 135 | 136 | 137 | 138 | /*Fastest Input */ 139 | 140 | Reader inp = new Reader(); 141 | 142 | int k=0; 143 | long start_reader = System.currentTimeMillis(); 144 | 145 | for (int j=0;j<15;j++) 146 | k = inp.nextInt(); 147 | 148 | long end_reader = System.currentTimeMillis(); 149 | 150 | System.out.println("Time taken by Fastest Input: " + (end_reader-start_reader)); 151 | 152 | 153 | 154 | 155 | // Scanner sc = new Scanner(System.in); 156 | 157 | // int n=0; 158 | // long start = System.currentTimeMillis(); 159 | 160 | // for (int i=0;i<15;i++) 161 | // n = sc.nextInt(); 162 | 163 | // long end = System.currentTimeMillis(); 164 | 165 | // System.out.println("Time taken by Scanner class: " + (end-start)); 166 | 167 | } 168 | } -------------------------------------------------------------------------------- /_basic/FileHandling.java: -------------------------------------------------------------------------------- 1 | import java.io.File; 2 | import java.io.FileWriter; 3 | 4 | 5 | public class FileHandling { 6 | 7 | 8 | public static void main(String[] args) { 9 | 10 | //file creation 11 | 12 | File f = new File("C:\\Users\\Bikash\\Desktop\\_git\\data.txt"); 13 | 14 | try{ 15 | if (f.createNewFile()) System.out.println("new file created.."); 16 | 17 | else System.out.println("file exists.."); 18 | } 19 | catch (Exception e){System.out.println("Exception");} 20 | 21 | 22 | 23 | //file writer can override existing file new data 24 | try{ 25 | FileWriter fw = new FileWriter("C:\\Users\\Bikash\\Desktop\\_git\\data.txt"); 26 | 27 | try{ 28 | fw.write("i m currently working on java improvement, one can see improvement day by day"); 29 | } 30 | 31 | finally{ 32 | fw.close(); 33 | } 34 | 35 | System.out.println("Successfully created"); 36 | } 37 | 38 | catch (Exception e){ 39 | System.out.println("already created"); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /_basic/README.MD: -------------------------------------------------------------------------------- 1 | here i have solved some problems 2 | using specific built-in functions 3 | -------------------------------------------------------------------------------- /_basic/ReadData.java: -------------------------------------------------------------------------------- 1 | import java.io.FileReader; 2 | import java.io.IOException; 3 | 4 | public class ReadData { 5 | 6 | 7 | public static void main(String[] args) { 8 | 9 | try{ 10 | FileReader fr = new FileReader("buffer.txt"); 11 | 12 | try{ 13 | int i=0; 14 | while ((i=fr.read())!=-1){ 15 | System.out.print((char) i); 16 | } 17 | } 18 | finally{ 19 | fr.close(); 20 | System.out.println("\nfile closed"); 21 | } 22 | } 23 | catch(IOException e){ 24 | System.out.println("Exception handled"); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /_basic/Ternary_Operator.java: -------------------------------------------------------------------------------- 1 | import java.io.IOException; 2 | import java.util.Scanner; 3 | 4 | public class Ternary_Operator { 5 | 6 | // ternary operator is alternate to 7 | // if-else conditional statement 8 | // syntax of ternary is follows: 9 | // condition ? ifConditionTrue : ifConditionFalse; 10 | 11 | 12 | public static void main (String[] args) 13 | { 14 | 15 | Scanner sc = new Scanner(System.in); 16 | 17 | int t = sc.nextInt(); 18 | 19 | while (t>0){ 20 | int x = sc.nextInt(); 21 | 22 | //below line of code is ternary operator 23 | String res = x >= 2000 ? "YES" : "NO"; //storing value to a variable condition wise 24 | 25 | //printing the result 26 | System.out.println(res); 27 | t--; 28 | } 29 | 30 | sc.close(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /_basic/bitwise.java: -------------------------------------------------------------------------------- 1 | class bitwise{ 2 | public static void main(String[] args) { 3 | int a = 4; 4 | int b = 4; 5 | 6 | 7 | System.out.println("bitwise and result is: " + (a & b)); // bitwise and ( & ) 8 | 9 | 10 | System.out.println("bitwise or result is: " + (a | b)); // bitwise or ( | ) 11 | 12 | System.out.println("bitwise xor result is: " + (a ^ b)); //bitwise XOR ( ^ ) 13 | } 14 | } -------------------------------------------------------------------------------- /_basic/bufferedReader_output.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.FileReader; 3 | import java.io.IOException; 4 | 5 | public class bufferedReader_output{ 6 | 7 | 8 | public static void main(String[] args) throws IOException{ 9 | 10 | BufferedReader br = new BufferedReader(new FileReader("buffer.txt")); 11 | 12 | String line; 13 | 14 | while((line=br.readLine())!=null){ 15 | System.out.println(line); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /_basic/bufferedWriter.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedWriter; 2 | import java.io.FileWriter; 3 | import java.io.IOException; 4 | 5 | public class bufferedWriter { 6 | 7 | 8 | public static void main(String[] args) throws IOException { 9 | 10 | 11 | FileWriter fw = new FileWriter("C:\\Users\\Bikash\\Desktop\\_git\\buffer.txt"); 12 | 13 | BufferedWriter bf = new BufferedWriter(fw); 14 | 15 | bf.write("buffered writer file created, using file writer too"); 16 | 17 | bf.close(); 18 | 19 | System.out.println("successfully written"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /_basic/do_while.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class do_while{ 4 | 5 | public static void main(String args[]){ 6 | 7 | Scanner sc = new Scanner(System.in); 8 | 9 | System.out.println("Enter any number: "); 10 | 11 | int num = sc.nextInt(); 12 | 13 | do{ 14 | System.out.print(num + " "); 15 | ++num; 16 | } 17 | while(num<10);{ 18 | System.out.println("\n" + num + " Learn Coding"); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /_basic/for_each.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | class for_each{ 4 | 5 | public static void main (String args[]){ 6 | 7 | int[] arr = {1 , 5 , 8, 12, 6, 9, 20, 24}; 8 | 9 | 10 | // for-each loop iterates through all elements 11 | // it's primarily used in iterating array/list 12 | // incrementation happens by itself in for_each 13 | 14 | for (int element : arr){ 15 | System.out.print(element + " , "); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /_basic/multiThreading.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | //multithreading refers to a process of executing 5 | // two or more threads simultaneously for maximum 6 | // utilization of cpu 7 | 8 | 9 | 10 | //in multithreading order of execution of threads 11 | // will be different in every run 12 | 13 | 14 | 15 | public class multiThreading { 16 | 17 | 18 | //main thread will considered as thread-1 19 | public static void main(String[] args) throws InterruptedException { 20 | 21 | result ref = new result(); 22 | 23 | ref.start(); // this will call thread-2 & both thread will run simultaneously 24 | 25 | for (int i=1; i<=5; i++) 26 | System.out.println("Tripura"); 27 | Thread.sleep(1000); 28 | } 29 | } 30 | 31 | 32 | //inheriting result class with Thread class 33 | class result extends Thread{ 34 | 35 | 36 | //override of run method from thread class 37 | @Override 38 | public void run(){ 39 | 40 | try{ 41 | for(int i=1;i<=5;i++){ 42 | System.out.println("India"); 43 | Thread.sleep(1000); 44 | } 45 | } 46 | catch (InterruptedException i){} 47 | 48 | } 49 | 50 | 51 | void fun(){ 52 | 53 | try{ 54 | for (int i=1;i<=5;i++){ 55 | System.out.println("Delhi"); 56 | Thread.sleep(1000);} 57 | } 58 | catch(InterruptedException i){} 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /_basic/multithreading_2nd.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | // in multithreading u cant expect the order of execution 4 | // of threads, every order of execution will be different 5 | 6 | 7 | 8 | public class multithreading_2nd { 9 | 10 | public static void main(String[] args) { 11 | 12 | thrds tr = new thrds(); 13 | 14 | 15 | //creating object of Thread cause Runnable interface 16 | // does not have any start method 17 | Thread ref = new Thread(tr); 18 | 19 | ref.start(); 20 | 21 | 22 | for (int i=1;i<=5;i++) 23 | System.out.println("Main thread"); 24 | 25 | 26 | } 27 | 28 | } 29 | 30 | 31 | 32 | class thrds implements Runnable{ 33 | 34 | 35 | public void run(){ 36 | 37 | for (int i=1; i<=5;i++) 38 | System.out.println("Child threaed"); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /_basic/string.java: -------------------------------------------------------------------------------- 1 | // String without new keyword called string 2 | // literal and stored in string constant pool 3 | 4 | 5 | 6 | // string with new keyword is actually a string object 7 | // and directly stored in Heap memory 8 | 9 | 10 | // both carries different reference's 11 | 12 | 13 | 14 | 15 | public class string { 16 | 17 | public static void main(String[] args) { 18 | 19 | 20 | 21 | String str = "hello world"; 22 | 23 | String str1 = "hello"; 24 | 25 | // if (str == str1){ 26 | // System.out.println("equal"); 27 | // } 28 | // else 29 | // System.out.println("not equal"); 30 | 31 | 32 | 33 | // System.out.println(str); 34 | 35 | String str2 = new String(" hello world"); 36 | 37 | // System.out.println(str2); 38 | 39 | // System.out.println(str.length()); 40 | // System.out.println(str.charAt(4)); 41 | 42 | // System.out.println(str.substring(0, 5)); 43 | 44 | // System.out.println(str.indexOf("w")); 45 | 46 | 47 | String new_str = str.concat(str2); 48 | 49 | System.out.println(new_str); 50 | 51 | // if (str.equals(str2)){ 52 | // System.out.println("both are equal"); 53 | // } 54 | // else 55 | // System.out.println("not equal"); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /_basic/tryCatch.java: -------------------------------------------------------------------------------- 1 | class tryCatch{ 2 | 3 | 4 | public static void main(String[] args) { 5 | 6 | System.out.println("Main started"); 7 | int a=10, b=0, c; 8 | 9 | try{ 10 | c = a/b; 11 | System.out.println(c); 12 | } 13 | catch (ArithmeticException e){ 14 | System.out.println(e); 15 | } 16 | 17 | System.out.println("Main ended"); 18 | } 19 | } -------------------------------------------------------------------------------- /_basic/type_casting.java: -------------------------------------------------------------------------------- 1 | public class type_casting { 2 | 3 | public static void main(String[] args) { 4 | 5 | String str = "1213"; // numerical string 6 | 7 | 8 | int n = Integer.parseInt(str); // String to integer 9 | 10 | String str2 = Integer.toString(n); //Integer to String 11 | 12 | byte b = (byte) n; // integer to byte 13 | 14 | short st = (short) n; // int to char 15 | 16 | long lg = (long) b; // byte to long 17 | 18 | System.out.println(str + 5); 19 | System.out.println(n + 5); 20 | 21 | System.out.println(str2+ " " + st + " " + lg + " " + b); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /_recursion/Fibonacci.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class fibonacci 4 | { 5 | static int fib(int n) 6 | { 7 | if (n==1 || n==2){ 8 | return 1; 9 | } 10 | return fib(n-1) + fib(n-2); 11 | } 12 | public static void main(String[] args) 13 | { 14 | int n; 15 | Scanner scn = new Scanner(System.in); 16 | n = scn.nextInt(); 17 | System.out.println(fib(n)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /_recursion/GeomatricSum.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | 4 | 5 | public class GeomatricSum { 6 | 7 | 8 | public static double geoSum(int i, int k, double res){ 9 | 10 | // this method will recursively increment Value of i 11 | // till i==k, when i & k becomes equal it will return 12 | // res as double value 13 | 14 | 15 | if (i>k){return res;} 16 | 17 | 18 | 19 | // storing value to res variable after every iteration 20 | // using geomatric sum method (1/2^i) 21 | 22 | res += 1/(Math.pow(2, i)); 23 | 24 | return geoSum(i+1, k, res); 25 | 26 | 27 | 28 | 29 | } 30 | 31 | public static double findGeoSum(int k){ 32 | 33 | 34 | // this method will call another method 35 | // called geoSum by assigning 36 | // two more params to that 37 | // and evntually geoSum method will 38 | // return the required double value 39 | 40 | return geoSum(0, k, 0.0); 41 | } 42 | 43 | 44 | public static void main(String[] args) { 45 | Scanner sc = new Scanner(System.in); 46 | 47 | 48 | System.out.println("Enter number here"); 49 | int k = sc.nextInt(); 50 | 51 | System.out.println("Geomatric Sum of " + k + " is " + findGeoSum(k)); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /_recursion/PairStar.java: -------------------------------------------------------------------------------- 1 | //this java program will recursively add "*" 2 | // between two consecutive same characters 3 | 4 | import java.util.Scanner; 5 | 6 | public class PairStar { 7 | 8 | static String res = ""; 9 | 10 | public static void pairStar(String str, int i){ 11 | 12 | //this method will add * between two 13 | // consecutive characters after called 14 | 15 | res += str.charAt(i); 16 | 17 | 18 | // base case: when becomes the length of 19 | // the string method will return itself 20 | 21 | if (i==str.length()-1) 22 | return; 23 | 24 | 25 | // below if statement will add * between two same char 26 | if (str.charAt(i) == str.charAt(i+1)){ 27 | res += "*"; 28 | } 29 | 30 | 31 | pairStar(str, i+1); 32 | } 33 | 34 | 35 | public static void main(String[] args) { 36 | Scanner sc = new Scanner(System.in); 37 | String str = sc.nextLine(); 38 | 39 | pairStar(str, 0); 40 | 41 | System.out.println("after calling pairStar method string is: " + res); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /_recursion/QuickSort.java: -------------------------------------------------------------------------------- 1 | public class QuickSort { 2 | 3 | public static int partition(int[] a,int si, int ei){ 4 | int c=0; 5 | for(int i=si+1;i<=ei;i++){ 6 | if (a[si]>=a[i]){c++;} 7 | } 8 | 9 | int tmp = a[si + c]; 10 | a[si + c] = a[si]; 11 | a[si] = tmp; 12 | 13 | int j=si, k=ei; 14 | while (j=a[c]){k--;} 17 | else{ 18 | tmp = a[j]; 19 | a[j] = a[k]; 20 | a[k] = tmp; 21 | j++; 22 | k--; 23 | } 24 | 25 | } 26 | return si+c; 27 | } 28 | 29 | public static void quickSort(int[] a,int si, int ei){ 30 | 31 | if (si>=ei){return;} 32 | 33 | int c = partition(a, si, ei); 34 | 35 | quickSort(a, si, c-1); 36 | quickSort(a, c+1, a.length-1); 37 | } 38 | 39 | public static void quickSort(int[] a){ 40 | quickSort(a, 0, a.length-1); 41 | } 42 | 43 | 44 | 45 | public static void printArray(int[] a){ 46 | for (int i:a){ 47 | System.out.print(i+ " "); 48 | } 49 | } 50 | 51 | 52 | public static void main(String[] args) { 53 | int[] arr = {3, 2, 5, 6, 1, 4, 7, 9, 8}; 54 | 55 | int[] arr2 = {3, 2, 5,6, 5, 6, 1, 4, 8, 3, 9 ,7}; 56 | 57 | quickSort(arr2); 58 | 59 | printArray(arr2); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /_recursion/README.MD: -------------------------------------------------------------------------------- 1 | # Recursion in Programming 2 | The process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called recursive function 3 | 4 | -------------------------------------------------------------------------------- /_recursion/StringToInt.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class StringToInt { 4 | 5 | 6 | static int x = 0; // x variable will store the value of coverted string 7 | 8 | public static int StringToInt(String str){ 9 | 10 | 11 | //this method will covert string into int 12 | // recursively, 13 | 14 | 15 | 16 | // base case: when length of the string 17 | // will become 1 method will return 18 | // x as int value of string 19 | 20 | if (str.length()==1){ 21 | x = (x*10) + Integer.parseInt(str.substring(0, 1)); 22 | return x; 23 | } 24 | 25 | 26 | //method will recursively call itself and add int 27 | //value of string to the decimal place to 28 | // x variable at the same time length of 29 | // string will be sliced with substring 30 | 31 | else{ 32 | x = (x*10) + Integer.parseInt(str.substring(0, 1)); 33 | return StringToInt(str.substring(1)); 34 | } 35 | } 36 | 37 | 38 | public static void main(String[] args) { 39 | Scanner sc = new Scanner(System.in); 40 | 41 | System.out.println("only type string of int here: "); 42 | 43 | String str = sc.nextLine(); 44 | 45 | System.out.println("int value of " + str + " is " + StringToInt(str)); 46 | 47 | sc.close(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /_recursion/TowerOfHanoi.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class TowerOfHanoi { 3 | 4 | 5 | public static void towerOfHanoi(int disks, char source, char auxiliary, char destination) { 6 | if (disks !=0){ 7 | if (disks==1){ 8 | System.out.println(source+" "+destination); 9 | return;} 10 | 11 | 12 | towerOfHanoi(disks-1, source, destination, auxiliary); 13 | System.out.println(source+" "+destination); 14 | towerOfHanoi(disks-1, auxiliary, source, destination); 15 | 16 | } 17 | 18 | } 19 | 20 | 21 | public static void main(String[] args) { 22 | Scanner s = new Scanner(System.in); 23 | int n = s.nextInt(); 24 | towerOfHanoi(n, 'a', 'b', 'c'); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /_recursion/binarySearch.java: -------------------------------------------------------------------------------- 1 | public class binarySearch { 2 | 3 | 4 | public static int binSrc(int[] arr,int si,int ei,int x){ 5 | 6 | if (si>ei){return -1;} 7 | 8 | int mi = (si+ei)/2; 9 | 10 | if (arr[mi] == x){return mi;} 11 | else if(arr[mi]arr[1]) 12 | return false; 13 | 14 | 15 | 16 | return isSorted(Arrays.copyOfRange(arr, 1, arr.length)); 17 | 18 | } 19 | 20 | 21 | public static boolean isSortedBetter(int[] arr, int si){ 22 | 23 | if (si == arr.length - 1) 24 | return true; 25 | 26 | if (arr[si]>arr[si+1]) 27 | return false; 28 | 29 | return isSortedBetter(arr, si+1); 30 | } 31 | 32 | 33 | static Scanner s = new Scanner(System.in); 34 | 35 | public static int[] takeInput(){ 36 | 37 | int sz = s.nextInt(); 38 | 39 | int[] arr = new int[sz]; 40 | 41 | for(int i=0; ii && b.length>j){ 10 | if (a[i]1 50 | 51 | 52 | if (m>1) 53 | return multiply(m-1, n, multi); 54 | 55 | 56 | 57 | // return multi as its holding the 58 | // addition value of n for m times 59 | 60 | return multi; 61 | } 62 | 63 | 64 | public static void main(String[] args) { 65 | Scanner sc = new Scanner(System.in); 66 | System.out.println("enter two integers to multiply: "); 67 | int m = sc.nextInt(); 68 | int n = sc.nextInt(); 69 | 70 | // calling multiplyTwoIntegers functions 71 | System.out.println("Multiple value of two int is: " + multiplyTwoIntegers(m, n)); 72 | 73 | 74 | 75 | // dont forget to close scanner object 76 | sc.close(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /_recursion/power_n.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class power_n{ 3 | 4 | public static int power(int x, int n) { 5 | if(n==0){return 1;} 6 | return x*power(x,n-1); 7 | 8 | } 9 | 10 | 11 | static Scanner s = new Scanner(System.in); 12 | 13 | public static void main(String[] args) { 14 | int x = s.nextInt(); 15 | int n = s.nextInt(); 16 | 17 | System.out.println(power(x, n)); 18 | } 19 | 20 | 21 | } -------------------------------------------------------------------------------- /_recursion/print_n_num.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class print_n_num { 3 | 4 | 5 | public static void print(int n){ 6 | if (n==0){return ;} 7 | print(n-1); 8 | System.out.print(n + " "); 9 | } 10 | 11 | 12 | public static void main(String args[]) { 13 | Scanner s = new Scanner(System.in); 14 | int n = s.nextInt(); 15 | print(n); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /_recursion/removeConsecutiveDuplicate.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class removeConsecutiveDuplicate { 4 | public static String pi(String str){ 5 | 6 | if (str.length()<=1){return str;} 7 | 8 | if (str.charAt(0) == str.charAt(1)){ 9 | String small = str.charAt(0) + str.substring(2); 10 | return pi(small); 11 | } 12 | 13 | else{ 14 | return str.charAt(0) + pi(str.substring(1)); 15 | } 16 | } 17 | 18 | 19 | static Scanner s = new Scanner(System.in); 20 | public static void main(String[] args) { 21 | 22 | String str = s.nextLine(); 23 | 24 | System.out.println(pi(str)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /_recursion/remove_X.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class remove_X { 4 | 5 | static String res = ""; 6 | 7 | public static String removeX(String str, char chr){ 8 | 9 | if (str.length()==0){return res;} 10 | 11 | if (str.charAt(0)!=chr){res += str.charAt(0);} 12 | 13 | return removeX(str.substring(1), chr); 14 | } 15 | 16 | 17 | 18 | static Scanner s= new Scanner(System.in); 19 | 20 | public static void main(String[] args) { 21 | 22 | System.out.println("Type a word: "); 23 | String str = s.nextLine(); 24 | 25 | System.out.println("Type a character to remove: "); 26 | char chr = s.nextLine().charAt(0); 27 | 28 | 29 | System.out.println("After remove word is: "+removeX(str, chr)); 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /_recursion/replacePI.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class replacePI { 4 | 5 | public static String pi(String str){ 6 | 7 | if (str.length()<=1){return str;} 8 | 9 | if (str.charAt(0)=='p' && str.charAt(1)=='i'){ 10 | return 3.14 + pi(str.substring(2)); 11 | } 12 | 13 | else{ 14 | return str.charAt(0) + pi(str.substring(1)); 15 | } 16 | } 17 | 18 | 19 | static Scanner s = new Scanner(System.in); 20 | public static void main(String[] args) { 21 | 22 | String str = s.nextLine(); 23 | 24 | System.out.println(pi(str)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /_recursion/sumOfDigits.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class sumOfDigits { 4 | 5 | public static int sumOfDigits(int num){ 6 | 7 | int sum = 0; 8 | 9 | return sumOfDigits(num, sum); 10 | } 11 | 12 | 13 | public static int sumOfDigits(int num, int sum){ 14 | 15 | if (num<10){ 16 | sum += num; 17 | return sum; 18 | } 19 | 20 | 21 | sum += num%10; 22 | 23 | num /= 10; 24 | 25 | return sumOfDigits(num,sum); 26 | 27 | } 28 | 29 | 30 | public static void main(String[] args) { 31 | Scanner sc = new Scanner(System.in); 32 | System.out.println("Enter the number u want sum: "); 33 | int num = sc.nextInt(); 34 | System.out.println("Sum of Digits of number is: "+sumOfDigits(num)); 35 | 36 | sc.close(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /_recursion/sum_array.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | public class sum_array { 4 | 5 | public static int sum(int input[]) { 6 | if (input.length==0){return 0;} 7 | 8 | return input[0] + sum(Arrays.copyOfRange(input, 1, input.length)); 9 | 10 | } 11 | 12 | 13 | 14 | static Scanner s = new Scanner(System.in); 15 | 16 | public static void main(String[] args) { 17 | int n = s.nextInt(); 18 | int input[] = new int[n]; 19 | for(int i = 0; i < n; i++) { 20 | input[i] = s.nextInt(); 21 | } 22 | System.out.println(sum(input)); 23 | } 24 | } 25 | --------------------------------------------------------------------------------