Solved

need simple explanition for a simple code

Posted on 2002-04-28
2
271 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
V.simple question about Android packages and libraries 1 46
Html Table Looping (part 2) 5 41
jsp error 6 72
Github api to fetch the number of collaborators in a git repo 1 70
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This video teaches viewers about errors in exception handling.
Suggested Courses

739 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