|
| 1 | +#Platform |
| 2 | +Java and Platform Independence |
| 3 | +- Build once, Run anywhere |
| 4 | +- Java is one of the most popular platform independent languages. Once we compile a java program and build a jar, we can run the jar (compiled java program) in any Operating System U where a JVM is installed. |
| 5 | +- JVM, ByteCode |
| 6 | +- TODO JavaPlatFormIndependence.png |
| 7 | +- The executable instructions are different in different operating systems. So, there are different JVM s for different operating systems. A JVM for windows is different from a JVM for mac. |
| 8 | +JDK vs JVM VS JRE |
| 9 | +- See jvm-jre-jdk.jpg |
| 10 | +- JVM |
| 11 | + - Virtual machine that run the Java bytecode. |
| 12 | + - Makes java portable. |
| 13 | +- JRE |
| 14 | + - JVM + Libraries + Other Components (to run applets and other java applications) |
| 15 | +- JDK |
| 16 | + - JRE + Compilers + Debuggers |
| 17 | + |
| 18 | +Classloaders and Types |
| 19 | +- TODO JavaClassLoaders.png |
| 20 | +- A Java program is made up of a number of custom classes (written by programmers like us) and core classes (which come preUpackaged with Java). When a program is executed, JVM needs to load the content of all the needed class. JVM uses a ClassLoader to find the classes. |
| 21 | +- System Class Loader U Loads all classes from CLASSPATH |
| 22 | +- Extension Class Loader U Loads all classes from extension directory |
| 23 | +- Bootstrap Class Loader U Loads all the Java core files |
| 24 | +- When JVM needs to find a class, it starts with System Class Loader. If it is not found, it checks with Extension Class Loader. If it not found, it goes to the Bootstrap Class Loader. If a class is still not found, a ClassNotFoundException is thrown. |
| 25 | + |
| 26 | +Why do we need Wrapper Classes? |
| 27 | +- See TODO WrapperExamples.java |
| 28 | +- A wrapper class wraps (encloses) around a data type and gives it an object appearance |
| 29 | +- Wrapper: Boolean,Byte,Character,Double,Float,Integer,Long,Short |
| 30 | +- Primitive: boolean,byte,char ,double, float, int , long,short |
| 31 | +- Reasons |
| 32 | + - null is a possible value |
| 33 | + - use it in a Collection |
| 34 | + - Object like creation from other types.. like String |
| 35 | + |
| 36 | +Are instances of Wrapper Classes Immutable? |
| 37 | +- Wrapper classes are final and immutable. |
| 38 | +- Examples of creating wrapper classes are listed below. |
| 39 | + - Integer number = new Integer(55);//int; |
| 40 | + - Integer number2 = new Integer("55");//String |
| 41 | + - Float number3 = new Float(55.0);//double argument |
| 42 | + - Float number4 = new Float(55.0f);//float argument Float number5 = new Float("55.0f");//String |
| 43 | + - Character c1 = new Character('C');//Only char constructor |
| 44 | + - Boolean b = new Boolean(true); |
| 45 | + |
| 46 | +What is Auto Boxing? |
| 47 | +``` |
| 48 | + // Auto Boxing |
| 49 | + Integer ten = 10;//new Integer(10); |
| 50 | + ten++;// allowed. Java does had work behind the screen for us |
| 51 | +``` |
| 52 | +Boxing and new instances |
| 53 | +Auto Boxing helps in saving memory by reusing already created Wrapper objects. However wrapper classes created using new are not reused. |
| 54 | +``` |
| 55 | + // Two wrapper objects created using new are not same object |
| 56 | + Integer nineA = new Integer(9); |
| 57 | + Integer nineB = new Integer(9); |
| 58 | + System.out.println(nineA == nineB);// false |
| 59 | + System.out.println(nineA.equals(nineB));// true |
| 60 | +
|
| 61 | + // Two wrapper objects created using boxing are same object |
| 62 | + Integer nineC = 9; |
| 63 | + Integer nineD = 9; |
| 64 | + System.out.println(nineC == nineD);// true |
| 65 | + System.out.println(nineC.equals(nineD));// true |
| 66 | +``` |
| 67 | +#Strings |
| 68 | +Immutability of Strings |
| 69 | +``` |
| 70 | + //Strings are immutable |
| 71 | + String str3 = "value1"; |
| 72 | + str3.concat("value2"); |
| 73 | + System.out.println(str3); //value1 |
| 74 | + |
| 75 | + //The result should be assigned to a new reference variable (or same variable) can be reused. |
| 76 | + String concat = str3.concat("value2"); |
| 77 | + System.out.println(concat); //value1value2 |
| 78 | +``` |
| 79 | + |
| 80 | +String vs StringBuffer vs StringBuilder |
| 81 | +- String is Immutable |
| 82 | +- StringBuilder is not synchronized |
| 83 | +- Performance |
| 84 | +- see TODO StringBufferBuilderExamples.java |
| 85 | + |
| 86 | +#OOPS Basics |
| 87 | +Inheritance |
| 88 | +- EveryClassExtendsObject |
| 89 | +- See InheritanceExamples |
| 90 | +- See [Inheritance and Polymorphism](docs/inheritance-and-polymorphism.md) |
| 91 | +- src/main/java/com/in28minutes/java/oops/inheritance/reuse |
| 92 | +Method OverLoading |
| 93 | +- src/main/java/com/in28minutes/java/oops/inheritance/overloading |
| 94 | +Method OverRiding |
| 95 | +- src/main/java/com/in28minutes/java/oops/inheritance/overriding |
| 96 | +Interface |
| 97 | +- [Interfaces](docs/interfaces.md) |
| 98 | +- /src/main/java/com/in28minutes/java/oops/interfaces |
| 99 | +Java and Multiple Inheritance |
| 100 | +Abstract Class |
| 101 | +- [Abstract Class](docs/abstract-class.md) |
| 102 | +Abstract Class vs Interface |
| 103 | +- TODO |
| 104 | +Polymorphism |
| 105 | +- [Polymorphism](docs/inheritance-and-polymorphism.md) |
| 106 | +Abstraction |
| 107 | +Encapsulation |
| 108 | +- See EncapsulationExample.java |
| 109 | +Inner Class |
| 110 | +- See /src/main/java/com/in28minutes/java/innerclass/InnerClassExamples.java |
| 111 | +- See /JavaInterviewGuide/src/main/java/com/in28minutes/java/innerclass/AnonymousClass.java |
| 112 | +Final Modifier |
| 113 | +- See FinalClass.java |
| 114 | +- See FinalMemberModifiersExample.java |
| 115 | +Member Access Modifiers |
| 116 | +- See Package com.in28minutes.java.membermodifiers.access |
| 117 | +Class Access Modifiers |
| 118 | +- See Package com.in28minutes.java.classmodifiers.defaultaccess |
| 119 | +Static Modifier |
| 120 | +- See StaticModifierExamples.java |
| 121 | +Constructors |
| 122 | +- See ConstructorExamples.java |
| 123 | +Static Initializers |
| 124 | +- See InitializerExamples.java |
| 125 | + |
| 126 | +Why do we need Collections? |
| 127 | +- Arrays are static in Size. |
| 128 | +Hierarchy of Collection Interface? |
| 129 | +- CollectionHierarchy.java |
| 130 | +List |
| 131 | +- See CollectionExamples.java for all examples |
| 132 | +Map |
| 133 | +Set |
| 134 | +List vs Map vs Set |
| 135 | +Comparing Objects in Collections |
| 136 | +Collection Keywords : |
| 137 | +Hash - No Order is Maintained |
| 138 | +Tree - Collection is Sorted |
| 139 | +Linked - Insertion Order Maintained |
| 140 | +Set - No Duplicates |
| 141 | +HashSet vs TreeSet vs LinkedHashSet |
| 142 | +TreeMap vs HashMap |
| 143 | + |
| 144 | +Concurrency in Collections |
| 145 | +- Synchronized collections are implemented using synchronized methods and synchronized blocks. Only one thread can executing any of the synchronized code at a given point in time. This places severe restrictions on the concurrency of threads – thereby affecting performance of the application. All the pre Java 5 synchronized collections (HashTable & Vector, for example) use this approach. Post Java 5, collections using new approaches to synchronization are available in Java. These are called concurrent collections. More details below. |
| 146 | +- Copy on Write |
| 147 | + - All values in collection are stored in an internal immutable (not-changeable) array. A new array is created if there is any modification to the collection. |
| 148 | + - Read operations are not synchronized. Only write operations are synchronized. |
| 149 | + - Copy on Write approach is used in scenarios where reads greatly out number write’s on a collection. CopyOnWriteArrayList & CopyOnWriteArraySet are implementations of this approach. Copy on Write collections are typically used in Subject – Observer scenarios, where the observers very rarely change. Most frequent operations would be iterating around the observers and notifying them. |
| 150 | +- Compare and Swap |
| 151 | + - Compare and Swap is one of the new approaches (Java 5) introduced in java to handle synchronization. In traditional approach, a method which modifies a member variable used by multiple threads is completely synchronized – to prevent other threads accessing stale value. |
| 152 | + - In compare and swap approach, instead of synchronizing entire method, the value of the member variable before calculation is cached. After the calculation, the cached value is compared with the current value of member variable. If the value is not modified, the calculated result is stored into the member variable. If another thread has modified the value, then the calculation can be performed again. Or skipped – as the need might be. |
| 153 | + - ConcurrentLinkedQueue uses this approach. |
| 154 | +- Locks |
| 155 | + - When 10 methods are declared as synchronized, only one of them is executed by any of the threads at any point in time. This has severe performance impact. |
| 156 | + - Another new approach introduced in Java 5 is to use lock and unlock methods. Lock and unlock methods are used to divide methods into different blocks and help enhance concurrency. The 10 methods can be divided into different blocks, which can be synchronized based on different variables. |
| 157 | + |
| 158 | +Fail Safe vs Fail Fast |
| 159 | + - Fail Fast Iterators throw a ConcurrentModificationException if there is a modification to the underlying collection is modified. This was the default behavior of the synchronized collections of pre Java 5 age. |
| 160 | + - Fail Safe Iterators do not throw exceptions even when there are changes in the collection. This is the default behavior of the concurrent collections, introduced since Java 5. |
| 161 | + |
| 162 | +Atomic Operations |
| 163 | +- Atomic Access Java Tutorial states “In programming, an atomic action is one that effectively happens all at once. An atomic action cannot stop in the middle: it either happens completely, or it doesn't happen at all. No side effects of an atomic action are visible until the action is complete”. |
| 164 | +- Let’s assume we are writing a multi threaded program. Let’s create an int variable i. Even a small operation, like i++ (increment), is not thread safe. i++ operation involves three steps. |
| 165 | + - Read the value which is currently stored in i |
| 166 | + - Add one to it (atomic operation). |
| 167 | + - Store it in i |
| 168 | +- In a multi-threaded environment, there can be unexpected results. For example, if thread1 is reading the value (step 1) and immediately after thread2 stores the value (step 3). |
| 169 | +- To prevent these, Java provides atomic operations. Atomic operations are performed as a single unit without interference from other threads ensuring data consistency. |
| 170 | +- A good example is AtomicInteger. To increment a value of AtomicInteger, we use the incrementAndGet() method. Java ensures this operation is Atomic. |
| 171 | + |
| 172 | +Why do we use Generics? |
| 173 | +- Generics are used to create Generic Classes and Generic methods which can work with different Types(Classes). |
| 174 | +- See GenericsExamples,GenericsExamples2 and GenericsExamples3 in com.in28minutes.java.generics |
| 175 | +What are the restrictions that can be enforced on Generics? |
| 176 | +- See GenericsExamples,GenericsExamples2 and GenericsExamples3 in com.in28minutes.java.generics |
| 177 | + |
| 178 | +Exception Handling in Java |
| 179 | +- See [Exception Handling](docs/exception-handling.md) |
| 180 | +Finally and when is code in finally not executed? |
| 181 | +New Exception Handling Features |
| 182 | +Puzzles on Exception Handling |
| 183 | +Hierarchy of Exception Related Classes |
| 184 | +When do you use Custom Exception? |
| 185 | +When do you use a Checked Exception? |
| 186 | + |
| 187 | +Need for Threads. |
| 188 | +-- See five examples in com.in28minutes.java.threads |
| 189 | +Different States of a Thread |
| 190 | +Synchronization and Join Methods |
| 191 | +Executor Service |
| 192 | + |
| 193 | +Coupling |
| 194 | +- See [More about OOPS](docs/oops-advanced.md) |
| 195 | +Cohesion |
| 196 | +- [More about OOPS](docs/oops-advanced.md) |
| 197 | +Solid Principles |
| 198 | +Object class |
| 199 | +- see ObjectExamples.java |
| 200 | +toString method |
| 201 | +- See TODO ToStringExamples.java |
| 202 | +hashCode method |
| 203 | +- See TODO EqualsHashCodeExamples.java |
| 204 | +HashCode's are used in hashing to decide which group (or bucket) an object should be placed into. A group of object's might share the same hashcode. |
| 205 | +- See TODO EqualsHashCodeExamples.java |
| 206 | +- The implementation of hash code decides effectiveness of Hashing. A good hashing function evenly distributes object's into different groups (or buckets). |
| 207 | +- A good hashCode method should have the following properties |
| 208 | + - If obj1.equals(obj2) is true, then obj1.hashCode() should be equal to obj2.hashCode() |
| 209 | + - obj.hashCode() should return the same value when run multiple times, if values of obj used in |
| 210 | +equals() have not changed. |
| 211 | + - If obj1.equals(obj2) is false, it is NOT required that obj1.hashCode() is not equal to |
| 212 | +obj2.hashCode(). Two unequal objects MIGHT have the same hashCode. |
| 213 | + |
| 214 | +equals method |
| 215 | +- See TODO EqualsHashCodeExamples.java |
| 216 | +- Any equals implementation should satisfy these properties: |
| 217 | + - Reflexive. For any reference value x, x.equals(x) returns true. |
| 218 | + - Symmetric. For any reference values x and y, x.equals(y) should return true if and only ify.equals(x) returns true. |
| 219 | + - Transitive. For any reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) must return true. |
| 220 | + - Consistent. For any reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, if no information used in equals is modified. |
| 221 | + - For any non-null reference value x, x.equals(null) should return false. |
| 222 | + |
| 223 | +New Features in Java 5 |
| 224 | +New Features in Java 6 |
| 225 | +New Features in Java 7 |
| 226 | +New Features in Java 8 |
| 227 | +Annotations |
| 228 | +Examples of Design Patterns used in Java |
| 229 | +Reflection |
| 230 | +Assert |
| 231 | +Garbage Collection and finalize |
| 232 | +Which datatype should we use for financial calculations? |
| 233 | +What is a Market Interface? |
| 234 | +Need for Serialization |
| 235 | + |
| 236 | +Why do we need an Enum? |
| 237 | +- Refer 3 Files enum\Enum.java, enum\Advanced.java, enum\Advanced2.java |
| 238 | +What are variable arguments? |
| 239 | +Cloning - Deep vs Shallow |
| 240 | +Stream |
| 241 | +Lambda Expressions |
| 242 | + |
| 243 | +What is JavaDoc? |
| 244 | +What is Unit Testing? |
| 245 | +What is Continuous Integration? |
| 246 | +What is Maven? |
| 247 | + |
| 248 | + |
1 | 249 | #Java Topics
|
2 | 250 | - [Abstract Class](docs/abstract-class.md)
|
3 | 251 | - [Arrays](docs/arrays.md)
|
|
12 | 260 | - [Inheritance and Polymorphism](docs/inheritance-and-polymorphism.md)
|
13 | 261 | - [Initializers](docs/initializers.md)
|
14 | 262 | - [Inner Classes](docs/inner-class.md)
|
15 |
| - - [Interfaces](docs/interfaces.md) |
16 | 263 | - [Class Access Modifiers - Default, Public, Private and Protected](docs/modifiers-class-access.md)
|
17 | 264 | - [Member Access Modifiers](docs/modifiers-members-access.md)
|
18 | 265 | - [Final Modifier](docs/modifiers-nonaccess-final.md)
|
|
0 commit comments