Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

Java vs C: Object-Oriented vs Procedural

In java everything breaks down into objects. Each object has certain capability and
objects are reusable. While C is a procedural program ie. It will start
at the top and work its way down in a linear fashion. Although the code might re-
route to different points in the program, it’s still following a specified
sequence

C vs Java: Low Level vs High Level


C is a low-level language. This means that your interaction with your computer
while writing in C is closer to the machine code (the ones and zeros) that is
at the lowest level of the machine. It’s still using syntax that you’ll recognize
with the English language, but it has less abstraction or distance from
machine code. Java is a high-level language: it has a syntax that’s more distant or
abstracted from the machine instructions; it’s closer to human language.
Because of this Java is typically easier to learn and use.Low level language is
harder to learn compared to high level language but its more effective.

Java is a semi interpreted language using the java virtual machine while C is a
compiled language.
Whenever you write a program—no matter what language, high or low level—it’s always
interpreted in some way by the processor. In other words, it has more
steps of translation it has to go through to run your program. An interpreted
program is like having a native speaker translate a text for you as you read it,
whereas a compiled program is like having the full text sent to you already
translated. The program has to be built by the compiler before they can run.
This means an extra step every time you make a change In your program. Interpreted
languages can run after any change without that extra step. Simply change
what you want and run it.

C vs Java: Memory
One big task that C programmers have to manage themselves is memory management.
When manipulating data in a C program, the developer needs to use calls like
‘malloc’ (memory allocation) and ‘free’ to outline whatever memory their program
will need to use. Java uses something called a garbage collector to delete
any objects that are no longer used. In other words, Java manages memory for you.

C vs Java: Portability
Portability of C is possible but with careful discipline while in case of java its
very easy.

C vs Java: Character Type


C uses 8 bit ASCII while java uses 16 bit unicode.

C vs Java: Syntax
C: #include<stdio.h>
int main(void) {
printf("Hello\n");
return 0;
}
Java: public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello");
}
}

C: for (i = 0; i < N; i++)


Java: for (int i = 0; i < N; i++)
Allocating Memory:-
C: malloc
Java: new

De-allocating memory:-
C: free
Java: Automatic garbage collector

C: int *a = malloc(N * sizeof(*a));


Java: int[] a = new int[N];

C: #include <stdio.h>
Java: import java.io.File;

C: printf("sum = %d", x);


Java: System.out.println("sum = " + x);
Output in both case: sum = (value of x)

declaring constants
C: const and #define
Java: final

Unlike Java where the output of the program can show on any screen
(external or original), file etc. , program in C can only be
shown on the original screen using printf.

C: scanf("%d %d %d",&n, &f, &a);


Java: a=Integer.parseInt(in.readLine());

In C like Java when an int or long is combined with double or float


in an arithmetic expression there is an automatic promotion to the
longest data type in this case double.
Explicit type conversion is possible in C as well as java using the
same syntax.
(Data_type)expression;

You might also like