snippetjournal

– notes, snippet codes, and my journal

Archive for April 2013

Video Spring Tutorial

leave a comment »

video tutorial Spring :

Spring MVC
Quote:http://extabit.com/file/28ckfw9sr0u2n/2013244161218_72510.rar

Spring Fundamental
Quote:http://extabit.com/file/28xj82ksj383d/

Advertisements

Written by snippetjournal

April 30, 2013 at 2:07 am

local variables inside loop

leave a comment »

Written by snippetjournal

April 18, 2013 at 7:09 am

Posted in Programming

Tagged with ,

Example Basic Reflection In Java

leave a comment »

Apa itu reflection, silahkan baca di link berikut 😀
http://docs.oracle.com/javase/tutorial/reflect/index.html

http://stackoverflow.com/questions/37628/what-is-reflection-and-why-is-it-useful

konsep singkat dari reflection yang saya pahami adalah dengan reflection kita dapat memanggil suatu method pada class lain dan pada package tertentu, sifat reflection adalah dinamis.

Dengan reflection kita dapat membuat suatu method pada class lain dan kemudian memanggil suatu method dengan “less codes”.

Pada reflection parameter yang “dilempar” ketika memanggil suatu method bisa kita kendalikan jenis object nya.

Apa yang saya rasakan ketika memakai reflection adalah susunan class class yang saya pakai menjadi lebih terstruktur. dan kemudahan dalam memanggil method method pada class lain.

berikut ini snippet codes untuk example reflection yang saya buat.

ReflectApp.java


package ASN.Coders.reflection;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ReflectApp{

public static Map callBusinessClass(String packageClassName, String methodName, Object object) throws InstantiationException, IllegalAccessException {
 Class cls;
 Class[] paramPassMap = new Class[1];
 paramPassMap[0] = Map.class;

 Class[] paramPassList = new Class[1];
 paramPassList[0] = List.class;

 Class noparams[] = {};

 try {
 cls = Class.forName(packageClassName);
 Object obj = cls.newInstance();

 if(object != null){
 if(object instanceof Map){
 Method method = cls.getDeclaredMethod(methodName, paramPassMap);
 method.invoke(obj, object);
 }else if(object instanceof List){
 Method method = cls.getDeclaredMethod(methodName, paramPassList);
 method.invoke(obj, object);
 }else{
 System.out.println("Paramater Unknown . . . .");
 }
 }else{
 Method method = cls.getDeclaredMethod(methodName, noparams);
 method.invoke(obj, null);
 }

 } catch (ClassNotFoundException e) {
 e.printStackTrace();
 } catch (SecurityException e) {
 e.printStackTrace();
 } catch (NoSuchMethodException e) {
 e.printStackTrace();
 } catch (IllegalArgumentException e) {
 e.printStackTrace();
 } catch (InvocationTargetException e) {
 e.printStackTrace();
 }

 return null;

 }

}

AppTest.java

package ASN.Coders.reflection;

import java.util.List;
import java.util.Map;

public class AppTest {

private int counter;

public void printIt() {
 System.out.println("printIt() no param");
 }

public void printItString(String temp) {
 System.out.println("printIt() with param String : " + temp);
 }

public void printItInt(int temp) {
 System.out.println("printIt() with param int : " + temp);
 }

public void setCounter(int counter) {
 this.counter = counter;
 System.out.println("setCounter() set counter to : " + counter);
 }

public void printCounter() {
 System.out.println("printCounter() : " + this.counter);
 }

public Map getQuery(Map map) {
 System.out.println("map Contents" + map);
 return map;
 }

public List getQuery(List list) {
 System.out.println("list Contents" + list);
 return list;
 }

 public void getQuery() {
 System.out.println("No Parameter ");
 }
}

ReflectMain.JAVA

package ASN.Coders.reflection;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ReflectMain {

public static void main(String[] args) {

 try{

 Map paramMap = new HashMap();
 paramMap.put("dodol1", "dodol_A");
 paramMap.put("dodol2", "dodol_B");
 paramMap.put("dodol3", "dodol_C");
 paramMap.put("dodol4", "dodol_D");
 paramMap.put("dodol5", "dodol_E");
 paramMap.put("dodol6", "dodol_F");
 paramMap.put("dodol7", "dodol_G");
 paramMap.put("dodol8", "dodol_H");
 paramMap.put("dodol9", "dodol_I");
 paramMap.put("dodol10", "dodol_J");

 List list = new ArrayList();
 list.add("dodol_A");
 list.add( "dodol_B");
 list.add( "dodol_C");
 list.add("dodol_D");
 list.add("dodol_E");
 list.add("dodol_F");
 list.add("dodol_G");
 list.add("dodol_H");
 list.add("dodol_I");
 list.add("dodol_J");

 String string = "";

 paramMap = ReflectApp.callBusinessClass("ASN.Coders.reflection.AppTest", "getQuery", paramMap);
 paramMap = ReflectApp.callBusinessClass("ASN.Coders.reflection.AppTest", "getQuery", list);
 paramMap = ReflectApp.callBusinessClass("ASN.Coders.reflection.AppTest", "getQuery", null);

 }catch(Exception ex){
 ex.printStackTrace();
 }
 }
}

Written by snippetjournal

April 17, 2013 at 6:31 am

Posted in Programming

Tagged with , , , ,

Disable or Uninstall Eclipse Plugins (Helios)

leave a comment »

To disable eclipse plugins : 

Go to window – preferences – General – Startup and Shutdown.

There will be list of installed plugins, if your plugin which you want disable is in the list, simply  uncheck the checkboxes.

But if your plugins is not in the list, you must uninstall it. You can uninstall them all by the next procedure:

Help > About Eclipse SDK > Installation Details > Installed Software Tab > Select a plug-in you want to Uninstall > Click Uninstall button at the bottom

http://stackoverflow.com/questions/4164535/how-to-disable-plugins-in-eclipse-3-6-helios

http://wiki.eclipse.org/FAQ_How_do_I_remove_a_plug-in%3F

Written by snippetjournal

April 17, 2013 at 3:25 am

Java One 2011 Migrating Spring Applications to Java EE 6

with one comment

found great slides in the slideshare, a good material to read 😀

http://www.slideshare.net/ertmanb/javaone-2011-migrating-spring-applications-to-java-ee-6#

 

Written by snippetjournal

April 12, 2013 at 7:32 am

Posted in Programming

Tagged with , , ,