Why C and Java have many language constructs in common
 

Java is a "descendent language" of C:

  • 1972: Dennis Ritchie developed C at Bell Labs to write the UNIX operating system

  • 1979: Bjarne Stroustrup at Bell Labs added object oriented features to C and called the new language C++. ( click here )

    C++ gradually expands with (too) many features...

  • 1995: James Gosling at Sun Microsystem designed a stripped down and safer version of a C++ based object oriented language called Java ( click here )

Language constructs that are identical in C and Java
 

Signed number data types

   byte (Java) / char (C)
   short
   int
   long

   float
   double
   

Note: C also has unsigned integer data types

Language constructs that are identical in C and Java
 

Syntax to define variables:

   char  a;      // char data type in C is equivalent to byte in Java
   short b = 4;  // Initialization has the same syntax
   int   c;
   
   float  x;
   double y;
   

Language constructs that are identical in C and Java
 

The arithmetic operators:

   +   -   *   /   %  
 

The assignment operators:

   =   +=   -=   *=   /=   %=  
 

The pre/post increment/decrement operators:

   ++x      --x 
   x++      x-- 

Language constructs that are identical in C and Java
 

The comparison operators:

    <   <=   >   >=   ==   !=    
 

The logical operators:

    &&      ||        !   

Language constructs that are identical in C and Java

All the statements:

   Assignment statement:

            x = (a + b) * (c + d % e);

   Conditional statement:

            if ( a > b )
               max = a;
            else
               max = b;

   Switch statement:

            switch ( x )
            {
	       case 1: y = 1; break;
	       case 2: y = 2; break;
	       default: y = 3; break;
            }
   

Language constructs that are identical in C and Java

All the statements: (continued)

   Loop  statement:

            while ( x < 10 )
	       x++;

	    for ( i = 0; i < 10; i++ )
	       sum += i;

	    do
	    {
	       x = x + 1;
	    } while (x < 10)

   Loop control statements:

            continue
	    break