by Ron Zucker
|
type |
COBOL |
Java |
|
Sequential |
move c to a, [b,...] |
a=[b=...]c; |
|
Sequential |
add b to a |
a=a+b; or a+=b; |
|
Sequential |
add b to a giving c |
c=b+a; |
|
Sequential |
add 1 to a |
++a; or a++; |
|
Selection |
if cond |
if (cond) |
|
Selection |
evaluate a |
switch (a) |
|
Repetition, counting |
perform varying a from start by inc
until cond |
for (a=start;cond;a+=inc)
|
|
Repetition, |
perform [test before] until cond |
while (cond) |
|
Repetition, |
perform test after until cond |
do |
|
I/O keyboard |
accept a |
BufferedReader input=new BufferedReader(new
InputStreamReader(System.in)); |
|
I/O screen |
display a |
System.out.println(a); |
|
I/O file |
open input filea |
BufferedReader filea=null; |
|
I/O file |
read filea into recorda |
recorda=filea.readLine(); |
|
I/O file |
open output filea |
filea=new DataOutputStream(new FileOutputStream("extfile.dat")); |
|
I/O file |
write recorda |
filea.writeBytes(recorda+"\r\n"); |
|
I/O file |
close filea |
try |
|
Array |
05 table occurs n times. |
datatype [ ] table; |
|
Comments |
asterisk(*) in column seven |
// single line comment |
The operators are used in conditions referenced by cond above
|
COBOL |
Java |
|
equal to |
= = |
|
not equal |
!= |
|
greater than |
> |
|
greater than or equal |
>= |
|
less than |
< |
|
less than or equal |
<= |
The operators are used in conditions referenced by cond above and are listed in Java precedence order
|
COBOL |
Java |
|
AND |
& |
|
Note: exclusive or (XOR) is not provided in COBOL but may
be given as: |
^ |
|
OR |
| |
|
AND |
&& (short circuit AND, if left side evaluates false right side is not evaluated) |
|
OR |
|| (short circuit OR, if left side evaluates true right side is not evaluated) |
|
Prec |
Operator |
Order |
Comments |
|
1 |
++,--, |
R to L |
~ is bitwise complement |
|
2 |
*,/,% |
L to R |
% is mod |
|
3 |
+,- |
L to R |
+ may also be used for string concatenation |
|
4 |
<<,>>,>>> |
L to R |
>>> is right shift with zero fill, while >> is right shift with sign propogation |
|
5 |
<.<= |
L to R |
instanceof returns true if the object is an instance of the a class or subclass of the object |
|
6 |
= = |
L to R |
boolean equality and not equal |
|
7 |
& |
L to R |
& maybe a bitwise AND or a boolean value |
|
8 |
^ |
L to R |
^ maybe a bitwise XOR or a boolean value |
|
9 |
| |
L to R |
| maybe a bitwise OR or a boolean value |
|
10 |
&& |
L to R |
always a boolean |
|
11 |
|| |
L to R |
always a boolean |
|
12 |
?: |
R to L |
always a boolean |
|
13 |
=, |
R to L |
assignment operators |
|
Sequence |
Char |
|
|
\b |
BS |
Backspace |
|
\f |
FF |
Formfeed |
|
\n |
LF |
Newline |
|
\r |
CR |
carriage Return |
|
\\ |
\ |
backslash |
|
\' |
' |
single quote |
|
\" |
" |
double quote |
|
\? |
? |
question mark |
Additions, corrections, comments please email to rzucker@unf.edu(click to send mail)