Friday 29 March 2013

Java and C


Java is derived from C. many of its syntactic characteristics are similar to C.
However, There are some huge differences
(1). Relational operators
Relational Operator works the same way but returns different results:
>, >=, =, <=, <, ==, !=
 

In Java, they returns true and false
In C/C++, they returns 1 or 0
 

In C/C++,              a value of zero means false.              any value that is not zero means true ( <<very important )

(2). unary operator
The following unary operators are available C/C++ but not in Java
~                 invert the bits of a word
*                  pointer dereference
&                 pointer creation
(type)           cast (i.e., forceable type conversion)
sizeof           # of bytes in operand or data type
->                 pointer dereference with field selection

(3).  No goto statement
Java doesn't support a goto statement. Use of goto except in certain well-defined circumstances is regarded as poor programming practice. Java adds exception handling and labeled break and continue statements to the flow-control statements offered by C. These are a good substitute for goto.

(4). Command-line Argument
args[ 0 ] is first argument supplied (in Java !)
args[ 0 ] is program name (in C !) 

 
(5). Default values
in C , All Variables deault contains garbage value but in Java it has default values.

Variable Type Default Value
Object reference null
byte, short, int, long 0
float, double 0.0
boolean false
char '\u0000'

(6).Variable declarations anywhere
C requires local variable declarations to be made at the beginning of a method or block, while Java allows them anywhere in a method or block.

(7).Forward references
The Java compiler is smarter than the C compiler, in that it allows methods to be invoked before they are defined. This eliminates the need to declare functions in a header file before defining them in a program file, as is done in C.

(8). Method overloading
Java programs can define multiple methods with the same name, as long as the methods have different parameter lists.

(9).No global variables
Java defines a very clean namespace. Packages contain classes, classes contain fields and methods, and methods contain local variables. But there are no global variables in Java, and, thus, there is no possibility of namespace collisions among those variables.


For More detailed difference ::

http://wiki.answers.com/Q/What_is_the_difference_between_Java_and_the_C_programming_language
http://www.durofy.com/programming/10-major-differences-between-c-and-java/

Kindly Bookmark and Share it:

0 comments :

Post a Comment

Any Query ? any suggestion ? comment here

 

Recent Post

Recent Comments

© 2010 IamLearningHere Template by MBT