Sunteți pe pagina 1din 4

CHANDAN MUKHERJEE 26630615 9831125100

__________________MTech (IT), BE (Computer Science), Diploma (Electrical Engg) _________________

0B C Programming vs. Java Programming


Thing C Java
type of language function oriented object oriented
basic
programming function class = ADT
unit
portability of
possible with discipline yes
source code
portability of no, recompile for each
yes, bytecode is "write once, run anywhere"
compiled code architecture
security limited built-in to language
gcc hello.c creates machine javac Hello.java creates Java virtual
compilation
language code machine language bytecode
joint gcc main.c helper1.c javac Main.java - any dependent files are
compilation helper2.c automatically re-compiled if needed
a.out loads and executes
execution java Hello interprets byte code
program
public class HelloWorld {
#include<stdio.h>
public static void main(String[]
int main(void) {
args) {
hello, world printf("Hello\n");
System.out.println("Hello");
return 0;
}
}
}

int usually 32 bit 2's


complement; int is 32 bit 2's complement;
integer types
long usually 32 bit 2's long is 64 bit 2's complement
complement
floating point float usually 32 bit; float is 32 bit IEEE 754 binary floating point;
types double usually 64 bit double is 64 bit IEEE 754

use int: 0 for false, nonzero boolean is its own type - stores value true or
boolean type false
for true
character type char is usually 8 bit ASCII char is 16 bit UNICODE

for loops for (i = 0; i < N; i++) for (int i = 0; i < N; i++)

array int *a = malloc(N * int[] a = new int[N];

_____________________________________________________________________________________
Teaches All major subjects for Engineering (BE) / MCA / BCA / Diploma / AMIE / DOEACC Students.
Project Guide for BE / MCA / BCA / Diploma Students
Address:- 80, Ramlal Dutta Road, P.O- Bhadrakali, Dist:- Hooghly, 712232. Rly Station:- Uttarpara
(Nera Amarendra Vidyapith Boys School)
CHANDAN MUKHERJEE 26630615 9831125100
__________________MTech (IT), BE (Computer Science), Diploma (Electrical Engg) _________________

declarations sizeof(*a));

arrays don't know their own a.length


array size
size
'\0'-terminated character
strings built-in String data type
array
accessing a #include <stdio.h> import java.io.File;
library
#include "math.h"
accessing a x = sqrt(2.2); x = Math.sqrt(2.2);
library function all function and variables functions have different namespaces
names are global
printing to printf("sum = %d", x); System.out.println("sum = " + x);
standard output
java.text.DecimalFormat f;
f = new
formatted printf("avg = %3.2f", java.text.DecimalFormat("#.##");
printing avg); System.out.println(f.format(avg));
System.out.printf coming to Java 1.5

reading from Java library support, but easier to use our


scanf("%d", &x); library
stdin int x = StdIn.readInt();

memory address pointer reference


manipulating
*, &, + no direct manipulation permitted
pointers
functions int max(int a, int b) static int max(int a, int b)

primitive data types, structs,


all primitive data types and references (which
pass-by-value and pointers are passed by
includes arrays), are passed by value
value; array decays to pointer
defining a data struct
class - key differene is language support for
structure defining methods to manipulate data
accessing a data a.numerator for data members,
a.numerator for elements
structure c = a.plus(b) for methods

pointer chasing x->left->right x.left.right

allocating malloc new


memory
de-allocating free automatic garbage collection
memory
_____________________________________________________________________________________
Teaches All major subjects for Engineering (BE) / MCA / BCA / Diploma / AMIE / DOEACC Students.
Project Guide for BE / MCA / BCA / Diploma Students
Address:- 80, Ramlal Dutta Road, P.O- Bhadrakali, Dist:- Hooghly, 712232. Rly Station:- Uttarpara
(Nera Amarendra Vidyapith Boys School)
CHANDAN MUKHERJEE 26630615 9831125100
__________________MTech (IT), BE (Computer Science), Diploma (Electrical Engg) _________________

memory
allocation of
heap, stack, data, or bss heap
data structures
and arrays
segmentation fault, core
buffer overflow dump, unpredicatable checked run-time error exception
program
declaring final
const and #define
constants
data members initialized to 0, null, or false,
variable auto-
not guaranteed compile time error to access uninitialized
initialization
variables
data hiding opaque pointers and static private

interface method non-static function public method

data type for void * Object


generic item
casting anything goes checked exception at run-time or compile-time
automatic, but might lose must explicitly cast, e.g., to convert from long
demotions
precision to int

polymorphism union inheritence

overloading no yes for methods, no for operators


Java library support, use our Turtle graphics
graphics use external libraries
library
null NULL null

enumeration enum typesafe enum coming to Java 1.5


preprocessor yes no
variable
at beginning of a block before you use it
declaration
variable naming sum_of_squares sumOfSquares
conventions
commenting /* */ /* */ or //

file naming
stack.c, stack.h Stack.java - file name matches name of class
conventions

_____________________________________________________________________________________
Teaches All major subjects for Engineering (BE) / MCA / BCA / Diploma / AMIE / DOEACC Students.
Project Guide for BE / MCA / BCA / Diploma Students
Address:- 80, Ramlal Dutta Road, P.O- Bhadrakali, Dist:- Hooghly, 712232. Rly Station:- Uttarpara
(Nera Amarendra Vidyapith Boys School)
CHANDAN MUKHERJEE 26630615 9831125100
__________________MTech (IT), BE (Computer Science), Diploma (Electrical Engg) _________________

callbacks pointers to global functions use interfaces for commmand dispatching


HU UH

variable number
varargs varargs ( datatype varname)
of arguments
assertions assert HU assert UH

exit and return exit(1) System.exit(1)


value to OS

_____________________________________________________________________________________
Teaches All major subjects for Engineering (BE) / MCA / BCA / Diploma / AMIE / DOEACC Students.
Project Guide for BE / MCA / BCA / Diploma Students
Address:- 80, Ramlal Dutta Road, P.O- Bhadrakali, Dist:- Hooghly, 712232. Rly Station:- Uttarpara
(Nera Amarendra Vidyapith Boys School)

S-ar putea să vă placă și