Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 7th, 2005, 07:04 AM
Registered User
 
Join Date: Dec 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default question in core java

how to create a file for constant variables in java and how to use those constants in other files


 
Old December 21st, 2005, 07:31 AM
Registered User
 
Join Date: Dec 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Usually this is done by creating an interface providing the constant values, which then can be implemented by any class that wants to use the fields.

Example:

Code:
public interface MyConstants{
 public final String CONST = "CONST";
}

public class UsingTheConstants implements MyConstants{
...
}
 
Old December 23rd, 2005, 11:08 AM
Authorized User
 
Join Date: Dec 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You don't have to implement that interface.

all attributes declared within an interface are
implicitely public static and final. So, you can
directly use them as MyConstants.CONST and so on.

________
Adarsh

 
Old September 7th, 2007, 10:07 AM
ski ski is offline
Registered User
 
Join Date: Sep 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
If you define variables in an interface, then those will be
constants by default, and these values cann't be changed.

For more questions and answers, I found a good link

http://www.freewebs.com/java-j2ee-questions-answers/

Thanks.






Similar Threads
Thread Thread Starter Forum Replies Last Post
simple C Core question melvik C# 4 January 28th, 2008 12:50 PM
Regex question in Java rangalo Java Basics 2 October 26th, 2006 09:26 AM
Java question hlchuah77 JSP Basics 2 October 5th, 2004 08:40 AM
A Java question hlchuah77 JSP Basics 0 September 27th, 2004 02:47 PM
Flash remoting with core Java and Tomcat. How?? miasjors Flash (all versions) 0 July 14th, 2003 10:38 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.