I have used bits of java code in the form of 1 or 2 method calls like

from import InetAddress 
compname = InetAddress.getLocalHost().getHostName() 

But what if i want to instantiate a standard Java class and use the new method, declare some variables and so on. Where can i insert it and how do i indicate to the PMI script interpreter that the code is Java.

Can you help me on this

Do you mean you want to define a new, custom class? You’d declare a new class in Python, not Java. If this isn’t what you meant, please clarify.

Where do i declare this new python class and how do i call it.

I am asking how to use java inside PMI because i saw in the help using Java code when pmi’s own functions fall short

I would for example like to insert a few lines of Java code like the bit below. Where do i insert it and can i use it as is or do i have to modify it?
(The code below is just cut out of another context)

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;


SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd" );
TimeZone local = TimeZone.getDefault();
sdf.setTimeZone( local );

// new Date() gets current date/elapsedTime
String dateString = sdf.format( new Date() );

// Get TimeZone
String timeZoneName = local.getDisplayName();

Here the functions Date() and TimeZone.getDefault() are used.

Oh, I think I misunderstood. You simply want to use existing classes from the Java standard library?

This is possible because the Python engine that we use is Jython, which has the ability to use Java classes. See more here:

The code you posted translated to Jython would become:

from java.text import SimpleDateFormat
from java.util import Date
from java.util import TimeZone
sdf = SimpleDateFormat(“yyyy-MM-dd”)
local = TimeZone.getDefault()

dateString = sdf.format(Date())

timeZoneName = local.getDisplayName()[/code]

Note that for date formatting you could also just call fpmi.db.dateFormat()

Hope this helps,

Just what i needed.
Thanks again

No problem!