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.
$ docker pull foodtiny/native:latest
$ git clone https://github.com/foodtiny/native.git
$ ./configure && make native -j4 && sudo make install
#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
- 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
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 = {};
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