CMPS 134 Fall 2022
Preview for Test #1 (Oct. 5)
Among the things that you should know:
- Java is the programming language that we are using in this
course as a vehicle to learn about computer programming.
- jGrasp is the "integrated development environment" (IDE)
that we are using (in lectures and labs) to aid us in developing
and testing Java code.
- Among the kinds of errors that can be present in computer programs
are syntax, logical, and run-time.
Syntax errors, which are detected by the Java compiler, are analogous
to errors in English grammar.
A run-time error occurs when a program's execution is aborted
due to an unexpected condition occurring (e.g., invalid input (such as
a real number or a string of characters when an integer was expected)),
division by zero). A logical error is caused by a programmer making
a mistake that results in a program that, when executed, behaves in
a way that was not intended. For example, the program could produce
output that is not correct with respect to its input.
Run-time errors are often the result of an underlying logical error.
- Comments appear in programs to provide useful information to human
Among the kinds of information that comments might convey are
- the program's intended behavior/purpose
- the author(s) (i.e., who developed the code)
- the date(s) on which the program was modified
- an explanation of the reasoning that justifies certain
code segments being written as they were
- Java has eight primitive data types. Among them are
the four that are most imporant in this course:
int (for representing integers (e.g., 13)),
double (for representing real numbers (e.g., 27.35)),
(for representing true and false),
and char (for representing character values
(e.g., '$', 'A')).
- How to evaluate arithmetic and boolean expressions involving
literals (e.g., 32, 1.52, true), variables,
arithmetic operators (+, -, *, /,
and relational operators (<, <=, >,
>=, ==, !=).
Examples (where k, m, x, etc., are variables whose data types and
values would be indicated on the test):
|5 + k * 8||k / 4||(k+3) % m||5 * 2.5
|(char)('A' + 4)||(double)(k - 2)||Math.abs(k)
||(3 * k) / m * x
- How to evaluate expressions involving calls to methods in
the java.lang.String class.
Examples (where s and t are variables of
type String and k and m are of type
int, all having values indicated on the test):
|s + t.substring(k)||s.indexOf('A')
||s.substring(s.indexOf(','), s.lastIndexOf(' '))
- You should be able to "trace execution" of a Java program
involving variable declarations, assignment statements, methods,
calls to methods (possibly with parameters being passed and/or values
being returned by the method), for-loops, and String objects.
For example, you may be given a Java program and asked to show
what output it would produce if it were executed.
- Given a Java program, you should be able to identify pieces of it
that are examples of the following elements of the Java language:
- key/reserved word (e.g., class, int,
- comment (e.g., /* This program does nothing. */)
- assignment statement (e.g., x = 3.5 or
grossPay = hoursWorked * hourlyWage)
- numeric literal (e.g., 3.5 in line above)
- String literal (e.g., "Hello, World!")
- variable declaration (e.g., int numHours)
- method call (e.g., drawRightTriangle(k+1))
- actual parameter/argument (e.g., the k+1 in line above)
- method heading (e.g.,
public static void drawRightTriangle(int size))
- formal parameter/argument declaration
(e.g., int size in line above)
- class heading (e.g., public class Stupid)
- Given a simple computational task that can be accomplished using
assignment statements, arithmetic or boolean expressions,
calls to methods in the java.lang.Math class,
and possibly a for-loop, you should be able to
write Java code (perhaps a method body) that performs it.
- Given a number of inches, express it in terms of feet and inches.
- Print each even integer in the range 4..51.
- Print the sum of the odd integers in the range 0..13.
- Print the sum of the square roots of the integers in the range 0..13.
- "Draw" a figure similar to ones drawn by the
DrawFiguresWithLoops application program.