DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2006
    Posts
    5

    Where to declare global constants?

    Hi;

    If I have a project with a few java files and I want to declare a constant variable that all classes will have access to it, where do I write:
    Code:
    public static final int ROWS = 8;
    thanks

  2. #2
    Join Date
    Dec 2004
    Posts
    61
    You put your code in any of public classes.
    Code:
    // example
    
    public class Test {
        // a public static field
        public static final int ROWS = 8;
        public Test() {}
    }
    
    public class AppStart {
        public static void main() {
            System.out.println (Test.ROWS);
        }
    }

  3. #3
    Join Date
    Jan 2006
    Location
    Sydney
    Posts
    49
    Define a Constants interface and put all your constants which are shared by other classes. If that constant is specific to the class you are writing then store it in that class/interface itself.
    Arul

Similar Threads

  1. call function for button
    By angela_quests in forum VB Classic
    Replies: 2
    Last Post: 04-13-2007, 04:57 AM
  2. Getting remote registry entries
    By Pedro Avila in forum VB Classic
    Replies: 4
    Last Post: 04-02-2001, 11:31 AM
  3. How do I detect an FTP timeout?
    By Julian Milano in forum VB Classic
    Replies: 2
    Last Post: 08-11-2000, 12:11 PM
  4. How do I detect an FTP timeout?
    By Julian Milano in forum VB Classic
    Replies: 0
    Last Post: 08-10-2000, 09:16 PM
  5. Replies: 2
    Last Post: 04-13-2000, 01:53 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links