C vs. Java

Similarities

Subject Keywords/Syntax Comments
Primitive Types int, short, long, float, double  
Control if, else, for, while, do, switch, case, default, break, continue, return note Boolean expressions below
Operators assignment, arithmetic, relational operators, logical operators, bitwise operators, casts, conditional operator note Boolean expressions below
Punctuation { } (braces for program blocks)
[ ] (brackets for array indexing)
; (semicolon for ending (most) statements)
, (comma for delimiting parameters)
 

A Little Different

Subject C Java
char Type holds ASCII characters holds UNICODE characters
Printing to Standard Output printf System.out.printf
Java also has System.out.println and System.out.print
Boolean Expressions evaluates to 0 or 1 evaluates to true or false
Fixed Size Array int foo[13]; int[ ] foo = new int[13];

A Lot Different

Subject C Java
Program File Names anything.c public class Foo must be in Foo.java
Main Function main( ) { ... } public static void main(String[ ] args) { ... }
must be inside a public class Foo { ... }
Simple Functions int bar(double a) { ... }
call by bar(a)
public static int bar(double a) { ... }
must Foo.bar(a)
Structure Functions int bar(struct Foo *x, double a) { ... }
call by bar(x,a)
public int bar(double a) { ... }
must be inside public class Foo { ... }
call by x.bar(a)
Booleans use ints as booleans separate boolean type and expressions
Strings char * and many char * functions String class, + operator and many String methods
References pointers arrays and objects
no pointer arithmetic
Declare Data Structures struct separate class file
Allocating Memory calloc, malloc, realloc new
Accessing Structures . (dot) and -> only . (dot)
Deallocating Memory free automatic garbage collection
Input scanf and fscanf Scanner and various java.io classes
Output fprintf PrintStream and other java.io classes
Declarations from other Files #include header files import packages
or use fully qualified name, e.g., java.lang.Math.sqrt(2)
Compiler Directives preprocessor (#define, #ifdef, etc.) annotations (@SuppressWarnings, @Override, etc.)