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
class CustomerFactory | |
{ | |
public static ICustomer GetCustomer(int i) | |
{ | |
switch (i) | |
{ | |
case 1: | |
GoldCustomer goldCustomer = new GoldCustomer(); | |
goldCustomer.GoldOperation(); | |
goldCustomer.AddPoints(); |
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
public enum CarType { | |
SMALL, LUXURY | |
} | |
public Interface class Car { // abstract class or Interface. | |
} | |
public class CarFactory { | |
public static Car buildCar(CarType model) { | |
Car car = null; |
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
public abstract class MazeGame { | |
public MazeGame() { | |
Room room1 = makeRoom(); | |
Room room2 = makeRoom(); | |
room1.connect(room2); | |
this.addRoom(room1); | |
this.addRoom(room2); | |
} | |
abstract protected Room makeRoom(); |
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
//GuiFactory example | |
//Abstract Product | |
interface Button { | |
void paint(); | |
} | |
//Abstract Product | |
interface Label { | |
void paint(); | |
} |
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
public static void printMap(Map map) { | |
Iterator iterator = map.entrySet().iterator(); | |
while (iterator.hasNext()) { | |
Map.Entry entry = (Map.Entry)iterator.next(); | |
System.out.println(entry.getKey() + " = " + entry.getValue()); | |
} | |
} | |
//or |
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
//The first two ways are using iterator() method of the Collection Interface | |
Iterator<String> iterator = list.iterator(); | |
while (iterator.hasNext()) { | |
System.out.println(iterator.next()); | |
} | |
//or | |
for(Iterator<String> iterator=list.iterator();iterator.hasNext(); ) | |
{ | |
System.out.println(iterator.next()); | |
} |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<beans xmlns="http://www.springframework.org/schema/beans" | |
xmlns:xsi=<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a> | |
xsi:schemaLocation="http://www.springframework.org/schema/beans | |
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> | |
<!-- <bean/> definitions here --> | |
</beans> | |
</xml> |
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.cache</groupId> | |
<artifactId>caching</artifactId> | |
<version>0.0.1-SNAPSHOT</version> | |
<properties> | |
<ehcache.version>2.4.2</ehcache.version> |