Yes, Java has pointers - they are called
references - however, Java references are much more constrained than C’s general pointers
- Pointers in C can point to any memory address
- References in Java can only point to an object
- And only to its first element - not to the middle of it
Strings are bounded by hidden length field at beginning of string.
So, it can triggers a bounds-check.
all variables are references to objects.
- In C, we can cast any pointer into any other pointer.
- In Java, we can only cast compatible object references.
JVM Operand Stack Example:
iload 1 // push 1st argument from table onto stack
istands for integer
astands for reference
bstands for byte
cstands for char
dstands for double
We have no knowledge of registers or memory locations (each instruction is 1 byte - bytecode)
We leave many information (address) to the C program that interprets bytecode.
Class File Format
- Magic number
- Version of class file format
- Constant pool
- Access flags
- This class
- Super class
Other languages for JVMs
JVMs run on so many computes that compilers have been built to translate many other languages to Java bytecode:
(just using Java bytecode)
- And many others, even including C
Microsoft’s C# and .NET Framework
- C# has similar motivations as Java
- Virtual machine is called the
Common Language Runtime; Common Intermediate Language is the bytecode for C# and other languages in the .NET framework (VB.NET, J#).