

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


CMPSCI 377 Operating Systems Spring 2007
Lecturer: Emery Berger Scribes: Alex Schultz, Alden Wheeler
C is low level and allows direct access to the computer, which gives the programmer a greater degree of control over the system. In Java, the programmer is insulated form the computer hardware and operating system by the Java runtime environment.
C is a better choice for systems programming:
Fast and space ecient.
Low-Level. Very close to the machine architecture.
Direct access to memory.
What you see is what you get.
In C, what you code is what the computer does.
In Java, each action you take is backed up by many calls done by the runtime environment, whether or not you absolutely need them all.
Example: Garbage Collection
In C, there are no "read" or "write" barriers - that is, garbage collection is not done by the C language.
In Java, every time an object reference is changed, the garbage collector must be alerted to check for references to the old object to see if that object's space can be reused. This tacks on a performance hit so that one does not have to manage their own variable pointers and references.
All the Java code that actually "talks" to the hardware of your computer is written in C.
3-2 Lecture 3: September 13
C++ extends C in a couple of ways.
Upward compatibility: C code can be compiled with a C++ compiler.
Classes like the ones used in Java for better structuring of data and algorithms.
Encapsulation allows public/private members of classes.
Templates, which are analogous to Java generics.
Inlining instead of macros for increased eciency by inserting function code directly where it is called (Macros also allowed you to do evil substitutions, like switching while loops to if statements)
For the most part, conditionals are the same between Java and C++. However, in C++, any non-zero value will evaluate to true.
In Java, the main function is passed an array of strings that have the command line arguments. In C/C++, the values passed in are a pointer to an array of characters that hold the command line arguments as well as an integer with the size of the array.
In Java, you are not allowed to directly look at memory addresses, whereas in C++ you can. A pointer is a variable that holds the memory address of another variable and is declared using. A reference is declared using a & and allows you to get the address of a variable so that a pointer may point to it - this is called dereferencing a variable.
In C, all variables are copied when they are passed, which means that any changes made in the function the variable is passed to will not echo back to the originally passed variable. In order to return your results, you should pass in the value to be worked on by reference, and return the value by reference, which will save it from being destroyed after the function dies.
Variables either live on the stack, which is intended for temporary variables in a function, or on the heap, which is used for persistant objects throughout a program. In C/C++, the heap is explicitly managed by