ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Well, I don't know if it's possible... It's from memories about C/C++.
Is it possible to define global variable, like DEBUG, DISPLAY, which could tune displayed information... Typically, while debugging, I want to see every thing but later on, no time for that.
I don't know how to do that, except of course, by adding an extra variable to all my methods but it would be neither tractable nor handy.
As far as I know, java does not work with Global Variables. You could defined a static variable at your highest class and all other class would inheritance that variable, but that is it
Java still has no concept of true global variables, but as far as I'm concerned it shouldn't anyway cuz it's pure OO by design (as a rule), and thus every variable should have a scope. You might serve better to do something like setting what System.out is with System.setOut(java.io.PrintWriter) at convenient times... like:
One way you can achieve is that, create a new class and define a static variables inside.
For example,
public class LogLevel {
public static final int DISPLAY = 0;
public static final int DEBUG = 1;
public static final int RELEASE = 2;
}
and you can refer to these variables from anywhere in your program like,
LogLevel.DEBUG
LogLevel.RELEASE
so it's the same as the global variables in C++ except that you need to add the class name in front.
But the more efficient way is that, you can use the logging facilities. Jdk1.4 and onwards have the build-in logging features with different levels.
And there is more powerful, and feature-rich 3rd party tool available for logging from http://www.apache.org , which is called log4j under the jakarta project which is very popular and a lot of ppl using it.
Last edited by moeminhtun; 04-16-2004 at 02:59 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.