CONTENTS CONTENTS
Contents
1 Introduction 6
2 The Java Programming Language 19
2.1 Overview ...................................... 19
2.2 CompilationandExecution ............................ 21
2.3 ClassesandObjects ................................ 27
2.3.1 ClassesandObjects ............................ 27
2.3.2 InstantiationandConstructors ...................... 32
2.3.3 ClassesandEncapsulation......................... 34
2.3.4 Arrays.................................... 36
2.3.5 GarbageCollectorsvsDestructors .................... 38
2.3.6 ClassFields,ClassMethods........................ 45
2.4 Inheritance ..................................... 51
2.4.1 OverviewandSimpleExample ...................... 52
2.4.2 InheritanceandConstructors ....................... 54
2.4.3 Hiding,Overriding,Overloading... .................... 59
2.5 Polymorphism.................................... 64
2.5.1 Overview .................................. 64
2.5.2 Polymorphism,inheritanceandabstractclasses............. 65
2.5.3 AbstractandFinalClasses ........................ 68
2.5.4 PolymorphismandInterfaces ....................... 73
2.5.5 InterfacesvsMultipleInheritance..................... 76
2.6 InheritanceandEncapsulation .......................... 80
2.6.1 InheritanceandPrivate .......................... 80
2.6.2 EncapsulationandOverriding....................... 81
2.6.3 ProtectedModifier............................. 84
2.7 Exceptions ..................................... 86
2.7.1 AnatomyandLifeCycle.......................... 86
2.7.2 Throwing .................................. 88
2.7.3 Propagation . . . . ............................. 89
2.7.4 Catching .................................. 90
2.7.5 Execution.................................. 92
2.7.6 ObfuscatedExamples ........................... 92
2.8 Conversions..................................... 97
2.8.1 Primitivestypesandconversion/promotions............... 97
2.8.2 ExplicitConversionsandWrappers....................101
2.8.3 ImplicitConversionandOverloading...................102
2.8.4 Conversionofreferencesandinheritance.................103
2.8.5 GenericclassesandConversions .....................105
2.9 Packages.......................................107
2.9.1 PackageandNaming............................108
2.9.2 Publicclasses,Packageclasses ......................111
2.9.3 Public,Private,ProtectedandPackage .................116
2.9.4 Package,EncapsulationandInheritance .................118
3 Threads 122
3.1 Overview ......................................122
3.2 Example.......................................123
3.3 ThreadsAttributes.................................125
3.3.1 TheStatesoftheThreads.........................125
3.3.2 Priorities ..................................126
3.3.3 Threaddaemons ..............................135
3.3.4 GroupsofThreads.............................136
3.4 Multi-ThreadedPrograms.............................138
Laurent Andrey (andrey@loria.fr) 3 IUT de Dijon