What kind of things can be done with Java but not Python?

You would surely love reading the comparisons made below between these 2 languages.
Check them :

  • Java is Dead ! Long live Python
  • Python-Java : A side-by-side comparison
  • Python is NOT java

I guess using Jython, you can do anything with Python that you can do in Java.

Conversely, Python has the PyPy compiler, which is pretty cool - a virtual machine with multiple backeds (Java Runtime, LLVM, .net, and Python IIRC), multiple garbage collectors, multiple implementations (Stackless), etc. I know Java has a big choice of virtual machines, but the growth of PyPy is amazing, due to it being written in RPython - a fairly productive language.

Also, can a Java do this, in 1 file and less that 20 lines, with no library imports? Obviously both languages have libraries that can do this, but I'm just talking about the flexibility of the languages.

class Logger(object): # boilerplate code
    def log(self,level,msg,*args,**kwargs): # *args, **kwargs = flexible arguments
        self._log(level,msg,*args,**kwargs) # call with flexible argments

    def _log(self,level,msg,*args,**kwargs):
        # override me at runtime :) 
        # I think Java people call this Dependency Runtime Injection
        if level>1:
            print msg,args,kwargs

logger = Logger() # boilerplate code

def logged(level): # what pattern do you call this?
    def logged_decorator(function): # and this? 
        def func(*args,**kwars): 
            name = func.__name__ # look ma, reflective metaprogramming!
            logger.log(level,name,*args,**kwargs)
            return func(*args,**kwargs)
        return func # boilerplate code
    return logged_decorator # boilerplate code

Example use:

@logged
def my_func(arg1,arg2):
   # your code here
   pass

Both languages are Turing complete, both have vast libraries, and both support extensions written in C so that you can access low level code if needed. The main difference is where they are currently supported. Java in general has wider support than Python.

Your example of Android is one place where Java is the standard choice, although Python also has some support in the form of Android Scripting Environment. Java is already installed on most home computers. You can write Java applets and expect them to work in most browsers.

One thing you can't easily do in Java is quickly write short scripts that perform useful tasks. Python is more suitable for scripting than Java (although there are of course other alternatives too).