Professional Documents
Culture Documents
Java Language Specification – technical definition of the Java programming language’s syntax and semantics
API – Application Programmers Interface – library – predefined classes and interfaces for developing Java programs
JDK – Java Development Kit
JRE – Java Runtime Environment
JVM – Java Virtual Machine
IDE – Integrated Development Environment – e.g. BlueJ, Eclipse, NetBeans
Identifiers – program defined name that represents some element of a program, eg variables, class or method names
Syntax errors
Runtime errors
Logic errors
• Primitive
numeric: integer – byte, short, int, long
decimal – float, double
character: char
(represented internally by numbers, Java uses Unicode, Appendix B)
boolean: boolean
Integer Division
• Assignment operators: =
• Arithmetic operators: +, -, *, /, %
• Augmented assignment operators: +=, -=, *=, /=, %=
• Concatenation operator: +
• Cast operators: (typecasting) (int), (long), (double), etc.
• Logical operators: &&, ||, !
• Comparison operators: ==, !=, >, <, >=, <=
• Increment & decrement operators: ++, --, +=, -=
( prefix : ++num, postfix: num++)
CMPP269 Module 1 -5 Chapter 1-5 Review
• if Statement
if (BooleanExpression)
{
statement
statement
Etc.
}
• if – else statement
if (BooleanExpression)
{
statement;
statement;
Etc.
}
else
{
statement;
statement;
Etc.
}
• nested if statements
if (BooleanExpression)
{
if (BooleanExpression2)
{
statement;
statement;
Etc.
}
else
{
statement;
Etc.
}
}
else
{
statement;
Etc.
}
CMPP269 Module 1 -5 Chapter 1-5 Review
• if – else – if
if (BooleanExpression1)
{
statement
statement
Etc.
}
else if (BooleanExpression2)
{
statement;
statement;
Etc.
}
else
{
statement;
statement;
Etc.
}
• switch statement
switch (testexpression)
{
case value_1:
statement;
break;
case value_2:
statement;
break;
default:
statement;
break;
}
Loops
• while
while (BooleanExpression)
{
statement;
statement;
Etc. (something must happen that makes to BooleanExpression false to exit the loop
}
• do – while
do
{
statement;
statement;
Etc. (something must happen that makes to BooleanExpression false to exit the loop
}
while (BooleanExpression);
• for
• nested loops
• sentinel values
• pretest loops: while, for
• post test loops: do-while
CMPP269 Module 1 -5 Chapter 1-5 Review
1. Does the problem (or portion of the problem) seem to make a decision and then execute a group of instructions
only once? If yes, it is probably a type of branch.
2. Does the problem (or portion of the whole problem) seem to require that a series of instructions are run
multiple times depending on some condition? If so, it is probably a loop.
2. Does the problem seem to be related to one value falling into a range of different values which controls the
instructions that are to be run? If so, consider using an if-else if construct.
3. Does the problem seem to do one thing if the condition is true and another thing if the condition is false? If
so look at a simple if-else construct.
4. Does the problem seem to do something if a condition is true and nothing if the condition is false? If so look
at a simple if construct.
Loops
1. Does the problem decide when to terminate based on some special value input from the user or by
detecting some special condition (e.g. the end of a file if you are file processing)? If yes, then it is best to
solve the problem with a while or do-while construct.
//priming read
while (amount !=0)
{
//body of instructions to be executed over and over again
// secondary read
}
2. Does the problem seem to be based on the value of a variable going up in a very specific increment (eg by 1
or by 10, etc.) and the calculations within the loop are based on that value ? If so, a for loop will yield the
best solution.
Escape Characters
\b – backspace
\n – new line
\t – tab
\r – carriage return
\f – formfeed
\\ - to put a \ in a string
\” - to put a ” in a string
Printing Output
Use concatenation operator + to join multiple part into one output string.
Formatting Output
Flags:
- left justify
+ outputs a + or – for numerical values
0 forces numerical value to be zero padded
, grouping separator for number >1000
space will display a minus sign if number is negative or a space if it is positive.
Conversion Characters:
d decimal-integer
f floating point
c character
C uppercase the letter
s String
S Uppercase all the letters in a string
n newline – use %n instead of \n for greater platform compatibility
CMPP269 Module 1 -5 Chapter 1-5 Review