-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunning Notes.txt
More file actions
2663 lines (2014 loc) · 61.4 KB
/
Running Notes.txt
File metadata and controls
2663 lines (2014 loc) · 61.4 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
Date : 12.08.2022
=================
Steps to prepare First Application
==================================
Step 1: Install any version of Java Software.(Recommended JDK 1.8)
Step 2: Create a folder in any drive with any name.
Step 3: Open Notepad or Notepadd++ or Editplus and type the Java program.
[Dont use any IDE's]
Step 4: Save the Java program with any name if and only if
the application doesn't contain any public class.
[Recommended approach is to take the class name where we kept
main method]
Ex:
class Test{
public static void main(String[] args){
System.out.println("Hello World!!");
}
}
Save it as Demo.java.
Step 5: Compile the Java Code.
A. Open The command prompt.
Open Search Box -> Type CMD --> Right Click Pin to Taksbar
Change the default location to ur current working
directory where u saved ur java application.
C:\Users\sarka>E:
--------------
default working directory
E:\>cd eceworkspace
E:\eceworkspace>javac Test.java
E:\eceworkspace>
Step 6: Run the application
E:\eceworkspace>java Test
Hello World!!
Compile and Run of a java application having pacakage statement:
----------------------------------------------------------------
Compile :javac -d . Test.java
Run :java com.wipro.test.Test
Test Case of Hello World Program
=================================
Tes Case Compile Time error Run Time error
======== ================= ==============
1. Remove ; error: ';' expected NA
2. Remove Ending " unclosed string literal NA
3. Remove beginning " unclosed string literal NA
4. system.out.println error: package system does not exist NA
5. String[] args No Error NA
See Paint Document for remaing test case.
In Java we haave two contexts.
1. static context
2. non-static context
-> 'static' is a non-access modifier.
-> 'static' modoifier is applicable for variables, methods,bloks and
in import statements.
Static method:
-> The method which is declared with 'static' modifier is known as
'static' method.
-> If we declare a method as static we can call the method from anywhere[either from static context or from non static context.]
Q> Why main method is public ?
Ans.The main intention to declare main() method as public is to make available main() method to JVM in order to access from anywhere.
Note: In Java application, if we declare main() method without public then compiler will not give any error, because compiler will treat main() method as normal Java method but JVM will provide the following.
JAVA8 Onwards all versions:
JAVA 8: Error: Main method not found in class Test, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
Q> Why main method is static?
The keyword static declares the method as that belong to the entire class not a part of any object of a class. Without existing object JVM has to call this method, that’s why it should be static.
Date: 19.08.2022
================
Based on the value represented by a variable we have two different types:
1. primitive variable : It is used to represent primitive value.
2. reference variable : It is used to refer objects.
========
Based on position of declartion and behavior all variables are callssified into
three types.
1. non-static(instance) variable
2. static variable
3. local variable
static variable:
================
Q> When should we go for static variables?
-> If the value of the variable doesn't change with respect to obejct to object
such type of variables are called static variable.
Ex: cname is a static variabale with respect to a particular college.
Q> For Static variables how many copies will be created?
-> For static variables only one copy of that variable will be created irrespective of the number of objects.
static variable will be considered as shared variable.
Q> Where static varibale will be stored ?
-> Static variable will be stored in Method area of JVM memory.
Q> What is the default value for static variable?
-> For sttaic variable default value will be provided by JVM based on their type.
Q> Where static variables are decalred ?
-> 'static' variable are declared inside the class directly but non inside any method .
Q> When static variable is created ?
->'static' variable are created at the time of class loading.
Hence the lifee of static variable is as long as the lide of a class.
Q>What is class loading? How class can be laoded ?
Ans. Brininging class from hard disk to JVM memory of RAM is called class loading.
Class Loader brings the .class file from hard disk to JVM memory of RAM.
Approach #1: At the time of running the java applciation
Ex: java Test
Approach #2:
class Test{
/*static method*/
public static void main(String[] args){
System.out.println(Student.cname);
}
}
class Student{
/*static varibale*/
static String cname;
}
In the above example when we run the application by
writing java Test
as a part of Test.class execution in the System.out.println(Student.cname)
Student class also will be loaded.
->'static' variables are also called as class level variables.
-> 'static' variables are decalred with 'static' modifier.
Q> How to access staic variable ?
-> We can access static variable in 3 different ways.
App #1 By using class name.
class Student{
/*static varibale*/
static String cname;
}
class Test{
/*static method*/
public static void main(String[] args){
/*Accessing static variable by using class name*/
System.out.println(Student.cname);
}
}
App #2 Within the same class we can drop the class name.
class Test{
static int x;
/*static method*/
public static void main(String[] args){
/*Accessing static variable without using class name*/
System.out.println(x);
}
}
App #3: Will be discussed after learning new keyword.
non-static:
==========
Q.When should i go for non-static varibale?
1.If the value of the variable is varied from object ot object
such type of variables are called non-static variables or instance
variables.
Ex: String sname,int roll;
2.The no of copies that will be cretaed for non-static variable
is equal to the number of objects.
3. The non-static variables are stored in heap memory
of jvm memory as a part of the object.
4. The default value for non-stattic variable is provided by
JVM based on the type of the variable.
5. The non-static variables are created at the time of object creation.
Hence the life time of non-static variable is upto the life time of object
6. The non-static variables are called as object level variables or instance variable.
7. How to access non-static variable from static area ?
-> non-static variable can't be access directly from static context.
Ex:
class Student{
/*non-static variable*/
String name;
int roll;
public static void main(String[] args){
System.out.println(name);
System.out.println(roll);
}
}
Test.java:6: error: non-static variable name cannot be referenced from a static context
System.out.println(name);
^
Test.java:7: error: non-static variable roll cannot be referenced from a static context
System.out.println(roll);
^
2 errors
-> To access non-static variable from static context directly we need to create object first
and then using reference variable we can access.
class Student{
/*non-static variable*/
String name;
int roll;
public static void main(String[] args){
/*Approach #1 : Create Object(Nsmmed Object) */
Student student = new Student();
System.out.println(student.name);
System.out.println(student.roll);
}
}
Q> How to create object?
Ans. There are multiple ways to create object.
Approach #1:
------------
By using new keyword/ new operator.
Q>What is the syntax of object creation ?
Ans. Class_Name reference_variable_name = new Class_Name();
Ex: Test t = new Test();
Note: Class_Name() will be read as Constructor.
Responsibility of new keyword:
-------------------------------
1. new keyword first creates the object.
2. After that new keyword will return(giving) the reference value of the created object.
local variable:
---------------
Q> What is called local variable ?
Ans. For temporary requirement of the programmer we can declare a variable inside a method or a loop or block or constructor.Such variables are called as local variable or automatic variable or temporary variable or stack variable.
Q> When should we go for local variable ?
-> If we use any variable for temporary purpose that variabe is called local variable.
-> For local variable before using initializing is compulsory.
Ex#1:
class Test{
public static void main(String[] args){
int i;
System.out.println("i:"+i);
}
}
Test.java:4: error: variable i might not have been initialized
System.out.println("i:"+i);
^
1 error
In the above program before using as the local variable is not initialized hence the reason of
Compilation error.
Ex#2:
class Test{
public static void main(String[] args){
int i;
System.out.println("Hello");
}
}
O.P: Hello
In the above program as i is not used thats why even the local variable is not initialized there is no error.
-> Local variables will be stored inside the stack area.
-> Local variables will be created at the time of block execution in the block where it is declared and the variable will be destroyed once the block execution is over.
class Test{
public static void main(String[] args){
/*local variable to main method*/
int i=0;
for(int j=0;j<5;j++){ /*local variable to for loop*/
i=i+j;
}
System.out.println(i+" : "+j);
}
}
Test.java:8: error: cannot find symbol
System.out.println(i+" : "+j);
^
symbol: variable j
location: class Test
1 error
-> It is not recommended to initialize local variable inside any logical block. Becasue for logical block execution will take place or not that guarantee can't be given.
class Test{
/*static variable*/
static double area;
public static void main(String[] args){
double p,b,h; /*Line #1*/
if(area==0.0){
b=3;
h=4;
p=0.5;
}
area=p*b*h; /*Line#2*/
System.out.println(area);
}
}
E:\tempworkspace>javac Test.java
Test.java:12: error: variable p might not have been initialized
area=p*b*h; /*Line#2*/
^
Test.java:12: error: variable b might not have been initialized
area=p*b*h; /*Line#2*/
^
Test.java:12: error: variable h might not have been initialized
area=p*b*h; /*Line#2*/
^
3 errors
-> For local variable only modifier that is applicable is final.
class Test{
public static void main(String[] args){
//public int x=0;
//private int x=0;
//protected int x=0;
//static int x=0;
final int x=0;
System.out.println(x);
}
}
final Modifier:
---------------
-> 'final' is a non-access modifier.
-> 'final' is applicable at variable level, method level and class level.
final variable:
---------------
-> For final variable reassignment can't be done.
class Test{
public static void main(String[] args){
final int x=0;
System.out.println(x);
x=0+5;
System.out.println(x);
}
}
E:\tempworkspace>javac Test.java
Test.java:9: error: cannot assign a value to final variable x
x=0+5;
final method:
-------------
For final method overring is not possible.
class P{
public void properry(){
System.out.println("Gold+Cash+Land");
}
public final void marry(){
System.out.println("Athma");
}
}
class C extends P{
public void marry(){
System.out.println("Priyanka");
}
}
E:\tempworkspace>javac Test.java
Test.java:10: error: marry() in C cannot override marry() in P
public void marry(){
^
overridden method is final
1 error
final class:
-------------
final class can't be inherited.
final class P{
public void properry(){
System.out.println("Gold+Cash+Land");
}
public void marry(){
System.out.println("Athma");
}
}
class C extends P{
public void marry(){
System.out.println("Priyanka");
}
}
E:\tempworkspace>javac Test.java
Test.java:9: error: cannot inherit from final P
class C extends P{
^
1 error
Q> What is constructor ? Why it is needed ?
===========================================
Constructor is a special method[Because the name of the constructor must be same as name of the class]that is called whenever an object is created by using new operator.
It contains a block of statements that is used to initialize non-static variable of the object.
Constructor is needed to initialize non-static variable of the class.
Default Constructor:
===================
The compiler provided constructor in the absence of
programer defined constructor is called Default Constructor.
class Test{ class Test{
compiler Test(){
---------> super();
} }
}
Q#How to prove Deault Constructor is provided by Compiler ?
Ans.
class Test {
}
1. Save it as Test.java
2. Compile as javac Test.java
3. javap Test
Compiled from "Test.java"
class Test {
Test();
}
No-Param Constructor:
=======================
Programmer defined constructor without parameters is called No-Argument/Non-Parameterized Constructor.
class Test{
Test(){
System.out.println("This is a no-arg constructor");
}
public static void main(String[] args){
Test t=new Test();
}
}
Parameterized Constructor:
==========================
A Constructor which has parameters in it called as Parameterized
Constructor,which is used to assign different values for the different objects.
class Student{
/*non-static variable*/
String name;
int roll;
Student(String name, int roll){
this.nam=name;
this.roll=roll;
}
public static void main(String[] args){
Student s1=new Student("AAA",111); // Ref + local
System.out.println(s1.name);
System.out.println(s1.roll);
Student s2=new Student("BBB",222);
System.out.println(s2.name);
System.out.println(s2.roll);
}
}
Rule of Constructors:
=====================
-> Name of the constructor must be same as the class name.
-> Constructor can't have any return type not even void.
If we provide any return type for the constructor we will
not get any compile time error,because compile will
treat it as a method.
class Test{
void Test(){
System.out.println("Method but not Constructor");
}
public static void Test(String[] args){
Test t=new Test();
t.Test();
}
}
-> The only applicable modifiers for constructor is public,private, protected,<default>(pppd).
If we try to use any other modifer we will get Compile time error.
Q#1. Can the constructor be static ?
Ans.No, the only applicable modifiers for constructor is public,private, protected,<default>(pppd).
If we try to use any other modifer we will get Compile time error.
Test Case #1:
class Demo{
static Demo(){
}
public static void main(String[] args){
Demo d=new Demo();
}
}
E:\testworkspace>javac Test.java
Test.java:2: error: modifier static not allowed here
static Demo(){
^
1 error
Q#2.Can the costructor be final ?
Ans.No, the only applicable modifiers for constructor is public,private, protected,<default>(pppd).
If we try to use any other modifer we will get Compile time error.
class Demo{
final Demo(){
}
public static void main(String[] args){
Demo d=new Demo();
}
}
E:\testworkspace>javac Test.java
Test.java:2: error: modifier final not allowed here
final Demo(){
^
1 error
Concept of this :
================
Q#1. What is "this" ?
-> 'this' is "non-static", "final" reference variable used to refer current class object.
Test Case#1 : To proof "this" is "non-static" variable.
class Test{
/*non-static variable */
int x=10;
public static void main(String[] args){
Test t=new Test();
System.out.println(this.x);
}
}
E:\tempworkspace>javac Test.java
Test.java:9: error: non-static variable this cannot be referenced from a static context
System.out.println(this.x);
^
1 error
Test Case#2 : To proof "this" is "final" variable.
class Test{
/*non-static method*/
public void m1(){
Test t=new Test();
this=t;
}
public static void main(String[] args){
Test t=new Test();
t.m1();
}
}
E:\tempworkspace>javac Test.java
Test.java:6: error: cannot assign a value to final variable this
this=t;
^
1 error
Q#2. What are the different use cases of "this"?
Ans.
Case #1:"this" is used to refer curent object non-static variable.
class Rectangle{
int l,b;
Rectangle(int l, int b){
this.l=l;
this.b=b;
}
int area(){
return l*b;
}
}
class Test{
public static void main(String[] args){
Rectangle r1=new Rectangle(10,20);
System.out.println(r1.area());
}
}
Case #2: "this" can be used to call/invoke current class methods(static and non-static).
class Test{
/*non-static methods*/
public void show(){
System.out.println("Inside show() method");
}
/*static methods*/
public static void display(){
System.out.println("Inside display() method");
}
/*non-static methods*/
public void m1(){
this.show();
System.out.println("Inside m1() method");
this.display();
}
public static void main(String[] args){
Test t=new Test();
t.m1();
}
}
Conclusion:"this" can be used to call static methods but this can't be usued inside static area.
Case #3: "this" can be used as an argument to a method call
class Test{
/*non-static methods*/
public void m1(){
m2(this); //10,10.23,10.23f,'a'
}
public void m2(Test t){//int,double,float,char
System.out.println("m2() method executed");
}
public static void main(String[] args){
Test t=new Test(); // t->Ref + local
t.m1();
}
}
Case #4: "this" can be used to return current class object reference
class Test{
/*non-static methods*/
public Test m1(){
System.out.println("m1() method called");
return this;
}
public void m2(){
System.out.println("m2() method called");
}
public static void main(String[] args){
/*Test t=new Test();
Test t1=t.m1();
t1.m2();*/
new Test().m1().m2();
}
}
Case #5: "this" can be used as an argument to a constructor call
class Student{
Student(Test t){
System.out.println("Str:"+t.str);
}
}
class Test{
/*non-static variable*/
String str; //str=null;
Test(String str){ // str is local here
new Student(this);
}
public static void main(String[] args){
Test t=new Test("ECE");
}
}
Case #6: We can use this()[this constructor]to call current class constructor.
class Test{
Test(){
this(10);
System.out.println("Test class no-arg constructor");
}
Test(int i){
System.out.println("Test class one-arg constructor");
}
public static void main(String[] args){
Test t=new Test();
}
}
Q> Inside a constructor can we have this() and super() constructor both?
Ans. No,Inside a constructor if we dont provide anything by default it will be super() constructor.
Q> Can we have recursive method call ?
Ans. Yes, but if we dont handle recursive method call perfectly it will lead to
StackOverFlowError.
Q>Can we have Recursive Constructor call?
Ans. Nooo...Recursive Constructor call is a compilation issue.
Q#3. If the class is public then what is the access modifer for the default constructor?
Ans. public.
Q#4. Can a public class have non-public constructor or vice versa.
Ans. Yes,if the class is having no-arg or parameterzed constructor then we can have this option.
Case #1:
public class Test{
Test(){
}
}
Case #2:
class Test{
public Test(){
}
}
Both Case#1 and Case#2 will compile and run successfully.
Constructor Overloading:
-------------------------
Inside a Java class if we are having more than one constructor which differs either in number of arguments,
types of arguments or sequence or order of arguments is the concept of Constructor Overlaoding.
Case #1: Differs in number of arguments
class Rectangle{
int length,breadth;
Rectangle(int i){
length=i;
breadth=i;
}
Rectangle(int length,int breadth){
this.length=length;
this.breadth=breadth;
}
int area(){
return length*breadth;
}
}
class Test{
public static void main(String[] args){
Rectangle r1=new Rectangle(5);
System.out.println("Area of the Rectangle is :"+r1.area());
Rectangle r2=new Rectangle(7,8);
System.out.println("Area of the Rectangle is :"+r2.area());
}
}
Case #2: Differs in types of arguments
class Test{
int i;
double d;
Test(int i){
this.i=i;
}
Test(double d){
this.d=d;
}
}
Case #3: Differs in order/sequence of arguments
class Test{
int i;
double d;
Test(int i,double d){
this.i=i;
this.d=d;
}
Test(double d,int i){
this.i=i;
this.d=d;
}
}
3 pillers of oops:
-----------------
1. Encapsualtion : Class, Package --> Security
2. Inheritance : extends --> Reusability
3. Polymorphism : --> Flexibility
Why Inhertince:
===============
Without Inheritance:
====================
class BsnlSim{
// 300 methods
}
class AirtelSim{
//300 methods
}
class JioSim{
//300 methods
}
900 methods ------> 90 hours
1. Code Redundancy i.e. duplicate code.
2. Length of the code is incresing like anythng.
3. Readability is getting down.
===================================================
Let us assume 250 methods are common in every class
With Inheritance:
==================
class Sim{
//250 common methods
}
class BsnlSim extends Sim{
//50 Specific methods
}
class AirtelSim extends Sim{
//50 specific methods
}
class JioSim extends Sim{
//50 specif methods
}
400 methods ------> 40 hours
1. Code Redundancy is removed
2. Length of the code is reduced.
3. Readablity is improved.
Inheritance:
------------
-> It is one of the main cornerstone of OOPs.
-> We will use "extends" to achieve Inheritance."extends" means increasing functionality.
-> Inheriance provides "Reusability".
-> Inheritance is a mechanism in Java in which one class inherits the features of another class and can
add its own features.
-> The class which does inheriting is called as child class/sub class/ derived class.
-> The class from which we inherit is called parent class/super class/ Base class.
-> Inheriatnce can be considered as "IS-A" realtionship.
-> By using "extends"" keyword we achieve "IS-A" realtionship.
Ex#1:
class P{
/*non-static variable*/
int x;
/*static variable*/
static int y;
/*non-static method*/
public void m1(){
System.out.println("P class m1() method");
}
/*static method*/
public static void m2(){
System.out.println("P class m2() method");
}
}
class C extends P{
/*non-static variable*/
int x1;
/*static variable*/
static int y1;
/*non-static method*/
public void m3(){
System.out.println("C class m3() method");
}
/*static method*/
public static void m4(){
System.out.println("C class m4() method");
}
}
/*Driver class/Main class*/
class Test{
public static void main(String[] args){
C c=new C();
c.m1();
c.m2();
c.m3();
c.m4();
System.out.println(c.x);
System.out.println(C.y);
System.out.println(c.x1);
System.out.println(C.y1);
}
}
Note: In Java there is "Object" class which is considered parent class of all classes until it is having any explicit parent class.
E:\tempworkspace>javap java.lang.Object
Compiled from "Object.java"
public class java.lang.Object {
public java.lang.Object();
public final native java.lang.Class<?> getClass();
public native int hashCode();
public boolean equals(java.lang.Object);
protected native java.lang.Object clone() throws java.lang.CloneNotSupportedException;
public java.lang.String toString();
public final native void notify();
public final native void notifyAll();
public final void wait() throws java.lang.InterruptedException;
public final native void wait(long) throws java.lang.InterruptedException;
public final void wait(long, int) throws java.lang.InterruptedException;
protected void finalize() throws java.lang.Throwable;
}
Ex#2: