Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Saturday, June 12, 2010

Attending Singapore Google Technology Group Meetup

 

Today I attended this Singapore Google Technology User Group Meeting. It's my first time to attend such a Google meetings. Some of previous meet ups had always fallen on the wrong days -- on the day that I have something else to do. Today I am glad to be able to make it, attended the meeting, and Wesley Chun, was the speaker. He presented 2 sessions, one about Python and the other one about Google App Engine.

This guy's a hardcore Python guy, wrote the Core Python series of book, and was a presenter in the PyCon Asia Pacific 2010, Singapore -- an event that has been held last 3 days. Awesome in depth knowledge, vast industrial experiences, and keep the talk flows fluent.

The rest about the meeting can be found here: http://www.sg-gtug.org/2010/05/sg-gtug-special-tutorial-session-june.html

Monday, November 2, 2009

Setting Up Your Own Jython 2.5.1 Environment

In this post I'll show you how to setup your own Jython environment.

Prerequisite to this, you must have a Java Runtime Environment (JRE) installed in your system. Chances are when you already have browser running some Java applet or Java Web Start application, you already have JRE installed on your system.
Get the latest JRE from http://java.com/en/download/manual.jsp.

First you need to download a Jython binaries installer, currently the latest one is version 2.5.1, which you could download from this link.

After download completion you should have a file named jython_installer-2.5.1.jar, click on the file, or run from command line:

[sourcecode lang="shell"]<br />$ java -jar jython_installer-2.5.1.jar<br />[/sourcecode]


Or in some other platform:

[sourcecode lang="shell"]<br />c:\&gt; java -jar jython_installer-2.5.1.jar<br />[/sourcecode]


Now you need to add you Jython path to your OS Path variable, so that the shell or command line interpreter is able to find Jython. In my sample Windows installation case:

[sourcecode lang="shell"]<br />C:\&gt; set PATH=%PATH%;c:\opt\env\jython2.5.1<br />[/sourcecode]


Alternatively, if you are running bash shell (assuming you installed Jython to /opt/env/jython2.5.1 folder):

[sourcecode lang="shell"]<br />$ export PATH=$PATH:/opt/env/jython2.5.1<br />[/sourcecode]


Now you may proceed with the first invocation of Jython.

[sourcecode lang="shell"]<br />C:\&gt; jython<br />*sys-package-mgr*: processing new jar, 'C:\opt\env\jython2.5.1\jython.jar'<br />*sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\resources.jar'<br />*sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\rt.jar'<br />*sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\jsse.jar'<br />*sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\jce.jar'<br />*sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\charsets.jar'<br />*sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\ext\dnsns.jar'<br />*sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\ext\localedata.jar'<br />*sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\ext\QTJava.zip'<br />*sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\ext\sunjce_provider.jar'<br />*sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\ext\sunmscapi.jar'<br />*sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\ext\sunpkcs11.jar'<br />Jython 2.5.1 (Release_2_5_1:6813, Sep 26 2009, 13:47:54)<br />[Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.6.0_16<br />Type "help", "copyright", "credits" or "license" for more information.<br />&gt;&gt;&gt;<br />[/sourcecode]



The jython command line actually invoked a Windows batch file jython.bat, which
When first time invoked, Jython interpreter will activate sys-package-mgr to add standard Java library classes as Python package.

 

After the installation, just play around with simple thing such as:

[sourcecode lang="shell"]<br />Jython 2.5.1 (Release_2_5_1:6813, Sep 26 2009, 13:47:54)<br />[Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.6.0_16<br />Type "help", "copyright", "credits" or "license" for more information.<br />&gt;&gt;&gt; from java.lang import System<br />&gt;&gt;&gt; System.out.println(&amp;quot;Hello, world!&amp;quot;)<br />Hello, world!<br />&gt;&gt;&gt; System.out.println('Hello, world!')<br />Hello, world!<br />&gt;&gt;&gt; System.currentTimeMillis()<br />1257145977410L<br />&gt;&gt;&gt; from java.lang import String<br />&gt;&gt;&gt; s = String(&amp;quot;abc&amp;quot;)<br />&gt;&gt;&gt; s.toString()<br />u'abc'<br />[/sourcecode]


Look at how System.out.println is able to receive both single quote and double quote Python string, and also the java.lang.String type by a Java class method is a Unicode string (u'abc').