Where to declare global constants?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Where to declare global constants?

  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, 05:57 AM
  2. Getting remote registry entries
    By Pedro Avila in forum VB Classic
    Replies: 4
    Last Post: 04-02-2001, 12:31 PM
  3. How do I detect an FTP timeout?
    By Julian Milano in forum VB Classic
    Replies: 2
    Last Post: 08-11-2000, 01:11 PM
  4. How do I detect an FTP timeout?
    By Julian Milano in forum VB Classic
    Replies: 0
    Last Post: 08-10-2000, 10:16 PM
  5. Replies: 2
    Last Post: 04-13-2000, 02:53 PM

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


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center