-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemo.java
More file actions
1159 lines (1156 loc) · 34.7 KB
/
Demo.java
File metadata and controls
1159 lines (1156 loc) · 34.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import java.util.HashMap;
import java.util.Map;
// {
// int a = 6;
// public int add(int n1, int n2)
// {
// int result = n1 + n2;
// return result;
// }
// public int Multi(int n1 , int n2)
// {
// int multiResult = n1 * n2;
// return multiResult;
// }
// }
// public class Demo
// {
// public static void main(String a[])
// {
// int num1 = 10;
// int num2 = 5;
// Calculator calc = new Calculator();
// int myResult = calc.add(num1, num2);
// int myMultiResult = calc.Multi(num1, num2);
// // int myInt = calc.a();
// System.out.println(myResult + " Addition");
// System.out.println(myMultiResult + " Multiplication");
// // System.out.println(myInt + " the intiger");
// }
// }
// class Mycalculator
// {
// public int add(int n1, int n2)
// {
// System.out.println("Add function called");
// int myr= n1 +n2;
// return myr;
// }
// }
// public class Demo
// {
// public static void main(String a[])
// {
// int num1 = 4;
// int num2 = 5;
// Mycalculator refCal = new Mycalculator();
// int result =refCal.add(num1, num2);
// System.out.println(result);
// }
// }
// class MyComputer
// {
// public void playMusic()
// {
// System.out.println("The Music is playing");
// }
// public String getMyPen(int cost)
// {
// if(cost >= 10)
// return "The Pen";
// return "Nothing";
// }
// }
// public class Demo
// {
// public static void main(String a[])
// {
// MyComputer theComp = new MyComputer();
// theComp.playMusic();
// String thePenResult = theComp.getMyPen(22);
// System.out.println(thePenResult);
// }
// }
// Method Overloading:
// class Mycalculator
// {
// public int add(int n1, int n2, int n3)
// {
// int result = n1 + n2 + n3;
// return result;
// }
// // You can have same name for the method, but the number of parameters should be differ
// public int add(int n1, int n2)
// {
// int result = n1 + n2;
// return result;
// }
// // you can have the same method name and same number of parameters, the type of parameters should differ.
// public double add(double n1, int n2)
// {
// int result = n1 + n2 + n3;
// return result;
// }
// }
// public class Demo {
// public static void main(String a[])
// {
// Mycalculator theNewCalculator = new Mycalculator();
// int ThecalulatorResult = theNewCalculator.add(55, 8);
// System.out.println(ThecalulatorResult +" The Calclulator Result ");
// }
// }
// creation of an array:
// public class Demo {
// public static void main(String aa[])
// {
// // int num[] = {4,5, 7,9};
// // num[1] = 10;
// int num[] = new int[4];
// num[0] = 4;
// num[1] = 10;
// num[2] = 3;
// num[3] = 2;
// for (int i=0; i< 4; i++)
// {
// System.out.println(num[i]);
// }
// }
// }
// Multi Dimensional array:
// public class Demo
// {
// public static void main(String a[])
// {
// int num[][] = new int[4][4];
// for(int i = 0; i < 4 ; i++)
// {
// for(int j = 0; j < 4; j++)
// {
// num[i][j] = (int)(Math.random() * 10);
// }
// // System.out.println();
// }
// for(int i = 0; i < 4 ; i++)
// {
// for(int j = 0; j < 4; j++)
// {
// System.out.print(num[i][j]+ " ");
// }
// System.out.println();
// }
// System.out.println();
// // Enhanced For loop:
// for (int n[]: num)
// {
// for(int m:n){
// System.out.print(m + " ");
// }
// System.out.println();
// }
// }
// }
// Jagged Array:
// public class Demo
// {
// public static void main(String a[])
// {
// int num[][] = new int[3][];
// num[0] = new int[3];
// num[1] = new int[4];
// num[2] = new int[2];
// for(int i = 0; i < num.length; i++)
// {
// for (int j = 0; j< num[i].length; j++)
// {
// num[i][j] = (int)(Math.random() * 10);
// }
// }
// for(int n[]:num)
// {
// for(int m:n)
// {
// System.out.print(m + " ");
// }
// System.out.println();
// }
// }
// }
// Three Dimensionl Array:
// public class Demo
// {
// public static void main(String a[])
// {
// int num[][][] = new int[3][4][5];
// for(int i = 0; i < num.length; i++)
// {
// for (int j = 0; j< num[i].length; j++)
// {
// for(int k = 0; k < num[i][j].length; k++){
// num[i][j][k] = (int)(Math.random() * 10);
// }
// }
// }
// for(int[][] n:num)
// {
// for(int[] m:n){
// for(int o:m){
// System.out.print(o + ' ');
// }
// System.out.println();
// }
// System.out.println();
// }
// }
// }
// array of objects:
// class Student
// {
// int rollNo;
// String name;
// int marks;
// }
// public class Demo
// {
// public static void main(String a[])
// {
// Student s1 = new Student();
// s1.rollNo = 1;
// s1.name = "Deepak";
// s1.marks = 55;
// Student s2 = new Student();
// s2.rollNo = 2;
// s2.name = "Syam";
// s2.marks = 65;
// Student s3 = new Student();
// s3.rollNo = 3;
// s3.name = "Sri";
// s3.marks = 100;
// // System.out.println(s1.name + " : " + s1.marks);
// Student students[] = new Student[3];
// students[0] = s1;
// students[1] = s2;
// students[2] = s3;
// // for(int i = 0; i < students.length; i++)
// // {
// // System.out.println(students[i].name + " : " + students[i].marks);
// // }
// for(Student stud : students)
// {
// System.out.println(stud.name + " : " + stud.marks);
// }
// }
// }
// class Demo
// {
// public static void main(String a[])
// {
// String name = "Deepak";
// name = name + " Kumar";
// System.out.println("Hi "+name);
// String Name1 = "Deepak";
// String Name2 = "Deepak";
// System.out.println(Name1 == Name2);
// }
// }
// String Buffer:
// class Demo {
// public static void main(String a[]) {
// StringBuffer sb = new StringBuffer("Deepak");
// sb.append(" Kumaar");
// System.out.println(sb);
// String MyNewStr = sb.toString();
// sb.deleteCharAt(3);
// sb.insert(4, " none ");
// System.out.println(sb);
// }
// }
// Static key example: inside the class
// class Mobile {
// String company;
// int Price; // when you give static word, then this price is common for all the obejects which you have creatred, change at one place it will effect every where.
// static String model;
// public void show() {
// System.out.println(company + " : " + Price + " : " + model);
// }
// }
// public class Demo {
// public static void main(String[] args) {
// Mobile MyMobile = new Mobile();
// MyMobile.company = "Apple";
// MyMobile.Price = 3000;
// Mobile.model = "iphone 13";
// Mobile MyMobileTwo = new Mobile();
// MyMobileTwo.company = "Samsung";
// MyMobileTwo.Price = 4000;
// Mobile.model = "S25 Plus";
// // MyMobileTwo.Price = 1500;
// MyMobile.show();
// MyMobileTwo.show();
// }
// }
// Static example inside the Method:
// class Mobile {
// String brand;
// int price;
// static String name;
// public void show() {
// System.out.println(brand + " : " + price + " : " + name);
// }
// public static void showTwo(Mobile myMobile) {
// System.out.println(myMobile.brand + " : " + myMobile.price + " : " + name + " from static method");
// }
// }
// class Demo {
// public static void main(String a[]) {
// System.out.println("something");
// Mobile MyMpbileOne = new Mobile();
// MyMpbileOne.brand = "Something";
// MyMpbileOne.price = 1000;
// Mobile.name = "Mobile One";
// Mobile MyMpbileTwo = new Mobile();
// MyMpbileTwo.brand = "Something Two";
// MyMpbileTwo.price = 2000;
// Mobile.name = "Mobile One two";
// MyMpbileTwo.show();
// MyMpbileOne.show();
// Mobile.showTwo(MyMpbileTwo);
// }
// }
// staci block in java:
// class Mobile {
// String brand;
// static String name;
// int price;
// static {
// name = "";
// System.out.println("inside the staatci");
// }
// public Mobile() {
// brand = "";
// name = "My name";
// System.out.println("Inside the constructor");
// }
// }
// public class Demo {
// public static void main(String a[]) throws ClassNotFoundException {
// // If we are not going to define the any object but still want to get the static data:
// Class.forName("Mobile");
// // Mobile myMobile = new Mobile();
// // Mobile myMobile2 = new Mobile();
// }
// }
// Encapsulation In Java:
// when you defined the valriable as private, it can not be accessed the outside of its class;
// class Human {
// // private int age = 101;
// // private String name = "Myname is somthing";
// private int age;
// private String name;
// public String getMyname() {
// return name;
// }
// public int getMyage() {
// return age;
// }
// public void setAge(int a) {
// age = a;
// }
// public void setName(String a) {
// name = a;
// }
// }
// public class Demo {
// public static void main(String[] args) {
// Human MyHuman = new Human();
// MyHuman.setAge(25);
// MyHuman.setName("This is something i wanna try");
// System.out.println(MyHuman.getMyage() + " : " + MyHuman.getMyname());
// }
// }
// This keyword in JAVA:
// This is the key word which represent the current object;the object which is calling the method
// class Human {
// private String name;
// private int age;
// public int getAge() {
// return age;
// }
// public String getName() {
// return name;
// }
// public void setAge(int age) {
// this.age = age;
// // here this key represents the currrent object, which means the object which is calling the method;
// }
// public void setName(String name) {
// this.name = name;
// }
// }
//whenever if we want to give the both parameters and instatnce variable name same, then it will not work, like
// public void setAge(int age) {
// age = age;
// }
// public class Demo {
// public static void main(String a[]) {
// Human NewHuman = new Human();
// NewHuman.setAge(66);
// NewHuman.setName("Ramesh");
// System.out.println(NewHuman.getName() + " : " + NewHuman.getAge());
// }
// }
// Constructor:
// This keyword in JAVA:
// This is the key word which represent the current object;the object which is calling the method
// class Human {
// private String name;
// private int age;
// Constructor is a special method, it has a same name as class name. the constructor never returns anything,
// this runs even before the object gets created and run; same as useeffect in reacr js
// Evert time we create the object it gets called, no need to call specifically.
// and you can give default values to the instance variables;
// public Human() {
// System.out.println("Inside the constructor");
// name = "Mustaq";
// age = 19;
// }
// public int getAge() {
// return age;
// }
// public String getName() {
// return name;
// }
// public void setAge(int age) {
// this.age = age;
// }
// public void setName(String name) {
// this.name = name;
// }
// }
// public class Demo {
// public static void main(String a[]) {
// Human NewHuman = new Human();
// System.out.println(NewHuman.getName() + " : " + NewHuman.getAge());
// Human NewHuman3 = new Human();
// NewHuman.setAge(66);
// NewHuman.setName("Ramesh");
// System.out.println(NewHuman.getName() + " : " + NewHuman.getAge());
// }
// }
// Parameterized Constructor:
// class Human {
// private String name;
// private int age;
// public Human() { // Default Constructor
// // System.out.println("Inside the constructor");/
// name = "Mustaq";
// age = 19;
// }
// public Human(int age, String name) { // Parameterized constructor, cause we are passing the parameters
// this.name = name;
// this.age = age;
// }
// public int getAge() {
// return age;
// }
// public String getName() {
// return name;
// }
// public void setAge(int age) {
// this.age = age;
// }
// public void setName(String name) {
// this.name = name;
// }
// }
// public class Demo {
// public static void main(String a[]) {
// Human NewHuman = new Human();
// Human NewHuman2 = new Human(21, "mahesha");
// // System.out.println(NewHuman.getName() + " : " + NewHuman.getAge());
// // NewHuman.setAge(66);
// // NewHuman.setName("Ramesh");
// System.out.println(NewHuman.getName() + " : " + NewHuman.getAge());
// System.out.println(NewHuman2.getName() + " : " + NewHuman2.getAge());
// }
// }
// Inherentance example:
// public class Demo {
// public static void main(String a[]) {
// SuperCalc calv1 = new SuperCalc();
// int addre = calv1.add(10, 22);
// int subbre = calv1.subb(20, 2);
// int MultiResult = calv1.multiply(10, 5);
// int DivideResult = calv1.devide(12, 5);
// double PowerResult = calv1.power(4, 3);
// System.out.println(addre + " : addre " + subbre + " : subbre " + MultiResult + " MultiResult " + DivideResult + " DivideResult " + PowerResult + " PowerResult");
// }
// }
// super Example:
// class A {
// public A() {
// super();
// System.out.println("inside the A");
// }
// public A(int N) {
// super();
// System.out.println("inside the int parameter A");
// }
// }
// class B extends A {
// public B() {
// super();
// System.out.println("inside the B");
// }
// // public B(int N) {
// // super(N);
// // System.out.println("Inside the int parameter B");
// // }
// // This is to call both the constructors of class B and one default constructor of class A
// public B(int N) {
// this();
// System.out.println("Inside the int parameter B");
// }
// }
// // Super Method:
// public class Demo {
// public static void main(String[] args) {
// B obj = new B(5);
// }
// }
// Methos OverRiding:
// class A {
// public void show() {
// System.out.println("Inside the show");
// }
// public void Something() {
// System.out.println("Just something inside the class A");
// }
// }
// class B extends A {
// public void show2() {
// System.out.println("Inside the B show");
// }
// public void show() {
// System.out.println("This is to show the method overriding in JAVA");
// }
// }
// public class Demo {
// public static void main(String[] args) {
// B OBJ = new B();
// OBJ.show();
// OBJ.show2();
// OBJ.Something();
// }
// }
// Access MOdifiers:
// import others.*;
// public class Demo {
// public static void main(String[] args) {
// A obj = new A();
// System.out.println(obj.marks);
// }
// }
// Polymorphism:
// There are two types of polyporphism one is compile time morphism and another one is run time morphisim, method overloading will be compile and mehtod over-riding will be run time.
// Dynamic Mehod Dispatch:
// This is also the run time polymorphism
// class A {
// public void show() {
// System.out.println("This is inside the class A");
// }
// };
// class B extends A {
// public void show() {
// System.out.println("This is inside the class B");
// }
// };
// class C extends A {
// public void show() {
// System.out.println("This is inside the class C");
// }
// };
// public class Demo {
// public static void main(String[] args) {
// A obj = new A();
// obj.show();
// obj = new B();
// obj.show();
// obj = new C();
// obj.show();
// }
// }
// Final Keyword in Java:
// When you give finally word to the any class then it will not be extended to any other classes;
// we are just stopping the inheritence:
// final class Calc {
// class Calc {
// // public final void show() { // if you give the final word to the your method no can override your method:s
// public void show() {
// System.out.println("This is just the show inside calc");
// }
// public int add(int n1, int n2) {
// return n1 + n2;
// }
// }
// class C extends Calc {
// public void show() {
// System.out.println("THis is inside the C");
// }
// }
// public class Demo {
// public static void main(String[] args) {
// final int num = 7; // Finally is like const in javascript;
// C MyCalc = new C();
// int resutl = MyCalc.add(10, 55);
// System.out.println(resutl + " : " + "the add result");
// MyCalc.show();
// }
// }
// The UpCastiomg and DownCasting:
// class Calc {
// public void show() {
// System.out.println("This is just the show inside calc");
// }
// }
// class C extends Calc {
// public void show2() {
// System.out.println("THis is inside the C");
// }
// }
// public class Demo {
// public static void main(String[] args) {
// Calc MyCalc = new C();
// MyCalc.show();
// C obj = (C) MyCalc;
// obj.show2();
// }
// }
// Inner Class:
// class A {
// int a;
// public void show() {
// System.out.println("Print This");
// }
// // class B {
// // public void show2() {
// // System.out.println("This is inside the inner class");
// // }
// // }
// static class B {
// public void show2() {
// System.out.println("This is inside the inner class");
// }
// }
// }
// public class Demo {
// public static void main(String[] args) {
// A MyObje = new A();
// MyObje.show();
// // A.B MyObje2 = MyObje.new B();
// // MyObje2.show2();
// // This works only when the class B is with static word:
// A.B MyObje2 = new A.B();
// MyObje2.show2();
// }
// }
// Anonymus Inner Class:
// class A {
// public void show() {
// System.out.println("inside the show");
// }
// }
// public class Demo {
// public static void main(String[] args) {
// A MyObj = new A() {
// public void show() {
// System.out.println("Inside the inner class");
// }
// };
// MyObj.show();
// }
// }
// Abstract and Inner class:
// abstract class A {
// public void show() {
// System.out.println("This is inside the show");
// }
// }
// class B extends A {
// public void show2() {
// System.out.println("Inside the show two");
// }
// }
// public class Demo {
// public static void main(String[] args) {
// A MyObject = new A() {
// public void show() {
// System.out.println("Inside the abstract inner class");
// }
// };
// MyObject.show();
// }
// }
// Interface :
// interface A {
// int age = 10;
// String Name = "Something";
// void show();
// void show2();
// }
// class B implements A {
// public void show() {
// System.out.println("Inside the show");
// }
// public void show2() {
// System.out.println("Inside show two");
// }
// }
// public class Demo {
// public static void main(String[] args) {
// A MyObj = new B();
// MyObj.show();
// MyObj.show2();
// System.out.println(A.age + " : " + A.Name);
// }
// }
// interface Computer {
// public abstract void code();
// }
// class Laptop implements Computer {
// public void code() {
// System.out.println("Inside the laptop code");
// }
// }
// class Desktop implements Computer {
// public void code() {
// System.out.println("Inside the desktop code");
// }
// }
// class Developer {
// public void devApp(Computer lap) {
// lap.code();
// }
// }
// public class Demo {
// public static void main(String[] args) {
// Computer Lap = new Laptop();
// Computer Desk = new Desktop();
// Developer Dev = new Developer();
// Dev.devApp(Lap);
// }
// }
// enum Status {
// Running, Failed, Pending, Success;
// }
// public class Demo {
// public static void main(String[] args) {
// Status s = Status.Success;
// // System.out.println(s);
// // System.out.println(s.ordinal());
// // Status[] ss = Status.values();
// // for (Status s : ss) {
// // System.out.println(s + " : " + s.ordinal());
// // }
// // if else using enum
// if (s == Status.Failed) {
// System.out.println("Try once again");
// } else if (s == Status.Running) {
// System.out.println("Its all good");
// } else if (s == Status.Pending) {
// System.out.println("Please wait its taking time");
// } else {
// System.out.println("No Need to worry");
// }
// switch (s) {
// case Running:
// System.out.println("Its all good");
// break;
// case Failed:
// System.out.println("Try once again");
// break;
// case Pending:
// System.out.println("Please wait its taking time");
// break;
// default:
// System.out.println("No Need to worry");
// break;
// }
// }
// }
// enum Laptop {
// MacBook(2000), Sony(1500), Lenovo(1200), HP(1800);
// private int price;
// private Laptop(int price) {
// this.price = price;
// }
// public int getPrice() {
// return price;
// }
// public void setPrice() {
// this.price = price;
// }
// }
// public class Demo {
// public static void main(String[] args) {
// for (Laptop lap : Laptop.values()) {
// System.out.println(lap + " : " + lap.getPrice());
// }
// }
// }
// Functional Interface:
// When you want only one method in the ineterface we need to define it as fuctional interface @fuctionalinterface:
// @FunctionalInterface
// interface A {
// void show();
// }
// public class Demo {
// public static void main(String[] args) {
// A obj = new A() {
// public void show() {
// System.out.println("Printing inside the anonymus class");
// }
// };
// obj.show();
// }
// }
// functional interface with labda expression:
// interface A {
// void show(int a);
// }
// public class Demo {
// public static void main(String[] args) {
// // Here in lambda expresstion the "new A() { public void show() {" is replaced with a arrow, "->", which interm does the same work as the removed code,
// // Here the method of reducing the code is called syntactical sugar;
// A obj = i -> System.out.println("Printing inside the anonymus class" + ": " + i);
// obj.show(5);
// }
// }
// Lambda Expression with returns something:
// Lambda is liek a arrow fucntion in Javascript and it works onlt with the functional interface, like in react arrow function works only in functional compnent:
// @FunctionalInterface
// interface A {
// int add(int a, int b);
// }
// public class Demo {
// public static void main(String[] args) {
// A obj = (a, b) -> a + b;
// int result = obj.add(10, 8);
// System.out.println(result + " : " + "the result");
// }
// }
// Typs of interfaces:
// i) Normal Interface.
// ii) Funcational / SAM Interface.
// iii) Marker Interface.
// i) A interface where there are more than one method is there then its called as normal interface:
// ii) SAM(Single Abstract Method):A interface where it has only one mehtod in it, its also called as functional interface.
// iii) Marker Interface : which has no method, (a blank interface);(its created to update the complier)
// THE EXCEPTIONS:
// i) Compile Time erros:
// ii) Run Time Error: Exceprions are basically run time errors. we just try to handle the execptions.
// iii)Logical Errors:
// Try catch in java
// public class Demo {
// public static void main(String[] args) {
// int i = 2;
// int j = 0;
// String name = null;
// int nums[] = new int[5];
// try {
// j = 12 / i;
// // System.out.println(name.length());
// System.out.println(nums[2]);
// System.out.println(nums[5]);
// } catch (ArithmeticException e) {
// System.err.println("Can not devide witn zero");
// } catch (ArrayIndexOutOfBoundsException e) {
// System.out.println("Not able to find the given index value");
// } catch (Exception e) {
// System.out.println("Something went wrong : " + e);
// }
// System.out.println("The Result" + " : " + j);
// }
// }
// The Throw:
// public class Demo {
// public static void main(String[] args) {
// int i = 32;
// int j = 0;
// try {
// j = 12 / i;
// if (j == 0) {
// throw new ArithmeticException("The value is zero");
// }
// } catch (ArithmeticException e) {
// j = 18 / 1;
// System.err.println("This is the default value " + e);
// } catch (Exception e) {
// System.out.println("Something went wrong : " + e);
// }
// System.out.println("The Result" + " : " + j);
// }
// }
// Custom Exception throw
// class MycustomExecptions extends Exception {
// public MycustomExecptions(String string) {
// super(string);
// }
// }
// public class Demo {
// public static void main(String[] args) {
// int i = 32;
// int j = 0;
// try {
// j = 12 / i;
// if (j == 0) {
// throw new MycustomExecptions("The value is zero my custom exception ");
// }
// } catch (MycustomExecptions e) {
// j = 18 / 1;
// System.err.println("This is the default value " + e);
// } catch (Exception e) {
// System.out.println("Something went wrong : " + e);
// }
// System.out.println("The Result" + " : " + j);
// }
// }
// Thorows Examples:
// class A {
// public void show() throws ClassNotFoundException {
// Class.forName("Something");
// }
// }
// public class Demo {
// static {
// System.out.println("Class Is Loaded");
// }
// public static void main(String[] args) {
// A obj = new A();
// try {
// obj.show();
// } catch (ClassNotFoundException ex) {
// ex.printStackTrace();
// }
// }
// }
// public class Demo {
// public static void main(String[] args) throws IOException {
// System.out.println("Print Something");
// // int num = System.in.read();
// // InputStreamReader IN = new InputStreamReader(System.in);
// // BufferedReader bf = new BufferedReader(IN);
// // int Num = Integer.parseInt(bf.readLine());
// // System.out.println(Num);
// Scanner MyScanner = new Scanner(System.in);
// int Num = MyScanner.nextInt();
// System.out.println(Num);
// }
// }
// public class Demo {
// public static void main(String[] args) throws IOException {
// int num = 0;
// try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
// System.out.println("Enter a number");
// num = Integer.parseInt(br.readLine());
// System.out.println(num);
// }
// }
// }
// class A extends Thread {
// public void run() {
// for (int i = 1; i <= 100; i++) {
// System.out.println("Hi");
// }
// }
// }
// class B extends Thread {
// public void run() {
// for (int i = 1; i <= 100; i++) {
// System.out.println("Bye");
// }
// }
// }
// public class Demo {
// public static void main(String a[]) {
// A obj1 = new A();
// B obj2 = new B();
// obj1.start();
// obj2.start();
// }
// }
// Setting the priority for the thread:
// The set priority only suggest the scheduler to run the threads on priority, only sugest:
// class A extends Thread {
// public void run() {
// for (int i = 1; i <= 100; i++) {
// System.out.println("Hi");
// try {
// Thread.sleep(10); // Here you are asking to wait the thread for a some time'
// } catch (InterruptedException ex) {
// ex.printStackTrace();
// }
// }
// }
// }
// class B extends Thread {
// public void run() {
// for (int i = 1; i <= 100; i++) {