Solved

need simple explanition for a simple code

Posted on 2002-04-28
2
235 Views
Last Modified: 2010-03-31
i have this function to produce different colors ,
why i need the word final here , what is its function ?
does the function work with out it ?

public static final String[] COLORS={
       "#EEE8AA","#FFEFD5","#FFDAB9","#FFFFFF"
  };
0
Comment
Question by:star4
2 Comments
 
LVL 4

Accepted Solution

by:
pellep earned 50 total points
ID: 6975378
That is not a function, that's a constant (static final). The different string values in the array represent different colors according to the RGB color scheme.
R=Red
G=Green
B=Blue

Thus, #EEE8AA means EE parts red, E8 parts green and AA parts blue. The values are hexadecimal ie ranging from
00 = 0
to
FF = 255
Pure red in this format would look like #FF0000, green would look like #00FF00, blue #0000FF. The color white is an equal mix of the entire spectrum and thus looks like #FFFFFF.

as for the keyword 'final'. That simply tells the compiler that this value cannot be changed in code later
ie

class Test {
private final String finalString = "FINAL STRING";
public void setFinalString(String newVal) {
this.finalString = newVal;
//Compiler will generate an error
//because you are trying to change a 'final' variable
}
}
0
 
LVL 2

Expert Comment

by:vasan_sr
ID: 6976527
when u declare as final we cannot change the value. So we will use final.(final i =10; we cannot change the value. Always i remains 10)

regards
VasanS
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now