diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/java-backend-bootcamp-fork.iml b/.idea/java-backend-bootcamp-fork.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/java-backend-bootcamp-fork.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..432b646 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..a91dbf0 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/session-02-big-picture/student-notes-repos.md b/session-02-big-picture/student-notes-repos.md index a57c910..7750557 100644 --- a/session-02-big-picture/student-notes-repos.md +++ b/session-02-big-picture/student-notes-repos.md @@ -21,3 +21,4 @@ - https://github.com/Raj04/Spring-Bootcamp - https://github.com/shawchandankumar/Java-Backend-Development - https://github.com/bogdanbilcan/JavaBrains-BootCampNotes +- https://github.com/sahilpandith/java-backend-bootcamp/blob/main/README.md diff --git a/session-03-java-basics/.idea/.gitignore b/session-03-java-basics/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/session-03-java-basics/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/session-03-java-basics/.idea/misc.xml b/session-03-java-basics/.idea/misc.xml new file mode 100644 index 0000000..432b646 --- /dev/null +++ b/session-03-java-basics/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/session-03-java-basics/.idea/modules.xml b/session-03-java-basics/.idea/modules.xml new file mode 100644 index 0000000..22b7f7e --- /dev/null +++ b/session-03-java-basics/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/session-03-java-basics/.idea/session-03-java-basics.iml b/session-03-java-basics/.idea/session-03-java-basics.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/session-03-java-basics/.idea/session-03-java-basics.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/session-03-java-basics/.idea/vcs.xml b/session-03-java-basics/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/session-03-java-basics/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/session-03-java-basics/README.md b/session-03-java-basics/README.md index c6516bc..31b0352 100644 --- a/session-03-java-basics/README.md +++ b/session-03-java-basics/README.md @@ -3,6 +3,29 @@ ## Contents ### Basic Syntax: Explains the basic syntax of the Java programming language, including how to declare variables, use control structures, and perform input/output operations. + +public class Main { + public static void main(String[] args){ + //variable declaration + int i =0; + String s = "str"; + + if(i==0) { + System.out.println(i) + } + } +} +There are two types of variable declaration in java + 1) Primitives : These are immutable. + 1. int + 2. double + 3. float + 4. long + 5. boolean + 6. short + 7. byte + 8. chat + ### Data Types: Explains the different data types in Java, including primitive types (such as int, double, and boolean) and non-primitive types (such as Strings). ### Operators: diff --git a/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/A.java b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/A.java new file mode 100644 index 0000000..f48ae3e --- /dev/null +++ b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/A.java @@ -0,0 +1,10 @@ +package io.javabrains.javabasics; + +public class A { + String var = "string"; + private String privateVar = "privateString"; + protected String protectedVar = "protectedString"; + + public String publicVar = "publicString"; + +} diff --git a/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/AnonymousInnerClasses.java b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/AnonymousInnerClasses.java index cc3de0b..c50b58d 100644 --- a/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/AnonymousInnerClasses.java +++ b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/AnonymousInnerClasses.java @@ -5,8 +5,29 @@ Create an anonymous inner class implementation of `Animal2` and then call the `makeSound` method */ +abstract class Animal2{ + abstract void makesound(); +} public class AnonymousInnerClasses { public static void main(String[] args) { + Animal2 cat = new Animal2(){ + @Override + public void makesound(){ + System.out.println("meow"); + + } + }; + cat.makesound(); + + Animal2 dog = new Animal2(){ + @Override + public void makesound(){ + System.out.println("bow"); + + } + }; + dog.makesound(); + } } diff --git a/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/ArrayChallenge.java b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/ArrayChallenge.java index 206699d..948c381 100644 --- a/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/ArrayChallenge.java +++ b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/ArrayChallenge.java @@ -1,12 +1,31 @@ package io.javabrains.javabasics; +import java.util.Arrays; + public class ArrayChallenge { public static void main(String[] args) { // Step 1: Create an array of integers - + int[] arr = {10,20,33,10}; // Step 2: Use arrays and array operations to find the sum, average, and largest number in the array + int sum = 0; + double avg; + int largest =arr[0]; + for (int i :arr){ + sum+=i; + if(i>largest){ + largest =i; + } + } + avg = sum / arr.length; + System.out.println("sum = " + sum); + System.out.println("avg = " + avg); + System.out.println("largest = " + largest); + int[] arrCopy = new int[3] ; + System.arraycopy(arr,1,arrCopy,0,3); + System.out.println("arrCopy = " + Arrays.toString(arrCopy)); + System.out.println("arr = " + Arrays.toString(arr)); } } diff --git a/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/Assigments.java b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/Assigments.java new file mode 100644 index 0000000..7705d86 --- /dev/null +++ b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/Assigments.java @@ -0,0 +1,159 @@ +package io.javabrains.javabasics; + +import org.w3c.dom.css.Rect; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Scanner; + + +public class Assigments { + + public static void main(String[] args) throws IOException { + + // Assignment1 + Scanner scanner = new Scanner(System.in); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); + +// +// System.out.println("Enter first number"); +// double num1 = Double.parseDouble(scanner.nextLine()); +// +// System.out.println("Enter second number"); +// double num2 = Double.parseDouble(bufferedReader.readLine()); +// +// +// System.out.println("sum " + (num1+num2)); +// System.out.println("sub " + (num1-num2)); +// System.out.println("product " + (num1*num2)); +// System.out.println("quotient " + (num1/num2)); +// +// +// //assognemtn2 +// +// System.out.println("Enter name"); +// String name = scanner.nextLine(); +// System.out.println("Enter age"); +// int age = Integer.parseInt(bufferedReader.readLine()); +// System.out.println("Enter salary"); +// double salary = Double.parseDouble(scanner.nextLine()); +// +// System.out.println("name = " + name); +// System.out.println("age = " + age); +// System.out.println("salary = " + salary); +// +// +// //assignemt 3 +// +// if(num1==0){ +// System.out.println("zero"); +// }else if (num1>0){ +// System.out.println("positive"); +// }else { +// System.out.println("negative"); +// } +// +// +// //Assignent 4 +// System.out.println("enter the size of array"); +// int length = Integer.parseInt(scanner.nextLine()); +// +// ArrayList list = new ArrayList(); +//// Integer[] list = {}; +// for (int i =0; i vowels = new ArrayList<>(); +// vowels.add('a'); +// vowels.add('e'); +// vowels.add('i'); +// vowels.add('o'); +// vowels.add('u'); +// int count=0; +// for(char c : str.toCharArray()){ +// if(vowels.contains(Character.toLowerCase(c))){ +// count++; +// } +// } +// +// System.out.println("count = " + count); +// +// +// scanner.close(); +// bufferedReader.close(); +// + + // Assignment 6 + Rectangle1 rect = new Rectangle1(12,23); + System.out.println(rect.calculateArea()); + + //Assignment 6 + Animal1 loin = new Lion1("timothy",178,21); + Animal1 cow = new Cow("jersey",154,20); + + loin.feed();; + cow.feed(); + } +} + +class Rectangle1{ + int height; + int width; + Rectangle1(int height,int width){ + this.height = height; + this.width = width; + } + + public int calculateArea(){ + return this.height* this.width; + } +} + +class Animal1 { + String name; + double weight; + int age; + Animal1(String name,double weight,int age){ + this.name = name; + this.weight = weight; + this.age = age; + } + public void feed(){ + System.out.println("Animal eats food"); + } +} + +class Lion1 extends Animal1{ + Lion1(String name,double weight, int age){ + super(name,weight,age); + } + public void feed(){ + System.out.println("Loin eats meat"); + } + +} + +class Cow extends Animal1{ + Cow(String name,double weight, int age){ + super(name,weight,age); + } + public void feed(){ + System.out.println("Cow eats grass"); + } + + +} diff --git a/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/B.java b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/B.java new file mode 100644 index 0000000..476fbb2 --- /dev/null +++ b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/B.java @@ -0,0 +1,17 @@ +package io.javabrains.javabasics; + +class B { + public void accessVars(){ + A a = new A(); +// System.out.println("a.privateVar = " + a.privateVar); // can't perform this since it is private var + System.out.println("a.var = " + a.var); + System.out.println("a.protectedVar = " + a.protectedVar); + System.out.println("a.publicVar = " + a.publicVar); + } + public static void main(String[] args) { + B b = new B(); + b.accessVars(); + } +} + + diff --git a/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/ClassesAndObjects.java b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/ClassesAndObjects.java index a4d18d7..26f41c7 100644 --- a/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/ClassesAndObjects.java +++ b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/ClassesAndObjects.java @@ -18,9 +18,49 @@ */ +class Car{ + String make; + String model; + int year; + Car(String make, String model,int year){ + this.make = make; + this.model = model; + this.year = year; + } + + public String getMake(){ + return make; + } + public String getModel(){ + return model; + } + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + + public void setMake(String make) { + this.make = make; + } + + public void setModel(String model) { + this.model = model; + } + + public String toString(){ + return year + " " + make + " " + model; + } +} public class ClassesAndObjects { public static void main(String[] args) { - + Car car = new Car("Tata", "Nexon", 2024); + System.out.println("make = " + car.make); + System.out.println("model = " + car.model); + System.out.println("year = " + car.year); + System.out.println("Details : " + car.toString()); } } diff --git a/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/InheritanceChallenge.java b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/InheritanceChallenge.java index a2a4f17..9aeb27b 100644 --- a/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/InheritanceChallenge.java +++ b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/InheritanceChallenge.java @@ -12,9 +12,52 @@ */ +class Animal{ + String name; + int age; + Animal(String name,int age){ + this.name = name; + this.age = age; + } + + public String makeSound(){ + return "make sound"; + } +} +class Dog extends Animal{ + String breed; + Dog(String name, int age, String breed) { + super(name, age); + this.breed = breed; + } + + @Override + public String makeSound(){ + return "The Dog Barks"; + } +} + +class Cat extends Animal{ + int lives; + Cat(String name, int age,int lives) { + super(name, age); + this.lives = lives; + } + @Override + public String makeSound(){ + return "The Cat Meows"; + } +} public class InheritanceChallenge { public static void main(String[] args) { + Animal cat = new Cat("Cat",2,5); + Animal dog = new Dog("Scooby",3,"labora"); + Animal lion = new Animal("lion",3); + Animal[] animals = {cat,dog,lion}; + for (Animal animal: animals){ + System.out.println(animal.name + " " + animal.age + " " + animal.makeSound()); + } } } diff --git a/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/InstanceOf.java b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/InstanceOf.java index fe0349f..fe999c1 100644 --- a/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/InstanceOf.java +++ b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/InstanceOf.java @@ -12,6 +12,19 @@ public static void main(String[] args) { }; // Challenge: Use instanceof to determine the type of each object in the array - + for (Object o : objects){ + if(o instanceof Integer){ + System.out.println(o + " is an Integer"); + } + else if(o instanceof String){ + System.out.println(o + " is an String"); + } + else if(o instanceof Boolean){ + System.out.println(o + " is an Boolean"); + } + else if(o instanceof Double){ + System.out.println(o + " is an Double"); + } + } } } diff --git a/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/JavaVariables.java b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/JavaVariables.java index 2e84ae0..abd1a76 100644 --- a/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/JavaVariables.java +++ b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/JavaVariables.java @@ -5,28 +5,47 @@ public class JavaVariables { public static void main(String[] args) { // Step 1: Declare and initialize variables of different data types // int variable to store an integer value - + int i =23; // long variable to store a long value - + long l = 234567L; // float variable to store a floating-point value - + float f = 3.4444f; // double variable to store a double value - + double d = 3.44444; // char variable to store a single character - + char c = 'A'; // boolean variable to store a boolean value - + boolean b = true; // String variable to store a string of characters - + String s = "str"; // Step 2: Print the values of the variables to the console - + System.out.println(i); + System.out.println(l); + System.out.println(f); + System.out.println(d); + System.out.println(c); + System.out.println(b); + System.out.println(s); // Step 3: Modify the values of the variables and print the updated values - + i =10; + l = 233L; + f =2.23f; + d =222222.22; + c ='B'; + b = false; + s = "str1"; + System.out.println(i); + System.out.println(l); + System.out.println(f); + System.out.println(d); + System.out.println(c); + System.out.println(b); + System.out.println(s); } } diff --git a/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/Operators.java b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/Operators.java index f35cf5f..eb7532c 100644 --- a/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/Operators.java +++ b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/Operators.java @@ -6,31 +6,36 @@ public class Operators { public static void main(String[] args) { // Step 1: Declare variables - ArrayList + int a = 30; + int b = 20; // Step 2: Perform arithmetic operations - + int sum = a+b; + int sub = a-b; + // Step 3: Print the results of the arithmetic operations - + System.out.println("sub = " + sub); // Step 4: Perform increment and decrement operations - + a++; + b--; // Step 5: Print the results of the increment and decrement operations - + System.out.println("a = " + a); + System.out.println("b = " + b); // Step 6: Perform comparison operations - + boolean comp = a==b; // Step 7: Print the results of the comparison operations - + System.out.println("comp = " + comp); // Step 8: Perform logical operations - + boolean l = a!=b && b==b ? true : false; // Step 9: Print the results of the logical operations - + System.out.println("l = " + l); } } diff --git a/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/PrimitiveAndWrapperClasses.java b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/PrimitiveAndWrapperClasses.java index 07155d1..e1e534f 100644 --- a/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/PrimitiveAndWrapperClasses.java +++ b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/PrimitiveAndWrapperClasses.java @@ -3,14 +3,14 @@ public class PrimitiveAndWrapperClasses { public static void main(String[] args) { // Step 1: Declare primitive variables - + int i =10; // Step 2: Convert primitive variables to wrapper objects - + Integer iWrapper = i; // Step 3: Print the values of the wrapper objects - + System.out.println("iWrapper = " + iWrapper); // Step 4: Convert wrapper objects back to primitive variables - + i = iWrapper; // Step 5: Print the values of the primitive variables - + System.out.println("i = " + i); } } diff --git a/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/ReadWrite.java b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/ReadWrite.java new file mode 100644 index 0000000..3be0426 --- /dev/null +++ b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/ReadWrite.java @@ -0,0 +1,67 @@ +package io.javabrains.javabasics; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Scanner; + +public class ReadWrite { + public static void main(String[] args) throws IOException { + Scanner scanner = new Scanner(System.in); + System.out.println("Enter name"); + String name = scanner.nextLine(); + System.out.println("Enter Destination"); + String dest = scanner.nextLine(); + System.out.println(name + " travelling towards " + dest); + + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); + System.out.println("Enter place of brith"); + String from = bufferedReader.readLine(); + System.out.println(from); + + scanner.close(); + bufferedReader.close(); + + } +} + + + +//Writing Output: +//You can write output to the standard output stream (usually the console) using the System.out.println() method. +//Example: +//java +//Copy code +//public class Main { +// public static void main(String[] args) { +// System.out.println("Hello, world!"); +// } +//} +//Reading/Writing Files: +//import java.io.BufferedReader; +//import java.io.FileReader; +//import java.io.IOException; +// +//public class Main { +// public static void main(String[] args) throws IOException { +// BufferedReader reader = new BufferedReader(new FileReader("input.txt")); +// String line; +// while ((line = reader.readLine()) != null) { +// System.out.println(line); +// } +// reader.close(); +// } +//} +// +//import java.io.BufferedWriter; +//import java.io.FileWriter; +//import java.io.IOException; +// +//public class Main { +// public static void main(String[] args) throws IOException { +// BufferedWriter writer = new BufferedWriter(new FileWriter("output.txt")); +// writer.write("Hello, world!"); +// writer.newLine(); +// writer.close(); +// } +//} \ No newline at end of file diff --git a/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/StaticChallenge.java b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/StaticChallenge.java index a6c781c..93e6172 100644 --- a/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/StaticChallenge.java +++ b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics/StaticChallenge.java @@ -10,9 +10,39 @@ 5. In this main method, create several `Rectangle` objects, calculate and print their area and perimeter, and finally print the number of rectangles created without keeping count in this class. */ +class Rectangle{ + int width; + int height; + static int noOfRectangles=0; + + Rectangle(int width,int height){ + this.width=width; + this.height=height; + noOfRectangles++; + } + public int getArea(){ + return this.width*this.height; + } + public int getPerimeter(){ + return 2*(this.width+this.height); + } + static int getNoOfRectangles(){ + return noOfRectangles; + } +} public class StaticChallenge { public static void main(String[] args) { + Rectangle rect1 = new Rectangle(10,20); + Rectangle rect2 = new Rectangle(30,20); + + System.out.println("rect1.getArea() = " + rect1.getArea()); + System.out.println("rect1.getPerimeter() = " + rect1.getPerimeter()); + + System.out.println("rect2.getArea() = " + rect2.getArea()); + System.out.println("rect2.getPerimeter() = " + rect2.getPerimeter()); + + System.out.println(Rectangle.getNoOfRectangles()); } } diff --git a/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics1/C.java b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics1/C.java new file mode 100644 index 0000000..46bdf0c --- /dev/null +++ b/session-03-java-basics/java-basics-exercises/src/main/java/io/javabrains/javabasics1/C.java @@ -0,0 +1,17 @@ +package io.javabrains.javabasics1; + +import io.javabrains.javabasics.A; + +class C { + public void accessVars(){ + A a = new A(); +// System.out.println("a.privateVar = " + a.privateVar); // can't perform this since it is private var +// System.out.println("a.var = " + a.var); // can access in different package; +// System.out.println("a.protectedVar = " + a.protectedVar); // can't access in different package + System.out.println("a.publicVar = " + a.publicVar); + } + public static void main(String[] args) { + C b = new C(); + b.accessVars(); + } +} \ No newline at end of file diff --git a/session-04-java-collections/java-collections-exercises/.idea/misc.xml b/session-04-java-collections/java-collections-exercises/.idea/misc.xml index 06e8b35..bffff61 100644 --- a/session-04-java-collections/java-collections-exercises/.idea/misc.xml +++ b/session-04-java-collections/java-collections-exercises/.idea/misc.xml @@ -7,6 +7,7 @@ +