Programming This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
04-15-2004, 06:06 AM
|
#1
|
|
Member
Registered: Apr 2004
Location: Edinburgh
Posts: 78
Rep:
|
Java : Meta variables ?
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.
Thanks. Cheers,
Pierre-Yves
|
|
|
|
04-15-2004, 09:54 AM
|
#2
|
|
Guru
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339
Rep:
|
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 
|
|
|
|
04-15-2004, 09:57 AM
|
#3
|
|
Member
Registered: Apr 2004
Location: Edinburgh
Posts: 78
Original Poster
Rep:
|
Thanks Megaman... My programs won't have the possibility to change their log level...

|
|
|
|
04-15-2004, 09:59 AM
|
#4
|
|
Guru
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339
Rep:
|
Cool, my pleasure. I could be wrong though  That has been a long since I last touched Java. I might start at it again, it was so cool 
|
|
|
|
04-15-2004, 10:08 AM
|
#5
|
|
Member
Registered: Apr 2004
Location: Edinburgh
Posts: 78
Original Poster
Rep:
|
I always trust someone who says 'There's no point to try, get some rest'... ;-)
|
|
|
|
04-15-2004, 08:14 PM
|
#6
|
|
Member
Registered: Jul 2003
Location: Toronto, Canada
Distribution: Debian etch, Gentoo
Posts: 312
Rep:
|
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:
if(System.getProperty("debug") == null) {
System.setOut(new NullPrintWriter());
}
...
class NullPrintWriter extends PrintWriter {
(some code to do nothing when you write to it)
}
This is all from memory but I'm sure it's not that far off... it might be an outputstream instead of a printwriter.
HTH
B.
|
|
|
|
04-15-2004, 10:12 PM
|
#7
|
|
Member
Registered: Dec 2002
Location: Singapore
Distribution: Fedora Core 6
Posts: 647
Rep:
|
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.
|
|
|
|
04-16-2004, 03:46 AM
|
#8
|
|
Member
Registered: Apr 2004
Location: Edinburgh
Posts: 78
Original Poster
Rep:
|
Thanks very much... I'll have a look... ;-)
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 05:44 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.
|
Latest Threads
LQ News
|
|