From 301e84a0eb65918dedc02e145b4ddc0f0676d16e Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Tue, 24 Jan 2023 19:22:29 +0530 Subject: [PATCH 01/42] Create vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 125 ++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 vishal_karanjekar _source_codes_java(1-4) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) new file mode 100644 index 0000000..c1052cb --- /dev/null +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -0,0 +1,125 @@ +// lecture 1source code (vishal_karanjekar) +//hello world code + +class HelloWorld { + public static void main(String[] args) { + + System.out.println("Hello, World!");// for printing output + + } +} + + + +//lecture 2 source code (vishal_karanjekar) +//various datatypes in java + +public class DataType { + public static void main(String[] args) { + int i=1; + System.out.println(i); + short a=32767; + System.out.println("a= " + a); + String a_1="My name is Vishal \b"; + System.out.println(a_1); + String z="NULL \b"; + System.out.println(z); + float pi=3.14_15F; + System.out.println("pi= " + pi); + + + } + +} + +//lecture 3 source code (vishal_karanjekar) +// nested while loop concept + +public class Solution{ + +public static void main(String[] args) { + int i=1,j=1; //initialization + while(i<=10) { + while(j<=5) { + System.out.print("*"); //loop 1 + j++; + + } + System.out.println(""); //loop 2 + i++; + j=1; + + } + // TODO Auto-generated method stub + } + + +} + + +//lecture 4 source code(vishal_karanjekar) +//oops concepts & strings + +//abstraction + +package Abstraction_code; + +abstract class AbstractClass { + public void Mymethod(){ + System.out.println("Hi,I'm Vishal"); + } + abstract public void anotherMethod(); + +} + +//abtraction in inherited class +package Abstract; + +public class Demo extends AbstractClass { + + public void anotherMethod() { + System.out.println("Hi, this is Ramesh"); + } + + public static void main(String[] args) { + + AbstractClass obj=new Demo(); + obj.anotherMethod(); //abstract method + obj.Mymethod(); //normal method + + } +} + +//strings functions + +public class StringFunctions { + + public static void main(String[] args) { + + char a='V'; + String b="Ramesh"; + String c="vishal"; + System.out.println(b.length()); + + System.out.println(c.charAt(0)); + + System.out.println(c.compareTo(b)); //compare two strings based on their ASCII values + + System.out.println(b.strip()); //to remove the spaces at the start and at the end of a string + + System.out.println(c.toUpperCase()); //convert in to upper case + + System.out.println(c.toLowerCase()); //convert in to lower case + + System.out.println(c.substring(1,3)); //return substring from position 1 to position 3-1 + System.out.println(c.substring(3)); + + + System.out.println(c.isBlank()); //tell us whether the string is empty or not + + // TODO Auto-generated method stub + + } + +} + From 08ee550003a6d99bb27f227eb0894bd64cb9cf0d Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Thu, 26 Jan 2023 16:10:14 +0530 Subject: [PATCH 02/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index c1052cb..3ed29a5 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -115,7 +115,7 @@ public class StringFunctions { System.out.println(c.substring(3)); - System.out.println(c.isBlank()); //tell us whether the string is empty or not + System.out.println(c.isBlank()); //tell us whether the string is empty or not // TODO Auto-generated method stub From 0e3e98b7574d344aba5e19086f583bc3c26a8efb Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Thu, 26 Jan 2023 18:34:27 +0530 Subject: [PATCH 03/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 3ed29a5..72abecb 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -123,3 +123,31 @@ public class StringFunctions { } + +//lecture 5 source code(vishal_karanjekar) +//creating class and objects + +class Demo{ + String name; + int age; + int rollno; + + public void info() + { + System.out.println("Name = " + name); + System.out.println("Age = " + age); + System.out.println("Roll No = " + rollno); + } + + + + public static void main (String[] args) + { + Demo student=new Demo(); + student.name="Vishal"; + student.age=21; + student.rollno=272; + student.info(); + } + + } From f3a32245c3941f4045e8b14f61fca0a6c2fa5476 Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Thu, 26 Jan 2023 18:43:55 +0530 Subject: [PATCH 04/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 72abecb..a3fd79a 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -151,3 +151,33 @@ class Demo{ } } + + +//searching in an array + +class DemoArray +{ + public static void main (String[] args) + { + int[] arrayInt = {32,87,3,589,1076,12,2000,8,622,127}; //declaration of an array + + int key = 2000; + int i; + boolean flag = false; + for(i=0;i Date: Thu, 26 Jan 2023 18:44:27 +0530 Subject: [PATCH 05/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index a3fd79a..e0702aa 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -1,4 +1,4 @@ -// lecture 1source code (vishal_karanjekar) +// lecture 1 source code (vishal_karanjekar) //hello world code class HelloWorld { From fe20e312a7d80d1b49e76766e502fe8b4638cfb6 Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Thu, 26 Jan 2023 19:15:45 +0530 Subject: [PATCH 06/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index e0702aa..84cc449 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -181,3 +181,23 @@ class DemoArray } } } + + +// 2D array creation + +class Matrix +{ + public static void main (String[] args) + { + + int [][]a=new int[15][15]; //10 rows and 10 column + for(int i=0;i<=11;i++){ + for(int j=0;i<10;j++) + { + System.out.println(a[i][j]); + } + System.out.println(); + } + } +} + From 7fb5b946102fd49847e5c325ede418c85c113e07 Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Thu, 26 Jan 2023 19:21:54 +0530 Subject: [PATCH 07/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 34 ++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 84cc449..d10d777 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -190,7 +190,7 @@ class Matrix public static void main (String[] args) { - int [][]a=new int[15][15]; //10 rows and 10 column + int [][]a=new int[15][15]; //defining size for(int i=0;i<=11;i++){ for(int j=0;i<10;j++) { @@ -201,3 +201,35 @@ class Matrix } } + +//printing elements in an array + +class Array_Demo +{ + public static void main (String[] args) + { + int[] anArray; //declaration + + anArray=new int[13]; //Allocation + + //intialization + anArray[0]=15; + anArray[1]=26; + anArray[2]=65; + anArray[3]=200; + anArray[4]=300; + anArray[5]=100; + anArray[6]=400; + anArray[7]=500; + anArray[8]=600; + anArray[9]=700; + anArray[10]=800; + anArray[11]=900; + anArray[12]=10; + + for(int i=0;i<13;i++){ + System.out.println("Element at index "+i+": "+anArray[i]); + } + } +} + From 8ca490d8c1b4392aa7f3495692f8f7c775bbd3ac Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Thu, 26 Jan 2023 19:38:09 +0530 Subject: [PATCH 08/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 43 +++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index d10d777..34009dd 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -233,3 +233,46 @@ class Array_Demo } } +//problem on course + +import java.util.*; + +class CourseDemo +{ + public static void main (String[] args) + { + Scanner sc = new Scanner(System.in); + + System.out.println("Enter no of course:"); + int n = sc.nextInt(); + if(n<=0){ + System.out.println("Invalid Range"); + } + else{ + System.out.println("Enter course names:"); + String course[]=new String[n]; + int count =0,i; + for(i=0;i Date: Fri, 27 Jan 2023 15:51:44 +0530 Subject: [PATCH 09/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 34009dd..dd886be 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -276,3 +276,28 @@ class CourseDemo } } } + + +//lecture 6 source code (vishal_karanjekar) +// array elements input code + +import java.util.Scanner; + +class Read_Input +{ + public static void main(String[] args) + { + int n; + Scanner sc= new Scanner(System.in); + System.out.println("Enter the number of elements you want to store: "); + n=sc.nextInt(); + + int[] array=new int[10]; + System.out.println("Enter the elements of the array: "); + for(int i=0;i Date: Fri, 27 Jan 2023 15:54:35 +0530 Subject: [PATCH 10/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index dd886be..32944a7 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -287,8 +287,8 @@ class Read_Input { public static void main(String[] args) { - int n; - Scanner sc= new Scanner(System.in); + int n; // size of the array + Scanner sc= new Scanner(System.in); //reading input System.out.println("Enter the number of elements you want to store: "); n=sc.nextInt(); @@ -297,7 +297,7 @@ class Read_Input for(int i=0;i Date: Fri, 27 Jan 2023 16:17:53 +0530 Subject: [PATCH 11/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 36 +++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 32944a7..5a25bff 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -301,3 +301,39 @@ class Read_Input } } } + + +// 2D array using nested for loops + +import java.util.Scanner; + +class TwoDArray +{ + public static void main(String[] args) + { + System.out.println("Enter the size of 2D array: "); + Scanner sc= new Scanner(System.in); + int rows=sc.nextInt(); + int columns=sc.nextInt(); + int twoD[][]= new int[rows][columns]; + System.out.println("Enter the elements of the 2D array: "); + for(int i=0;i Date: Fri, 27 Jan 2023 16:31:32 +0530 Subject: [PATCH 12/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 5a25bff..4b65e07 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -337,3 +337,22 @@ class TwoDArray } } + + +//nested loop + +class Vishal +{ + public static void main(String[] args) + { + for(int i=0;i<4;i++) + { + for(int j=0;j<5;j++) + { + System.out.println("i value:: "+i + " j value:: " +j); + } + System.out.println("........................."); + } + + } +} From 9eddaa2088a9bad346a48c1ba78008b86311c6dc Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Fri, 27 Jan 2023 16:32:48 +0530 Subject: [PATCH 13/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 4b65e07..e9587d0 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -339,7 +339,7 @@ class TwoDArray } -//nested loop +//nested for loop class Vishal { From c5baba3bfec14ba043b1d1ec74c3b42d498711c3 Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Fri, 27 Jan 2023 16:39:33 +0530 Subject: [PATCH 14/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index e9587d0..fe66d79 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -356,3 +356,27 @@ class Vishal } } + + +//nested while loop + +class Vishal +{ + public static void main(String[] args) + { + int i=0; + int j=0; + while(i<4) + { + while(j<5) + { + System.out.println("i value:: "+i + " j value:: " +j); + j++; + + i++; + } + + } + + } +} From 30312b3a151fe5235448e1c3231e4ceadf3b99b9 Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Fri, 27 Jan 2023 16:42:28 +0530 Subject: [PATCH 15/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index fe66d79..55d4622 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -380,3 +380,21 @@ class Vishal } } + + +//nested do while loop + +class Vishal +{ + public static void main(String[] args) + { + int i=1; + do + { + System.out.println("i value:: "+i ); + i++; + } + while(i<10) ; + + } +} From a6bc1f400113fd04fcb9b6611412a17373f885e1 Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Fri, 27 Jan 2023 16:45:41 +0530 Subject: [PATCH 16/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 55d4622..e69aed9 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -398,3 +398,22 @@ class Vishal } } + +//if else statement + +class Vishal +{ + public static void main(String[] args) + { + int a=5; +if(a<6) +{ + System.out.println("true"); + +} +else +{ + System.out.println("false"); +} +} +} From 8d85057c93737dcaee0fa49bd3db9cdce35e8329 Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Fri, 27 Jan 2023 16:49:25 +0530 Subject: [PATCH 17/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index e69aed9..88673ff 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -399,7 +399,7 @@ class Vishal } } -//if else statement +//if else condition class Vishal { From db18d1a74f65352c383f50b1073d46610a9cf225 Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Sat, 28 Jan 2023 10:55:39 +0530 Subject: [PATCH 18/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 40 +++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 88673ff..9c8c2ce 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -417,3 +417,43 @@ else } } } + + +//lecture 7 source code(vishal_karanjekar) +//inheritance in java + + + public class C extends B{ + + public static void main(String[] args) { + A a= new A(); + B b=new B(); + System.out.println(a.x); + System.out.println(b.getb()); + // TODO Auto-generated method stub + + } + +} + + class B extends A { + + public int getb() { + set(2); + return x; + // TODO Auto-generated method stub + + + } + +} + +class A { + + int x=1; + void set(int a) { + x=a; + + } +} + From cfd44bde8f8ea5001ed6fbd88bfe87e11caa0f0d Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Sat, 28 Jan 2023 11:27:40 +0530 Subject: [PATCH 19/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 9c8c2ce..2cc4ede 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -457,3 +457,24 @@ class A { } } + +//function overloading + +public class V extends V1 { + public static void main(String[] args) { + V obj= new V(); //creating an object + obj.disp('x',10); + obj.disp(10,'x'); + + } +} + +class V1{ + public void disp(char c,int num){ + System.out.println("1st defination of method"); + } + public void disp(int num,char c){ + System.out.println("2nd defination of method"); + } + +} From 93259e0607de4288bfa5a40ef69f5ed5a51b616c Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Sat, 28 Jan 2023 11:30:30 +0530 Subject: [PATCH 20/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 2cc4ede..c81e6d8 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -465,16 +465,19 @@ public class V extends V1 { V obj= new V(); //creating an object obj.disp('x',10); obj.disp(10,'x'); - + obj.disp(10); } } class V1{ public void disp(char c,int num){ - System.out.println("1st defination of method"); + System.out.println(" 1st defination of method "); } public void disp(int num,char c){ - System.out.println("2nd defination of method"); + System.out.println(" 2nd defination of method "); + } + public void disp(int num){ + System.out.println(" 3rd defination of method "); } - } + From ec0fdb9dcc912020c99cdb70beee4ab281bf46c1 Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Sat, 28 Jan 2023 12:34:13 +0530 Subject: [PATCH 21/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 32 ++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index c81e6d8..360c388 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -457,7 +457,7 @@ class A { } } - +//polymorphism //function overloading public class V extends V1 { @@ -481,3 +481,33 @@ class V1{ } } + + +//function overriding + +class Parent { + void disp() + { + System.out.println("Parent's disp()"); + } +} + +// Inherited class +class Child extends Parent { + + void disp() //method override + { + System.out.println("Child's disp()"); + } +} + +class Main { + public static void main(String[] args) + { + Parent obj1 = new Parent(); + obj1.disp(); + + Parent obj2 = new Child(); + obj2.disp(); + } +} From 2c0d23badc74fedd6bd156d618f8d2965116d42f Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Sat, 28 Jan 2023 12:55:21 +0530 Subject: [PATCH 22/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 28 ++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 360c388..0a85e57 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -457,7 +457,6 @@ class A { } } -//polymorphism //function overloading public class V extends V1 { @@ -511,3 +510,30 @@ class Main { obj2.disp(); } } + + +//polymorphism + +class V { + + static int sum(int a, int b) //method 1 + { + return a + b; + } + + static int sum(int a, int b, int c) // Method 2 + { + return a + b + c; + } +} + +class Sum { + + public static void main(String[] args) + { + // Calling method by passing values + + System.out.println(V.sum(2, 4)); //method 1 + System.out.println(V.sum(6,2,9)); // Method 2 +} +} From 6e0d4e6f1db6d2cd23f4420fa8761741328b5ab6 Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Sun, 29 Jan 2023 16:15:57 +0530 Subject: [PATCH 23/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 0a85e57..972bd83 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -537,3 +537,18 @@ class Sum { System.out.println(V.sum(6,2,9)); // Method 2 } } + + + +//lecture 8 source code (vishal_karanjekar) +//interface + +public interface NameOfInterface + +{ + + //Any number of final ,static fields + + //Any number of abstract method declarations + +} From 96391716bc8fd9684c29981a4751c6332577d38b Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Sun, 29 Jan 2023 16:32:21 +0530 Subject: [PATCH 24/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 52 +++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 972bd83..771c18f 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -552,3 +552,55 @@ public interface NameOfInterface //Any number of abstract method declarations } + + +// example of an interface + + +interface Bank +{ + float rateOfInterest(); //after compilation it will convert into abstract static +} + + +class PNB implements Bank + +{ + +public float rateOfInterest() + { + + return 9.7f; + + } + +} + +class SB implements Bank +{ + +public float rateOfInterest() + { + + return 9.15f; + +} + +} + +class Test +{ + + public static void main(String[] args) + { + + Bank b= new SB(); + + Bank p=new PNB(); + + System.out.println("ROI: " +b.rateOfInterest()); + System.out.println("ROI: " +p.rateOfInterest()); + + } + +} From 014e7da8ab659a0dfdbe2e6981f456dc9406f3f9 Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Mon, 30 Jan 2023 15:25:12 +0530 Subject: [PATCH 25/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 33 +++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 771c18f..d15404a 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -604,3 +604,36 @@ class Test } } + + +//multiple inheritance using interface + +interface Printable{ + void print(); +} +interface Showable{ + void show(); +} +class Exercise implements Printable,Showable{ + @Override + public void show() { + System.out.println("Showable "); + + } + @Override + public void print() { + System.out.println("Printable"); + + } + +} + +class Interfaces{ + public static void main(String args[]) { + + Exercise obj =new Exercise(); + obj.show(); + obj.print(); + + } +} From 595d3b53c7501402f3571be846359e9d43de60ea Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Mon, 30 Jan 2023 15:43:50 +0530 Subject: [PATCH 26/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index d15404a..4babb2f 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -637,3 +637,30 @@ class Interfaces{ } } + + + +//lecture 9 source code(vishl_karanjekar) +//encapsulation +//access specifiers + +public class B extends A +{ + public static void main(String[] args) + { + B b=new B(); + //System.out.println(q.x); //this one is showing error because 'x' is private so can't be accessed from this class + System.out.println(b.y); + System.out.println(b.z); + System.out.println(b.w); + } +} + + class A +{ + private int x =23; + public int y = 15; + protected int z = 50; + int w = 10; +} + From 3f68ee780858da3b2f72c30482e0b2a64bdf0dd3 Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Mon, 30 Jan 2023 15:47:47 +0530 Subject: [PATCH 27/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 4babb2f..201295e 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -649,18 +649,19 @@ public class B extends A public static void main(String[] args) { B b=new B(); + System.out.println(b.w); //System.out.println(q.x); //this one is showing error because 'x' is private so can't be accessed from this class System.out.println(b.y); System.out.println(b.z); - System.out.println(b.w); - } + } } class A { - private int x =23; + int w = 10; + private int x =23; public int y = 15; protected int z = 50; - int w = 10; + } From 15b9b116f449647a3a7199bf502633303db91ccd Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Mon, 30 Jan 2023 16:03:15 +0530 Subject: [PATCH 28/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 201295e..06c77b9 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -665,3 +665,28 @@ public class B extends A } + + +//encapsulation + +private int vishal = 10; + +class A +{ + private int vishal=10; + int rishabh = 100; +} + + + +public Class B extends A +{ + public static void main(String[] args) + { + B b = new B(); + System.out.println(b.rishabh); + System.out.println(b.vishal); + } +} + + From 43e17b415126d8884cc693007a697d2991be0d32 Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Tue, 31 Jan 2023 16:35:20 +0530 Subject: [PATCH 29/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 41 +++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 06c77b9..749f14d 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -690,3 +690,44 @@ public Class B extends A } + +//lecture 11 source code (vishal_karanjekar) +//jshell + + +jshell> 1 +$1 ==> 1 + +jshell> 5 +$2 ==> 5 + + +jshell> 2+3 +$3 ==> 5 + + +jshell> 3*4 +$4 ==> 12 + +jshell> + String print(String s){ + ...> return s+s; + ...> } +| created method print(String) + + +jshell> print("Vishal") +$6 ==> "vishalvishal" + +jshell> int x=5 +x ==> 5 + +jshell> + int sum(int x,int y){ + ...> return x+y; + ...> } +| created method sum(int,int) + +jshell> sum(12,13) +$9 ==> 25 + From ba14e3946960ad9aa895a8b734f588fe5ec92f59 Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Tue, 31 Jan 2023 16:54:35 +0530 Subject: [PATCH 30/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 749f14d..20fd7b6 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -731,3 +731,25 @@ jshell> jshell> sum(12,13) $9 ==> 25 + + +//lecture 12 source code(vishal_karanjekar) +//jlambda + + +import java.util.ArrayList; + + class Program_1 +{ + public static void main(String[] args) { + ArrayList numbers = new ArrayList(); + numbers.add(1); + numbers.add(2); + numbers.add(3); + numbers.add(4); + numbers.add(5); + numbers.forEach( (i) -> {System.out.println(i); }); + } + } + + From 2777efa5d51280a4bcc40271c97d7e6d7c74fbe2 Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Tue, 31 Jan 2023 16:55:26 +0530 Subject: [PATCH 31/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 20fd7b6..9531f8b 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -739,7 +739,7 @@ $9 ==> 25 import java.util.ArrayList; - class Program_1 + class A { public static void main(String[] args) { ArrayList numbers = new ArrayList(); From e91e1c5768544bd51e670686928b71ee14943801 Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Wed, 1 Feb 2023 16:14:41 +0530 Subject: [PATCH 32/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 9531f8b..47b38f3 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -753,3 +753,17 @@ import java.util.ArrayList; } + +//lecture 1 data structures (vishal_karanjekar) +//Exception Handling + +public class ExceptionTest{ + + public static void main(String[] args) + { + //String age="33";//error (exception handling) + int age = 33; + int maxheartrate = 220 - age ; + System.out.println("Max heart rate is = " + maxheartrate); + } +} From 9eeb060383d23d0434316aab9639388bc21ba778 Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Wed, 1 Feb 2023 16:25:58 +0530 Subject: [PATCH 33/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 47b38f3..4da08d2 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -767,3 +767,32 @@ public class ExceptionTest{ System.out.println("Max heart rate is = " + maxheartrate); } } + + +//Exception Handling Example + +import java.util.Scanner; + + class ExceptionTest{ + + public static void main(String[] args) + { + System.out.println("Welcome to Max Heart Rate Calculator"); + Scanner sc=new Scanner(System.in); + + System.out.println("Please enter your age : "); + int age =sc.nextInt(); + int maxheartrate = 220 - age ; + System.out.println("Max heart rate is = " + maxheartrate); + } +} + +output: +Welcome to Max Heart Rate Calculator +Please enter your age : Twenty One +Exception in thread "main" java.util.InputMismatchException +at java.base/java.util.Scanner.throwFor(Scanner.java:939) +at java.base/java.util.Scanner.next(Scanner.java:1594) + at java.base/java.util.Scanner.nextInt(Scanner.java:2258) + at java.base/java.util.Scanner.nextInt(Scanner.java:2212) +at ExceptionTest.main(ExceptionTest.java:14) From 8ef59cce823b1ede61f8c3bdf7393d1949926011 Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Wed, 1 Feb 2023 16:34:13 +0530 Subject: [PATCH 34/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 4da08d2..5299ce8 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -796,3 +796,33 @@ at java.base/java.util.Scanner.next(Scanner.java:1594) at java.base/java.util.Scanner.nextInt(Scanner.java:2258) at java.base/java.util.Scanner.nextInt(Scanner.java:2212) at ExceptionTest.main(ExceptionTest.java:14) + + +//Exception Handling + +import java.util.InputMismatchException; +import java.util.Scanner; + + class ExceptionTest{ + + public static void main(String[] args) + { + //exception handling + try{ + System.out.println("Welcome to Max Heart Rate Calculator"); + Scanner sc=new Scanner(System.in); + + System.out.println("Please enter your age : "); + int age =sc.nextInt(); + int maxheartrate = 220 - age ; + System.out.println("Max heart rate is = " + maxheartrate); + }catch(InputMismatchException e){ + System.out.println("Please enter integer only"); + } + } +} + +output: Welcome to Max Heart Rate Calculator +Please enter your age : Twenty One +Please enter integer only + From 9829492b9ea6d1be8021c62072b8304b44372800 Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Thu, 2 Feb 2023 15:28:58 +0530 Subject: [PATCH 35/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 36 +++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 5299ce8..aab07dd 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -826,3 +826,39 @@ output: Welcome to Max Heart Rate Calculator Please enter your age : Twenty One Please enter integer only + + +//lecture 2 DSA souce code(vishal_karanjekar) +//Advanced Exception Handling + +import java.util.InputMismatchException; +import java.util.Scanner; + + class ExceptionTest{ + + public static void main(String[] args) + { + //exception handling + try{ + System.out.println("Welcome to Max Heart Rate Calculator"); + Scanner sc=new Scanner(System.in); + + System.out.println("Please enter your age : "); + int age =sc.nextInt(); + int maxheartrate = 220 - age ; + System.out.println("Max heart rate is = " + maxheartrate); + }catch(Exception e){ + System.out.println("Please enter integer only"); + System.out.println(e.getLocalizedMessage()); + System.out.println(e.getMessage()); + + } + } +} +output: +Welcome to Max Heart Rate Calculator +Please enter your age : +twenty one +Please enter integer only +null +null From 8813379187a58799c9bf82436227ace76ce47465 Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Thu, 2 Feb 2023 15:58:33 +0530 Subject: [PATCH 36/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 40 +++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index aab07dd..06ffdf1 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -862,3 +862,43 @@ twenty one Please enter integer only null null + + +//lecture 2 DSA souce code(vishal_karanjekar) +//Advanced Exception Handling +//try catch and finally blocks + +import java.util.InputMismatchException; +import java.util.Scanner; + + class TryCatchFinallyTest{ + + public static void main(String[] args) + { + try{ + Scanner sc=new Scanner(System.in); + System.out.println("Enter no 1: "); + int a =sc.nextInt(); + System.out.println("Enter no 2: "); + int b =sc.nextInt(); + int d=add(a,b); + System.out.println("Sum is equal to= "+d); + }catch(InputMismatchException e){ + System.out.println("please enter integers only "); + }finally{ + System.out.println("Integers not found"); + } + } + private static int add(int a, int b){ + int c=0; + try{ + c=a+b; + }catch(Exception e) { + System.out.println("Please enter integers only"); + }finally { + System.out.println("Fianlly executed "); + return c; + } + + } + } From bd30cd6d220e1a4ceaaed1e6069bf93072e3e0ea Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Thu, 2 Feb 2023 16:17:27 +0530 Subject: [PATCH 37/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 06ffdf1..10b8def 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -902,3 +902,26 @@ import java.util.Scanner; } } + + +//throwing an exception + +import java.util.Scanner; + + public class ThrowExceptionTest{ + + public static void main(String[] args) + { + Scanner sc=new Scanner(System.in); + System.out.println("Please enter your age: "); + int age =sc.nextInt(); + if (age<=0){ + throw new NumberFormatException(); + } + else if(age>=120){ + throw new NumberFormatException(); + } + System.out.println("Max Heart Rate is" + (220 - age)); + + } + } From f3793755204663344bbb988761b82bf1ad08fc70 Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Thu, 2 Feb 2023 16:22:31 +0530 Subject: [PATCH 38/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 10b8def..b1c273f 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -925,3 +925,31 @@ import java.util.Scanner; } } + + + //chained exception + +import java.util.InputMismatchException; +import java.util.Scanner; + +public class ChainedException { + + public static void main(String[] args) + { + try + { + Scanner sc=new Scanner(System.in); + System.out.println("Please enter your height in cm "); + float height =sc.nextInt(); + + double idealWeight=50+(0.91*(height-152.4)); //Standard ideal weight + + System.out.println("your ideal weight is : "+idealWeight); + } + catch(InputMismatchException e) + { + throw new NumberFormatException(); + } + + } +} From f0b9889e4c6ad3aa9cba891f215d642b5963f38d Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Fri, 3 Feb 2023 16:46:46 +0530 Subject: [PATCH 39/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 61 +++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index b1c273f..f8b96d3 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -953,3 +953,64 @@ public class ChainedException { } } + + + +//lecture 3 (DSA) source code(vishal_karanjekar) +//Lists interface and arraylist in java + +import java.util.ArrayList; + +public class MyArrayListTest{ + + public static void main(String[] args){ + ArrayList myArrayList= new ArrayList(); + myArrayList.add(1); + myArrayList.add(2); + myArrayList.add(3); + myArrayList.add(4); + myArrayList.add(5); + System.out.println("printing list 1: "); + System.out.println(myArrayList.get(1)); + System.out.println(myArrayList.get(0)); + System.out.println(myArrayList.get(4)); + + + System.out.println("updating elements"); + myArrayList.add(1,6); + System.out.println(myArrayList.get(1)); + + ArrayList List2= new ArrayList(); + List2.addAll(myArrayList); + + System.out.println("printing list 2: "); + System.out.println(List2.get(1)); + System.out.println(List2.get(0)); + System.out.println(List2.get(4)); + + List2.clear(); + try{ + System.out.println("printing list 2: "); + System.out.println(List2.get(1)); + System.out.println(List2.get(0)); + System.out.println(List2.get(4)); + }catch(IndexOutOfBoundsException e){ + System.out.println("list is cleared"); + } + + ArrayList myArrayListClone = (ArrayList) myArrayList.clone(); + System.out.println("printing from my arraylist clone"); + System.out.println(myArrayListClone.get(1)); + System.out.println(myArrayListClone.get(0)); + System.out.println(myArrayListClone.get(4)); + + System.out.println("check if my arraylist clone contains 6"); + boolean result=myArrayListClone.contains(6); + if(result){ + System.out.println("item exists"); + } + else{ + System.out.println("item does not exist"); + } + } +} From 829a0c62ba7032ab1687a3e332299c074f7f345c Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Sat, 4 Feb 2023 13:32:31 +0530 Subject: [PATCH 40/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index f8b96d3..15ec57e 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -1014,3 +1014,25 @@ public class MyArrayListTest{ } } } + + + +//lecture 4 (DSA) source code (vishal_karanjekar) +//stacks in java + +import java.util.Stack; + +public class MyStack{ + public static void main(String[] args){ + Stack intStack = new Stack(); + System.out.println("Is stack empty " + intStack.empty()); + intStack.push(10); + intStack.push(20); + intStack.push(30); + System.out.println(" Get the top element " + intStack.peek()); + System.out.println("Is stack contains 20 "+ intStack.search(20)); + intStack.pop(); + System.out.println("Top element after pop "+ intStack.peek()); + } +} + From bc2874c0212bb684fe13173771a7ff1498c07ad4 Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Sat, 4 Feb 2023 13:34:49 +0530 Subject: [PATCH 41/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 15ec57e..561a0a8 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -1025,14 +1025,14 @@ import java.util.Stack; public class MyStack{ public static void main(String[] args){ Stack intStack = new Stack(); - System.out.println("Is stack empty " + intStack.empty()); + System.out.println("Is stack empty: " + intStack.empty()); intStack.push(10); intStack.push(20); intStack.push(30); - System.out.println(" Get the top element " + intStack.peek()); - System.out.println("Is stack contains 20 "+ intStack.search(20)); + System.out.println(" Get the top element: " + intStack.peek()); + System.out.println("Is stack contains 20: "+ intStack.search(20)); intStack.pop(); - System.out.println("Top element after pop "+ intStack.peek()); + System.out.println("Top element after pop: "+ intStack.peek()); } } From 2a052c39d5ad1a423e2fde94c0ec79dd08ee3cab Mon Sep 17 00:00:00 2001 From: Vishal Karanjekar <119437719+vsk03116@users.noreply.github.com> Date: Sat, 4 Feb 2023 13:45:34 +0530 Subject: [PATCH 42/42] Update vishal_karanjekar _source_codes_java(1-4) --- vishal_karanjekar _source_codes_java(1-4) | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/vishal_karanjekar _source_codes_java(1-4) b/vishal_karanjekar _source_codes_java(1-4) index 561a0a8..e5a376d 100644 --- a/vishal_karanjekar _source_codes_java(1-4) +++ b/vishal_karanjekar _source_codes_java(1-4) @@ -1036,3 +1036,35 @@ public class MyStack{ } } + + +//ArrayDeque + +import java.util.ArrayDeque; +import java.util.Iterator; + +public class StackUsingDeque{ + public static void main(String[] args) + { + ArrayDeque myDeque = new ArrayDeque(); + + myDeque.add(" Vishal "); + myDeque.addFirst(" Rishabh "); + myDeque.addLast(" New Person "); + + myDeque.offerFirst(" Ram "); //at the first + myDeque.offer(" Lakhan "); //at the last + + System.out.println(" First Element: " + myDeque.getFirst()); + System.out.println(" Last Element: " + myDeque.getLast()); + System.out.println(" Deque contains Rishabh: " + myDeque.contains(" Rishabh ")); + + System.out.println("Iterating all the elements in descending order"); + + Iterator myIterator = myDeque.descendingIterator(); + + while(myIterator.hasNext()) { + System.out.println(myIterator.next()); + } + } +}