static void Main(string[] args) { // Create Java Runtime using (JavaRuntime jre = new JavaRuntime()) { // Load Java Virtual Machine jre.Load(); // Get the "System" type, than get the static field "out" and than invoke method "println" with parameter. jre.GetClass("java.lang.System").GetStaticFieldValue <JObject>("out", "java.io.PrintStream").Invoke <object>("println", "Hello from Java World !!!"); } }
static void Main(string[] args) { // Create Java Runtime Environment using (JavaRuntime jre = new JavaRuntime()) { var options = new Dictionary <string, string>(); options.Add("-Djava.class.path", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); // Load Java Virtual Machine jre.Load(options); // Call sample Java static method. jre.GetClass("JOptionPane").InvokeStaticMethod <object>("showMessageDialog", null, "Hello C# from Java <3"); } }
static void Main(string[] args) { // Create Java Runtime using (JavaRuntime jre = new JavaRuntime()) { // Load Java Virtual Machine jre.Load(); // This is equal with -> String myValue = System.getProperty("java.version") // Splitted if for easier debugging. JClass javaType = jre.GetClass("java.lang.System"); // Invokes static method "getProperty" with parameter "java.version" which returns "java.lang.String" and casts it to generic parameter "string". string javaVersion = javaType.InvokeStaticMethod<string>("getProperty", "java.lang.String", "java.version"); Console.WriteLine($"Currently used Java version: { javaVersion }"); } }