"java import" in script

I'm a python3 programmer. I see a lot of "from java.XXX import XXX". I wonder is it a standard function in jython, or only ingition? Where should I start, is there a manual or guide?
Before this, I used to use python libraries for everything.

Standard function in jython. With some quirks:

  • Wildcard imports are not supported for java packages.

  • Jython automatically "wraps" java objects with a dynamic subclass of PyObject, creating matching methods and fields. When such a wrapped object is handed to a true java method that doesn't take a PyObject, but does take the inner java type, the wrapper is automatically stripped back off.

  • Python native types are marshalled into similar java types. SImilar in reverse for java primitive types. Jython has a central system for managing and customizing this marshalling and unmarshalling process. See this related topic:

  • java's getXyz() and setXyz(val) are automatically mapped to jython property xyz via jython's internal java machinery that implements @property. So both the original java methods and a python-style property become available on such "NetBeans" objects. Using the property is fewer opcodes for the jython interpreter, so should be used wherever applicable.

Thanks reply.

Generally speaking in Ignition, you should prefer a Java-centric approach over a Python one. The environment is the JVM, so Java libraries (including the standard library) are better maintained and supported than Jython. If you need a third party library or SDK for something, you'll also usually have a much better time getting the Java code to work in Ignition than a Python library.

1 Like