I am writing a java program that solves for program complexity using Halstead metrics. I just want to know what java keywords are considered "Operators" and "Operands" in halstead metrics. Any help from you guys will be appreciated...

Recommended Answers

All 5 Replies

Member Avatar for coil

Java operators are +, -, *, /, and possibly %. Operands are the variables on either side of the operator.

Java operators are actually a bit more involved of a list. Look in the Language Spec (search google for Java Language Specification, and bookmark it, you'll be referring to it a lot, especially if I answer your questions)

To help you out, here's the relevant section:
3.12 Operators
The following 37 tokens are the operators, formed from ASCII characters:

Operator: one of
= > < ! ~ ? :
== <= >= != && || ++ --
+ - * / & | ^ % << >> >>>
+= -= *= /= &= |= ^= %= <<= >>= >>>=


There's your operators. You might say instanceof is an operator as well, it acts more like one of these than anything else.

Then there are the keywords. Again, I'll be nice:

3.9 Keywords
The following character sequences, formed from ASCII letters, are reserved for use as keywords and cannot be used as identifiers (§3.8):

Keyword: one of
abstract continue for new switch
assert default if package synchronized
boolean do goto private this
break double implements protected throw
byte else import public throws
case enum instanceof return transient
catch extends int short try
char final interface static void
class finally long strictfp volatile
const float native super while


The keywords const and goto are reserved, even though they are not currently used. This may allow a Java compiler to produce better error messages if these C++ keywords incorrectly appear in programs.

While true and false might appear to be keywords, they are technically Boolean literals (§3.10.3). Similarly, while null might appear to be a keyword, it is technically the null literal (§3.10.7).

I don't know how keywords fit into your Halstead metrics as operators, that's up to you to determine, since I don't know anything about Halstead or his metrics, but those are your keywords and your operators. Have fun.

commented: good post, useful also for others +2

hello, could you please post your program or a link to your program?i am interested in it. i am a compsci student and i want to have some references how to program it.thanks in advance

dansm88 Please don't just ask people to give you code. If yuo have a Java question, or there's some aspect of Java you want to learn about, please start your own thread and explain what you have done already.

alright jamescherill..i am currently working on it.thanks for reminding me that..apart from halstead, im working on mccabe complexity analysis at the moment and just wanted to look for sample codes or references of halstead.cause i need to finish 50% of it by december..anyways, thanks..ill be updating

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.