# Create/Open Databases in Java

> As demonstrated in the Java Quick Start, databases are created by the Database method `open()`. There are two versions of the `open()` method:

>         open( String dbName, Parameters params, long size)

>         open( String dbName, Parameters params, Devices[] devices)

> The first version is appropriate for In-Memory databases as it allows simply specifying the database `size` as the third argument. The second version is necessary if a shared memory device or additional memory devices are required, which is typically necessary only for persistent databases. However for an In-Memory database an additional one or more memory devices could be necessary if database memory might need to be extended.

> For an in-memory database the relevant parameters are described below. For persistent databases there are additional considerations. Please use the following link to view detailed instructions for creating or opening persistent databases.

> ## Database Parameters

> The Database.Parameters class is used to specify the classes that will be stored in the eXtremeDB database and other properties that determine runtime behavior. The Database.Parameters constructor initializes the database parameters with default values. For In-Memory databases, apart from the default values, typically the only parameters to specify are `memPageSize`, `classes` and `maxConnections`. For example:

>         public static void main(String[] args)
>         {
>             ...
>             Database.Parameters params = new Database.Parameters();
>             ...
>             params.memPageSize = 128; // Memory page size
>             params.classes = new Class[] { OpenObj.class }; // List of classes that will be stored in eXremeDB database.
>             params.maxConnections = 10;

> The key properties of the Database.Parameters class for in-memory databases are:

> memPageSize | The size in bytes of the database object and index pages
> diskPageSize | Set to zero to indicate an in-memory database (and disable disk operations)
> classes | The list of Java classes that will be stored in eXtremeDB database (The classes must use @Persistent annotation)
> maxConnections | The total number of connections allowed to the database

> ## Memory page size

> The `memPageSize` property defines the size of memory pages for conventional memory. The `memPageSize` can be calculated to optimize performance and will vary depending on the application dynamics, but as a rule of thumb, page size should be between 80 and 512 bytes; a 128 byte page size is good in most situations.

> (Note that for all-in-memory databases `diskPageSize` will be set to zero by the Database.Parameters constructor.)

> (Also note that `rtree` indexes require larger page sizes. If error codes `MCO_ERR_RTREE` or `MCO_E_DISK_PAGE_POOL_EXHAUSTED` are encountered during database transactions, increase the page size in increments until these error codes are remedied.)

> ## Max database connections

> The `maxConnections` property specifies the maximum number of connections that will be managed for this database.

> ## Example

> Typical application code to create an in-memory database could look like the following:

>         static final int DATABASE_SIZE = 16*1024*1024;

>         public static void main(String[] args)
>         {
>             Database db = new Database();
>             Database.Parameters params = new Database.Parameters();
>             ...
>             params.memPageSize = 128; // Memory page size
>             params.classes = new Class[] { Record.class }; // List of classes that will be stored in eXremeDB database.

>             db.open("operations-db", params, DATABASE_SIZE);