├── .gitignore ├── README.md └── src ├── ArrayList.java ├── Arrays.java ├── ArraysProblems.java ├── CGPA.java ├── Changing_The_Elements_In_Array.java ├── DetectInteger.java ├── Github.java ├── Greet.java ├── If_Else_Switch.java ├── InputTaking.java ├── JavaRecursion.java ├── Km_To_M.java ├── MUltiDimentional_Array.java ├── MainTwo.java ├── MarkSheet.java ├── MethodOverloading.java ├── NonStaticMethod.java ├── OOps ├── AbstractClass.java ├── AccessModifiers.java ├── Can_We_Achieve_Multiple_Inheritance_In_Java_Classes_.java ├── CellPhone.java ├── Circle.java ├── Constructor_In_Inheritence.java ├── DynamicMethodDispatch.java ├── Employee.java ├── Game.class ├── Guess_The_Number.class ├── Guess_The_Number.java ├── HowMemoryWork.java ├── Inheritance_Problems.java ├── Inheritence.java ├── Interface_In_Java.java ├── Library_Game.java ├── Main.java ├── MethodOverRiding.java ├── MethodOverloaded.java ├── Rectangle.java └── Square.java ├── Practiceset.java ├── Recursion_And_Methods_Problem.java ├── StaticMethod.java ├── String_Methods.java ├── String_Problem.java ├── VariableArguments.java ├── arrays_problems.class ├── chnaging.class ├── loops.java ├── loopsImpl.java └── methods.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Project exclude paths 2 | /out/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Basic Java 📚🚀 2 | 3 | This repository contains basic Java programs and examples covering various concepts of object-oriented programming and fundamental Java topics. It serves as a beginner's guide to Java programming. 📖🎨 4 | 5 | Java has two categories in which data types are segregated 6 | 7 | **Primitive Data Type:** such as boolean, char, int, short, byte, long, float, and double\ 8 | **Non-Primitive Data Type or Object Data type:** such as String, Array, etc. 9 | 10 | 11 | # Types Of Primitive Data Types 12 | Primitive data are only single values and have no special capabilities. There are 8 primitive data types. They are depicted below in tabular format below as follows: 13 | 14 | 15 | 16 | 17 | 18 | # Non-Primitive Data Type or Reference Data Types 19 | 20 | The Reference Data Types will contain a memory address of variable values because the reference types won’t store the variable value directly in memory. They are strings, objects, arrays, etc. 21 | 22 | 23 | 24 | ## List of Files 📑🪄 25 | 26 | - `ArrayList.java` 📑: Demonstrates the usage of the `ArrayList` class in Java. 27 | - `Arrays.java` 📑: Contains examples related to arrays in Java. 28 | - `ArraysProblems.java` 📑: Solves problems related to arrays using Java. 29 | - `CGPA.java` 📑: Calculates and displays the CGPA (Cumulative Grade Point Average) based on the given inputs. 30 | - `Changing_The_Elements_In_Array.java` 📑: Modifies the elements of an array based on certain conditions. 31 | - `DetectInteger.java` 📑: Detects whether a given input is an integer or not. 32 | - `Github.java` 📑: Interacts with the GitHub API using Java to perform various operations. 33 | - `Greet.java` 📑: Displays a greeting message on the console. 34 | - `If_Else_Switch.java` 📑: Demonstrates the usage of if-else and switch statements in Java. 35 | - `InputTaking.java` 📑: Takes user input and displays it on the console. 36 | - `JavaRecursion.java` 📑: Illustrates recursion in Java with example programs. 37 | - `Km_To_M.java` 📑: Converts distance in kilometers to meters. 38 | - `MultiDimensional_Array.java` 📑: Deals with multi-dimensional arrays in Java. 39 | - `MainTwo.java` 📑: Contains the main method and serves as the entry point for the program. 40 | - `MarkSheet.java` 📑: Calculates the marks and grade of a student based on the given inputs. 41 | - `MethodOverloading.java` 📑: Demonstrates method overloading in Java. 42 | - `NonStaticMethod.java` 📑: Illustrates the usage of non-static methods in Java. 43 | - `Practiceset.java` 📑: Provides a set of practice problems to enhance Java programming skills. 44 | - `Recursion_And_Methods_Problem.java` 📑: Solves recursion and method-related problems using Java. 45 | - `StaticMethod.java` 📑: Illustrates the usage of static methods in Java. 46 | - `String_Methods.java` 📑: Demonstrates various string methods in Java. 47 | - `String_Problem.java` 📑: Solves string-related problems using Java. 48 | - `VariableArguments.java` 📑: Explains the usage of variable arguments in Java methods. 49 | - `arrays_problems.class` 📑: Compiled version of `arrays_problems.java` file. 50 | - `changing.class` 📑: Compiled version of `changing.java` file. 51 | - `loops.java` 📑: Contains examples related to loops in Java. 52 | - `loopsImpl.java` 📑: Implements different types of loops in Java. 53 | - `methods.java` 📑: Contains examples of different types of methods in Java. 54 | 55 | ## Contributing 👍🏻🔦 56 | 57 | Contributions are welcome! If you find any issues or want to enhance the repository, feel free to submit a pull request or raise an issue. Your contributions, whether it's fixing a bug, adding new features, or improving documentation, are greatly appreciated! 🙌🏻💎 58 | 59 | To contribute to this repository, follow these steps: 60 | 61 | 1. Fork the repository. 🍴 62 | 2. Create a new branch for your feature or bug fix. 🌱 63 | 3. Make your changes and ensure they are properly tested. 🧪 64 | 4. Commit your changes and push them to your forked repository. 🔃 65 | 5. Submit a pull request with a detailed description of your changes. 📤 66 | 67 | 68 | 69 | ## 📬 Contact 70 | 71 | If you want to contact me, you can reach me through below handles. 72 | 73 |

74 | linkedin  75 | mail-me  76 | whatsapp-me  77 |

78 | 79 |
80 | 81 |
82 | 💓 Thank you for your interest in contributing to this repository! Let's code and create something amazing together! 😄💻 83 |
84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /src/ArrayList.java: -------------------------------------------------------------------------------- 1 | import java.util*; 2 | 3 | public class Array_List{ 4 | 5 | 6 | public static void main(String[] args){ 7 | 8 | List arr = new ArrayList<>(); 9 | 10 | arr.add(1); 11 | arr.add(2); 12 | arr.add(3); 13 | arr.add(4); 14 | arr.add(5); 15 | 16 | System.out.println(arr); 17 | 18 | 19 | } 20 | 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/Arrays.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Arrays { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | System.out.println("Enter any 5 numbers"); 7 | int[] arr = new int[5]; 8 | for(int i=0;i40 && m1>33 && m2>33 && m3>33) 23 | System.out.println("You are pass"); 24 | else 25 | System.out.println("You are fail"); 26 | // 27 | // Question 3 :Calculate income tax paid by an employee to the government as per the slabs mentioned below: 28 | // 29 | // Income Slab Tax 30 | 31 | // 2.5L – 5.0L 5% 32 | // 5.0L – 10.0L 20% 33 | // Above 10.0L 30% 34 | 35 | System.out.println("Enter Your Income"); 36 | int salary = sc.nextInt(); 37 | 38 | if(salary<250000 && salary<500000){ 39 | int tax = salary*5/100; 40 | System.out.format("Tax is %d",tax); 41 | } else if (salary>500000 && salary<1000000) { 42 | int tax = salary*20/100; 43 | System.out.printf("Tax is %d",tax); 44 | } else if (salary>1000000) { 45 | int tax = salary*30/100; 46 | System.out.printf("Tax is %d",tax); 47 | }else{ 48 | System.out.println("Not Eligible for Paying Tax"); 49 | } 50 | 51 | System.out.println(); 52 | 53 | // Question 4: Write a Java program to find out the day of the week given the number [1 for Monday, 2 for Tuesday … and so on!]? 54 | System.out.println("Enter day"); 55 | int day = sc.nextInt(); 56 | 57 | switch (day){ 58 | 59 | case 1: 60 | System.out.println("Monday"); 61 | break; 62 | 63 | case 2: 64 | System.out.println("Tuesday"); 65 | break; 66 | 67 | case 3: 68 | System.out.println("Wednesday"); 69 | break; 70 | 71 | case 4: 72 | System.out.println("Thursday"); 73 | break; 74 | 75 | case 5: 76 | System.out.println("Friday"); 77 | break; 78 | 79 | case 6: 80 | System.out.println("Saturday"); 81 | break; 82 | 83 | case 7: 84 | System.out.println("Sunday"); 85 | break; 86 | 87 | default: 88 | System.out.println("Enter Day Between 1 to 7"); 89 | 90 | } 91 | 92 | 93 | // Question 5:Write a Java program to find whether a year entered by the user is a leap year or not. 94 | 95 | // int year = sc.nextInt(); 96 | 97 | // 98 | // Question 6:Write a program to find out the type of website from the URL: 99 | // 100 | //.com – commercial website 101 | //.org – organization website 102 | //.in – Indian website 103 | 104 | System.out.println("Enter Website"); 105 | String web = sc.next(); 106 | 107 | if(web.endsWith(".com")) 108 | System.out.println("This is Commercial Website"); 109 | else if (web.endsWith(".org")) { 110 | System.out.println("This is Organisation Website"); 111 | } else if (web.endsWith(".in")) { 112 | System.out.println("This is Indian Website"); 113 | } 114 | else 115 | System.out.println("Please enter valid website"); 116 | 117 | 118 | } 119 | } 120 | 121 | 122 | -------------------------------------------------------------------------------- /src/InputTaking.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class InputTaking { 3 | 4 | public static void main(String[] args) { 5 | System.out.println("Taking Input"); 6 | 7 | Scanner sc = new Scanner(System.in); 8 | System.out.println("enter number 1"); 9 | int num1=sc.nextInt(); 10 | System.out.println("enter number 2"); 11 | int num2=sc.nextInt(); 12 | int sum=num1+num2; 13 | System.out.println("The sum of number 1 and number 2 id "+sum ); 14 | 15 | System.out.println("Now enter your age"); 16 | Byte age = sc.nextByte(); 17 | System.out.println("Your age is"+age); 18 | 19 | System.out.println("Enter your firstname"); 20 | String name = sc.next(); 21 | System.out.println("Enter your lastname"); 22 | String name2 = sc.next(); 23 | System.out.println("Your Full Name is "+ name+" "+name2); 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/JavaRecursion.java: -------------------------------------------------------------------------------- 1 | public class JavaRecursion { 2 | // Recursion => Method (Function) call itself again and again 3 | 4 | static int factorial(int n){ 5 | 6 | if(n==1 || n==0){ 7 | return 1; 8 | } 9 | else{ 10 | System.out.println(n); 11 | return n*factorial(n-1); 12 | } 13 | 14 | 15 | } 16 | 17 | static void show(String str){ 18 | if(str.length()==0){ 19 | System.out.println("Empty!"); 20 | } 21 | else{ 22 | if(str.startsWith("am")){ 23 | System.out.println("Matches"); 24 | return; 25 | } 26 | System.out.println(str); 27 | str=str.substring(1, 28 | str.length()); 29 | show(str); 30 | } 31 | 32 | 33 | } 34 | 35 | 36 | public static void main(String[] args) { 37 | 38 | // int b=2; 39 | // int n = factorial(5); 40 | // System.out.println(n); 41 | 42 | show("Shubham"); 43 | } 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/Km_To_M.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class Km_To_M { 3 | public static void main(String[] args) { 4 | 5 | Scanner sc = new Scanner(System.in); 6 | 7 | System.out.println("Enter KiloMeter"); 8 | float km = sc.nextFloat(); 9 | 10 | double m = km*1000; 11 | 12 | System.out.println("Total Meter is "+m); 13 | 14 | 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /src/MUltiDimentional_Array.java: -------------------------------------------------------------------------------- 1 | public class MUltiDimentional_Array { 2 | 3 | public static void main(String[] args) { 4 | int[][] matirx = new int[3][5]; 5 | 6 | for(int i=0;i5){ 21 | System.out.println(this.name + " Congratulations! Next Month you will get salary increment"); 22 | }else if(experience > 4 && experience < 3 ){ 23 | System.out.println(this.name + " Wait for 1 Years"); 24 | }else{ 25 | System.out.println(this.name + " Work Hard and Again some experience"); 26 | } 27 | } 28 | 29 | void bonus(){ 30 | if(age>20){ 31 | System.out.println(this.name + " Congratulations!, You are eligible for Bonus "); 32 | } 33 | else if(age > 30){ 34 | System.out.println(this.name + " WOW! Mega Reward"); 35 | } 36 | else{ 37 | System.out.println(this.name + " Wait for bonus"); 38 | } 39 | } 40 | 41 | 42 | void tax(){ 43 | if(salary >= 50000){ 44 | System.out.println("30% of salary"); 45 | }else if(salary < 50000 && salary >= 30000){ 46 | System.out.println("20% of salary"); 47 | }else if(salary < 30000 && salary >= 25000){ 48 | System.out.println("10% of salary"); 49 | }else{ 50 | System.out.println("Not Eligible of Paying Tax"); 51 | } 52 | } 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/OOps/Game.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shubh2-0/Basic-Java/03a0c042b1eb7019579b0510c063fcacdc6414df/src/OOps/Game.class -------------------------------------------------------------------------------- /src/OOps/Guess_The_Number.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shubh2-0/Basic-Java/03a0c042b1eb7019579b0510c063fcacdc6414df/src/OOps/Guess_The_Number.class -------------------------------------------------------------------------------- /src/OOps/Guess_The_Number.java: -------------------------------------------------------------------------------- 1 | package OOps; 2 | import java.util.Random; 3 | import java.util.Scanner; 4 | 5 | //Create a class Game, which allows a user to play "Guess the Number" game once. 6 | // 7 | // Game should have the following methods: 8 | // Constructor to generate the random number 9 | // takeUserInput() to take a user input of number 10 | // isCorrectNumber() to detect whether the number entered by the user is true 11 | // getter and setter for noOfGuesses 12 | // Use properties such as noOfGuesses(int),etc to get this task done! 13 | 14 | class Game{ 15 | 16 | int number; 17 | int userGuess; 18 | int numberOfTry=0; 19 | 20 | Game(){ 21 | Random rn = new Random(); 22 | int number = rn.nextInt(50); 23 | this.number=number; 24 | } 25 | 26 | public void setNumberOfTry(int numberOfTry){ 27 | this.numberOfTry=numberOfTry; 28 | } 29 | 30 | public int getNumberOfTry(){ 31 | return numberOfTry; 32 | } 33 | public int takeUserInput(){ 34 | System.out.println("Guess The Number"); 35 | Scanner sc = new Scanner(System.in); 36 | this.userGuess=sc.nextInt(); 37 | return userGuess; 38 | } 39 | 40 | 41 | public boolean isCorrectNumber(int UserGuess){ 42 | numberOfTry++; 43 | if(this.userGuess==this.number){ 44 | System.out.format("!!HOORAY!! you guess the correct number it was %d and you guess in %d attempts",number,getNumberOfTry()); 45 | return true; 46 | }else if(this.userGuess>this.number){ 47 | System.out.println("Too High"); 48 | System.out.println(); 49 | return false; 50 | }else{ 51 | System.out.println("Too Low"); 52 | System.out.println(); 53 | return false; 54 | 55 | } 56 | } 57 | 58 | 59 | } 60 | 61 | 62 | public class Guess_The_Number { 63 | 64 | public static void main(String[] args) { 65 | 66 | System.out.println("!!!WELCOME TO THE Guess THE NUMBER GAME!!!"); 67 | Game player = new Game(); 68 | 69 | 70 | 71 | 72 | boolean n =false; 73 | 74 | while (!n){ 75 | int user = player.takeUserInput(); 76 | n = player.isCorrectNumber(user); 77 | } 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/OOps/HowMemoryWork.java: -------------------------------------------------------------------------------- 1 | package OOps; 2 | 3 | class Memory{ 4 | 5 | String str; 6 | int age; 7 | 8 | public Memory(String str, int age) { 9 | this.str = str; 10 | this.age = age; 11 | } 12 | } 13 | 14 | 15 | public class HowMemoryWork { 16 | 17 | public static void main(String[] args) { 18 | Memory m1 = new Memory("Memory1",20); 19 | int power = (int) Math.pow(2,2); 20 | System.out.println(power); 21 | 22 | System.out.println(m1); 23 | // second time run = OOps.Memory@6d03e736 24 | // first time run = OOps.Memory@6d03e736 25 | // third time run = OOps.Memory@6d03e736 26 | 27 | } 28 | 29 | 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/OOps/Inheritance_Problems.java: -------------------------------------------------------------------------------- 1 | package OOps; 2 | 3 | //Exercise & Practice Questions on Inheritance 4 | // Create a class circle and use inheritance to create another class cylinder from it 5 | // Create a class rectangle and use inheritance to create another class cuboid, try to keep it as close to the real-world scenario as possible 6 | // Create a method for area and volume in 1 7 | // create methods for area & volume in 2 also create getters and setters 8 | // What is the order of constructor execution for the following inheritance hierarchy 9 | // Base 10 | // Derived 1 11 | // Derived 2 12 | // Derived obj = new Derived 2( ); 13 | // Which constructor(s) will be executed & in what order? 14 | 15 | class circle{ 16 | private int radius; 17 | 18 | public int getRadius() { 19 | return radius; 20 | } 21 | 22 | public void setRadius(int radius) { 23 | this.radius = radius; 24 | } 25 | 26 | public double GetArea(){ 27 | double j= (radius*radius) * 3.14159265 ; 28 | j=Math.round(j*100.0)/100.0; 29 | return j; 30 | } 31 | } 32 | 33 | 34 | 35 | class cylinder extends circle{ 36 | int height; 37 | 38 | public int getHeight() { 39 | return height; 40 | } 41 | 42 | public void setHeight(int height) { 43 | this.height = height; 44 | } 45 | 46 | @Override 47 | public double GetArea(){ 48 | double k = 2*3.14159265*getRadius()*(getRadius()+height); 49 | k=Math.round(k*100.0)/100.0; 50 | return k; 51 | } 52 | 53 | } 54 | 55 | class rectangle{ 56 | private int width; 57 | private int height; 58 | 59 | public int getWidth() { 60 | return width; 61 | } 62 | 63 | public void setWidth(int width) { 64 | this.width = width; 65 | } 66 | 67 | public int getHeight() { 68 | return height; 69 | } 70 | 71 | public void setHeight(int height) { 72 | this.height = height; 73 | } 74 | 75 | public int GetArea(){ 76 | return this.height*this.width; 77 | } 78 | } 79 | 80 | 81 | class cuboid extends rectangle{ 82 | private int length; 83 | 84 | public int getLength() { 85 | return length; 86 | } 87 | 88 | public void setLength(int length) { 89 | this.length = length; 90 | } 91 | 92 | @Override 93 | public int GetArea(){ 94 | return 2*( ( length * getWidth() ) + ( getWidth() * getHeight() ) + ( length * getHeight() ) ); 95 | } 96 | 97 | } 98 | 99 | 100 | 101 | public class Inheritance_Problems { 102 | 103 | public static void main(String[] args) { 104 | 105 | circle circle1 = new circle(); 106 | System.out.println(circle1); 107 | 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/OOps/Inheritence.java: -------------------------------------------------------------------------------- 1 | package OOps; 2 | 3 | 4 | 5 | class Vehicles{ 6 | 7 | String Color; 8 | int Price; 9 | String Number; 10 | int ManufactureYear; 11 | String Average; 12 | 13 | public Vehicles(String color, int price, String number, int manufactureYear, String average) { 14 | Color = color; 15 | Price = price; 16 | Number = number; 17 | ManufactureYear = manufactureYear; 18 | Average = average; 19 | } 20 | } 21 | 22 | class Bike extends Vehicles{ 23 | boolean TwoSeater; 24 | int TotalWeals; 25 | boolean helmet; 26 | 27 | public Bike(String color, int price, String number, int manufactureYear, String average, boolean twoSeater, int totalWeals, boolean helmet) { 28 | super(color, price, number, manufactureYear, average); 29 | TwoSeater = twoSeater; 30 | TotalWeals = totalWeals; 31 | this.helmet = helmet; 32 | } 33 | 34 | public void PrintDetails() { 35 | System.out.println("the following properties of Bike are : -" + 36 | " \nTwoSeater : " + TwoSeater + 37 | " \n TotalWeals : " + TotalWeals + 38 | " \n helmet : " + helmet + 39 | " \n Color : " + Color + 40 | " \n Price : " + Price + 41 | " \n Number : " + Number + 42 | " \n ManufactureYear : " + ManufactureYear + 43 | " \n Average : " + Average); 44 | 45 | } 46 | } 47 | 48 | 49 | class Car extends Vehicles { 50 | boolean CNG; 51 | boolean Petrol; 52 | 53 | int NumberOfSeats; 54 | 55 | boolean SitBelt; 56 | 57 | public Car(String color, int price, String number, int manufactureYear, String average, boolean CNG, boolean petrol, int numberOfSeats, boolean sitBelt) { 58 | super(color, price, number, manufactureYear, average); 59 | this.CNG = CNG; 60 | Petrol = petrol; 61 | NumberOfSeats = numberOfSeats; 62 | SitBelt = sitBelt; 63 | } 64 | 65 | public void PrintDetails() { 66 | System.out.println("The Properties of Car are :-" + 67 | "\nCNG : " + CNG + 68 | "\nPetrol : " + Petrol + 69 | "\nNumberOfSeats : " + NumberOfSeats + 70 | "\nSitBelt : " + SitBelt + 71 | "\nColor : " + Color + 72 | "\nPrice : " + Price + 73 | "\nNumber : " + Number + 74 | "\nManufactureYear : " + ManufactureYear + 75 | "\nAverage : " + Average 76 | ); 77 | } 78 | } 79 | class Truck extends Vehicles{ 80 | boolean BlowHornSticker; 81 | int NumberOfWheals; 82 | int Hieght; 83 | String Type; 84 | 85 | public Truck(String color, int price, String number, int manufactureYear, String average, boolean blowHornSticker, int numberOfWheals, int hieght, String type) { 86 | super(color, price, number, manufactureYear, average); 87 | BlowHornSticker = blowHornSticker; 88 | NumberOfWheals = numberOfWheals; 89 | Hieght = hieght; 90 | Type = type; 91 | } 92 | 93 | 94 | public void PrintDetails() { 95 | System.out.println("The Properties of Truck are :-"+ 96 | "\nBlowHornSticker : " + BlowHornSticker + 97 | "\nNumberOfWheals : " + NumberOfWheals + 98 | "\nHieght : " + Hieght + 99 | "\nType : " + Type + 100 | "\nColor : " + Color + 101 | "\nPrice : " + Price + 102 | "\nNumber : " + Number + 103 | "\nManufactureYear : " + ManufactureYear + 104 | "\nAverage : " + Average 105 | ); 106 | 107 | 108 | } 109 | } 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | public class Inheritence { 120 | 121 | public static void main(String[] args) { 122 | 123 | Bike bike1 = new Bike("black",70000,"MH-3249",2013,"55KM/HHS",true,2,true); 124 | bike1.PrintDetails(); 125 | Car car1 = new Car("Blue",500000,"GH-2671",2001,"20KM/HRS",true,true,6,true); 126 | car1.PrintDetails(); 127 | Truck truck1 = new Truck("White",3000000,"DS-2=5630",2005,"10KM/HRS",true,8,10,"Jumbo"); 128 | truck1.PrintDetails(); 129 | 130 | } 131 | 132 | 133 | } 134 | -------------------------------------------------------------------------------- /src/OOps/Interface_In_Java.java: -------------------------------------------------------------------------------- 1 | package OOps; 2 | 3 | interface Bicycle{ 4 | public void Break(int num); 5 | public void Speed(int num); 6 | } 7 | 8 | interface Moter{ 9 | public void PowerUp(int num); 10 | public void AutoBreak(int num); 11 | } 12 | 13 | 14 | class ranger implements Bicycle ,Moter { 15 | public void Break(int num){ 16 | System.out.println("Speed Decrease By "+num); 17 | } 18 | 19 | public void Speed(int num){ 20 | System.out.println("Speed Up By "+num); 21 | } 22 | 23 | public void PowerUp(int num){ 24 | System.out.println("Cycle PowrUp By "+num); 25 | } 26 | 27 | public void AutoBreak(int num){ 28 | if(num==0){ 29 | System.out.println("Auto Break OFF"); 30 | } 31 | else if(num==1){ 32 | System.out.println("Auto Break ON"); 33 | }else{ 34 | System.out.println("Command Not Found"); 35 | } 36 | 37 | 38 | } 39 | 40 | } 41 | 42 | 43 | 44 | 45 | public class Interface_In_Java { 46 | 47 | public static void main(String[] args) { 48 | 49 | ranger cycle1 = new ranger(); 50 | cycle1.Break(4); 51 | cycle1.Speed(10); 52 | cycle1.AutoBreak(9); 53 | cycle1.PowerUp(30); 54 | 55 | 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/OOps/Library_Game.java: -------------------------------------------------------------------------------- 1 | package OOps; 2 | 3 | //You have to implement a library using Java Class "Library" 4 | // 5 | // Methods: addBook, issueBook, returnBook, showAvailableBooks 6 | // Properties: Array to store the available books, 7 | // Array to store the issued books 8 | import javax.xml.namespace.QName; 9 | import java.util.Scanner; 10 | 11 | class Library { 12 | 13 | int size; 14 | String[] Books; 15 | int count = 0; 16 | 17 | 18 | 19 | 20 | 21 | Library(){ 22 | System.out.println("Provide a size of Library"); 23 | Scanner sc = new Scanner(System.in); 24 | int size = sc.nextInt(); 25 | Books = new String[size]; 26 | 27 | } 28 | 29 | public void issueBook() { 30 | if (count < Books.length) { 31 | System.out.println("Enter Book Name"); 32 | Scanner sc = new Scanner(System.in); 33 | String name = sc.nextLine(); 34 | Books[count] = name; 35 | count++; 36 | System.out.println("Book Successfully Added"); 37 | System.out.println(); 38 | } else { 39 | System.out.println("Library is Full Now"); 40 | System.out.println(); 41 | } 42 | 43 | } 44 | 45 | public void showAvailableBooks() { 46 | System.out.println("Available Books are :-"); 47 | for(int i=0;i s2.getArea(); 60 | // System.out.println(ans); 61 | // s2.area(); 62 | // s2.perameter(); 63 | 64 | // Rectangle r1 = new Rectangle("Rectangle 1",3,5); 65 | // Rectangle r2 = new Rectangle("Rectangle 2",2,4); 66 | // Rectangle r3 = new Rectangle("Rectangle 3",2,1); 67 | // Rectangle r4 = new Rectangle("Rectangle 4",8,10); 68 | // 69 | // r1.printArea(); 70 | // r1.printPerimeter(); 71 | // 72 | // boolean an1 = r2.GetArea() > r3.GetArea() && r2.GetArea() > r4.GetArea(); 73 | // System.out.println(an1); 74 | // 75 | // Circle c1 = new Circle(5, "Circle 1"); 76 | // Circle c2 = new Circle(2, "Circle 2"); 77 | // Circle c3 = new Circle("Circle 3",3); 78 | // Circle c4 = new Circle("Circle 4",1); 79 | 80 | // boolean cans = c1.GetArea() > c2.GetArea() && c3.GetPerimeter() < c4.GetPerimeter(); 81 | // System.out.println(cans); 82 | // 83 | // c1.PrintArea(); 84 | // c1.PrintPeriMeter(); 85 | // 86 | // 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | } 99 | 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/OOps/MethodOverRiding.java: -------------------------------------------------------------------------------- 1 | package OOps; 2 | 3 | class parent1{ 4 | 5 | public void print(){ 6 | System.out.println("I am Print Method of class parent 1"); 7 | } 8 | 9 | public void sum(int a,int b){ 10 | System.out.println("Parent1 Method of a+b = "+ (a+b)); 11 | } 12 | 13 | } 14 | 15 | class child1 extends parent1{ 16 | @Override 17 | public void print(){ 18 | System.out.println("I am Print Method of class child 1"); 19 | } 20 | 21 | public void sum(int a,int b){ 22 | System.out.println("child1 Method of a*b = "+ a*b); 23 | } 24 | 25 | 26 | } 27 | 28 | public class MethodOverRiding { 29 | public static void main(String[] args) { 30 | 31 | parent1 p1 = new parent1(); 32 | child1 c1 = new child1(); 33 | 34 | p1.print(); 35 | c1.print(); 36 | c1.sum(3,4); 37 | p1.sum(3,4); 38 | 39 | 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/OOps/MethodOverloaded.java: -------------------------------------------------------------------------------- 1 | package OOps; 2 | 3 | class Employees{ 4 | int Salary; 5 | String Name; 6 | String City; 7 | String MobileNumber; 8 | 9 | public Employees(int salary, String name, String city, String mobileNumber) { 10 | Salary = salary; 11 | Name = name; 12 | City = city; 13 | MobileNumber = mobileNumber; 14 | } 15 | 16 | public Employees(String name, String city, String mobileNumber) { 17 | Salary = 40000; 18 | Name = name; 19 | City = city; 20 | MobileNumber = mobileNumber; 21 | } 22 | public Employees(int salary, String name, String mobileNumber) { 23 | Salary = salary; 24 | Name = name; 25 | City = "Indore"; 26 | MobileNumber = mobileNumber; 27 | } 28 | public Employees() { 29 | Salary = 50000; 30 | Name = "Shubham"; 31 | City = "Indore"; 32 | MobileNumber = "6232133187"; 33 | } 34 | 35 | 36 | public void PrintDetails() { 37 | System.out.println( 38 | "Salary : " + Salary + 39 | "\nName : " + Name + 40 | "\nCity : " + City + 41 | "\nMobileNumber : " + MobileNumber 42 | ); 43 | 44 | } 45 | } 46 | 47 | public class MethodOverloaded { 48 | 49 | public static void main(String[] args) { 50 | Employees em1 = new Employees("Aman","Ujjain","6231982872"); 51 | em1.PrintDetails(); 52 | 53 | } 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/OOps/Rectangle.java: -------------------------------------------------------------------------------- 1 | package OOps; 2 | 3 | public class Rectangle { 4 | 5 | 6 | int width; 7 | int height; 8 | String name; 9 | 10 | Rectangle(String name,int width, int height){ 11 | this.name=name; 12 | this.width=width; 13 | this.height=height; 14 | } 15 | 16 | public void printArea(){ 17 | System.out.println("The Area of "+name+" is "+ GetArea() ); 18 | } 19 | public void printPerimeter(){ 20 | System.out.println("The PeriMeter of "+name+" is "+ GetPerimeter()); 21 | } 22 | public int GetArea(){ 23 | return height*height; 24 | } 25 | public int GetPerimeter(){ 26 | return 2*(height+width); 27 | } 28 | 29 | 30 | public void setHeight() { 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/OOps/Square.java: -------------------------------------------------------------------------------- 1 | package OOps; 2 | 3 | public class Square { 4 | 5 | int size; 6 | 7 | Square(int size){ 8 | this.size=size; 9 | } 10 | 11 | public void area(){ 12 | System.out.println("The Area of Squre is " + size*size); 13 | } 14 | 15 | public int getArea(){ 16 | return size*size; 17 | } 18 | public int getPerimeter(){ 19 | return 4*size; 20 | } 21 | 22 | public void perameter(){ 23 | System.out.println("The PeriMeter of Square is "+ 4*this.size); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/Practiceset.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class Practiceset { 3 | 4 | public static void main(String[] args) { 5 | 6 | Scanner sc = new Scanner(System.in); 7 | System.out.println("Enter Number One"); 8 | int num1 = sc.nextInt(); 9 | System.out.println("Enter Number Two"); 10 | int num2 = sc.nextInt(); 11 | System.out.println("Enter number three"); 12 | int num3 = sc.nextInt(); 13 | int sum = num1+num2+num3; 14 | System.out.println("Total Sum Of Numbers is "+ sum); 15 | 16 | 17 | 18 | } 19 | 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/Recursion_And_Methods_Problem.java: -------------------------------------------------------------------------------- 1 | public class Recursion_And_Methods_Problem { 2 | static void table(int num){ 3 | int i=1; 4 | while(i<11){ 5 | System.out.println(i*num); 6 | i++; 7 | } 8 | 9 | 10 | 11 | 12 | 13 | } 14 | 15 | static void pattern1(int n){ 16 | for (int i=1;i<=n;i++){ 17 | for(int j=1;j<=i;j++){ 18 | System.out.print("* "); 19 | } 20 | System.out.println(); 21 | } 22 | 23 | 24 | } 25 | 26 | static int sum(int i){ 27 | if(i==1){ 28 | return 1; 29 | }else{ 30 | return i+sum(i-1); 31 | } 32 | 33 | 34 | } 35 | 36 | static void pattern2(int num){ 37 | 38 | for (int i=num;i>0;i--){ 39 | for (int j=0;j0){ 63 | pattern1_rec(i-1); 64 | for (int j=0;j, Thanks a lot” 18 | // Replace <|name|> with a string (some name) 19 | String letter = "Dear <|name|>, Thanks a lot"; 20 | letter=letter.replace("<|name|>","Shubham"); 21 | System.out.println(letter); 22 | 23 | // 4. Write a Java program to detect double and triple spaces in a string. 24 | String space = "HEllo My name is Shubham"; 25 | System.out.println(space.indexOf(" ")); 26 | System.out.println(space.indexOf(" ")); 27 | 28 | 29 | // 5. Write a program to format the following letter using escape sequence characters. 30 | // Letter = “Dear Harry, This Java Course is nice. Thanks” 31 | String Unknow_Method = "Dear Shubham,\n\tThis Java Course is very Helpful for you.\nThanks!"; 32 | System.out.println(Unknow_Method); 33 | 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/VariableArguments.java: -------------------------------------------------------------------------------- 1 | public class VariableArguments { 2 | // Variable_Arguments : one method for different parameter in main method 3 | static void sum(int... arr){ 4 | int total = 0; 5 | for(int el : arr){ 6 | total+=el; 7 | } 8 | System.out.println(total); 9 | } 10 | static void sum(String... arr){ 11 | for(String el : arr){ 12 | System.out.print(el+" "); 13 | } 14 | System.out.println(); 15 | } 16 | 17 | //this method is showing that show at least one parameter is compulsory for use or call this method wer can use multiple perameters here 18 | static void sum2(int x,int... arr){ 19 | int result = x; 20 | for(int el : arr){ 21 | result+=el; 22 | } 23 | System.out.println(result); 24 | } 25 | 26 | public static void main(String[] args) { 27 | sum(1,2,3,4,5); 28 | sum(3,52,4); 29 | sum(1,2); 30 | sum(23,3); 31 | sum(2,1,4); 32 | sum(1,62,7,3,7,3); 33 | // ################################ 34 | sum("Shubham","aman","dev","boby","chinmay"); 35 | sum("good","Morning"); 36 | sum("hello","Shubham"); 37 | sum("hello","Shubham","kaise","ho"); 38 | 39 | // ################################## 40 | 41 | sum2(1); 42 | // sum2() throw error 43 | 44 | sum2(2,2,3,2,23); 45 | sum2(2,8,2,3); 46 | sum2(7,2,8,1,5,2,4,7); 47 | } 48 | 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/arrays_problems.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shubh2-0/Basic-Java/03a0c042b1eb7019579b0510c063fcacdc6414df/src/arrays_problems.class -------------------------------------------------------------------------------- /src/chnaging.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shubh2-0/Basic-Java/03a0c042b1eb7019579b0510c063fcacdc6414df/src/chnaging.class -------------------------------------------------------------------------------- /src/loops.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class loops { 3 | 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | // Question 1: Write a program to print the following pattern : 7 | // **** 8 | // *** 9 | // ** 10 | // * 11 | // int n=4; 12 | // for(int i=0;i=1;i--){ 42 | // System.out.println(i*num1); 43 | // } 44 | 45 | // Question 5: Write a program to find the factorial of a given number using for loops. 46 | System.out.println("Enter number that you want Factorial"); 47 | int j=sc.nextInt(); 48 | int product=1; 49 | for (int i=1;i<=j;i++){ 50 | product*=i; 51 | } 52 | System.out.println("the factorial of "+j+" is "+product); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/loopsImpl.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shubh2-0/Basic-Java/03a0c042b1eb7019579b0510c063fcacdc6414df/src/loopsImpl.java -------------------------------------------------------------------------------- /src/methods.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class methods { 3 | boolean check(int num){ 4 | if(num==1) 5 | return false ; 6 | for(int i=2;i