{"library":"pemja","title":"PemJa","description":"PemJa is a Python-Java bridge that enables embedding a JVM within a Python process, allowing dynamic interaction with Java objects and classes. It simplifies calling Java methods from Python and provides mechanisms for classpath management. The current version is 0.6.1, with releases occurring as features are added or bugs are fixed, but without a strict regular cadence.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install pemja"],"cli":null},"imports":["from pemja import launch_jvm","from pemja import find_jar","from pemja import JavaObject"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import pemja\n\n# Ensure JDK 8+ is installed and accessible in your system's PATH or JAVA_HOME.\n# In a production environment, consider explicit JVM options or classpath management.\n\ntry:\n    print(\"Launching JVM...\")\n    # Using a context manager ensures the JVM is shut down cleanly\n    with pemja.launch_jvm() as jvm:\n        print(\"JVM launched successfully.\")\n\n        # 1. Access a static method from a core Java class\n        System = jvm.find_class(\"java.lang.System\")\n        java_version = System.getProperty(\"java.version\")\n        print(f\"Java version reported by JVM: {java_version}\")\n\n        # 2. Create an instance of a Java class and call a method\n        String = jvm.find_class(\"java.lang.String\")\n        greeting = jvm.create_instance(String, \"Hello from PemJa in Python!\")\n        print(f\"Original Java string: {greeting}\")\n        print(f\"Uppercase Java string: {greeting.toUpperCase()}\")\n\n        # 3. Handle exceptions from Java\n        # This is a simple example; real error handling would be more robust\n        try:\n            Integer = jvm.find_class(\"java.lang.Integer\")\n            Integer.parseInt(\"not_a_number\") # This will throw a Java NumberFormatException\n        except jvm.JavaException as e:\n            print(f\"Caught Java Exception: {e.get_stack_trace()}\")\n\nexcept pemja.PemjaException as e:\n    print(f\"PemJa specific error: {e}\")\n    print(\"Please ensure JDK 8+ is correctly installed and configured.\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates launching a JVM, accessing static Java methods, creating Java object instances, calling instance methods, and basic Java exception handling. It's crucial to have JDK 8+ installed on your system for PemJa to function.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}