Giter Club home page Giter Club logo

darknotes's Introduction

Dark Notes

Description

Dark Notes is a library that uses the Java Native Interface (JNI) to load the Java VM into a .NET process on Windows, and exposes the Java classes and methods in an easy-to-call way using the .NET Dynamic Language Runtime (DLR). This is meant for situations where you have some Java functionality/classes that you really want to invoke within your .NET programs, but would rather avoid shelling out to a separate Java program just to do that. It's been optimized for usability rather than speed.

Quick usage

Important: You need to have Java installed for this to work. Specifically Dark Notes needs the jvm.dll library, and looks for it under "$JAVA_HOME\bin\server\jvm.dll". Also typically this DLL is 64-bit, so you need to run this in a 64-bit process.

using (dynamic java = DarkJava.CreateVm())
{
    java.ImportPackage("java.lang");
    dynamic s = java.String.@new("Hello world");
    Assert.AreEqual("hello world", (string)s.toLowerCase());
}

This "Hello world" example shows a few things:

  1. How to create the entry point: DarkJava.CreateVm(). You typically want just one invocation of that in your application (JNI doesn't respond kindly to attempting to host the JVM multiple times in a process). It has overloads that lets you specify additional options to the JVM or explicitly give the path to the jvm.dll library instead of trying to infer it.
  2. Importing packages: this is Dark Notes' equivalent of "using" statements.
  3. How to call constructors: You can call the constructor of any type by navigating to that type (java.String in the above example, which thanks to the package import resolves to java.lang.String), then invoking the "new" method on it. You can then pass in any parameters you want to that constructor.
  4. How to call instance methods (this should just look familiar to you). Dark Notes does the magic under the covers to call the proper corresponding Java method on that instance.
  5. How to convert to .NET types: the result of s.toLowerCase() is a Java String object, but when we cast it to string Dark Notes does the requisite magic to give you back a .NET string.

darknotes's People

Contributors

mooso avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.