: junc++ion code (v3)

Coding With the C++ v3 Proxy Types Tutorial

The purpose of this tutorial is to introduce you to the basics of writing C++ applications that use C++ v3 Proxy Types.

The v3 moniker stems from Codemesh's C++ runtime library that has to be compatible with the proxy types because the proxy types delegate most of their work to that runtime library. The runtime library is currently at major version 3, hence the v3 label.

We strive to make the C++ proxy types as faithful to their underlying Java types as possible, but that does not mean that there aren't any pitfalls. Some surprises are simply unavoidable. For example, there is simply no way you will ever be able in C++ to use the .class suffix to refer to a type; class is a reserved name and cannot be used like that. So how do you write C++ code that uses a Java type instance?

This tutorial will hopefully answer this and all similar questions that you might run into while using the C++ v3 proxy types.

 

Prerequisites

The focus of this tutorial is to introduce you to writing code with proxy types, not necessarily to teach you how to configure the application so it will actually run. We will have a lesson on how to configure your C++ project and as one of the tests we'll try to run the application you built but another tutorial deals with the application's runtime configuration in much more detail.

You should have access to a properly set up C++ compiler if you are going to try to follow the step-by-step instructions but you can also just read the lessons, in which case a C++ compiler is not necessary.

 

Lesson Plan

Project Setup

Learn what you need to do to use proxy types in your C++ projects.

Constructing Proxy Objects

Learn how to instantiate a Java object through its proxy type. Introduction to _use_java_ctor and discussion of new.

The Proxy Object Lifecycle

Learn what happens under the hood when you assign, copy, and destroy proxy objects.

Using Strings

Learn how to use strings in connection with proxy types.

Dealing With null

Learn how to check whether a return value is null or not. Watch out for null vs. NULL!

Accessing Fields

Learn how to access fields in your proxy types.

Calling Methods

Learn how to call methods on your proxy types.

Using Array Proxy Types

Learn how to create arrays and access their elements.

Casting Between Proxy Types

Learn how to cast a proxy object to a different proxy type. This lesson discusses the dyna_cast() function.

Handling Exceptions

Learn how to handle exceptions thrown on the Java side.