Skip to content

Instantly share code, notes, and snippets.

View karanmalhi's full-sized avatar

Karan Singh Malhi karanmalhi

  • MuleSoft
  • San Francisco
View GitHub Profile
@karanmalhi
karanmalhi / ProxyCreator.java
Created August 17, 2011 17:23
Creating a proxy with JavAssist
package mit.proxy;
import java.lang.reflect.Method;
import java.util.ArrayList;
import javassist.util.proxy.MethodHandler;
import javassist.util.proxy.ProxyFactory;
import javassist.util.proxy.ProxyObject;
public class ProxyCreator {
@karanmalhi
karanmalhi / Test.java
Created July 28, 2011 21:25
Challenge to invoke methods using reflection and annotation processing
package learnquest;
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Field;
import java.util.Date;
@karanmalhi
karanmalhi / Debugger.java
Created July 28, 2011 19:37
ThreadLocal example
import java.util.ArrayList;
import java.util.List;
public class Debugger {
public static void main(String[] args) {
ThreadGroup cleanupThreads = new ThreadGroup("Cleanup group");
Thread t1 = new Thread(cleanupThreads, new Printer());
Thread t2 = new Thread(cleanupThreads, new Printer());
t1.start();
t2.start();
@karanmalhi
karanmalhi / Manager.java
Created July 28, 2011 19:21
Example of countdown latch
import java.io.BufferedReader;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@karanmalhi
karanmalhi / Test.java
Created July 28, 2011 14:54
Template class
package learnquest;
public class Test {
public static void main(String[] args) {
}
}
@karanmalhi
karanmalhi / samples.txt
Created June 24, 2011 18:39
svn repo for spring samples
https://anonsvn.springframework.org/svn/spring-samples
https://github.com/SpringSource
@karanmalhi
karanmalhi / eclipse.ini
Created June 24, 2011 18:36
example eclipse.ini file
-startup
plugins/org.eclipse.equinox.launcher_1.1.1.R36x_v20101122_1400.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.2.R36x_v20101222
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
512m
--launcher.defaultAction
openFile
@karanmalhi
karanmalhi / InnerclassExample.java
Created June 23, 2011 17:38
Anonymous inner class example
package com.lq;
public class InnerClassExample {
public static void main(String[] args) {
Driver d = new Driver();
Car c = new Car();
d.operate(c);
d.operate(
// anonymous Inner class
new Driveable(){
@karanmalhi
karanmalhi / GenericsExample.java
Created June 21, 2011 13:51
Simple example on generics
package com.lq;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
public class GenericsExample {
public static void main(String[] args) {
@karanmalhi
karanmalhi / CreditCardType.java
Created June 20, 2011 15:21
Example of an advanced enum
package com.lq;
public enum CreditCardType {
VISA("111-22-3333") {
@Override
public boolean isValid() {
System.out.println("Validating a " + this.name());
return false;
}