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
//This is the class that creates the two “Singleton” instances on the same JVM: | |
import java.lang.reflect.Method; | |
public class ClassLoaderSingletonBreakingTest { | |
public static void main(String[] args) { | |
MyClassLoader cl1 = new MyClassLoader(); | |
Object o1; | |
try { |
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
package com.codinko.oddeven; | |
/* OddEvenThreadType1: One thread prints odd, other thread prints even so o/p will be 0 2 4 6 8 10 1 3 5 7 9 11 | |
*/ | |
public class OddEvenThreadType1 { | |
public static void main(String[] args) { | |
Runnable r1 = new Runnable1(); | |
Runnable r2 = new Runnable2(); | |
Thread t1 = new Thread(r1); | |
Thread t2 = new Thread(r2); |
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 lang="en"> | |
<head> | |
<title>Bootstrap Carousel Multiple Columns Example</title> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script> |
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
String jsonString = Util.readFileFromClassPathAndConvert2String(fileNameInCP); | |
JsonNode root = objectMapper.readTree(jsonString); | |
--------------------- | |
APPROACH-1 | |
--------------------- | |
JsonNode nodes = root.get("companies"); | |
// imp note that you are going to iterate over the node values, not the keys ... | |
Iterator<JsonNode> itr = nodes.iterator(); |
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.json.util; | |
import java.io.BufferedReader; | |
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
public class Util { | |
public static String readFileFromClassPathAndConvert2String(String filenameInCP) { |
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
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.codinko</groupId> | |
<artifactId>mavenprofilesample</artifactId> | |
<version>0.0.1-SNAPSHOT</version> | |
<profiles> |
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.caching; | |
import java.util.List; | |
import org.springframework.context.ApplicationContext; | |
import org.springframework.context.support.ClassPathXmlApplicationContext; | |
public class Main { | |
public static void main(String[] args) { |
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.caching; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Random; | |
import org.springframework.cache.annotation.Cacheable; | |
import org.springframework.stereotype.Component; |
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.caching; | |
public class Employee { | |
private int id; | |
private String name; | |
private String designation; | |
public Employee(int id, String name, String designation) { | |
super(); | |
this.id = id; |