Python vs Java In CS Classes: A Comparison

As I work my way through Learn Python The Hard Way, exercise 12, which elaborates on how to get user input from the command line, made me reminisce on my time programming in Java. In my Java programs I would have used the following code to get the user input from the command line and store it in variable ‘age’:

import java.util.Scanner;

public class Question {
    public static void main(String[] args) {
        System.out.print("How old are you? ");
        Scanner question = new Scanner(System.in);
        int age = question.nextInt();
    }
}

And this is how I do the same in Python:

age = raw_input("How old are you? ")

Please note that my Java is rusty and there is probably a shorter way to do the same, but look at the difference!

As I understand it, more and more universities are using Python in their Introductory Computer Sciences classes. Even though I had fun in my Programming in Java class, I think this is a good development. Python provides an easier first experience into the world of programming and is less intimidating at first sight for new students.

Personally, I find it a big relief not having to work with the ugly Java-syntax and being able to focus on writing awesome code instead of searching for missing semi-colons and curly brackets. Off course there will always be the need for Java, C, or other languages that are much faster, but for introductory purposes, I would be happy to see Python used in the classrooms more often!

2 thoughts on “Python vs Java In CS Classes: A Comparison

  1. It’s a touch tradeoff. While Java is pretty horrible, it is more widely used in US corporations (although Python is much more prevalent in startup community if that’s more your interest).

    • You’re right, it is. I can imagine a lot of high-school students being intimidated by Java in the beginning, deciding Computer Science is not for them in University. Why not give introductory courses in Python, going into Java and others later on in the program.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>