Problem programming with assertion

L

lonelyplanet999

Hi,

I'm studying the 310-035 exam and encounter below problem when I write
code for assertion then compile the program (I used java 1.4.1).

class Assert0 {
public static void main (String [] args) {
assert false;
}
}

assert0.java:6: warning: as of release 1.4, assert is a keyword, and
may not be used as an identifier
assert false;
^
assert0.java:6: not a statement
assert false;
^
assert0.java:6: ';' expected
assert false;
^
2 errors
1 warning

As my training book "Sun Certified Programmer & Developer for Java 2
by Kathy Sierra & Bert Bates" teached me similar assertion syntax but
it's full of typing mistakes, I browsed sun's homepage to double
verified if I made any syntax error during coding.

I found the page http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html
also has similar assert false; assert <expression>; statements.

Could any commented what's wrong with my code ?

Tks!
 
P

Phil...

me study too
you have to compile with "-source 1.4" flag
you have to run with "-ea" flag
like this

javac -source 1.4 Assert.java

java -ea Assert

HTH
 
L

lonelyplanet999

Phil... said:
me study too
you have to compile with "-source 1.4" flag
you have to run with "-ea" flag
like this

javac -source 1.4 Assert.java

java -ea Assert
Tks!

HTH
lonelyplanet999 said:
Hi,

I'm studying the 310-035 exam and encounter below problem when I write
code for assertion then compile the program (I used java 1.4.1).

class Assert0 {
public static void main (String [] args) {
assert false;
}
}

assert0.java:6: warning: as of release 1.4, assert is a keyword, and
may not be used as an identifier
assert false;
^
assert0.java:6: not a statement
assert false;
^
assert0.java:6: ';' expected
assert false;
^
2 errors
1 warning

As my training book "Sun Certified Programmer & Developer for Java 2
by Kathy Sierra & Bert Bates" teached me similar assertion syntax but
it's full of typing mistakes, I browsed sun's homepage to double
verified if I made any syntax error during coding.

I found the page http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html
also has similar assert false; assert <expression>; statements.

Could any commented what's wrong with my code ?

Tks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top