Files changed (22)
The word elegant is defined as “pleasingly graceful and stylish in appearance or manner.” *Uncomplicated* and *powerful* could also be great words to assist in the description of this language.
This chapter is going to cover the basics of object-oriented programming. We’ll start with covering the basic reasons why you would want to write object-oriented code in the first place, and then cover all the basic syntax, and finally we’ll show you a non-trivial example.
Object-oriented programming is a method of programming where you package your code up into bundles of data and behavior. In Jython, you can define a template for this bundle with a class definition. With this first class written, you can then create instances of that class that include instance-specific data, as well as bits of code called methods that you can call to do things based on that data. This helps you organize your code into smaller, more manageable bundles.
In this chapter, we will discuss developing Jython applications using two of the most popular integrated development environments, Eclipse and Netbeans. There are many other development environments available for Python and Jython today, however, these two are perhaps the most popular and contain the most Jython-specific tools. Eclipse has had a plugin known as PyDev for a number of years, and this plugin provides rich support for developing and maintaining Python and Jython applications alike. Netbeans began to include Python and Jython support with version 6.5 and beyond. The Netbeans IDE also provides rich support for development and maintenance of Python and Jython applications.
One of the major benefits of using Jython is the ability to make use of Java platform capabilities programming in the Python programming language instead of Java. In the Java world today, the most widely used web development technique is the Java servlet. Now, in JavaEE there are techniques and frameworks used so that we can essentially code HTML or other markup languges as opposed to writing Pure Java servlets. However, sometimes writing a pure Java servlet still has it's advantages. We can use Jython to write servlets and this adds many more advantages above and beyond what Java has to offer because now we can make use of the Python language features as well. Similarly, we can code web start applications using Jython instead of pure Java to make our lives easier. Coding these applicatons in pure Java has proven sometimes to be a difficult and sometimes grueling task. We can use some of the techiques available in Jython to make our lives easier. We can even code WSGI applications with Jython making use of the *modjy* integration in the Jython project.
Deployment of Jython applications varies from container to container. However, they are all very similar and usually allow deployment of WAR file or exploded directory web applications. Deploying to "the cloud" is a different scenario all together. Some cloud environments have typical Java application servers available for hosting, while others such as the Google App Engine, and moble run a bit differently. In this chapter, we'll discuss how to deploy web based Jython applications to a few of the more widely used Java application servers. We will also cover deployment of Jython web applicaitons to the Google App Engine and mobile devices. While many of the deployment scenarios are quite similar, this chapter will walk through some of the differences from container to container.