To get started understanding the differences between Java and Python and create a reference sheet for yourself to use throughout the term as you write your own Java programs.
This is a lab assignment that you’ll be handing in on Moodle. You should complete it on Wednesday Sept 15th, but it isn’t due until Friday Sept 17th at 5:00pm Central.
You should work on this with your in-class partner, but you both need to submit separately. If you finish it outside of class without your partner, note which sections you completed together and which you completed separately in the header of the document.
Learning your second programming language is different from learning your first. You already know about many of the nearly-universal language constructs: assignments, loops, conditionals, functions, operators, (often) 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. That doesn’t mean the second one is easy to learn — “easy” starts to happen around the fourth or fifth language — but there are definitely opportunities to learn more efficiently the second time around. This lab will guide you through making a reference sheet of the important things in Java.
a. Introduce yourselves!
b. Download the Comparing Python and Java project.
c. Mount the COURSES drive and move your project into your STUWORK folder so that you don’t lose it. If you don’t do this, everything you write will disappear when you log out!!!!
d. Open the folder in Visual Studio Code and make a new file
ReferenceSheet.java. Be sure to save it to your STUWORK folder so you don’t lose it!
The files in ``Comparing Python and Java’’ contain programs in both Python and Java that do the same things and these will be a valuable resource in figuring out how to do things in Java. To get you used to looking through these files, I’m going to ask you to find examples of doing various common programming tasks and save them into your reference sheet. If you are stuck, I recommend looking through the Python examples until you find what you are looking for, and then looking at the corresponding Java example.
a. First things first, you should label each of the code snippets that you find with a comment so that you know what they do. Find how to do both multi-line and single line comments in Java and save examples in your reference sheet.
b. Java requires a fair amount of ‘boiler plate’ code to do even a basic Hello World. Find an example of that boiler plate code and put it in your reference sheet (with a comment).
c. Finally, find an example of making a variable and add it to your reference sheet with a comment.
Next, let’s figure out how to do some interesting things in Java.
a. Find an example of a for-loop and while-loop and put it in your reference sheet.
b. Find an example of a conditional and put it in your reference sheet.
c. Find an example of printing and put it in your reference sheet.
d. Find an example of reading from a FILE and put it in your reference sheet.
We’ll talk about lists more in depth in the coming weeks, but you probably will want to use one sooner rather than later.
Find examples of:
a. Making a list
b. Adding to a list
c. Getting an item from a list
d. Looping over the items in a list
Here are some other interesting things you might want to do. If any of these are things you aren’t familiar with at all, please ask your partner, me, or the prefect.
Find examples of:
a. Getting a command line argument from the user.
b. Making a constructor for a class
c. Instantiating an instance of a class
d. Calling methods of a class
e. Importing a Java library
f. Getting a random number (note there are three steps required)
If there is anything else that you see in these files that you’d like to keep track of how to do, feel free to add it to your reference sheet; it’s for you after all!
Finally, you probably want to actually run a Java program at some point here right?
To run a Java program, you have to first compile it:
And then run it (notice no
Put those two commands in your reference sheet as well.
Grading and submission
This activity is graded entirely on effort.
You are expected to finish it and make sure that you understand it, but you will get full credit as long as you submit something that shows that you attempted all the exercises by the deadline.
Submit your file
ReferenceSheet.java on Moodle.
Remember to note who your in-class partner was and what portion you completed with them and what portion you completed separately.
If you got help from anyone else (or any outside sources), remember to cite them in the header of the file.