Here you can find the source of newInstance(String className)
public static Object newInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException
//package com.java2s; //License from project: LGPL import java.io.Serializable; import java.lang.reflect.InvocationTargetException; public class Main { public static Object newInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException { Object result = null;//from w w w. j ava 2 s .com Class<?> type = loadClass(className); result = (type != null ? type.newInstance() : null); return result; } public static Object newInstance(Class<?> type) throws ClassNotFoundException, InstantiationException, IllegalAccessException { Object result = null; result = (type != null ? type.newInstance() : null); return result; } public static Object newInstance(Class<?> type, Long param) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { Object result = null; result = (type != null ? type.getConstructor(Long.class).newInstance(param) : null); return result; } public static Object newInstance(String className, Long param) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException { Object result = null; Class<?> type = loadClass(className); result = newInstance(type, param); return result; } public static Object newInstance(Class<?> type, Serializable param) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { Object result = null; result = (type != null ? type.getConstructor(Serializable.class).newInstance(param) : null); return result; } public static Object newInstance(String className, Serializable param) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException { Object result = null; Class<?> type = loadClass(className); result = newInstance(type, param); return result; } public static Class<?> loadClass(String className) throws ClassNotFoundException { Class<?> result = null; if (className != null) { ClassLoader cl = Thread.currentThread().getContextClassLoader(); result = (cl != null ? cl.loadClass(className) : null); } return result; } }