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
Solved

need simple explanition for a simple code

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

839 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