code: private Class parse(String str, ScriptContext ctx) throws ScriptException {		
  		String fileName = getFileName(ctx);
  		String sourcePath = getSourcePath(ctx);
  		String classPath = getClassPath(ctx);
  
  		Map<String, byte[]> classBytes = compiler.compile(fileName, str,
  							ctx.getErrorWriter(), sourcePath, classPath);
  
  		if (classBytes == null) {
  			throw new ScriptException("compilation failed");
  		}
  
  		// create a ClassLoader to load classes from MemoryJavaFileManager
  		MemoryClassLoader loader = new MemoryClassLoader(classBytes, classPath,
  											getParentLoader(ctx));
  
  		String mainClassName = getMainClassName(ctx);
  		if (mainClassName != null) {
  			try {
  				Class clazz = loader.load(mainClassName);
  				Method mainMethod = findMainMethod(clazz);
  				if (mainMethod == null) {
  					throw new ScriptException("no main method in " + mainClassName);
  				}
  				return clazz;
  			} catch (ClassNotFoundException cnfe) {
  				throw new ScriptException(cnfe);
  			}
  		}
  
  		// no main class configured - load all compiled classes
  		Iterable<Class> classes;
  		try {
  			classes = loader.loadAll();
  		} catch (ClassNotFoundException exp) {
  			throw new ScriptException(exp);
  		}
  		
  		// search for class with main method
  		Class c = findMainClass(classes);
  		if (c != null) {
  			return c;
  		} else {
  			// if class with "main" method, then
  			// return first class
  			Iterator<Class> itr = classes.iterator();
  			if (itr.hasNext()) {
  				return itr.next();
  			} else {
  				return null;
  			}
  		} 
  	}
docs: Internals only below this point