This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Well, I'd say double and int are primitive types that can be assigned a literal value, but I wouldn't say double and int are literals.
String s = "Cameron";
That would be assigning a literal value to the String s, because "Cameron" is hardcoded.
double d = 10.0; int eresting = 50;
Both of those lines of code assign literal values to the variables d and eresting. You see, 10 and 50 are hardcoded into the program.
double trouble = d * eresting;
Well, trouble wouldn't really be assigned a literal value, because the value trouble takes on can vary depending upon how d and eresting are initialized.
From the Sun tutorials on what a litera is:
A literal is the source code representation of a fixed value; literals are represented directly in your code without requiring computation. As shown below, it's possible to assign a literal to a variable of a primitive type:
boolean result = true; char capitalC = 'C'; byte b = 100; short s = 10000; int i = 100000;
One of the things that I found interesting is that true, false and null are actually considered literal values, and not necessarily keywords in Java. It's just that they're used so frequently, that most people consider them to be true Java keywords, but in fact, they're just literal values.