This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.codinko; | |
import java.util.ArrayList; | |
import java.util.Iterator; | |
import java.util.List; | |
public class ConcurrentModificationExceptionDemo { | |
public static void main(String[] args) { | |
new ConcurrentModificationExceptionDemo().method1(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.codinko; | |
public class GenericClassT<T> { | |
private T t; | |
public T get() { | |
return this.t; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.codinko.generics; | |
public class GenericClass<T> { | |
private T t; | |
public T get() { | |
return this.t; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Pass By Value | |
In Java, all parameters are passed by value, i.e. assigning a method argument is not visible to the caller. | |
*/ | |
Example 1: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.codinko.example; | |
/** | |
* | |
* Feel free to play around with this code to try various topics covered under Threads & Locks: | |
* | |
* Theory reference: https://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html | |
* | |
*/ | |
public class ThreadWaitDemo { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Aim: Set does not allow duplicates. So if you have a hashset of employee | |
* objects with same name and id, then will the Set allow them to be added? | |
* | |
* So: Set does not allow duplicates with the help of hashcode() and equals() method | |
* Basically when you add an element to Set, it checks if the element is already present. | |
* | |
* If you use HashSet, this checking is done like this: | |
* It internally make use of hashcode() and equals() to find out. | |
The add() method of HashSet - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Output WITHOUT Join [although the mix sequence could vary but inconsistent] | |
Thread 1 arrived... | |
Thread 2 arrived... | |
Thread 1 working on 1... | |
Thread 2 working on 1... | |
Thread 1 working on 2... | |
Thread 2 working on 2... | |
Thread 2 working on 3... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.codinko.sample; | |
import java.util.HashMap; | |
import java.util.Map.Entry; | |
import java.util.TreeMap; | |
public class CompareTreeMapHashMap { | |
public static void main(String[] args) { | |
Employee emp1 = new Employee("Harley", 100); | |
Employee emp2 = new Employee("Peter", 100); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.codinko.sample; | |
public class Employee { | |
String name; | |
Employee(String name) { | |
this.name = name; | |
} | |
@Override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script> | |
function clickCounter() { | |
if(typeof(Storage) !== "undefined") { | |
if (sessionStorage.clickcount) { | |
sessionStorage.clickcount = Number(sessionStorage.clickcount)+1; | |
} else { | |
sessionStorage.clickcount = 1; |
OlderNewer