Over a million developers have joined DZone.

JAVA C++ - Status I

·

I previously described the start of the JCPP project in a very short article: http://java.dzone.com/articles/java-vs-cpp

I am going to write several statuses every time I have something significant to report. I think that I have now reached an interesting point, so it's time to share.

As a reminder, this project's aim is to offer a C++ API that looks like the JAVA API.

Here is the list achievements by packages:

  1. jcpp::io

Basic functionnalities are there. We can marshal and unmarshal a Java object to/from a JCPP C++ object. Of course, there are still lots of classes remaining but major ones like ObjectInputStream and ObjectOutputStream are stable and tested.

   2. jcpp::lang, jcpp::lang:reflect

It contains not only basic functionnalities but also acceptable level for reflection features. This allowed me to implement the object marshalling.


   3. jcpp::net, jcpp::rmi

Very few classes of net package done. rmi package contains a C++ RPC server implementation.

I also submitted a Java version of the server and tested that it works from C++ and Java.

I also solved the non existence of Proxy in C++. But for the moment, we have to know before hand which interfaces the Proxy class is implementing :(


    4. jcpp::util

I spent most of last days implementing Vector, HashMap, Hashtable, IdentityHashMap, ...

They are working, still more tests. Marshalling and unmarshalling is tested too.


Globally to check the status, we just have to compare the current coverage with the JAVA API. I am using JAVA 1.8.

This is the link to the project https://github.com/charb/rpc

Here are some code snapshot:


        JObject* JHashMapTest::testReflect(){
            JHashMap* s=new JHashMap(4);
            assert (s->getClass()->getName()=="java.util.HashMap");
            JShort* short1=new JShort(1);
            JLong* long1=new JLong(2);
            JInteger* int1=new JInteger(3);
            JFloat* f1=new JFloat(4);
            s->put(short1,new JString("short1"));
            s->put(long1,new JString("long1"));
            s->put(int1,new JString("int1"));
            s->put(f1,new JString("f1"));

            assert (s->get(short1)->equals(new JString("short1")));
            assert (s->get(long1)->equals(new JString("long1")));
            assert (s->get(int1)->equals(new JString("int1")));
            assert (s->get(f1)->equals(new JString("f1")));

            JSet* ks=s->keySet();
            assert (ks->contains(short1));
            assert (ks->contains(long1));
            assert (ks->contains(int1));
            assert (ks->contains(f1));

            JIterator* iks=ks->iterator();
            while (iks->hasNext()){
                JObject* o=iks->next();
                assert (o->equals(short1) || o->equals(long1) ||
                        o->equals(int1) || o->equals(f1));
            };

            JCollection* cv=s->values();
            assert (cv->contains(new JString("short1")));
            assert (cv->contains(new JString("long1")));
            assert (cv->contains(new JString("int1")));
            assert (cv->contains(new JString("f1")));

            JIterator* icv=cv->iterator();
            while (icv->hasNext()){
                JObject* o=icv->next();
                assert (o->equals(new JString("short1")) || o->equals(new JString("long1")) ||
                        o->equals(new JString("int1")) || o->equals(new JString("f1")));
            };



            return s;
        }


        JObject* JHashSetTest::testReflect(){
            JHashSet* s=new JHashSet();
            assert (s->getClass()->getName()=="java.util.HashSet");
            JShort* short1=new JShort(1);
            JLong* long1=new JLong(2);
            JInteger* int1=new JInteger(3);
            JFloat* f1=new JFloat(4);
            s->add(short1);
            s->add(long1);
            s->add(int1);
            s->add(f1);

            assert (s->contains(short1));
            assert (s->contains(long1));
            assert (s->contains(int1));
            assert (s->contains(f1));

            JIterator* iks=s->iterator();
            while (iks->hasNext()){
                JObject* o=iks->next();
                assert (o->equals(short1) || o->equals(long1) ||
                        o->equals(int1) || o->equals(f1));
            };

            return s;
        }



        JObject* JArrayListTest::testReflect(){
            JArrayList* s=new JArrayList(4);
            assert (s->getClass()->getName()=="java.util.ArrayList");
            JShort* short1=new JShort(1);
            JLong* long1=new JLong(2);
            JInteger* int1=new JInteger(3);
            JFloat* f1=new JFloat(4);
            s->add(short1);
            s->add(long1);
            s->add(int1);
            s->add(f1);
            return s;
        }
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}