Solved

need simple explanition for a simple code

Posted on 2002-04-28
2
278 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

626 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