This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Jython/Python and the fly likes Jython? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Languages » Jython/Python
Bookmark "Jython?" Watch "Jython?" New topic
Author

Jython?

Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
Ok, what is Jython, and as a java developer, why do I need it?


Rob
SCJP 1.4
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
It's an implementation of the Python scripting language in Java. From my limited experience, it provides you most of the same benefits Perl can, but it (a) doesn't look like line noise, and (b) is easier to integrate with Java.
[ April 08, 2002: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
for a java programmer, python is an obvious choice compared to perl.
I did try out OO Perl before checking out python.
Check out python2.2 (it has excellent features).
then learn jython.
Current version of jython is not same as that of python. SO you w'd'nt be seein the 2.2 features there. But that's fine.
You have access to all the java libraries + most of the python libraries also come for free.
But the documentation is'nt that good though :-(
I found python to be a little addictive once i started doing some stuff with that! ;-)
good luck.
Ajit Malleri
Greenhorn

Joined: Feb 10, 2002
Posts: 27
Hello,
I am a java programmer with 3 years of experience. I have been using perl scripts on linux. Does jython provide the same features and advantages as compared to perl? Going through the documentation, it seems quite interesting . Can anyone tell me more about the advantages and disadvantages of using jython as compared to python.
Thanks.


SCJP, SCWCD
Glenn Murray
Ranch Hand

Joined: Dec 07, 2001
Posts: 74
Originally posted by Ajit Malleri:
Hello,
I am a java programmer with 3 years of experience. I have been using perl scripts on linux. Does jython provide the same features and advantages as compared to perl? Going through the documentation, it seems quite interesting . Can anyone tell me more about the advantages and disadvantages of using jython as compared to python.
Thanks.

Yes, Python does what Perl does (generally speaking), but in a naturally more structured, object-oriented way. The advantages of Jython to Python include having immediate access to the Java class libraries and being able to run the script wherever there is a JVM. Disadvantages are that it may be slower and you cannot so easily interoperate with C/C++ (when running from a JVM).
Note, though, Jython, as much as possible, is Python. You can write and debug using Jython and then run the same script without a JVM using the Python interpreter (again, with a few caveats). Thus via Jython, Python is actually more platform independent than Java.
I speculate that the greatest value in learning Jython is to Java developers who don't know a scripting language, and who by learning one gain some tools they wouldn't otherwise have.
Cheers,
Glenn


Glenn Murray
Author of Yo Soy Una Vaca De Hoy
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61316
    
  66

OK, but could someone provide some small examples of where it could be used and how?
thanks,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
bob dapaah
Ranch Hand

Joined: Jan 15, 2002
Posts: 46
Does anyone know of a good online resource for Jython?
Shawn Meyers
Greenhorn

Joined: Mar 19, 2002
Posts: 23
http://www.jython.org/
that's the main place to start out at.But like someone said earlier, learn python first, because that's what jython is, just a more highly glueable version of it, and it was written in Java too
http://www.python.org/ is the main page for Python, you can find pleanty of documentation of it there.Try out the download for the Python tutorial, it comes in PDF format, pretty cool. And also they have in the Jython section of the site a downloadable version of "Thinking in Paterns with Java",, if you don't already have it, it's some good reading.And it's apparently been somewhat updated to cater to Jython users out there. Ohh and by the way, two cool things about the Python language, it's got alot of cool libraries beside the basic ones Python and Jython comes with.There is also Vpython, V stands for visual, and Pygame, which has special libraries for game developement.And the other thing is, scripts written in this language are very much shorter than programs written in other languages
And for you Perl progragramers, there's Parrot, which I didn't see when I stopped by the site, should be somewhere though,looks like it got bumped out by the new release of Python, I dunna know, ok, I'll stop talking your ears off now
Shawn Meyers
Greenhorn

Joined: Mar 19, 2002
Posts: 23
http://sourceforge.net/foundry/python-foundry/
has assorted info on Python and forums too
and http://hackers.com/bulletin/index.php?s=
has some good scripting lanhuage forums too
and http://www.jython.org/applets/index.html
is some examples of applets written in Jython
Ohh, and do you know where the name python came from??A snake??Nope, Monty Python hmm?,?
ok, just some after thoughts
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
Ok, but what can I do with Jython that I can't in java? Or why would I want to do something particular in JYthon that I wouldn't/couldn't want to do in Java?
I still don't have a sense of how it "works" and what it can do for me as a current java developer
Shawn Meyers
Greenhorn

Joined: Mar 19, 2002
Posts: 23
Umm,,,what can you do that you can't do?,,umm, well,, you can make Java a scriptable language.Very simple and flexible string manipluation.Python has a little bit of everything you might like from other languages in it.I really think you should go over to http://www.python.org/doc/ ,, download the documentation and find out what Python is all about,after all, what Jython is, is an adaption of the Python language, in short, it is Python
Really,what it is about is intergrating a scripting language with Java.There are so many different functions and statements in it, even diferent kinds of lists, making your strings easier to manipulate later on in your code.But really, check out the Python tuitorial, find out what it's all about, it is pretty much the simplest language to learn, your not going to fry your brain checking it out, it's the ideal first language, and since it isn't you first language, you got it in the bag my friend And if it isn't to your likeing,awe well.
Robert W Bill
Author
Greenhorn

Joined: Apr 08, 2002
Posts: 21
Because Jython is written in Java, it's hard to say Jython does things that Java can't. But, if you look at it from a syntax point of view, Jython/Python is a higher level, uses dynamic typing, supports operator overloading, dynamic code evaluation (exec/eval) and has a full complement of functional programming tools. Don't forget that you also get Python's simple, clear syntax.
These attributes usually mean improved code readability, speedier development, shorter prototype/test cycle, and increased flexibility. I really get the sense that Jython is a great tool for trying to improve code quality too. The terse syntax, interactive interpreter and dynamic typing really help you see your design in a clear way.
Here's some of the places where it can't be beat. Extending apps with higher-level (scriping) languages is unparalelled because of how transparent the Java/Python boundary is. Unit testing is great because of how quick it is to write test scripts and because you can set "respectJavaAccessibility" to false Plugging Jython into servlet containers works well because Jython syntax is very text-processing friendly.
Hope this helps.
Burk Hufnagel
Ranch Hand

Joined: Oct 01, 2001
Posts: 814
    
    3
Originally posted by Robert W Bill:
Unit testing is great because of how quick it is to write test scripts and because you can set "respectJavaAccessibility" to false

Does that mean that Jython will let me access things marked private? If so, then I think I have found a Very Nice Tool indeed. Unit testing can reach a new level of completeness!


SCJP, SCJD, SCEA 5 "Any sufficiently analyzed magic is indistinguishable from science!" Agatha Heterodyne (Girl Genius)
Brett Anthoine
Greenhorn

Joined: Mar 12, 2002
Posts: 27
What about the speed issue ? In one word ? Comparing to a "normal" java app.
slower ? faster ?


Brett Anthoine<br />"640k should be enough for anybody."
Matthew X. Brown
Ranch Hand

Joined: Nov 08, 2000
Posts: 165
http://www.jython.org/docs/differences.html
Here is the best source for the differences between the two languages.
Robert W Bill
Author
Greenhorn

Joined: Apr 08, 2002
Posts: 21
Concerning "respectJavaAccessiblity"...
Yes, it means you can access private/protected fields/methods. Yes, it is good for unit testing, and there's an abvious warning that it's not intended for production, safety-critical apps.
Concerning speed, Jython is slower than Java. I usually write apps in Jython, then convert only the time-intensive portions to Java. This conversion usually gives me a 9x improvement in that class. It's usually 10% of classes that hog 90% of the machine, so that selective Java coding usually makes for acceptable apps in less dev time.
Brett Anthoine
Greenhorn

Joined: Mar 12, 2002
Posts: 27
Thanks for the answer.
Burk Hufnagel
Ranch Hand

Joined: Oct 01, 2001
Posts: 814
    
    3
Originally posted by Robert W Bill:
Concerning speed, Jython is slower than Java. I usually write apps in Jython, then convert only the time-intensive portions to Java. This conversion usually gives me a 9x improvement in that class. It's usually 10% of classes that hog 90% of the machine, so that selective Java coding usually makes for acceptable apps in less dev time.

Sounds like an improvement over the old 80/20 rule... I like it!
While I like the idea, I'm still concerend about the people who have to maintain "combination" apps after I'm gone. I have a button that says, "Write your code as if the person maintaining it is a homicidal maniac who knows where you live." It's a bit extreme I guess, but it reminds me that "tricky" code is often not a Good Thing - and that's kind of how I feel about mixing Jython and Java in the same app.
Mr. Bill, are you aware of any "best practices" to reduce this potential problem? Documentation easily falls behind - or is ignored altogether... is there something else you would recommend?
Thanks, Burk
Robert W Bill
Author
Greenhorn

Joined: Apr 08, 2002
Posts: 21
I don't know of any proposed best-practices specifically for the python/java mixture. However, the sense of "combination" is minimal when using Java classes in Jython because Jython uses any java class without modification. Embedding Jython within Java is a notch more complicated. When embedding, A lot of people store their Jython scripts in creative ways (databases, remote servers, etc). This brings up one point where confusion often resides. Java has the classpath to locate classes and Jython has the sys.path to locate modules. This can get hairy, so it's important to clearly document how and why your sys.prefix, sys.path and any other properties related to these things are set. That's the trick to keeping homicidal maniac successors happy
 
GeeCON Prague 2014
 
subject: Jython?