O'Reilly logo

Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython by Richard Hightower

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Python 101

Here's a Python class followed by its Java equivalent.

Python:

class Employee:
  def __init__(self, fname="John", lname="Doe", id=1, manager=None, dept=1):
        self.__firstName     =     fname
        self.__lastName      =     lname
        self.__id            =     id
        self.__manager       =     manager
        self.__dept          =     dept

  def getManager(self):
        return self.__manager

  def __str__(self):
        values = self.__lastName, self.__firstName, self.__id
        return join(values,',')

Java:

 public class Employee{ private String firstName, lastName; private int id, dept; private Employee manager; public Employee(){ firstName = "John"; lastName = "Doe"; id = 1; vmanager=null; dept=1; } public Employee(String fname, String lname, int id, Employee manager, int dept){ firstName = fname; lastName = lname; this.id = id; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required