The Artima Developer Community
Sponsored Link

Java Buzz Forum
Constants in Java, is it right to use them?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Ben Hosking

Posts: 208
Nickname: hoskinator
Registered: Apr, 2006

Ben Hosking is Java Developer with about 5 years experience and interest in OO
Constants in Java, is it right to use them? Posted: May 8, 2006 8:51 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Ben Hosking.
Original Post: Constants in Java, is it right to use them?
Feed Title: A Funny Java Flavoured Look at the World
Feed URL: http://businesslogs.com/WebLog/RSS.xml
Feed Description: The blog looks at using Java and programming in general as it pops up in life as a Java programmer. It will have links to interesting Java articles and resources. It will also have a lot of SCJP Java 1.5 information and links as I am currently studying
Latest Java Buzz Posts
Latest Java Buzz Posts by Ben Hosking
Latest Posts From A Funny Java Flavoured Look at the World

Advertisement

I have recently been thinking about constants and in particular static final constants. I know it is frowned upon in the OO world but sometimes I need to put a two strings in a few places

which I have called

/** a constant value for a blank String. */
public static final String BLANK = "";
/** a constant value for a blank space String. */
public static final String BLANKSPACE = " ";

These strings are often put inbetween values in error messages, initializing some string variables etc. As I found I kept needing them in a number of classes I thought I might as well put them in a constants class and just call them from there. So I have two questions really.

1. What are the alternatives to doing this? Does Java have these constants I was looking at String and Character but I couldn't find anything.

2. Is it wrong for my classes to have a dependency on this constants class just for the a blank space and a blank.

What do other people do? Basically I just got fed up of making BLANK constants after checkstyle kept moaning at me

http://hoskinator.blogspot.com/

Read: Constants in Java, is it right to use them?

Topic: MIDP 2.1 Review Previous Topic   Next Topic Topic: [Apr 27, 2006 11:16 PDT] 8 Links

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use