473,472 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to compile java with assert statement

how to compile java with assert statement
I failed to compile this simple example
public class Foo
{
public void m1( int value )
{
assert 0 <= value;
System.out.println( "OK" );
}

public static void main( String[] args )
{
Foo foo = new Foo();
System.out.print( "foo.m1( 1 ): " );
foo.m1( 1 );
System.out.print( "foo.m1( -1 ): " );
foo.m1( -1 );
}
}

# javac Foo.java
Foo.java:5: warning: as of release 1.4, assert is a keyword, and may not be
used as an identifier
assert 0 <= value;
^
Foo.java:5: not a statement
assert 0 <= value;
^
Foo.java:5: ';' expected
assert 0 <= value;

would you please tell me why? thank you
~ ªÑ²¼»ù®æ¦³¤É¦³¶^, ¶R½æ*n¯à©Ó¾á*·ÀI ~

~ Samba, more than a low cost File and Printer server ~

-- Let us OpenSource --
Jul 18 '05 #1
3 12187
SOAP wrote:
how to compile java with assert statement


Read the documentation that came with the JVM, specifically on the javac
tool.

HTH,
Ray

--
XML is the programmer's duct tape.
Jul 18 '05 #2
Most of current IDE tools have the option: "allow assert keyword"

By default it is usually off, and you can turn it on.

If you use javac, you can use the switch in the command line that enables
assertions.

javac -enableassertions YourFile.java
or
javac -ea YourFile.java

--
Jeff Zhuk

720-299-4701
http://JavaSchool.com
jz***@email.uophx.edu
alternative: jz***@javaschool.com
ITS, Inc., Chief Architect/Principal Instructor

"SOAP" <s@soap.com> wrote in message news:42******@usenet.hk...
how to compile java with assert statement
I failed to compile this simple example
public class Foo
{
public void m1( int value )
{
assert 0 <= value;
System.out.println( "OK" );
}

public static void main( String[] args )
{
Foo foo = new Foo();
System.out.print( "foo.m1( 1 ): " );
foo.m1( 1 );
System.out.print( "foo.m1( -1 ): " );
foo.m1( -1 );
}
}

# javac Foo.java
Foo.java:5: warning: as of release 1.4, assert is a keyword, and may not
be
used as an identifier
assert 0 <= value;
^
Foo.java:5: not a statement
assert 0 <= value;
^
Foo.java:5: ';' expected
assert 0 <= value;

would you please tell me why? thank you
~ ªÑ²¼»ù®æ¦³¤É¦³¶^, ¶R½æ*n¯à©Ó¾á*·ÀI ~

~ Samba, more than a low cost File and Printer server ~

-- Let us OpenSource --

Jul 18 '05 #3
You also need to enable runtime assertions with the switch

java -ea:your.package YourClass

Find more at
http://java.sun.com/j2se/1.4.2/docs/...html#compiling

--
Jeff Zhuk

720-299-4701
http://JavaSchool.com
jz***@email.uophx.edu
alternative: jz***@javaschool.com
ITS, Inc., Chief Architect/Principal Instructor

"SOAP" <s@soap.com> wrote in message news:42******@usenet.hk...
how to compile java with assert statement
I failed to compile this simple example
public class Foo
{
public void m1( int value )
{
assert 0 <= value;
System.out.println( "OK" );
}

public static void main( String[] args )
{
Foo foo = new Foo();
System.out.print( "foo.m1( 1 ): " );
foo.m1( 1 );
System.out.print( "foo.m1( -1 ): " );
foo.m1( -1 );
}
}

# javac Foo.java
Foo.java:5: warning: as of release 1.4, assert is a keyword, and may not
be
used as an identifier
assert 0 <= value;
^
Foo.java:5: not a statement
assert 0 <= value;
^
Foo.java:5: ';' expected
assert 0 <= value;

would you please tell me why? thank you
~ ªÑ²¼»ù®æ¦³¤É¦³¶^, ¶R½æ*n¯à©Ó¾á*·ÀI ~

~ Samba, more than a low cost File and Printer server ~

-- Let us OpenSource --

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: John Doe | last post by:
Hello, I'm currently working on a little tool that would benefit from having a little embedded script language. Although I have C++ source code available for such a script language, I have 2...
28
by: Fábio Mendes | last post by:
I'm sorry if it's an replicate. Either my e-mail program is messing with things or the python-list sent my msg to /dev/null. I couldn't find anything related in previous PEP's, so here it goes a...
1
by: Zean Smith | last post by:
I am working on a project to migrate a JavaBean + JSP application (running on Oracle application server) to Microsoft ASP.NET + SQL server. In order to see how the original code works, I need to...
0
by: Nick | last post by:
Hi, I'm facing certain issues while trying to compile a java class using the Visual J# compiler into a dot net readable DLL. However, I'm getting stuck at a point where there is a reference to a...
1
by: marco_segurini | last post by:
Hi, Is there any way in C# to perform a compile-time-assert (like BOOST_STATIC_ASSERT in C++)? Thanks a lot. Marco.
1
by: kaushikm | last post by:
How to access sql server inbuilt functions from java prepared statement ? I have used getdate() of sql in a java prepared statement and am connecting to sqlserver. But it's not working. What to do ?
11
by: Francois Grieu | last post by:
Hi, I'm using an assert()-like macro to test a constant expression at compile time #define ASSERT(condition) struct{char assert_failure;} The idea is that this macro cause a compilation...
4
by: robtyketto | last post by:
Greetings, I've got my head spinning with some very simple java coding, Im a newbie to Java and utilising the code below for a javabean for some jsp Im working on. The problem is my code I've...
2
by: bob2044 | last post by:
Ive just started using java . Ive a problem to compile java using cmd.need a help!
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.