# CreateObject

Creates a new object representation according to the {@code type} and {@code className} arguments.

Available **types** are:

* **class/component** - Creates a new instance of a BoxLang class (Default if not used)
* **java** - Creates a new instance of a Java class
* **webservice** - Creates a SOAP web service client from a WSDL URL
* **{anything}** - Passes the request to the {@code BoxEvent.ON\_CREATEOBJECT\_REQUEST} event for further processing

If the type requested is not supported, then it passes to an interception call to the {@code BoxEvent.ON\_CREATEOBJECT\_REQUEST} event, so any listeners can contribute to the object creation request (if any). If there are no listeners, an exception is thrown.

You can also target an explicit class from a loaded BoxLang module by using the {@code @moduleName} suffix. Example: {@code createObject( 'class', 'class.name.path\@module' )}

The **properties** is an optional argument that can be used to pass to the object creation process according to the type.

* **class/component** - The properties are not used
* **java** - The properties can be a single or an array of absolute path(s) to a directory containing Jars/Classes, or absolute path(s) to specific Jars/Classes to classload
* **webservice** - The properties are not used
* **{anything}** - The properties can be any object that the listener can use to create the object

**IMPORTANT:** For class/component types, this does NOT create an instance of the class. For that you will need to call the {@code init()} method on the returned object. For webservice type, a fully configured SoapClient is returned ready for method invocation.

## Method Signature

```
CreateObject(type=[string], className=[string], properties=[any], externalOnly=[boolean], classloader=[any])
```

### Arguments

| Argument       | Type      | Required | Description                                                                                          | Default |
| -------------- | --------- | -------- | ---------------------------------------------------------------------------------------------------- | ------- |
| `type`         | `string`  | `false`  | The type of object to create: java, class (component), webservice, or any other type                 | `class` |
| `className`    | `string`  | `false`  | For java/class types: a fully qualified class name. For webservice type: the WSDL URL.               |         |
| `properties`   | `any`     | `false`  | Depending on the type, this can be used to pass additional properties to the object creation process |         |
| `externalOnly` | `boolean` | `false`  |                                                                                                      |         |
| `classloader`  | `any`     | `false`  | Optional class loader to use when loading Java classes. Only applicable for type="java".             |         |

## Examples

### Create a BX / Component Instance

createObject Component

```java
<bx:script>
	tellTimeClass = createObject( "component", "appResources.components.tellTime" );
	tellTimeClass.getLocalTime();
</bx:script>

```

### Create a SOAP WebService Instance

createObject WebService

```java
<bx:script>
	ws = createObject( "webservice", "http://www.xmethods.net/sd/2001/TemperatureService.wsdl" );
	xlatstring = ws.getTemp( zipcode="55987" );
	writeOutput( "The temperature at 55987 is " & xlatstring );
</bx:script>
      
```

### Create a java class with specified bundle and version

createObject filesystem

```java
POIFSFileSystem = createObject( "java", "org.apache.poi.poifs.filesystem.POIFSFileSystem", "apache.poi", "3.11.0" );

```

### Additional Examples

[Run Example](https://try.boxlang.io/?code=eJxLKc0t0FDISUxKzbFVci5KTSxJ9U%2FKSk0uUcjMU8hKLEtU0lEoSyyyTUaS0lBQgsqAab3SkswcPY%2FE4gzfxAIlBU0FTWuuFJzGlmeWZADNzizR0CTC6JzEvHS94JKizLx0p9K0tNQioPl6EN0gawDE8j51)

```java
dump( label="CreateObject in java", var=createObject( "java", "java.util.HashMap" ) );
dump( label="CreateObject with init()", var=createObject( "java", "java.lang.StringBuffer" ).init() );

```

```java
dump( var=createObject( "class", "com.my.bx.class" ), expand=false );
// but even "class" is optional for bx
dump( var=createObject( "com.my.bx.class" ), expand=false );
// the modern new Object() syntax is also dynamic
dump( var=new "com.my.bx.class"(), expand=false );
dump( var=new com.my.bx.class(), expand=false );
myClass = "com.my.bx.class";
dump( var=new "#myClass#"(), expand=false );

```

## Related

* [ApplicationRestart](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/applicationrestart)
* [ApplicationStartTime](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/applicationstarttime)
* [ApplicationStop](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/applicationstop)
* [BoxAnnounce](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/boxannounce)
* [BoxAnnounceAsync](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/boxannounceasync)
* [BoxAST](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/boxast)
* [BoxModuleReload](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/boxmodulereload)
* [BoxRegisterInterceptionPoints](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/boxregisterinterceptionpoints)
* [BoxRegisterInterceptor](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/boxregisterinterceptor)
* [BoxRegisterRequestInterceptor](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/boxregisterrequestinterceptor)
* [BoxUnregisterInterceptor](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/boxunregisterinterceptor)
* [BoxUnregisterRequestInterceptor](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/boxunregisterrequestinterceptor)
* [CallStackGet](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/callstackget)
* [CreateGUID](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/createguid)
* [CreateUUID](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/createuuid)
* [DE](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/de)
* [DebugBoxContexts](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/debugboxcontexts)
* [Dump](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/dump)
* [Duplicate](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/duplicate)
* [echo](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/echo)
* [EncodeForHTML](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/encodeforhtml)
* [GetApplicationMetadata](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/getapplicationmetadata)
* [GetBaseTagData](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/getbasetagdata)
* [GetBaseTagList](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/getbasetaglist)
* [GetBaseTemplatePath](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/getbasetemplatepath)
* [GetBoxContext](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/getboxcontext)
* [GetBoxRuntime](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/getboxruntime)
* [GetBoxVersionInfo](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/getboxversioninfo)
* [GetClassMetadata](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/getclassmetadata)
* [GetComponentList](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/getcomponentlist)
* [GetContextRoot](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/getcontextroot)
* [GetCurrentTemplatePath](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/getcurrenttemplatepath)
* [GetFileFromPath](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/getfilefrompath)
* [GetFunctionCalledName](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/getfunctioncalledname)
* [GetFunctionList](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/getfunctionlist)
* [GetModuleInfo](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/getmoduleinfo)
* [GetModuleList](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/getmodulelist)
* [GetRequestClassLoader](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/getrequestclassloader)
* [GetSemver](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/getsemver)
* [GetSystemSetting](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/getsystemsetting)
* [GetTempDirectory](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/gettempdirectory)
* [GetTickCount](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/gettickcount)
* [htmlEditFormat](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/htmleditformat)
* [IIF](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/iif)
* [Invoke](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/invoke)
* [IsInstanceOf](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/isinstanceof)
* [JavaCast](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/javacast)
* [ObjectDeserialize](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/objectdeserialize)
* [ObjectSerialize](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/objectserialize)
* [PagePoolClear](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/pagepoolclear)
* [Print](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/print)
* [Println](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/println)
* [RunThreadInContext](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/runthreadincontext)
* [SessionInvalidate](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/sessioninvalidate)
* [SessionRotate](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/sessionrotate)
* [SessionStartTime](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/sessionstarttime)
* [Sleep](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/sleep)
* [SystemCacheClear](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/systemcacheclear)
* [SystemExecute](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/systemexecute)
* [SystemOutput](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/systemoutput)
* [Throw](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/throw)
* [Trace](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/trace)
* [URLDecode](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/urldecode)
* [URLEncodedFormat](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/urlencodedformat)
* [writeDump](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/writedump)
* [WriteLog](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/writelog)
* [WriteOutput](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/system/writeoutput)
