0% found this document useful (0 votes)
3 views2 pages

Java vs C: Syntax and Key Differences

The document compares Java and C programming languages, highlighting their syntax and rules. Key differences include Java's object-oriented structure with classes and garbage collection, while C is procedural with standalone functions and manual memory management. Additionally, Java supports exception handling, whereas C does not.

Uploaded by

clarissamay33
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Java vs C: Syntax and Key Differences

The document compares Java and C programming languages, highlighting their syntax and rules. Key differences include Java's object-oriented structure with classes and garbage collection, while C is procedural with standalone functions and manual memory management. Additionally, Java supports exception handling, whereas C does not.

Uploaded by

clarissamay33
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Java vs C Syntax and Rules

Java Syntax and Rules


- Program Structure: Code inside classes, entry point is public static void main(String[]
args).

- Case Sensitivity: Java is case-sensitive (age vs Age are different).

- Identifiers: Must start with letter, underscore (_), or dollar sign ($). Cannot start with a
number or use reserved keywords.

- Data Types: Primitive (int, double, char, boolean, etc.) and Non-primitive (String, arrays,
objects).

- Keywords: Reserved words like class, public, static, if, else, etc.

- Statements: End with semicolons (;).

- Braces: Curly braces { } group statements.

- Comments: // for single-line, /* */ for multi-line, /** */ for documentation.

- Operators: Arithmetic (+, -, *, /, %), Assignment (=, +=, etc.), Comparison (==, !=, >, <),
Logical (&&, ||, !).

- Control Structures: if-else, switch, loops (for, while, do-while).

- Arrays: Store multiple values of the same type.

- Methods: Defined inside classes with return types (int, void, etc.).

- Classes and Objects: Objects created with new keyword.

- Access Modifiers: public, private, protected, default.

- Inheritance: Classes extend other classes.

- Interfaces: Define methods a class must implement.

- Exception Handling: try-catch-finally to handle errors.

C Syntax and Rules


- Program Structure: Code inside functions, entry point is int main().

- Case Sensitivity: C is case-sensitive.


- Identifiers: Must start with letter or underscore (_), cannot use $ like Java.

- Data Types: int, float, double, char, void. No objects or classes.

- Keywords: Reserved words like int, return, if, else, for, while.

- Statements: End with semicolons (;).

- Braces: Curly braces { } group statements.

- Comments: // for single-line, /* */ for multi-line.

- Operators: Arithmetic, assignment, comparison, logical, increment/decrement (same as


Java).

- Control Structures: if-else, switch, loops (for, while, do-while).

- Arrays: Store multiple values of the same type.

- Functions: Standalone functions, not inside classes.

- Structs: Custom data types, alternative to objects.

- Pointers: Variables that store memory addresses.

- Memory Management: Manual with malloc() and free().

- No Exception Handling: Errors handled with return values or codes.

Key Differences: Java vs C


- Java is Object-Oriented, C is Procedural.

- Java requires classes, C uses standalone functions.

- Java has garbage collection, C requires manual memory management.

- Java supports exception handling, C does not.

- Java has objects, inheritance, and interfaces, C has structs and pointers.

You might also like