Skip to content

Native Library - Brings Java productivity into C++ program

License

Notifications You must be signed in to change notification settings

VietAnh14/native

 
 

Repository files navigation

Native Library

Join Gitter Chat Channel - Build status Build Status Coverage status Support Platform

Native Library brings productivity and maintainability for your C/C++ application as a Java program.

  • Blazing fast, small footprint with no dependency required
  • Provide rich Java Core classes beside C++ Standard Library
  • Prevents nearly all memory leak and segfaults via automatic storage
  • Classes are strictly tested with unit tests, clean with Valgrind and follow Oracle documentation
  • Feel free to use in your commercial products and welcome for contributions

This project is also useful for new developers in practical programming.

Getting started

Docker

$ docker pull foodtiny/native:latest

Installation

$ git clone https://github.com/foodtiny/native.git
$ ./configure && make native -j4 && sudo make install

Examples

#include <native/library.hpp>

class MainApplication {
public:
    static void main(Array<String> arguments) {
        HashMap<String, String> hashMap;
        int counter = 0;
        for (String argument : arguments) {
            hashMap.put("argument " + String::valueOf(counter), argument);
            counter++;
        }
        System::out::println("We have 4 pairs:");
        String pairs = "Pairs: \n";
        for (Map<String, String>::Entry entry : hashMap.entrySet()) {
            pairs += entry.getKey() + String(" - ") + entry.getValue() + String("\n");
        }
        System::out::println(pairs);
        ArrayList<HashMap<String, String>> arrayList;
        arrayList.add(hashMap);
        System::out::println(arrayList.toString());
    }
};

int main(int argc, char **argv) {
    return Application(MainApplication::main, argc, argv);
}

Compile your source and link with native library

$ g++ -c -o main.o HelloWorld.cpp
$ g++ -o main main.o -lnative
$ ./main one two three

Output:

We have 4 pairs:
argument 3 is three
argument 2 is two
argument 1 is one
argument 0 is ./main

[{"argument 0": "./main", "argument 1": "one", "argument 2": "two", "argument 3": "three"}]

More examples can be found here Support unit test by default via ApplicationTest here - Powered by C-Unit

Contributors

  • This library must be followed Oracle Java 8 Documentation for standardization
  • Make sure your commits must be passed with check before you create pull request
  • At least one contributor in this project reviews your commits (except you) before merging
  • Best practices guidelines in CONTRIBUTION.md

Documentation

Documentation

Differences

This library provides Java classes in C++ so its syntax are friendly for both programming languages:

  • Namespace - Package
// Java
System.out.println("Java");
// C++
System::out::println("C++");
  • Array
// Java
byte[] byes = {};
// C++
Array<byte> bytes = {};

Data Types

All data types are implemented and ready to use in C++ Application

  • char - Java.Lang.Character
  • byte - Java.Lang.Byte
  • string - Java.Lang.String
  • short - Java.Lang.Short
  • int - Java.Lang.Integer
  • long - Java.Lang.Long
  • float - Java.Lang.Float
  • double - Java.Lang.Double
  • boolean - Java.Lang.Boolean
  • enum - Java.Lang.Enum

About

Native Library - Brings Java productivity into C++ program

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 99.4%
  • CMake 0.6%