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
<!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; |
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
// Get all notes by userId | |
java.util.Optional; | |
java.util.Optional.map() | |
java.util.Optional class | |
// A container object which may or may not contain a non-null value. | |
// If a value is present, {@code isPresent()} will return {@code true} and | |
// {@code get()} will return the value. | |
// Approach-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
// How to get a Note from noteId and userId | |
private Note findNote(int noteId, List<Note> notes) { | |
return notes.stream() | |
.filter(note -> note.getNoteId() == noteId) | |
.findAny() | |
.orElse(null); | |
} | |
// Approach-1 |