Does Java have global variables?

Will Java ever support reference variables?

  • I know arrays and objects are pass-by-reference. but i'm really referring to primitive data types. I've noticed that when it comes to data structure and memory management, the vast majority switches out to C++. Will Java ever support pointers, you think? I'd also like to know exactly how an object it removed off stack after it has nothing pointing to it since Java is a garbage-collection language.

  • Answer:

    You have the primitive wrapper classes like Integer you can use on the rare occasions you need to treat a primitive as an object. It was an efficiency sacrifice the designers made. Pointers? No, and there's not much point. Pointers lead to some hairy memory management issues. Java objects are craeted on the heap, not the stack. Every time a new reference to an object is created, its reference count is incremented. When the reference's fall out of scope, the count is decremented. When the count hits zero, the object is made available for garbage collection. So: Object obj=new Object(); Object obja=obj; Object objb=obj; sets the reference count for the underlying object to 3.

Fadi at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

Never. Java prides itself on ignoring references altogether by making them part of the code. The downside to that is that primitives will always be pass-by-value.

Darnental

NO. Java is a porly designed language. and actually i dont even consider it a "language". i consider it a scripting language. It requires a RUNTIME! javascript and vbscript require runtimes too. whats the difference :P

Andrew Krieg

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.