Programming Languages Chapter 2 This Talk About The History Java And Describe Objects And

subject Type Homework Help
subject Pages 3
subject Words 957
subject Authors Barbara Ericson, Mark J. Guzdial

Unlock document.

This document is partially blurred.
Unlock all pages and 1 million more documents.
Get Access
page-pf1
Chapter 2
In this chapter we talk about the history of Java and describe objects and classes involved in a
restaurant. One good activity is to have the students role-play the people in a restaurant. You
can ask for students to play the greeter, customer, waiter, and chef. Tell them the task is to get
the customer fed and then tell them to go. Point out what they are doing and what data they need
to keep track of. For example, a greeter has a chart of all the tables in a restaurant, a waiter
knows the tables she is waiting on and the orders for the customers, a chef knows what food is
available and how to prepare it. Point out other objects like order, bill, and food. Point out that
there can be many objects of the same type, like 6 waiters, 3 chefs, and hundreds of customers.
In section 2.2 we introduce DrJava. You don’t have to use DrJava to use this book. However,
DrJava is free and has an interactions pane which allows students to type in Java statements and
executes them without having to create a class and a main. This is the main reason we use
DrJava. Many Java books start out with the students typing all Java code in the main method
But, even if you use another development environment consider using DrJava in class to show
your students what happens when you type things in the interactions pane. Students both enjoy
seeing things done live and enjoy when the teacher makes a mistake. Students learn from our
mistakes, so don’t be afraid to make some. Make sure that your students copy the bookClasses
directory from the CD to a directory they can modify and add the path to that directory to the
classpath in your development environment. Instructions for how to do this in DrJava are in
page-pf2
Figure 1. Adding bookClasses to the Extra Classpath List
Two things you might want to do as the instructor with DrJava are turn on line numbers and
change the font to a bigger font. You can do each of these in the Preferences Window. Click on
“Edit” and then on “Preferences”. The Preferences window will show. Click on “Display
Figure 2. Showing Line Numbers
page-pf3
Figure 3. Changing the Font
In section 2.3 we introduce Java math operations. We show how to print the results of an
expression to the console. We emphasize that parentheses must match: you must have a closing
parenthesis for each opening parenthesis. We show the difference between integer division and
floating point division and introduce casting as one way to stop the truncation to integer. We
introduce Java relational operators. We discuss the Java primitive types and how much memory
At some point in here show students that if they make is mistake when typing in the interactions
pane they can use the up arrow to bring up the last thing they typed and then use the left arrow to
get to the place that needs to be fixed and fix it.
In Section 2.4 we introduce variables, including declaring a variable, using variables in
calculations, showing memory maps of primitive type variables, and object variables. We also
point out the difference between primitive type variables and object variables. An activity to
underscore this is to use cups to hold liquid for primitive variables and cups that hold some
reference to other cups (not directly the address, because object references are not just the
address of the object in memory) for object variables. You can also do this with students. Tell

Trusted by Thousands of
Students

Here are what students say about us.

Copyright ©2022 All rights reserved. | CoursePaper is not sponsored or endorsed by any college or university.