0

I'm wondering how a programming language like Java can handle Variables and/or Pointers in an isolated environment like Java Virtual Machine and its own Byte-Code.

Examples in Assembly or binary equivalents are highly appreciated.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130

1 Answers1

0

I suggest you read a little of how Java actually works.

Java doesn't have pointers, it has references which you cannot examine in pure Java. An important distinction about references in Java is that they

  • can change at any time without notice
  • don't have to be a direct address in memory. It can be encoded. e.g. to allow 32-bit references to access up to 32 GB of memory.

It has variables like any other language but you can't get a reference to them.

The byte code is a literal translation of the Java code and read it is unlikely to be more useful than reading the Java code unles syou have a deep understanding of Java. Note: the JVM compiles this to native code, so it is not the code actually run much of the time.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • Well, I meant java as an example. I'm more interested in the general idea. Thanks by the way, and sorry I can't vote up yet! –  Jan 09 '13 at 10:12
  • I still suggest you look at Java as it is popular and lower level/simpler than most VM languages and follows the model more strictly than say C#. – Peter Lawrey Jan 09 '13 at 10:14
  • I will do, thanks for explanation! :) –  Jan 09 '13 at 10:38
  • If you are from a C++ background you take for granted that you will use pointers, destructors, macro processing, compiling to native machine code, unsigned types and other functionality Java just doesn't have. Java solves these problems a different way in each case (or just says you don't really need it) – Peter Lawrey Jan 09 '13 at 10:44
  • I'd seriously look into that, thanks again for mentioning that! Still a little bit confused about Pointers which are not exists in Java! –  Jan 09 '13 at 11:09
  • The key thing to remember is when you see `String` or `SomeObject` that is a *reference* to an object and it is *always* passed by value. Primitives are always passed by value also. Java keeps it's features to a minimum to reduce side effects and improve code maintainability. Never the less there is still plenty of ways to shoot yoursefl in the foot and write confusing code. Some you can't even do in C :D – Peter Lawrey Jan 09 '13 at 11:35