Lab_02 - CS1026a - Fall 2010 Lab 2: Java Expressions &...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS1026a - Fall 2010 Lab 2: Objectives: 1. To gain an initial understanding of expressions and variables in Java. 2. To practice with expressions using the Interactions pane of DrJava. 3. To gain some practice creating, compiling and running a program with DrJava. 4. To gain more understanding of compiler errors (syntax errors). Preparation: 1. You must have done Lab 1. It is assumed that you have tried out the following in DrJava: a) Using the Interactions pane to try out Java statements and arithmetic expressions b) Using the Definitions pane to type in a complete Java program c) Saving, compiling and running the complete Java program. d) The Java statement that prints on the screen, i.e. System.out.println(…); 2. Go over the Lecture Notes: Topic 2. 3. Textbook reading (optional): Chapter 2 of the book, particularly sections 2.1, 2.2 and 2.3. Exercise 1: Expressions in DrJava’s Interactions Pane In this exercise, you will be dealing with arithmetic expressions, which have a numeric value, for example 3 + (5 * 6) relational expressions, which have a Boolean value (true or false), for example 4 >= 0 String expressions, which are created by concatenating two strings, for example “CS” + “026” Expressions are not complete Java statements; in a Java program, they would have to be part of a Java statement. Java statements are formed according to Java syntax (the rules of the Java language) and must end with a semicolon. Examples of Java statements are: the Java statement that prints to the screen, System.out.println(…); declaration statement, for example int x; assignment statement, for example x = 7;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
In DrJava’s Interactions pane, we can try out Java statements, and we can also try out just expressions to see what they evaluate to. a) Trying out expressions by themselves : In the Interactions pane, type each of the following sequences to see what the expressions are evaluated to: i. int x = 7; x + 5 (x + 5) * 3 x + 5 * 3 Question: Why are the values of the last 2 expressions different? ii.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/06/2010 for the course PSYCH PSYC 1000 taught by Professor Atkinson during the Fall '10 term at UWO.

Page1 / 5

Lab_02 - CS1026a - Fall 2010 Lab 2: Java Expressions &...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online