Overview

In this reading, you will be introduced to the basics of the Java programming language. You’ll learn how to use the DrJava programming environment to do things such as perform calculations using numbers, print things to the screen, and create strings of text. You’ll also learn how to create and work with variables.

Don’t expect to fully understand everything on your first reading: you’ll likely need to work through the material several times before you get comfortable. I HIGHLY recommend that you keep DrJava open while reading so you can type in the code you read about; students who make this a habit tend to do better in the class.

Required Reading

Chapter 2 (pp. 14-35) from the course textbook.

Learning Objectives

BASIC Learning Objectives

Each student will be responsible for learning and demonstrating proficiency in the following objectives PRIOR to the class meeting. The reading quiz will test these objectives.

  1. Compare and contrast objects and classes.
  2. Describe the role of each pane in the DrJava program.
  3. Evaluate a series of Java statements using the Interactions Pane in DrJava, including basic math operations and printing text to the screen.
  4. Evaluate an expression that casts an int value to a double (or vice versa), without the use of DrJava.
  5. Evaluate an expression that uses a relational operator, without the use of DrJava.
  6. Create a new string by concatenating (i.e. appending) other strings.
  7. Declare and assign values to primitive variables and String variables, using proper variable naming.
  8. Given a sequence of Java statements, determine the contents of a specific primitive or object variable.

ADVANCED Learning Objectives

The following objectives should be mastered by each student DURING and FOLLOWING the class session through active work and practice.

  1. Describe the difference between the “=” operator and the “==” operator in Java.
  2. Trace the execution of a series of Java statements using a memory map.

Pre-class Exercises

These exercises are geared towards mastering the BASIC learning objectives listed above. You are expected to submit them before class and it is highly recommended that you complete them before attempting the reading quiz.

  1. Textbook Problem: 2.11

  2. Textbook Problem: 2.17 (please don’t use your real credit card number though!)

  3. Use the DrJava Interactions Pane to calculate the area of a circle whose radius is 7. Store the result in a variable name “area” and then print it out. The equation for the area of a circle is π × r2. You may use either simplify π to 3.14 or use the Java’s built-in Math.PI.

    Copy and paste the text you entered as well as what was printed.

  4. You are given the following sequence of Java statements.

    int x = 8;
    int y = 3;
    String s1 = "I like the number " + x;
    String s2 = "You like the number " + y;
    String s3 = s1;
    String s4;

    If you were to execute this code, what would be stored in each of the variables (x, y, s1, s2, s3, and s4)?