Home

 

Overview of Jython

Jython is an implementation of the Python language. The wsadmin tool uses Jython v2.1. The J in Jython represents its Java-like syntax. But Jython is also quite different than Java or C++ syntax. Though like Java, Jython is a typed, case-sensitive, and object-oriented language, but unlike Java, it is an indentation based language, which means that it does not have any mandatory statement termination characters (like a semi-colon in Java), and code blocks are specified by indentation.

To begin a code block, you have to indent in, and to end a block, indent out. Statements that expect an indentation level end in a colon (:). Functions are declared with the def keyword, and comments start with a pound sign (#). Example | 6-1 shows a Jython code snippet.

Example 26-1 Jython snippet

def listAllApps # This function lists all application
	apps = AdminApp.list()
   if len(apps) == 0:
      print "Inside if block - No enterprise applications"
   else:
      print "Inside the else block"
      appsList = apps.split(lSep)
      for app in appsList:
         print app

# This is a comment - Main section starts here
lSep = java.lang.System.getProperty('line.separator')
listAllApps 		 # call the listAllApps function defined above

ibm.com/redbooks