Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Statements and expressions

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could anybody make more clear the difference between statements and expressions.
What I don't understand is the below JLS " and do not have values ".
From what I see an expression int i=5, means i has the value 5. The expression "int i=5;", or a statement can "have values"?
JLS said in chapter 14 Blocks and Statements:
The sequence of execution of a program is controlled by statements, which are executed for their effect and do not have values.
Some statements contain other statements as part of their structure;
The break (�14.14), continue (�14.15), and return (�14.16) statements cause a transfer of control that may prevent normal completion of statements that contain them.
Best regards
 
Ranch Hand
Posts: 5390
1
Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think everyline of code you write is statement,
statement could be an expression also, expression is any statement which involves any operation(airthmetic/biwise/etc).
CMIW
------------------
Regards
Ravish
 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Salamina,
The java tutorial includes a useful discussion.
Here's a summary extract
~~~~~~~~~~~`
Variables and operators, which you met in the previous two sections, are basic building blocks of programs. You combine literals, variables, and operators to form expressions- segments of code that perform computations and return values. Certain expressions can be made into statements-complete units of execution. By grouping statements together with curly braces { and }, you create blocks of code.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There's more detail at http://java.sun.com/docs/books/tutorial/java/nutsandbolts/expressions.html
cheerio
rowan
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pardon me, but.. what is literals? is ["haha"] a literal? how about ['a']? how about the value [5] ? are all those literals? (man.. my english )
anyway, what i think.
x==5 <-- expression
if(x==5) <-- statement
am i correct?
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chin: You are right on literals.
"haha" is a String literal.
'a' is character literal.
5 is a valid integer literal.
5f is a float literal.
5d is a double literal.
------------------
Cheers,
Manoj
(http://www7.brinkster.com/manoj9/)
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Salamina,
Statements are similar to sentences in English; they give the language a structure. In English a sentence is built of nouns, verbs, adjectives, adverbs, clauses, sub-clauses, etc and sentences, in turn, can be grouped in paragraphs.
In Java statements can include expressions and can be grouped together to form code blocks. They also can take different forms.
For example, <code>int a;</code> is a declaration statement while <code>a=5;</code> is an initialization statment. It is also an expression; it has a value, '5'.
And <code>int a = 5;</code> is both a declaration and initializtion statement. The statement itself has no value but the expression (a = 5) does.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
Co-author Mike Meyers' Java 2 Certification Passport
[This message has been edited by Jane Griscti (edited November 20, 2001).]
 
Salamina Daniel
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot to all of you !

Best regards
    Bookmark Topic Watch Topic
  • New Topic