![]() ![]() ![]() ![]() |
|
|
|
|
Adapted from John December's Presenting Java | |||
Feature | C++ | Java | C# |
---|---|---|---|
Inheritance![]() | Multiple | Single | Multiple |
Preprocessor![]() | Yes | No | Yes |
Header files | Yes | No [1] | Yes |
Operator Overloading | Yes | No | Yes |
Pointers | Yes | No | Yes |
Auto. Garbage Collection | No | Yes | Yes* |
Native multi-threading | No | Yes | Yes |
Exception handling![]() | Yes | Yes | Yes |
Encapsulation![]() | ? | ? | |
Polymorphism![]() | ? | ? |
Unlike C, a new class written in Java can extend only one class. Java supports single inheritance. However, a Java program can use many interfaces. Interfaces can be used as data types. Interfaces specify the methods the class must have.
The outcome from an Object Oriented (OO) approach to Analysis and Design is an Object Model. During the design of an application, functions are identified and grouped based on common objectives and their relationship to each other:
Preprocessors handle compiler directives that are written as comments in code.
An example:
| OO and Java Development: Guidelines and Resources by Mark.Fussell at ChiMu.com.
| ![]() ![]() ![]() |
|
Javascript | Java | MS C++ |
MS VB |
MS C# |
|||
---|---|---|---|---|---|---|---|
abstract | |||||||
as | |||||||
base | |||||||
boolean | bool | ||||||
break | |||||||
byte | |||||||
case | |||||||
cast | |||||||
catch | |||||||
char | |||||||
checked | |||||||
class | |||||||
const | |||||||
continue | |||||||
default | |||||||
delegate | |||||||
delete | |||||||
do | |||||||
double | |||||||
else | |||||||
enum | |||||||
extends | |||||||
event | |||||||
explicit | |||||||
extern | |||||||
false | |||||||
final | |||||||
finally | |||||||
fixed | |||||||
float | |||||||
for | |||||||
foreach | |||||||
function | |||||||
future | |||||||
generic | |||||||
goto | |||||||
if | |||||||
implements | |||||||
implicit | |||||||
import | Imports | ||||||
in | |||||||
inner | |||||||
instanceof | |||||||
int | Integer | int | |||||
interface | |||||||
internal | |||||||
is | |||||||
lock | |||||||
long | |||||||
namespace | |||||||
native | |||||||
new | |||||||
null | |||||||
object | |||||||
operator | |||||||
outer | out | ||||||
override | |||||||
package | |||||||
params | |||||||
private | |||||||
protected | |||||||
public | |||||||
rest | |||||||
readonly | |||||||
ref | |||||||
return | |||||||
sbyte | |||||||
sealed | |||||||
short | |||||||
sizeof | |||||||
stackalloc | |||||||
static | |||||||
strictfp | |||||||
string | |||||||
struct | |||||||
super | |||||||
switch | |||||||
synchronized | |||||||
this | |||||||
throw | |||||||
throws | |||||||
transient | |||||||
true | |||||||
try | |||||||
typeof | TypeOf | ||||||
uint | |||||||
ulong | |||||||
uchecked | |||||||
unsafe | |||||||
ushort | |||||||
using | |||||||
var | |||||||
virtual | |||||||
void | |||||||
volatile | |||||||
while | |||||||
with |
With C#, a keyword can be used as a variable name by appending the "at" symbol @ in front of the name, such as @Xor.
| ComplexityMcCabe suggests that developers should keep each module's cyclomatic complexity number below 10. This numer defines the minimum number of tests to exercise a complete basis set of paths through the control flow graph of a single module. v(G) is calculated by adding up every decision in the module — 1 for each if and while statement, one for each edge and node. called predicates.August 1996 NIST Special Publication 500-235 by Arthur H. Watson and Thomas J. McCabe
Javaprepare.com by Naveen Gabrani Data Structures & Algorithms in Java by Robert Lafore (Sams, 1998), 617 pages.
| ![]() ![]() |
|
| ![]() ![]() |
| ![]() ![]() |
| ![]() ![]() |
| ![]() ![]() |
| ![]() ![]() |
| . | ![]() ![]() |
| ![]() ![]() ![]() |
Assignment Operators
With y = x++; the value assigned to y is the original value of x.
| ![]() ![]() ![]() |
| ![]() ![]() ![]() |
|
Operator | Description | Sample Coding | Before | After | |||
---|---|---|---|---|---|---|---|
x | y | x | y | ||||
* | Multiplication | x = x * y | 5 | 7 | 35 | 7 | |
/ | Division | x = x / y | 35 | 7 | 5 | 7 | |
% | Modulus (remainder) | x = x % y | 21 | 5 | 1 | 5 | (5 * 4) = 20 |
+ | Addition | x = x + y | 12 | 27 | 39 | 27 | |
- | Subtraction | x = x - y | 39 | 12 | 27 | 12 |
One use for Modulus is to determine whether aNumber is odd or even: calculate aNumber modulus 2. A result of zero means aNumber is even.
|
Operator | Description | Sample Coding | Result if x=6, y=5 | Result if x=5, y=5 | |
---|---|---|---|---|---|
<< | shift left (multiply by power of 2) | . | . | . | Trailing bits are discarded. Java does not have the Assembly languages rotate operation to define the value of such bits. |
>> | shift right (divide by power of 2) | . | . | . | Leading bits are padded with zero. |
>>> | unsigned (logical) shift right | . | . | . | Java only because (unlike C/C++) Java numeric types (except char) are signed. Don't use for data typed as byte because promotion occurs before the operator is applied. |
|
Operator | Description | Sample Coding | Result if x=6, y=5 | Result if x=5, y=5 |
---|---|---|---|---|
< | Less than | x < y | false | false |
<= | Less than or equal to | x <= y | False | True |
> | Greater than | x > y | True | False |
>= | Greater than or equal to | x >= y | True | True |
. | instanceof | . | . | . |
= = | Equals | x = = y | False | True |
!= | Not equals | x != y | True | False |
To compare the values referenced by two objects rather than the existance of the objects,
use the Boolean.equals() method
or the
to the HTTP 1.1 value of:
So defensive programmers should avoid using an equal operator which expects a precise match to check for “application/x-www-form-urlencoded”. Programmers should instead check whether the value is included in the CONTENT_TYPE string. In Perl, the code is:
This script would work for Internet Explorer 5.0, Navigator 4.x, and Navigator 5.0 because it allows for the inclusion of a charset specification in the CONTENT_TYPE string.
Column | Value |
---|---|
1st | 1 |
2nd | 2 |
3rd | 4 |
4th | 8 |
5th | 16 |
6th | 32 |
7th | 64 |
8th | 128 |
9th | 256 |
10th | 512 |
11th | 1028 |
Sum | 1184 |
With SQL 7, the IF statement below following is a bit-wise comparison:
A bit mask value of 14 tests whether the 2nd or 3rd or 4th columns of tableX have been updated. (values 2 + 4 + 8 = 14).
The bitmask to verify if columns 6, 8, or 11 was modified can be determined by the following: power(2,(6-1)) + power(2,(8-1)) + power(2,(11-1)) = 1184.
To detect if any rows have been updated:
To verify that all the rows in question have been updated:
Question: What bitwise operation was calculated if 5=0101 and 4=0100, return a result of 5?
Answer: AND, XOR, or OR
|
Operator | Description | Sample Coding | Condition x | Condition y | Result z |
---|---|---|---|---|---|
& | AND | z = x & y | true | false | false |
^ | XOR (eXclusive OR) | z = x ^ y | true | true | false |
| | OR | z = x | y | true | false | true |
&& | Optimized AND | z = x && y | true | false | false |
|| | Optimized OR | z = x || y | true | false | true |
For example: The b increment operation may not be performed if a is less than or equal to 0.
if((a > 0) && (b++ < 1)) { // do something }
Operator | Description | Sample Coding | Expanded Equivalent Coding | Before x,y | After x,y | Result z |
---|---|---|---|---|---|---|
? : | If-then-else |
z = x>y ? 2*x : 2*y |
if (x > y) { z = 2*x; } else { z = 2*y; } | 10, 30 | 10, 30 | 60 |
Operator | Description | Sample Coding | Expanded Equivalent Coding | Before x,y | After x,y |
---|---|---|---|---|---|
&= | AND Assignment | x &= y | x = x & y; | true, false | false, false |
|= | OR Assignment | x |= y | x = x | y; | true, false | true, false |
^= | XOR Assignment | x ^= y | x = x ^ y; | true, true | false, true |
A | B | AND | XOR | OR |
---|---|---|---|---|
0 | 0 | 0 | 0 | 0 |
0 | 1 | 0 | 1 | 1 |
1 | 0 | 0 | 1 | 1 |
1 | 1 | 1 | 0 | 1 |
0 OR 0 produces 0. Any 1 produces 1.
1 AND 1 produces 1. Unless all are 1, it's 0.
0 XOR 1 produces 1, as does
1 XOR 0 produces 1. All others produce 0.
|
Operator | Description | Sample Coding | Expanded Equivalent Coding | Before | After | ||
---|---|---|---|---|---|---|---|
x | y | x | y | ||||
+= | Addition Assignment | x += y; | x = x + y; | 12 | 27 | 39 | 27 |
-= | Subtraction Assignment | x -= y; | x = x - y; | 39 | 12 | 27 | 12 |
*= | Multiplication Assignment | x *= y; | x = x * y; | 5 | 7 | 35 | 7 |
/= | Division Assignment | x /= y; | x = x / y; | 35 | 7 | 5 | 7 |
%= | Modulus (Remainder) Assignment | x %= y; | x = x % y; | 21 | 5 | 1 | 5 |
| ![]() ![]() ![]() |
Related:
![]()
| Your first name: Your family name: Your location (city, country): Your Email address: |
Top of Page ![]() Thank you! |