Type: Individual Assignment

Due: by 9:30 PM on Wednesday, September 12, 2018

Part 1: Background and Logistics

  1. Read the course syllabus and familiarize yourself with the course schedule.
  2. Complete the background questionnaire.
  3. Enroll in th Piazza course and explore its features.
  4. Do the assigned Reading 1 for 9/12 and post at least one question you have about it to the corresponding folder reading1 on Piazza. Note that you will need to do this for each assigned reading on the course schedule for the whole term. You are also encouraged to post questions unrelated to readings (try to put them in an appropriate folder) and help answer questions posted by your classmates!

Part 2: Comparing Java with Python

Goals

The goal of this part is to help you to understand the similarities and differences between Java and Python and to prepare you to starting writing your own Java programs. Some of you may have learned Java in your first CS course, rather than Python. This assignment will still contain useful information about the process of learning a second language.

Java Basics

Learning your second programming language is different from learning your first. Assuming your first language was something relatively standard these days (Python, Scala, C, C++, etc.) you start out already knowing about many of the nearly-universal language constructs: assignments, loops, conditionals, functions, operators, classes, etc. Learning the second language involves a lot of learning new syntax for old ideas, rather than learning both the ideas and the syntax at the same time. As a result, learning your second language typically goes more quickly than learning the first. The more languages you learn, the faster you will get at this process.

For this class, I will assume that you are making a transition from Python (which we teach in CS 111) to Java (which we will use in CS 201). In fact, I imagine that a few of you met Java in high school, and some of you may even have skipped CS 111 and thus do not know Python. If you’re one of the latter and you plan to take courses beyond CS 201, you’ll eventually want to start teaching yourself Python, for which you may find some of these exercises useful in a backwards sort of way.

During the first few days of class, we’re going to focus our attention on the differences between Python and Java to help get you started in Java, and you may find Ken Lambert’s from Python to Java tutorial a useful resource for this. Some key differences include:

  • Explicit types (e.g. int, double, String, …) are specified for all variables, parameters, return values, etc.
  • There’s an awkward distinction between “primitive types” (int, short, long, float, double, byte, char, boolean) and “reference types” (everything else).
  • Program structure requires the use of classes. This was optional in Python. Braces {} are used instead of indentation to delimit if/else/for/while/etc. bodies (though indentation remains an essential element of good programming style).
  • Miscellaneous syntactical differences: semi-colons (;) are used to terminate instructions, // and /*...*/ for comments, only "" for string literals (you can’t use single quotes), try/catch for exceptions, etc.
  • No easy built-in lists [] or dictionaries {}.

Your Assignment

For each of the Python/Java program pairs,

  1. read the programs,
  2. run the programs (both Python and Java), and
  3. write down questions you have about the Java code.

Note: there are some questions and exercises in the comments of some of the programs that you should try. Remember that to run the Java programs, you need to compile them first:

$ javac Hello.java

Then you can run the compiled class:

$ java Hello

The Python programs are written for Python 3, so run them with:

$ python3 hello.py

When you’re done, post your questions (and answers if you have them!) to the assignment1 folder on Piazza.

Take this exercise seriously. Figure out what you know, what you don’t know, what’s easy, what’s confusing, etc. If you pay careful attention to these starter programs, you’ll have a great start on writing your own Java programs. You may find it helpful to do this exercise in conjunction with the readings for this week. The appendices of your book may be able to help you answer some of your or your classmates’ questions, and looking at these examples may help you recognize what parts of the reading you already know and what you should consider more closely.

Below is the list of program pairs. You can also download a zip file that contains all of the files.

Grading and Other Information

This assignment is graded entirely on participation; the absolute baseline is that you post two questions of your own and reply to two others’ questions to the assignment1 folder on Piazza, but you are encouraged to post more! Note that I may address your questions in class for this assignment rather than on Piazza.

Java is installed in the computer labs on campus (both in the CMC and elsewhere). You are welcome to install Java on your own computer as well using these instructions on the CS department website. Note that the only officially supported environment is the lab computers, but Mike Tie (mtie@carleton.edu, CMC 305) can help you troubleshoot if you run into problems installing Java on your home computer; I’m also happy to try to help you during office hours if you run into problems.

Start early, ask lots of questions, and have fun! Don’t hesitate to ask me, the prefect, or the lab assistants for help if you’re struggling!

Acknowledgments
Parts of this assignment were originally written by Jeff Ondich and Anna Rafferty. Later modifications were made by Layla Oesper, Eric Alexander, and Titus Klinge.